From 1bab2555cf0b473adcdffb2fe751fdb954cfed6b Mon Sep 17 00:00:00 2001 From: Patrik Oldsberg Date: Sat, 31 May 2025 16:33:15 +0200 Subject: [PATCH] cli: combine build and start modules Signed-off-by: Patrik Oldsberg --- .changeset/stupid-pens-serve.md | 5 + packages/cli/src/alpha.ts | 1 - packages/cli/src/commands/index.ts | 6 -- packages/cli/src/modules/build/alpha.ts | 75 ++++++++++++++ .../commands/package/start/command.ts | 0 .../commands/package/start/index.ts | 0 .../package/start/resolveLinkedWorkspace.ts | 0 .../commands/package/start/startBackend.ts | 0 .../commands/package/start/startFrontend.ts | 0 .../commands/package/start/startPackage.ts | 0 .../commands/repo/start.test.ts | 0 .../{start => build}/commands/repo/start.ts | 0 packages/cli/src/modules/build/index.ts | 48 +++++++++ .../{start => build}/lib/ipc/IpcServer.ts | 0 .../lib/ipc/ServerDataStore.ts | 0 .../modules/{start => build}/lib/ipc/index.ts | 0 .../{start => build}/lib/runner/index.ts | 0 .../{start => build}/lib/runner/runBackend.ts | 0 packages/cli/src/modules/start/alpha.ts | 99 ------------------- packages/cli/src/modules/start/index.ts | 69 ------------- 20 files changed, 128 insertions(+), 175 deletions(-) create mode 100644 .changeset/stupid-pens-serve.md rename packages/cli/src/modules/{start => build}/commands/package/start/command.ts (100%) rename packages/cli/src/modules/{start => build}/commands/package/start/index.ts (100%) rename packages/cli/src/modules/{start => build}/commands/package/start/resolveLinkedWorkspace.ts (100%) rename packages/cli/src/modules/{start => build}/commands/package/start/startBackend.ts (100%) rename packages/cli/src/modules/{start => build}/commands/package/start/startFrontend.ts (100%) rename packages/cli/src/modules/{start => build}/commands/package/start/startPackage.ts (100%) rename packages/cli/src/modules/{start => build}/commands/repo/start.test.ts (100%) rename packages/cli/src/modules/{start => build}/commands/repo/start.ts (100%) rename packages/cli/src/modules/{start => build}/lib/ipc/IpcServer.ts (100%) rename packages/cli/src/modules/{start => build}/lib/ipc/ServerDataStore.ts (100%) rename packages/cli/src/modules/{start => build}/lib/ipc/index.ts (100%) rename packages/cli/src/modules/{start => build}/lib/runner/index.ts (100%) rename packages/cli/src/modules/{start => build}/lib/runner/runBackend.ts (100%) delete mode 100644 packages/cli/src/modules/start/alpha.ts delete mode 100644 packages/cli/src/modules/start/index.ts diff --git a/.changeset/stupid-pens-serve.md b/.changeset/stupid-pens-serve.md new file mode 100644 index 0000000000..f7fe733254 --- /dev/null +++ b/.changeset/stupid-pens-serve.md @@ -0,0 +1,5 @@ +--- +'@backstage/cli': patch +--- + +Internal refactor to combine alpha `build` and `start` modules. diff --git a/packages/cli/src/alpha.ts b/packages/cli/src/alpha.ts index a29594e135..f7333073d8 100644 --- a/packages/cli/src/alpha.ts +++ b/packages/cli/src/alpha.ts @@ -33,7 +33,6 @@ import chalk from 'chalk'; initializer.add(import('./modules/maintenance/alpha')); initializer.add(import('./modules/migrate/alpha')); initializer.add(import('./modules/new/alpha')); - initializer.add(import('./modules/start/alpha')); initializer.add(import('./modules/test/alpha')); await initializer.run(); })(); diff --git a/packages/cli/src/commands/index.ts b/packages/cli/src/commands/index.ts index 8483fd79c0..8cfad48b14 100644 --- a/packages/cli/src/commands/index.ts +++ b/packages/cli/src/commands/index.ts @@ -21,10 +21,6 @@ import { registerRepoCommands as registerRepoBuildCommands, registerCommands as registerBuildCommands, } from '../modules/build'; -import { - registerPackageCommands as registerPackageStartCommands, - registerRepoCommands as registerRepoStartCommands, -} from '../modules/start'; import { registerCommands as registerInfoCommands } from '../modules/info'; import { registerCommands as registerMigrateCommand } from '../modules/migrate'; import { @@ -48,7 +44,6 @@ export function registerRepoCommand(program: Command) { .command('repo [command]') .description('Command that run across an entire Backstage project'); - registerRepoStartCommands(command); registerRepoBuildCommands(command); registerRepoTestCommands(command); registerRepoLintCommands(command); @@ -60,7 +55,6 @@ export function registerScriptCommand(program: Command) { .command('package [command]') .description('Lifecycle scripts for individual packages'); - registerPackageStartCommands(command); registerPackageBuildCommands(command); registerPackageTestCommands(command); registerMaintenancePackageCommands(command); diff --git a/packages/cli/src/modules/build/alpha.ts b/packages/cli/src/modules/build/alpha.ts index 5e2c6d6e7d..fb9365d7c5 100644 --- a/packages/cli/src/modules/build/alpha.ts +++ b/packages/cli/src/modules/build/alpha.ts @@ -18,6 +18,7 @@ import { Command, Option } from 'commander'; import { createCliPlugin } from '../../wiring/factory'; import { lazy } from '../../lib/lazy'; import { registerPackageCommands } from '.'; +import { configOption } from '../config'; export const buildPlugin = createCliPlugin({ pluginId: 'build', @@ -85,6 +86,80 @@ export const buildPlugin = createCliPlugin({ }, }); + reg.addCommand({ + path: ['package', 'start'], + description: 'Start a package for local development', + execute: async ({ args }) => { + const command = new Command(); + + const defaultCommand = command + .option(...configOption) + .option( + '--role ', + 'Run the command with an explicit package role', + ) + .option('--check', 'Enable type checking and linting if available') + .option('--inspect [host]', 'Enable debugger in Node.js environments') + .option( + '--inspect-brk [host]', + 'Enable debugger in Node.js environments, breaking before code starts', + ) + .option( + '--require ', + 'Add a --require argument to the node process', + ) + .option( + '--link ', + 'Link an external workspace for module resolution', + ) + .action(lazy(() => import('./commands/package/start'), 'command')); + + await defaultCommand.parseAsync(args, { from: 'user' }); + }, + }); + + reg.addCommand({ + path: ['repo', 'start'], + description: 'Starts packages in the repo for local development', + execute: async ({ args }) => { + const command = new Command(); + + const defaultCommand = command + .argument( + '[...packageNameOrPath]', + 'Run the specified package instead of the defaults.', + ) + .option( + '--plugin ', + 'Start the dev entry-point for any matching plugin package in the repo', + (opt: string, opts: string[]) => (opts ? [...opts, opt] : [opt]), + Array(), + ) + .option(...configOption) + .option( + '--inspect [host]', + 'Enable debugger in Node.js environments. Applies to backend package only', + ) + .option( + '--inspect-brk [host]', + 'Enable debugger in Node.js environments, breaking before code starts. Applies to backend package only', + ) + .option( + '--require ', + 'Add a --require argument to the node process. Applies to backend package only', + ) + .option( + '--link ', + 'Link an external workspace for module resolution', + ) + .action( + lazy(() => import('../build/commands/repo/start'), 'command'), + ); + + await defaultCommand.parseAsync(args, { from: 'user' }); + }, + }); + reg.addCommand({ path: ['build-workspace'], description: diff --git a/packages/cli/src/modules/start/commands/package/start/command.ts b/packages/cli/src/modules/build/commands/package/start/command.ts similarity index 100% rename from packages/cli/src/modules/start/commands/package/start/command.ts rename to packages/cli/src/modules/build/commands/package/start/command.ts diff --git a/packages/cli/src/modules/start/commands/package/start/index.ts b/packages/cli/src/modules/build/commands/package/start/index.ts similarity index 100% rename from packages/cli/src/modules/start/commands/package/start/index.ts rename to packages/cli/src/modules/build/commands/package/start/index.ts diff --git a/packages/cli/src/modules/start/commands/package/start/resolveLinkedWorkspace.ts b/packages/cli/src/modules/build/commands/package/start/resolveLinkedWorkspace.ts similarity index 100% rename from packages/cli/src/modules/start/commands/package/start/resolveLinkedWorkspace.ts rename to packages/cli/src/modules/build/commands/package/start/resolveLinkedWorkspace.ts diff --git a/packages/cli/src/modules/start/commands/package/start/startBackend.ts b/packages/cli/src/modules/build/commands/package/start/startBackend.ts similarity index 100% rename from packages/cli/src/modules/start/commands/package/start/startBackend.ts rename to packages/cli/src/modules/build/commands/package/start/startBackend.ts diff --git a/packages/cli/src/modules/start/commands/package/start/startFrontend.ts b/packages/cli/src/modules/build/commands/package/start/startFrontend.ts similarity index 100% rename from packages/cli/src/modules/start/commands/package/start/startFrontend.ts rename to packages/cli/src/modules/build/commands/package/start/startFrontend.ts diff --git a/packages/cli/src/modules/start/commands/package/start/startPackage.ts b/packages/cli/src/modules/build/commands/package/start/startPackage.ts similarity index 100% rename from packages/cli/src/modules/start/commands/package/start/startPackage.ts rename to packages/cli/src/modules/build/commands/package/start/startPackage.ts diff --git a/packages/cli/src/modules/start/commands/repo/start.test.ts b/packages/cli/src/modules/build/commands/repo/start.test.ts similarity index 100% rename from packages/cli/src/modules/start/commands/repo/start.test.ts rename to packages/cli/src/modules/build/commands/repo/start.test.ts diff --git a/packages/cli/src/modules/start/commands/repo/start.ts b/packages/cli/src/modules/build/commands/repo/start.ts similarity index 100% rename from packages/cli/src/modules/start/commands/repo/start.ts rename to packages/cli/src/modules/build/commands/repo/start.ts diff --git a/packages/cli/src/modules/build/index.ts b/packages/cli/src/modules/build/index.ts index 0135517cd8..c859985975 100644 --- a/packages/cli/src/modules/build/index.ts +++ b/packages/cli/src/modules/build/index.ts @@ -15,6 +15,7 @@ */ import { Command, Option } from 'commander'; import { lazy } from '../../lib/lazy'; +import { configOption } from '../config'; export function registerRepoCommands(command: Command) { command @@ -35,6 +36,35 @@ export function registerRepoCommands(command: Command) { 'Minify the generated code. Does not apply to app package (app is minified by default).', ) .action(lazy(() => import('./commands/repo/build'), 'command')); + + command + .command('start') + .description('Starts packages in the repo for local development') + .argument( + '[packageNameOrPath...]', + 'Run the specified package instead of the defaults.', + ) + .option( + '--plugin ', + 'Start the dev entry-point for any matching plugin package in the repo', + (opt: string, opts: string[]) => (opts ? [...opts, opt] : [opt]), + Array(), + ) + .option(...configOption) + .option( + '--inspect [host]', + 'Enable debugger in Node.js environments. Applies to backend package only', + ) + .option( + '--inspect-brk [host]', + 'Enable debugger in Node.js environments, breaking before code starts. Applies to backend package only', + ) + .option( + '--require ', + 'Add a --require argument to the node process. Applies to backend package only', + ) + .option('--link ', 'Link an external workspace for module resolution') + .action(lazy(() => import('../build/commands/repo/start'), 'command')); } export function registerPackageCommands(command: Command) { @@ -61,6 +91,24 @@ export function registerPackageCommands(command: Command) { Array(), ) .action(lazy(() => import('./commands/package/build'), 'command')); + + command + .command('start') + .description('Start a package for local development') + .option(...configOption) + .option('--role ', 'Run the command with an explicit package role') + .option('--check', 'Enable type checking and linting if available') + .option('--inspect [host]', 'Enable debugger in Node.js environments') + .option( + '--inspect-brk [host]', + 'Enable debugger in Node.js environments, breaking before code starts', + ) + .option( + '--require ', + 'Add a --require argument to the node process', + ) + .option('--link ', 'Link an external workspace for module resolution') + .action(lazy(() => import('./commands/package/start'), 'command')); } export function registerCommands(program: Command) { diff --git a/packages/cli/src/modules/start/lib/ipc/IpcServer.ts b/packages/cli/src/modules/build/lib/ipc/IpcServer.ts similarity index 100% rename from packages/cli/src/modules/start/lib/ipc/IpcServer.ts rename to packages/cli/src/modules/build/lib/ipc/IpcServer.ts diff --git a/packages/cli/src/modules/start/lib/ipc/ServerDataStore.ts b/packages/cli/src/modules/build/lib/ipc/ServerDataStore.ts similarity index 100% rename from packages/cli/src/modules/start/lib/ipc/ServerDataStore.ts rename to packages/cli/src/modules/build/lib/ipc/ServerDataStore.ts diff --git a/packages/cli/src/modules/start/lib/ipc/index.ts b/packages/cli/src/modules/build/lib/ipc/index.ts similarity index 100% rename from packages/cli/src/modules/start/lib/ipc/index.ts rename to packages/cli/src/modules/build/lib/ipc/index.ts diff --git a/packages/cli/src/modules/start/lib/runner/index.ts b/packages/cli/src/modules/build/lib/runner/index.ts similarity index 100% rename from packages/cli/src/modules/start/lib/runner/index.ts rename to packages/cli/src/modules/build/lib/runner/index.ts diff --git a/packages/cli/src/modules/start/lib/runner/runBackend.ts b/packages/cli/src/modules/build/lib/runner/runBackend.ts similarity index 100% rename from packages/cli/src/modules/start/lib/runner/runBackend.ts rename to packages/cli/src/modules/build/lib/runner/runBackend.ts diff --git a/packages/cli/src/modules/start/alpha.ts b/packages/cli/src/modules/start/alpha.ts deleted file mode 100644 index a5875df335..0000000000 --- a/packages/cli/src/modules/start/alpha.ts +++ /dev/null @@ -1,99 +0,0 @@ -/* - * Copyright 2024 The Backstage Authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import { Command } from 'commander'; -import { createCliPlugin } from '../../wiring/factory'; -import { lazy } from '../../lib/lazy'; -import { configOption } from '../config'; - -export const startPlugin = createCliPlugin({ - pluginId: 'start', - init: async reg => { - reg.addCommand({ - path: ['package', 'start'], - description: 'Start a package for local development', - execute: async ({ args }) => { - const command = new Command(); - - const defaultCommand = command - .option(...configOption) - .option( - '--role ', - 'Run the command with an explicit package role', - ) - .option('--check', 'Enable type checking and linting if available') - .option('--inspect [host]', 'Enable debugger in Node.js environments') - .option( - '--inspect-brk [host]', - 'Enable debugger in Node.js environments, breaking before code starts', - ) - .option( - '--require ', - 'Add a --require argument to the node process', - ) - .option( - '--link ', - 'Link an external workspace for module resolution', - ) - .action(lazy(() => import('./commands/package/start'), 'command')); - - await defaultCommand.parseAsync(args, { from: 'user' }); - }, - }); - - reg.addCommand({ - path: ['repo', 'start'], - description: 'Starts packages in the repo for local development', - execute: async ({ args }) => { - const command = new Command(); - - const defaultCommand = command - .argument( - '[...packageNameOrPath]', - 'Run the specified package instead of the defaults.', - ) - .option( - '--plugin ', - 'Start the dev entry-point for any matching plugin package in the repo', - (opt: string, opts: string[]) => (opts ? [...opts, opt] : [opt]), - Array(), - ) - .option(...configOption) - .option( - '--inspect [host]', - 'Enable debugger in Node.js environments. Applies to backend package only', - ) - .option( - '--inspect-brk [host]', - 'Enable debugger in Node.js environments, breaking before code starts. Applies to backend package only', - ) - .option( - '--require ', - 'Add a --require argument to the node process. Applies to backend package only', - ) - .option( - '--link ', - 'Link an external workspace for module resolution', - ) - .action(lazy(() => import('./commands/repo/start'), 'command')); - - await defaultCommand.parseAsync(args, { from: 'user' }); - }, - }); - }, -}); - -export default startPlugin; diff --git a/packages/cli/src/modules/start/index.ts b/packages/cli/src/modules/start/index.ts deleted file mode 100644 index 17225820f7..0000000000 --- a/packages/cli/src/modules/start/index.ts +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Copyright 2024 The Backstage Authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -import { Command } from 'commander'; -import { lazy } from '../../lib/lazy'; -import { configOption } from '../config'; - -export function registerRepoCommands(command: Command) { - command - .command('start') - .description('Starts packages in the repo for local development') - .argument( - '[packageNameOrPath...]', - 'Run the specified package instead of the defaults.', - ) - .option( - '--plugin ', - 'Start the dev entry-point for any matching plugin package in the repo', - (opt: string, opts: string[]) => (opts ? [...opts, opt] : [opt]), - Array(), - ) - .option(...configOption) - .option( - '--inspect [host]', - 'Enable debugger in Node.js environments. Applies to backend package only', - ) - .option( - '--inspect-brk [host]', - 'Enable debugger in Node.js environments, breaking before code starts. Applies to backend package only', - ) - .option( - '--require ', - 'Add a --require argument to the node process. Applies to backend package only', - ) - .option('--link ', 'Link an external workspace for module resolution') - .action(lazy(() => import('./commands/repo/start'), 'command')); -} - -export function registerPackageCommands(command: Command) { - command - .command('start') - .description('Start a package for local development') - .option(...configOption) - .option('--role ', 'Run the command with an explicit package role') - .option('--check', 'Enable type checking and linting if available') - .option('--inspect [host]', 'Enable debugger in Node.js environments') - .option( - '--inspect-brk [host]', - 'Enable debugger in Node.js environments, breaking before code starts', - ) - .option( - '--require ', - 'Add a --require argument to the node process', - ) - .option('--link ', 'Link an external workspace for module resolution') - .action(lazy(() => import('./commands/package/start'), 'command')); -}