diff --git a/.changeset/olive-roses-sleep.md b/.changeset/olive-roses-sleep.md new file mode 100644 index 0000000000..b402a5b2aa --- /dev/null +++ b/.changeset/olive-roses-sleep.md @@ -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. diff --git a/packages/create-app/src/createApp.test.ts b/packages/create-app/src/createApp.test.ts index ee01e8fd42..09099e2d15 100644 --- a/packages/create-app/src/createApp.test.ts +++ b/packages/create-app/src/createApp.test.ts @@ -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(); }); }); diff --git a/packages/create-app/src/createApp.ts b/packages/create-app/src/createApp.ts index d4d30364dc..36143a4172 100644 --- a/packages/create-app/src/createApp.ts +++ b/packages/create-app/src/createApp.ts @@ -30,7 +30,7 @@ import { templatingTask, } from './lib/tasks'; -export default async (cmd: Command, version: string): Promise => { +export default async (cmd: Command): Promise => { /* eslint-disable-next-line no-restricted-syntax */ const paths = findPaths(__dirname); @@ -80,7 +80,7 @@ export default async (cmd: Command, version: string): Promise => { 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 => { 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); diff --git a/packages/create-app/src/index.ts b/packages/create-app/src/index.ts index 8a2da2fad8..a8ff3dc9b9 100644 --- a/packages/create-app/src/index.ts +++ b/packages/create-app/src/index.ts @@ -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); }; diff --git a/packages/create-app/src/lib/tasks.test.ts b/packages/create-app/src/lib/tasks.test.ts index d7b4692aa4..0c92173dbf 100644 --- a/packages/create-app/src/lib/tasks.test.ts +++ b/packages/create-app/src/lib/tasks.test.ts @@ -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( diff --git a/packages/create-app/src/lib/tasks.ts b/packages/create-app/src/lib/tasks.ts index 4bd7050fc2..1650432969 100644 --- a/packages/create-app/src/lib/tasks.ts +++ b/packages/create-app/src/lib/tasks.ts @@ -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`, - ), - ); } /** diff --git a/packages/create-app/src/lib/versions.ts b/packages/create-app/src/lib/versions.ts index 7179b7924f..3c898f1e02 100644 --- a/packages/create-app/src/lib/versions.ts +++ b/packages/create-app/src/lib/versions.ts @@ -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, diff --git a/packages/create-app/templates/default-app/backstage.json.hbs b/packages/create-app/templates/default-app/backstage.json.hbs new file mode 100644 index 0000000000..2aa00ecaee --- /dev/null +++ b/packages/create-app/templates/default-app/backstage.json.hbs @@ -0,0 +1,3 @@ +{ + "version": "{{version 'root'}}" +}