From c318c3d809ddbab3c82d0f61b7f00ccfdbb7be19 Mon Sep 17 00:00:00 2001 From: Mark Kaylor Date: Mon, 31 May 2021 17:56:56 +0200 Subject: [PATCH] exit loop if path doesn't exist --- .../strapi/lib/commands/generate-template.js | 20 ++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/packages/strapi/lib/commands/generate-template.js b/packages/strapi/lib/commands/generate-template.js index 8a982773d6..20a35c1841 100644 --- a/packages/strapi/lib/commands/generate-template.js +++ b/packages/strapi/lib/commands/generate-template.js @@ -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}`); }