-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathautofile.js
36 lines (30 loc) · 1.17 KB
/
autofile.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
'use strict';
var rimraf = require('rimraf');
var async = require('async');
var glob = require('glob');
var path = require('path');
module.exports = function (task) {
task
.id('rm')
.name('Remove')
.description('Remove files and folders.')
.author('Indigo United')
.option('files', 'Which files should be removed. Accepts a filename and array of filenames. Also note that the filenames can be minimatch patterns.')
.option('glob', 'The options to pass to glob (check https://npmjs.org/package/glob for details).', null)
.do(function (opt, ctx, next) {
// TODO: optimize this with the expand function
var files = Array.isArray(opt.files) ? opt.files : [opt.files];
async.forEach(files, function (file, next) {
glob(file, opt.glob, function (err, matches) {
if (err) {
return next(err);
}
async.forEach(matches, function (match, next) {
match = path.normalize(match);
ctx.log.debugln('Removing ' + match);
rimraf(match, next);
}, next);
});
}, next);
});
};