diff --git a/packages/cli/src/commands/bundle/bundleApp.ts b/packages/cli/src/commands/build/buildApp.ts similarity index 93% rename from packages/cli/src/commands/bundle/bundleApp.ts rename to packages/cli/src/commands/build/buildApp.ts index 1ebd1f044e..3d86d796b7 100644 --- a/packages/cli/src/commands/bundle/bundleApp.ts +++ b/packages/cli/src/commands/build/buildApp.ts @@ -20,12 +20,12 @@ import { parseParallel, PARALLEL_ENV_VAR } from '../../lib/parallel'; import { loadCliConfig } from '../../lib/config'; import { paths } from '../../lib/paths'; -interface BundleAppOptions { +interface BuildAppOptions { writeStats: boolean; configPaths: string[]; } -export async function bundleApp(options: BundleAppOptions) { +export async function buildApp(options: BuildAppOptions) { const { name } = await fs.readJson(paths.resolveTarget('package.json')); await buildBundle({ entry: 'src/index', diff --git a/packages/cli/src/commands/bundle/bundleBackend.ts b/packages/cli/src/commands/build/buildBackend.ts similarity index 96% rename from packages/cli/src/commands/bundle/bundleBackend.ts rename to packages/cli/src/commands/build/buildBackend.ts index 0f240d87dc..a4d8858cf8 100644 --- a/packages/cli/src/commands/bundle/bundleBackend.ts +++ b/packages/cli/src/commands/build/buildBackend.ts @@ -26,11 +26,11 @@ import { buildPackage, Output } from '../../lib/builder'; const BUNDLE_FILE = 'bundle.tar.gz'; const SKELETON_FILE = 'skeleton.tar.gz'; -interface BundleBackendOptions { +interface BuildBackendOptions { skipBuildDependencies: boolean; } -export async function bundleBackend(options: BundleBackendOptions) { +export async function buildBackend(options: BuildBackendOptions) { const targetDir = paths.resolveTarget('dist'); const pkg = await fs.readJson(paths.resolveTarget('package.json')); diff --git a/packages/cli/src/commands/build/command.ts b/packages/cli/src/commands/build/command.ts index b2e5925119..8c13b515d7 100644 --- a/packages/cli/src/commands/build/command.ts +++ b/packages/cli/src/commands/build/command.ts @@ -16,19 +16,26 @@ import { Command } from 'commander'; import { buildPackage, Output } from '../../lib/builder'; -import { PackageRole, findRoleFromCommand, getRoleInfo } from '../../lib/role'; - -const bundledRoles: PackageRole[] = ['app', 'backend']; +import { findRoleFromCommand, getRoleInfo } from '../../lib/role'; +import { buildApp } from './buildApp'; +import { buildBackend } from './buildBackend'; export async function command(cmd: Command): Promise { const role = await findRoleFromCommand(cmd); - const roleInfo = getRoleInfo(role); - if (bundledRoles.includes(role)) { - throw new Error( - `Build command is not supported for package role '${role}'`, - ); + if (role === 'app') { + return buildApp({ + configPaths: cmd.config as string[], + writeStats: Boolean(cmd.stats), + }); } + if (role === 'backend') { + return buildBackend({ + skipBuildDependencies: Boolean(cmd.skipBuildDependencies), + }); + } + + const roleInfo = getRoleInfo(role); const outputs = new Set(); @@ -42,7 +49,7 @@ export async function command(cmd: Command): Promise { outputs.add(Output.types); } - await buildPackage({ + return buildPackage({ outputs, minify: Boolean(cmd.minify), useApiExtractor: Boolean(cmd.experimentalTypeBuild), diff --git a/packages/cli/src/commands/bundle/command.ts b/packages/cli/src/commands/bundle/command.ts deleted file mode 100644 index 4b8c718001..0000000000 --- a/packages/cli/src/commands/bundle/command.ts +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright 2020 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 { bundleApp } from './bundleApp'; -import { bundleBackend } from './bundleBackend'; -import { findRoleFromCommand } from '../../lib/role'; - -export async function command(cmd: Command): Promise { - const role = await findRoleFromCommand(cmd); - - const options = { - configPaths: cmd.config as string[], - writeStats: Boolean(cmd.stats), - skipBuildDependencies: Boolean(cmd.skipBuildDependencies), - }; - - if (role === 'app') { - return bundleApp(options); - } else if (role === 'backend') { - return bundleBackend(options); - } - - throw new Error(`Bundle command is not supported for package role '${role}'`); -} diff --git a/packages/cli/src/commands/bundle/index.ts b/packages/cli/src/commands/bundle/index.ts deleted file mode 100644 index 680fe9e11d..0000000000 --- a/packages/cli/src/commands/bundle/index.ts +++ /dev/null @@ -1,17 +0,0 @@ -/* - * Copyright 2022 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. - */ - -export { command } from './command'; diff --git a/packages/cli/src/commands/index.ts b/packages/cli/src/commands/index.ts index c9c06141c3..a33e7d4afe 100644 --- a/packages/cli/src/commands/index.ts +++ b/packages/cli/src/commands/index.ts @@ -45,25 +45,30 @@ export function registerScriptCommand(program: CommanderStatic) { command .command('build') - .description('Build a package for publishing') - .option('--minify', 'Minify the generated code') - .option('--experimental-type-build', 'Enable experimental type build') - .action(lazy(() => import('./build').then(m => m.command))); - - command - .command('bundle') - .description('Bundle a package for deployment') - .option(...configOption) - .option('--role ', 'Run the command with an explicit package role') + .description('Build a package for production deployment or publishing') + .option( + '--minify', + 'Minify the generated code. Does not apply to app or backend packages.', + ) + .option( + '--experimental-type-build', + 'Enable experimental type build. Does not apply to app or backend packages.', + ) .option( '--skip-build-dependencies', - 'Skip the automatic building of local dependencies', + 'Skip the automatic building of local dependencies. Applies to backend packages only.', ) .option( '--stats', - 'If bundle stats are available, write them to the output directory', + 'If bundle stats are available, write them to the output directory. Applies to app packages only.', ) - .action(lazy(() => import('./bundle').then(m => m.command))); + .option( + '--config ', + 'Config files to load instead of app-config.yaml. Applies to app packages only.', + (opt: string, opts: string[]) => [...opts, opt], + Array(), + ) + .action(lazy(() => import('./build').then(m => m.command))); program .command('lint') diff --git a/packages/cli/src/commands/migrate/packageScripts.ts b/packages/cli/src/commands/migrate/packageScripts.ts index 7a02411690..a3fdd20018 100644 --- a/packages/cli/src/commands/migrate/packageScripts.ts +++ b/packages/cli/src/commands/migrate/packageScripts.ts @@ -37,9 +37,7 @@ export async function command() { const expectedScripts = { ...(hasStart && { start: 'backstage-cli script start' }), - ...(isBundled - ? { bundle: 'backstage-cli script bundle', build: undefined } - : { build: 'backstage-cli script build', bundle: undefined }), + build: 'backstage-cli script build', lint: 'backstage-cli script lint', test: 'backstage-cli script test', clean: 'backstage-cli script clean',