cli: wrap create factories up in a bit more built-in logging
Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
This commit is contained in:
@@ -21,6 +21,7 @@ import { Command } from 'commander';
|
||||
import { FactoryRegistry } from '../../lib/create/FactoryRegistry';
|
||||
import { paths } from '../../lib/paths';
|
||||
import { assertError } from '@backstage/errors';
|
||||
import { Task } from '../../lib/tasks';
|
||||
|
||||
function parseOptions(optionStrings: string[]): Record<string, string> {
|
||||
const options: Record<string, string> = {};
|
||||
@@ -77,7 +78,11 @@ export default async (cmd: Command) => {
|
||||
return dir;
|
||||
}
|
||||
|
||||
let modified = false;
|
||||
try {
|
||||
Task.log();
|
||||
Task.log(`Creating new ${factory.name}`);
|
||||
|
||||
await factory.create(options, {
|
||||
isMonoRepo,
|
||||
defaultVersion,
|
||||
@@ -85,7 +90,30 @@ export default async (cmd: Command) => {
|
||||
npmRegistry: cmdOpts.npmRegistry,
|
||||
private: Boolean(cmdOpts.private),
|
||||
createTemporaryDirectory,
|
||||
markAsModified() {
|
||||
modified = true;
|
||||
},
|
||||
});
|
||||
|
||||
Task.log();
|
||||
Task.log(`🎉 Successfully created ${factory.name}`);
|
||||
Task.log();
|
||||
} catch (error) {
|
||||
assertError(error);
|
||||
Task.error(error.message);
|
||||
|
||||
if (modified) {
|
||||
Task.log('It seems that something went wrong in the creation process 🤔');
|
||||
Task.log();
|
||||
Task.log(
|
||||
'We have left the changes that were made intact in case you want to',
|
||||
);
|
||||
Task.log(
|
||||
'continue manually, but you can also revert the changes and try again.',
|
||||
);
|
||||
|
||||
Task.error(`🔥 Failed to create ${factory.name}!`);
|
||||
}
|
||||
} finally {
|
||||
for (const dir of tempDirs) {
|
||||
try {
|
||||
|
||||
@@ -30,6 +30,9 @@ export interface CreateContext {
|
||||
|
||||
/** Creates a temporary directory. This will always be deleted after creation is done. */
|
||||
createTemporaryDirectory(name: string): Promise<string>;
|
||||
|
||||
/** Signal that the creation process got to a point where permanent modifications were made */
|
||||
markAsModified(): void;
|
||||
}
|
||||
|
||||
export type AnyOptions = Record<string, string>;
|
||||
|
||||
Reference in New Issue
Block a user