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 <orta.therox+github@gmail.com>
This commit is contained in:
opensas 2020-07-27 07:44:40 -03:00 committed by GitHub
parent 16e4763560
commit 0ed46da681
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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