[npm] added "clean" script

"npm run clean" will now find all excess files, confirm they should be deleted, and then delete them. To exclude a file pass it as the --ignore argument
This commit is contained in:
spalger 2016-01-11 03:04:12 -07:00
parent 5fa8118a15
commit 247ad41583
2 changed files with 41 additions and 1 deletions

View file

@ -56,7 +56,8 @@
"lint": "grunt eslint:source",
"lintroller": "grunt eslint:fixSource",
"mocha": "mocha --compilers js:babel/register",
"mocha:debug": "mocha --debug-brk --compilers js:babel/register"
"mocha:debug": "mocha --debug-brk --compilers js:babel/register",
"clean": "grunt scrub"
},
"repository": {
"type": "git",

39
tasks/scrub.js Normal file
View file

@ -0,0 +1,39 @@
import { bgRed, white } from 'ansicolors';
import { execSync } from 'child_process';
import { createInterface } from 'readline';
export default function (grunt) {
grunt.registerTask('scrub', function () {
const cmd = 'git clean -fdx';
const ignores = [
'.aws-config.json',
'config/kibana.dev.yml'
]
.concat(String(grunt.option('ignore') || '').split(','))
.map(f => `-e "${f.split('"').join('\\"')}"`)
.reduce((all, arg) => `${all} ${arg}`, '');
const stdio = 'inherit';
execSync(`${cmd} -n ${ignores}`, { stdio });
const rl = createInterface({
input: process.stdin,
output: process.stdout
});
const danger = bgRed(white('DANGER'));
rl.on('close', this.async());
rl.question(`\n${danger} Do you really want to delete all of the above files?, [N/y] `, function (resp) {
var yes = resp.toLowerCase().trim()[0] === 'y';
rl.close();
if (yes) {
execSync(`${cmd} ${ignores}`, { stdio });
}
});
});
}