cli: repo start partial parsing of script options
Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
This commit is contained in:
@@ -77,6 +77,7 @@ DEPRECATION WARNING: React Router Beta is deprecated and support for it will be
|
||||
|
||||
const cliConfig = await loadCliConfig({
|
||||
args: options.configPaths,
|
||||
targetDir: options.targetDir,
|
||||
fromPackage: name,
|
||||
withFilteredKeys: true,
|
||||
watch(appConfigs) {
|
||||
|
||||
@@ -19,9 +19,11 @@ import { AppConfig, ConfigReader } from '@backstage/config';
|
||||
import { paths } from '../../../lib/paths';
|
||||
import { getPackages } from '@manypkg/get-packages';
|
||||
import { PackageGraph } from '@backstage/cli-node';
|
||||
import { resolve as resolvePath } from 'path';
|
||||
|
||||
type Options = {
|
||||
args: string[];
|
||||
targetDir?: string;
|
||||
fromPackage?: string;
|
||||
mockEnv?: boolean;
|
||||
withFilteredKeys?: boolean;
|
||||
@@ -32,8 +34,10 @@ type Options = {
|
||||
};
|
||||
|
||||
export async function loadCliConfig(options: Options) {
|
||||
const targetDir = options.targetDir ?? paths.targetDir;
|
||||
|
||||
// Consider all packages in the monorepo when loading in config
|
||||
const { packages } = await getPackages(paths.targetDir);
|
||||
const { packages } = await getPackages(targetDir);
|
||||
|
||||
let localPackageNames;
|
||||
if (options.fromPackage) {
|
||||
@@ -70,7 +74,7 @@ export async function loadCliConfig(options: Options) {
|
||||
: undefined,
|
||||
watch: Boolean(options.watch),
|
||||
rootDir: paths.targetRoot,
|
||||
argv: options.args.flatMap(t => ['--config', paths.resolveTarget(t)]),
|
||||
argv: options.args.flatMap(t => ['--config', resolvePath(targetDir, t)]),
|
||||
});
|
||||
|
||||
const appConfigs = await new Promise<AppConfig[]>((resolve, reject) => {
|
||||
|
||||
@@ -37,7 +37,7 @@ interface StartAppOptions {
|
||||
|
||||
export async function startFrontend(options: StartAppOptions) {
|
||||
const packageJson = (await readJson(
|
||||
paths.resolveTarget('package.json'),
|
||||
resolvePath(options.targetDir ?? paths.targetDir, 'package.json'),
|
||||
)) as BackstagePackageJson;
|
||||
|
||||
const waitForExit = await serveBundle({
|
||||
|
||||
@@ -23,6 +23,7 @@ import { relative as relativePath } from 'path';
|
||||
import { paths } from '../../../../lib/paths';
|
||||
import { resolveLinkedWorkspace } from '../package/start/resolveLinkedWorkspace';
|
||||
import { startPackage } from '../package/start/startPackage';
|
||||
import { parseArgs } from 'util';
|
||||
|
||||
const ACCEPTED_PACKAGE_ROLES: Array<PackageRole | undefined> = [
|
||||
'frontend',
|
||||
@@ -40,19 +41,46 @@ export async function command(
|
||||
`Starting ${targetPackages.map(p => p.packageJson.name).join(', ')}`,
|
||||
);
|
||||
|
||||
// Blocking
|
||||
// Each of these block until interrupt by user
|
||||
await Promise.all(
|
||||
targetPackages.map(async pkg => {
|
||||
const opts = { config: [], require: undefined };
|
||||
const startScript = pkg.packageJson.scripts?.start;
|
||||
if (!startScript) {
|
||||
console.log(
|
||||
`No start script found for package ${pkg.packageJson.name}, skipping...`,
|
||||
);
|
||||
return undefined;
|
||||
}
|
||||
|
||||
// Grab and parse --config and --require options from the start scripts, the rest are ignored
|
||||
// TODO(Rugvip): Prolly switch over to completely different arg parsing to avoid this duplication
|
||||
const { values: parsedOpts } = parseArgs({
|
||||
args: startScript.split(' '),
|
||||
strict: false,
|
||||
options: {
|
||||
config: {
|
||||
type: 'string',
|
||||
multiple: true,
|
||||
},
|
||||
require: {
|
||||
type: 'string',
|
||||
},
|
||||
},
|
||||
});
|
||||
const parsedRequire =
|
||||
typeof parsedOpts.require === 'string' ? parsedOpts.require : undefined;
|
||||
const parsedConfig =
|
||||
parsedOpts.config?.filter(c => typeof c === 'string') ?? [];
|
||||
|
||||
return startPackage({
|
||||
role: pkg.packageJson.backstage?.role!,
|
||||
targetDir: pkg.dir,
|
||||
configPaths: opts.config as string[],
|
||||
configPaths: options.config.length > 0 ? options.config : parsedConfig,
|
||||
checksEnabled: false,
|
||||
linkedWorkspace: await resolveLinkedWorkspace(options.link),
|
||||
inspectEnabled: false,
|
||||
inspectBrkEnabled: false,
|
||||
require: opts.require,
|
||||
require: parsedRequire,
|
||||
});
|
||||
}),
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user