From 0ed46da681a207bedb6db26ae2c275274a5f391f Mon Sep 17 00:00:00 2001 From: opensas Date: Mon, 27 Jul 2020 07:44:40 -0300 Subject: [PATCH] fixes #144 - do not delete scripts folder if it is not empty (#147) * fixes #144 - do not delete scripts folder if it is not empty * fixes 144 - do not remove scripts forlder if not empty, checking for DS_store file * fixes 144 - do not remove scripts forlder if not empty, checking DS_store is the only remaining file * Update scripts/setupTypeScript.js * Apply suggestions from code review Co-authored-by: Orta Therox --- scripts/setupTypeScript.js | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/scripts/setupTypeScript.js b/scripts/setupTypeScript.js index b1257dd..f26d1c5 100644 --- a/scripts/setupTypeScript.js +++ b/scripts/setupTypeScript.js @@ -97,8 +97,18 @@ fs.writeFileSync(tsconfigPath, tsconfig) if (!argv[2]) { // Remove the script fs.unlinkSync(path.join(__filename)) - // Remove the scripts folder - fs.rmdirSync(path.join(__dirname)) + + // Check for Mac's DS_store file, and if it's the only one left remove it + const remainingFiles = fs.readdirSync(path.join(__dirname)) + if (remainingFiles.length === 1 && remainingFiles[0] === '.DS_store') { + fs.unlinkSync(path.join(__dirname, '.DS_store')) + } + + // Check if the scripts folder is empty + if (fs.readdirSync(path.join(__dirname)).length === 0) { + // Remove the scripts folder + fs.rmdirSync(path.join(__dirname)) + } } // Adds the extension recommendation