cli: resolve config paths upfront
Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
This commit is contained in:
@@ -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(),
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user