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:
Patrik Oldsberg
2021-11-12 15:22:11 +01:00
parent 14e8162d19
commit e04cce9cdb
2 changed files with 31 additions and 0 deletions
@@ -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 {
+3
View File
@@ -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>;