Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/commands/new.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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 = {
Expand Down
29 changes: 13 additions & 16 deletions src/templating/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,19 @@ export async function downloadTemplate(
namespace: string,
targetDirectory: string
): Promise<void> {
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';