cli: remove separate bundle script, using build instead

Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
This commit is contained in:
Patrik Oldsberg
2022-02-03 13:35:53 +01:00
parent eaf67f0578
commit 3941ada3cf
7 changed files with 39 additions and 84 deletions
@@ -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',
@@ -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'));
+16 -9
View File
@@ -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<void> {
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<Output>();
@@ -42,7 +49,7 @@ export async function command(cmd: Command): Promise<void> {
outputs.add(Output.types);
}
await buildPackage({
return buildPackage({
outputs,
minify: Boolean(cmd.minify),
useApiExtractor: Boolean(cmd.experimentalTypeBuild),
@@ -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<void> {
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}'`);
}
-17
View File
@@ -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';
+18 -13
View File
@@ -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 <name>', '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 <path>',
'Config files to load instead of app-config.yaml. Applies to app packages only.',
(opt: string, opts: string[]) => [...opts, opt],
Array<string>(),
)
.action(lazy(() => import('./build').then(m => m.command)));
program
.command('lint')
@@ -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',