From 0e46432621cb7cd8e661cadea4617590e9165313 Mon Sep 17 00:00:00 2001 From: Patrik Oldsberg Date: Sun, 4 Sep 2022 16:41:57 +0200 Subject: [PATCH] cli: add baseVersion option to new command Signed-off-by: Patrik Oldsberg --- package.json | 2 +- packages/cli/cli-report.md | 1 + packages/cli/src/commands/index.ts | 4 ++++ packages/cli/src/commands/new/new.ts | 20 +++++++++----------- 4 files changed, 15 insertions(+), 12 deletions(-) diff --git a/package.json b/package.json index 77ee1dccc5..4edd364147 100644 --- a/package.json +++ b/package.json @@ -23,7 +23,7 @@ "lint:all": "backstage-cli repo lint", "lint:type-deps": "node scripts/check-type-dependencies.js", "docker-build": "yarn tsc && yarn workspace example-backend build --build-dependencies && yarn workspace example-backend build-image", - "new": "backstage-cli new --scope backstage --no-private", + "new": "backstage-cli new --scope backstage --baseVersion 0.0.0 --no-private", "create-plugin": "echo \"use 'yarn new' instead\"", "release": "node scripts/prepare-release.js && changeset version && yarn diff --yes && yarn prettier --write '{packages,plugins}/*/{package.json,CHANGELOG.md}' '.changeset/*.json' && yarn install --no-immutable", "prettier:check": "prettier --check .", diff --git a/packages/cli/cli-report.md b/packages/cli/cli-report.md index 1c86c8723c..8b71e8ca17 100644 --- a/packages/cli/cli-report.md +++ b/packages/cli/cli-report.md @@ -179,6 +179,7 @@ Options: --option = --scope --npm-registry + --baseVersion --no-private -h, --help ``` diff --git a/packages/cli/src/commands/index.ts b/packages/cli/src/commands/index.ts index 0af1674b6c..f2257f32a0 100644 --- a/packages/cli/src/commands/index.ts +++ b/packages/cli/src/commands/index.ts @@ -218,6 +218,10 @@ export function registerCommands(program: Command) { '--npm-registry ', 'The package registry to use for new packages', ) + .option( + '--baseVersion ', + 'The version to use for any new packages (default: 0.1.0)', + ) .option('--no-private', 'Do not mark new packages as private') .action(lazy(() => import('./new/new').then(m => m.default))); diff --git a/packages/cli/src/commands/new/new.ts b/packages/cli/src/commands/new/new.ts index a5f8f6763f..8aaa671614 100644 --- a/packages/cli/src/commands/new/new.ts +++ b/packages/cli/src/commands/new/new.ts @@ -51,17 +51,15 @@ export default async (opts: OptionValues) => { ); let defaultVersion = '0.1.0'; - try { - const rootLernaJson = await fs.readJson( - paths.resolveTargetRoot('lerna.json'), - ); - if (rootLernaJson.version) { - defaultVersion = rootLernaJson.version; - } - } catch (error) { - assertError(error); - if (error.code !== 'ENOENT') { - throw error; + if (opts.baseVersion) { + defaultVersion = opts.baseVersion; + } else { + const lernaVersion = await fs + .readJson(paths.resolveTargetRoot('lerna.json')) + .then(pkg => pkg.version) + .catch(() => undefined); + if (lernaVersion) { + defaultVersion = lernaVersion; } }