@jvdx/core
Version:
Personal nodejs toolbox
27 lines (21 loc) • 673 B
JavaScript
const { rimraf } = require('rimraf');
const { dim, underline, bold } = require('kleur');
const { stopwatch, printErr, fromRoot } = require('../utils');
async function clean(opts) {
const stop = stopwatch();
const hasPositionArgs = Boolean(opts._.length);
const filesToApply = hasPositionArgs ? opts._ : ['./node_modules', './dist'];
for (let f of filesToApply) {
await rimraf(fromRoot(f)).catch(() => {
printErr(`Error cleaning ${f}\n`);
});
}
const { s } = stop();
const output =
`Cleaned in ${bold(`${s}s`)}\n` +
`\n` +
`${underline('Directories removed')}\n` +
`${dim(filesToApply.join('\n'))}\n`;
return { output };
}
exports.clean = clean;