cli: add initial experimental repo sub-command with build
Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
This commit is contained in:
@@ -25,6 +25,21 @@ const configOption = [
|
||||
Array<string>(),
|
||||
] as const;
|
||||
|
||||
export function registerRepoCommand(program: CommanderStatic) {
|
||||
const command = program
|
||||
.command('repo [command]', { hidden: true })
|
||||
.description(
|
||||
'Command that run across an entire Backstage project [EXPERIMENTAL]',
|
||||
);
|
||||
|
||||
command
|
||||
.command('build')
|
||||
.description(
|
||||
'Build all packages in the project that use the standard backstage build script',
|
||||
)
|
||||
.action(lazy(() => import('./repo/build').then(m => m.command)));
|
||||
}
|
||||
|
||||
export function registerScriptCommand(program: CommanderStatic) {
|
||||
const command = program
|
||||
.command('script [command]', { hidden: true })
|
||||
@@ -312,6 +327,7 @@ export function registerCommands(program: CommanderStatic) {
|
||||
.description('Print configuration schema')
|
||||
.action(lazy(() => import('./config/schema').then(m => m.default)));
|
||||
|
||||
registerRepoCommand(program);
|
||||
registerScriptCommand(program);
|
||||
registerMigrateCommand(program);
|
||||
|
||||
|
||||
@@ -0,0 +1,75 @@
|
||||
/*
|
||||
* 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 chalk from 'chalk';
|
||||
import { relative as relativePath } from 'path';
|
||||
import { buildPackages, Output } from '../../lib/builder';
|
||||
import { PackageGraph } from '../../lib/monorepo';
|
||||
import { paths } from '../../lib/paths';
|
||||
import { getRoleInfo } from '../../lib/role';
|
||||
|
||||
const outputMap = {
|
||||
esm: Output.esm,
|
||||
cjs: Output.cjs,
|
||||
types: Output.types,
|
||||
bundle: undefined,
|
||||
};
|
||||
|
||||
export async function command(): Promise<void> {
|
||||
const packages = await PackageGraph.listTargetPackages();
|
||||
|
||||
const options = packages.flatMap(pkg => {
|
||||
const role = pkg.packageJson.backstage?.role;
|
||||
if (!role) {
|
||||
console.warn(`Ignored ${pkg.packageJson.name} because it has no role`);
|
||||
return [];
|
||||
}
|
||||
|
||||
const roleInfo = getRoleInfo(role);
|
||||
const outputs = roleInfo.output
|
||||
.map(output => outputMap[output])
|
||||
.filter((x): x is Output => Boolean(x));
|
||||
if (outputs.length === 0) {
|
||||
console.warn(`Ignored ${pkg.packageJson.name} because it has no output`);
|
||||
return [];
|
||||
}
|
||||
|
||||
const buildScript = pkg.packageJson.scripts?.build;
|
||||
if (!buildScript) {
|
||||
console.warn(
|
||||
`Ignored ${pkg.packageJson.name} because it has no build script`,
|
||||
);
|
||||
return [];
|
||||
}
|
||||
if (!buildScript.startsWith('backstage-cli script build')) {
|
||||
console.warn(
|
||||
`Ignored ${pkg.packageJson.name} because it has a custom build script, '${buildScript}'`,
|
||||
);
|
||||
return [];
|
||||
}
|
||||
|
||||
return {
|
||||
targetDir: pkg.dir,
|
||||
outputs: new Set(outputs),
|
||||
logPrefix: `${chalk.cyan(relativePath(paths.targetRoot, pkg.dir))}: `,
|
||||
// TODO(Rugvip): Use commander to parse the script and grab these instead
|
||||
minify: buildScript.includes('--minify'),
|
||||
useApiExtractor: buildScript.includes('--experimental-type-build'),
|
||||
};
|
||||
});
|
||||
|
||||
await buildPackages(options);
|
||||
}
|
||||
Reference in New Issue
Block a user