Created
May 25, 2019 12:52
-
-
Save bcinarli/07453bcca9301a39747e5bd4e307e9ae to your computer and use it in GitHub Desktop.
Cleaning node modules, dist and build files in monorepo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const fs = require('fs'); | |
const { rm } = require('./utils/file-actions'); | |
const cwd = process.cwd(); | |
const rm = (path) => { | |
if (fs.existsSync(path)){ | |
exec(`rm -r ${ path }`, (err) => { | |
if (err) { | |
console.log(err); | |
} | |
}); | |
} | |
}; | |
const clean = (dir) => { | |
rm(`${ dir }/node_modules`); | |
rm(`${ dir }/build`); | |
rm(`${ dir }/dist`); | |
}; | |
const cleanRoot = () => clean(cwd); | |
const cleanWorkSpaces = () => { | |
const workspaces = [ './packages' ]; | |
workspaces.forEach((workspace) => { | |
fs.readdir(workspace, (err, folders) => { | |
folders.forEach((folder) => { | |
clean(`${ cwd }/${ workspace }/${ folder }`); | |
}); | |
if (err) { | |
throw err; | |
} | |
}); | |
}); | |
}; | |
cleanRoot(); | |
cleanWorkSpaces(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment