create-app: switch to storing release version in backstage.json

Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
This commit is contained in:
Patrik Oldsberg
2022-03-04 11:22:52 +01:00
parent 968ee8d4fc
commit 1201383b60
8 changed files with 21 additions and 18 deletions
+5
View File
@@ -0,0 +1,5 @@
---
'@backstage/create-app': patch
---
Updated the template to write the Backstage release version to `backstage.json`, rather than the version of `@backstage/create-app`. This change is applied automatically when running `backstage-cli versions:bump` in the latest version of the Backstage CLI.
+3 -3
View File
@@ -59,7 +59,7 @@ describe('command entrypoint', () => {
test('should call expected tasks with no path option', async () => {
const cmd = {} as unknown as Command;
await createApp(cmd, '1.0.0');
await createApp(cmd);
expect(checkAppExistsMock).toHaveBeenCalled();
expect(createTemporaryAppFolderMock).toHaveBeenCalled();
expect(templatingMock).toHaveBeenCalled();
@@ -69,7 +69,7 @@ describe('command entrypoint', () => {
it('should call expected tasks with path option', async () => {
const cmd = { path: 'myDirectory' } as unknown as Command;
await createApp(cmd, '1.0.0');
await createApp(cmd);
expect(checkPathExistsMock).toHaveBeenCalled();
expect(templatingMock).toHaveBeenCalled();
expect(buildAppMock).toHaveBeenCalled();
@@ -77,7 +77,7 @@ describe('command entrypoint', () => {
it('should not call `buildAppTask` when `skipInstall` is supplied', async () => {
const cmd = { skipInstall: true } as unknown as Command;
await createApp(cmd, '1.0.0');
await createApp(cmd);
expect(buildAppMock).not.toHaveBeenCalled();
});
});
+3 -3
View File
@@ -30,7 +30,7 @@ import {
templatingTask,
} from './lib/tasks';
export default async (cmd: Command, version: string): Promise<void> => {
export default async (cmd: Command): Promise<void> => {
/* eslint-disable-next-line no-restricted-syntax */
const paths = findPaths(__dirname);
@@ -80,7 +80,7 @@ export default async (cmd: Command, version: string): Promise<void> => {
await checkPathExistsTask(appDir);
Task.section('Preparing files');
await templatingTask(templateDir, cmd.path, answers, version);
await templatingTask(templateDir, cmd.path, answers);
} else {
// Template to temporary location, and then move files
@@ -91,7 +91,7 @@ export default async (cmd: Command, version: string): Promise<void> => {
await createTemporaryAppFolderTask(tempDir);
Task.section('Preparing files');
await templatingTask(templateDir, tempDir, answers, version);
await templatingTask(templateDir, tempDir, answers);
Task.section('Moving to final location');
await moveAppTask(tempDir, appDir, answers.name);
+1 -1
View File
@@ -38,7 +38,7 @@ const main = (argv: string[]) => {
'--skip-install',
'Skip the install and builds steps after creating the app',
)
.action(cmd => createApp(cmd, version));
.action(cmd => createApp(cmd));
program.parse(argv);
};
+3 -2
View File
@@ -18,6 +18,7 @@ import fs from 'fs-extra';
import mockFs from 'mock-fs';
import child_process from 'child_process';
import path from 'path';
import { version as releaseVersion } from '../../../../package.json';
import {
buildAppTask,
checkAppExistsTask,
@@ -195,11 +196,11 @@ describe('templatingTask', () => {
name: 'SuperCoolBackstageInstance',
dbTypeSqlite: true,
};
await templatingTask(templateDir, destinationDir, context, '1.0.0');
await templatingTask(templateDir, destinationDir, context);
expect(fs.existsSync('templatedApp/package.json')).toBe(true);
expect(fs.existsSync('templatedApp/.dockerignore')).toBe(true);
await expect(fs.readJson('templatedApp/backstage.json')).resolves.toEqual({
version: '1.0.0',
version: releaseVersion,
});
// catalog was populated with `context.name`
expect(
-9
View File
@@ -14,7 +14,6 @@
* limitations under the License.
*/
import { BACKSTAGE_JSON } from '@backstage/cli-common';
import chalk from 'chalk';
import fs from 'fs-extra';
import handlebars from 'handlebars';
@@ -23,7 +22,6 @@ import recursive from 'recursive-readdir';
import {
basename,
dirname,
join,
resolve as resolvePath,
relative as relativePath,
} from 'path';
@@ -86,7 +84,6 @@ export async function templatingTask(
templateDir: string,
destinationDir: string,
context: any,
version: string,
) {
const files = await recursive(templateDir).catch(error => {
throw new Error(`Failed to read template directory: ${error.message}`);
@@ -136,12 +133,6 @@ export async function templatingTask(
});
}
}
await Task.forItem('creating', BACKSTAGE_JSON, () =>
fs.writeFile(
join(destinationDir, BACKSTAGE_JSON),
`{\n "version": ${JSON.stringify(version)}\n}\n`,
),
);
}
/**
+3
View File
@@ -30,6 +30,8 @@ Rollup will extract the value of the version field in each package at build time
leaving any imports in place.
*/
import { version as root } from '../../../../package.json';
import { version as appDefaults } from '../../../app-defaults/package.json';
import { version as backendCommon } from '../../../backend-common/package.json';
import { version as backendTasks } from '../../../backend-tasks/package.json';
@@ -75,6 +77,7 @@ import { version as pluginTechdocsBackend } from '../../../../plugins/techdocs-b
import { version as pluginUserSettings } from '../../../../plugins/user-settings/package.json';
export const packageVersions = {
root,
'@backstage/app-defaults': appDefaults,
'@backstage/backend-common': backendCommon,
'@backstage/backend-tasks': backendTasks,
@@ -0,0 +1,3 @@
{
"version": "{{version 'root'}}"
}