cli: resolve config paths upfront

Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
This commit is contained in:
Patrik Oldsberg
2023-04-04 11:51:51 +02:00
parent 3944ead310
commit 22d8703a26
2 changed files with 22 additions and 21 deletions
@@ -18,7 +18,6 @@ import os from 'os';
import fs from 'fs-extra';
import { resolve as resolvePath } from 'path';
import tar, { CreateOptions } from 'tar';
import { paths } from '../../lib/paths';
import { createDistWorkspace } from '../../lib/packager';
import { getEnvironmentParallelism } from '../../lib/parallel';
import { buildPackage, Output } from '../../lib/builder';
@@ -43,18 +42,11 @@ export async function buildBackend(options: BuildBackendOptions) {
outputs: new Set([Output.cjs]),
});
const resolvedConfigPaths = configPaths?.map(p => {
let path = paths.resolveTarget(p);
if (!fs.pathExistsSync(path)) {
path = paths.resolveOwnRoot(p);
}
return path;
});
const tmpDir = await fs.mkdtemp(resolvePath(os.tmpdir(), 'backstage-bundle'));
try {
await createDistWorkspace([pkg.name], {
targetDir: tmpDir,
configPaths: resolvedConfigPaths,
configPaths,
buildDependencies: !skipBuildDependencies,
buildExcludes: [pkg.name],
parallelism: getEnvironmentParallelism(),
+21 -12
View File
@@ -20,23 +20,32 @@ import { findRoleFromCommand, getRoleInfo } from '../../lib/role';
import { paths } from '../../lib/paths';
import { buildFrontend } from './buildFrontend';
import { buildBackend } from './buildBackend';
import { isValidUrl } from '../../lib/urls';
export async function command(opts: OptionValues): Promise<void> {
const role = await findRoleFromCommand(opts);
if (role === 'frontend') {
return buildFrontend({
targetDir: paths.targetDir,
configPaths: opts.config as string[],
writeStats: Boolean(opts.stats),
});
}
if (role === 'backend') {
return buildBackend({
targetDir: paths.targetDir,
configPaths: opts.config as string[],
skipBuildDependencies: Boolean(opts.skipBuildDependencies),
if (role === 'frontend' || role === 'backend') {
const configPaths = (opts.config as string[]).map(arg => {
if (isValidUrl(arg)) {
return arg;
}
return paths.resolveTarget(arg);
});
if (role === 'frontend') {
return buildFrontend({
targetDir: paths.targetDir,
configPaths,
writeStats: Boolean(opts.stats),
});
} else {
return buildBackend({
targetDir: paths.targetDir,
configPaths,
skipBuildDependencies: Boolean(opts.skipBuildDependencies),
});
}
}
const roleInfo = getRoleInfo(role);