cli: remove redundant util

Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
This commit is contained in:
Patrik Oldsberg
2025-11-30 10:26:53 +01:00
parent 6359995329
commit e750be29b5
2 changed files with 20 additions and 31 deletions
@@ -24,6 +24,7 @@ import {
} from '../types';
import { installNewPackage } from './installNewPackage';
import { writeTemplateContents } from './writeTemplateContents';
import { run } from '@backstage/cli-common';
type ExecuteNewTemplateOptions = {
config: PortableTemplateConfig;
@@ -54,14 +55,25 @@ export async function executePortableTemplate(
}
if (!options.skipInstall) {
await Task.forCommand('yarn install', {
cwd: targetDir,
optional: true,
});
await Task.forCommand('yarn lint --fix', {
cwd: targetDir,
optional: true,
});
for (const command of [
['yarn', 'install'],
['yarn', 'lint', '--fix'],
]) {
const commandStr = command.join(' ');
try {
await Task.forItem('executing', commandStr, async () => {
await run(command, {
cwd: targetDir,
stdio: 'ignore',
}).waitForExit();
});
} catch (error) {
assertError(error);
Task.error(
`Warning: Failed to execute command '${commandStr}', ${error}`,
);
}
}
}
Task.log();
-23
View File
@@ -16,8 +16,6 @@
import chalk from 'chalk';
import ora from 'ora';
import { assertError } from '@backstage/errors';
import { run } from '@backstage/cli-common';
const TASK_NAME_MAX_LENGTH = 14;
@@ -61,25 +59,4 @@ export class Task {
throw error;
}
}
static async forCommand(
command: string,
options?: { cwd?: string; optional?: boolean },
) {
try {
await Task.forItem('executing', command, async () => {
const parts = command.trim().split(/\s+/);
await run(parts, { cwd: options?.cwd }).waitForExit();
});
} catch (error) {
assertError(error);
if (options?.optional) {
Task.error(`Warning: Failed to execute command ${chalk.cyan(command)}`);
} else {
throw new Error(
`Failed to execute command '${chalk.cyan(command)}', ${error}`,
);
}
}
}
}