diff --git a/src/commands/new.ts b/src/commands/new.ts index 14c35d33..1655a994 100644 --- a/src/commands/new.ts +++ b/src/commands/new.ts @@ -5,7 +5,7 @@ import { Merge } from 'type-fest'; import { Arguments, Argv } from 'yargs'; import checkProjectStructure from '../checks/project-structure'; import { downloadTemplate, fetchListOfTemplates } from '../templating/actions'; -import { setLogLevelByName } from '../utils/logger'; +import { setLogLevelByName, logger } from '../utils/logger'; import { baseCliOptions, BaseFlags, ExternalCliOptions } from './shared'; import { CliInfo } from './types'; import { getFullCommand } from './utils'; @@ -112,7 +112,11 @@ export async function handler( const sanitizedNamespace = flags.namespace.replace(/\.js$/, ''); - downloadTemplate(flags.template, sanitizedNamespace, targetDirectory); + try { + await downloadTemplate(flags.template, sanitizedNamespace, targetDirectory); + } catch (error) { + logger.error(error.message, error.name); + } } export const cliInfo: CliInfo = { diff --git a/src/templating/actions.ts b/src/templating/actions.ts index ef026755..4cdd03af 100644 --- a/src/templating/actions.ts +++ b/src/templating/actions.ts @@ -9,22 +9,19 @@ export async function downloadTemplate( namespace: string, targetDirectory: string ): Promise { - try { - const files = await getTemplateFiles(templateName); - await writeFiles(files, targetDirectory, namespace, templateName); - logger.info( - chalk`{green SUCCESS} Downloaded new template into the "${namespace}" subdirectories.` - ); - logger.info( - `Check ${path.join( - 'readmes', - namespace, - `${templateName}.md` - )} for template instructions.` - ); - } catch (err) { - logger.error(err.message, err.name); - } + const files = await getTemplateFiles(templateName); + + await writeFiles(files, targetDirectory, namespace, templateName); + logger.info( + chalk`{green SUCCESS} Downloaded new template into the "${namespace}" subdirectories.` + ); + logger.info( + `Check ${path.join( + 'readmes', + namespace, + `${templateName}.md` + )} for template instructions.` + ); } export { fetchListOfTemplates } from './data';