From a0926bf38174f0e7dda47179e88f74139c73baaa Mon Sep 17 00:00:00 2001 From: Patrik Oldsberg Date: Tue, 11 Feb 2025 11:54:43 +0100 Subject: [PATCH] cli/commands/new: add option to skip install Signed-off-by: Patrik Oldsberg --- packages/cli/cli-report.md | 1 + packages/cli/src/commands/index.ts | 4 ++++ packages/cli/src/commands/new/new.ts | 3 +++ packages/cli/src/lib/new/createNewPackage.ts | 2 ++ .../new/execution/executePortableTemplate.ts | 19 +++++++++++-------- 5 files changed, 21 insertions(+), 8 deletions(-) diff --git a/packages/cli/cli-report.md b/packages/cli/cli-report.md index d9fec4db22..41b1ddab73 100644 --- a/packages/cli/cli-report.md +++ b/packages/cli/cli-report.md @@ -179,6 +179,7 @@ Usage: backstage-cli new [options] Options: --select --option = + --skip-install --scope --npm-registry --baseVersion diff --git a/packages/cli/src/commands/index.ts b/packages/cli/src/commands/index.ts index f1119053ec..47c362988c 100644 --- a/packages/cli/src/commands/index.ts +++ b/packages/cli/src/commands/index.ts @@ -257,6 +257,10 @@ export function registerCommands(program: Command) { (opt, arr: string[]) => [...arr, opt], [], ) + .option( + '--skip-install', + `Skips running 'yarn install' and 'yarn lint --fix'`, + ) .option('--scope ', 'The scope to use for new packages') .option( '--npm-registry ', diff --git a/packages/cli/src/commands/new/new.ts b/packages/cli/src/commands/new/new.ts index df495323f5..5c06555905 100644 --- a/packages/cli/src/commands/new/new.ts +++ b/packages/cli/src/commands/new/new.ts @@ -19,6 +19,7 @@ import { createNewPackage } from '../../lib/new/createNewPackage'; type ArgOptions = { option: string[]; select?: string; + skipInstall: boolean; private?: boolean; npmRegistry?: string; scope?: string; @@ -30,6 +31,7 @@ export default async (opts: ArgOptions) => { const { option: rawArgOptions, select: preselectedTemplateId, + skipInstall, scope, private: isPrivate, ...otherGlobals @@ -67,6 +69,7 @@ export default async (opts: ArgOptions) => { packageNamePrefix: packagePrefix, packageNamePluginInfix: pluginInfix, }, + skipInstall, }); }; diff --git a/packages/cli/src/lib/new/createNewPackage.ts b/packages/cli/src/lib/new/createNewPackage.ts index 0b832c1d2b..0e3d7e554e 100644 --- a/packages/cli/src/lib/new/createNewPackage.ts +++ b/packages/cli/src/lib/new/createNewPackage.ts @@ -27,6 +27,7 @@ export type CreateNewPackageOptions = { preselectedTemplateId?: string; configOverrides: Partial; prefilledParams: PortableTemplateParams; + skipInstall?: boolean; }; export async function createNewPackage(options: CreateNewPackageOptions) { @@ -50,5 +51,6 @@ export async function createNewPackage(options: CreateNewPackageOptions) { config, template, input, + skipInstall: options.skipInstall, }); } diff --git a/packages/cli/src/lib/new/execution/executePortableTemplate.ts b/packages/cli/src/lib/new/execution/executePortableTemplate.ts index 1dc34a71c9..42b5ab15f3 100644 --- a/packages/cli/src/lib/new/execution/executePortableTemplate.ts +++ b/packages/cli/src/lib/new/execution/executePortableTemplate.ts @@ -29,6 +29,7 @@ type ExecuteNewTemplateOptions = { config: PortableTemplateConfig; template: PortableTemplate; input: PortableTemplateInput; + skipInstall?: boolean; }; export async function executePortableTemplate( @@ -48,14 +49,16 @@ export async function executePortableTemplate( await addCodeownersEntry(targetDir, input.owner); } - await Task.forCommand('yarn install', { - cwd: targetDir, - optional: true, - }); - await Task.forCommand('yarn lint --fix', { - cwd: targetDir, - optional: true, - }); + if (!options.skipInstall) { + await Task.forCommand('yarn install', { + cwd: targetDir, + optional: true, + }); + await Task.forCommand('yarn lint --fix', { + cwd: targetDir, + optional: true, + }); + } Task.log(); Task.log(`🎉 Successfully created ${template.name}`);