Skip to content

Instantly share code, notes, and snippets.

@bcinarli
Created May 25, 2019 12:52
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save bcinarli/07453bcca9301a39747e5bd4e307e9ae to your computer and use it in GitHub Desktop.
Save bcinarli/07453bcca9301a39747e5bd4e307e9ae to your computer and use it in GitHub Desktop.
Cleaning node modules, dist and build files in monorepo
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