Skip to content

Instantly share code, notes, and snippets.

@whoisryosuke
Forked from bcinarli/clean-node-modules.js
Created March 11, 2021 16:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save whoisryosuke/fd534678d222e7c730f51b091fccfc83 to your computer and use it in GitHub Desktop.
Save whoisryosuke/fd534678d222e7c730f51b091fccfc83 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