exit loop if path doesn't exist

This commit is contained in:
Mark Kaylor 2021-05-31 17:56:56 +02:00
parent eec4aa2e56
commit c318c3d809

View File

@ -16,17 +16,19 @@ const TEMPLATE_CONTENT = ['api', 'components', 'config/functions/bootstrap.js',
async function copyContent(templatePath, rootBase) {
for (const item of TEMPLATE_CONTENT) {
try {
const folderExists = await fse.pathExists(join(process.cwd(), item));
const pathToCopy = join(process.cwd(), item);
if (folderExists) {
await fse.copy(join(process.cwd(), item), join(templatePath, item));
const currentProjectBase = basename(process.cwd());
console.log(
`${chalk.green(
'success'
)}: copy ${currentProjectBase}/${item} => ${rootBase}/template/${item}`
);
if (!(await fse.pathExists(pathToCopy))) {
continue;
}
await fse.copy(pathToCopy, join(templatePath, item));
const currentProjectBase = basename(process.cwd());
console.log(
`${chalk.green(
'success'
)}: copy ${currentProjectBase}/${item} => ${rootBase}/template/${item}`
);
} catch (error) {
console.error(`${chalk.red('error')}: ${error.message}`);
}