diff --git a/.changeset/big-months-deliver.md b/.changeset/big-months-deliver.md new file mode 100644 index 0000000000..1cf873beb1 --- /dev/null +++ b/.changeset/big-months-deliver.md @@ -0,0 +1,5 @@ +--- +'@backstage/cli': patch +--- + +Added `--since ` flag for `repo build` command.` diff --git a/packages/cli/src/commands/index.ts b/packages/cli/src/commands/index.ts index d3baa37b3f..5cb02c82b4 100644 --- a/packages/cli/src/commands/index.ts +++ b/packages/cli/src/commands/index.ts @@ -41,6 +41,10 @@ export function registerRepoCommand(program: CommanderStatic) { '--all', 'Build all packages, including bundled app and backend packages.', ) + .option( + '--since ', + 'Only build packages and their dev dependents that changed since the specified ref', + ) .action(lazy(() => import('./repo/build').then(m => m.command))); command diff --git a/packages/cli/src/commands/repo/build.ts b/packages/cli/src/commands/repo/build.ts index ceb468ebfa..fe50bee84f 100644 --- a/packages/cli/src/commands/repo/build.ts +++ b/packages/cli/src/commands/repo/build.ts @@ -78,7 +78,18 @@ function createScriptOptionsParser(anyCmd: Command, commandPath: string[]) { } export async function command(cmd: Command): Promise { - const packages = await PackageGraph.listTargetPackages(); + let packages = await PackageGraph.listTargetPackages(); + + if (cmd.since) { + const graph = PackageGraph.fromPackages(packages); + const changedPackages = await graph.listChangedPackages({ ref: cmd.since }); + const withDevDependents = graph.collectPackageNames( + changedPackages.map(pkg => pkg.name), + pkg => pkg.localDevDependents.keys(), + ); + packages = Array.from(withDevDependents).map(name => graph.get(name)!); + } + const apps = new Array(); const backends = new Array();