packages/cli: use current version when templating a plugin

This commit is contained in:
Patrik Oldsberg
2020-03-12 11:23:49 +01:00
parent e28922093f
commit 73517462f7
2 changed files with 11 additions and 6 deletions
+9 -4
View File
@@ -58,11 +58,13 @@ export const createFileFromTemplate = (
source: string,
destination: string,
answers: Answers,
version: string,
) => {
const template = fs.readFileSync(source);
const compiled = handlebars.compile(template.toString());
const contents = compiled({
name: path.basename(destination),
version,
...answers,
});
try {
@@ -102,12 +104,12 @@ const addExportStatement = (file: string, exportStatement: string) => {
export const addPluginDependencyToApp = (
rootDir: string,
pluginName: string,
version: string,
) => {
console.log();
console.log(chalk.green(' Adding plugin as dependency in app:'));
const pluginPackage = `@spotify-backstage/plugin-${pluginName}`;
const pluginPackageVersion = '0.0.0';
const packageFile = path.join(rootDir, 'packages', 'app', 'package.json');
process.stdout.write(
@@ -127,7 +129,7 @@ export const addPluginDependencyToApp = (
);
}
dependencies[pluginPackage] = pluginPackageVersion;
dependencies[pluginPackage] = `^${version}`;
packageFileJson.dependencies = sortObjectByKeys(dependencies);
fs.writeFileSync(
packageFile,
@@ -183,6 +185,7 @@ export const createFromTemplateDir = async (
templateFolder: string,
destinationFolder: string,
answers: Answers,
version: string,
) => {
console.log();
console.log(chalk.green(' Reading template files:'));
@@ -219,6 +222,7 @@ export const createFromTemplateDir = async (
file,
file.replace(templateFolder, destinationFolder).replace(/\.hbs$/, ''),
answers,
version,
);
} else {
try {
@@ -324,6 +328,7 @@ const createPlugin = async () => {
const templateFolder = resolvePath(cliPackage, 'templates', 'default-plugin');
const tempDir = path.join(os.tmpdir(), answers.id);
const pluginDir = path.join(rootDir, 'plugins', answers.id);
const version = require(resolvePath(cliPackage, 'package.json')).version;
console.log();
console.log(chalk.green('Creating the plugin...'));
@@ -331,12 +336,12 @@ const createPlugin = async () => {
try {
checkExists(rootDir, answers.id);
createTemporaryPluginFolder(tempDir);
await createFromTemplateDir(templateFolder, tempDir, answers);
await createFromTemplateDir(templateFolder, tempDir, answers, version);
movePlugin(tempDir, pluginDir, answers.id);
await buildPlugin(pluginDir);
if (existsSync(appPackage)) {
addPluginDependencyToApp(rootDir, answers.id);
addPluginDependencyToApp(rootDir, answers.id, version);
addPluginToApp(rootDir, answers.id);
}
@@ -1,6 +1,6 @@
{
"name": "@spotify-backstage/plugin-{{id}}",
"version": "0.0.0",
"version": "{{version}}",
"main": "dist/cjs/index.js",
"types": "dist/cjs/index.d.ts",
"license": "Apache-2.0",
@@ -11,7 +11,7 @@
"test": "backstage-cli plugin:test"
},
"devDependencies": {
"@spotify-backstage/cli": "^1.2.0"
"@spotify-backstage/cli": "^{{version}}"
},
"dependencies": {
"@material-ui/lab": "4.0.0-alpha.45"