-
Notifications
You must be signed in to change notification settings - Fork 1
/
cli.js
92 lines (87 loc) · 2.28 KB
/
cli.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
'use strict';
var EOL = require('os').EOL,
bemNaming = require('bem-naming'),
stream = require('through2'),
util = require('bem-tools-find/lib/util'),
remove = require('./lib/remove');
/**
* Executes find process with given cli options and arguments
* @param {Object} opts - cli options
* @param {Object} args - cli arguments
*/
function execute(opts, args) {
var conditions = util.conditionsFromBEMItems(args.entity);
conditions.push(util.conditionsFromOptions(opts));
remove(conditions)
.pipe(report())
.pipe(process.stdout);
}
/**
* Returns stream for print all removed files and their total count
* @returns {Stream}
*/
function report() {
var count = 0;
return stream.obj(function(item, enc, cb) {
this.push('removed: ' + item + EOL);
count++;
cb();
}, function(cb) {
this.push(count + ' files were removed' + EOL);
cb();
});
}
module.exports = function() {
return this
.title('BEM Tool for removing BEM entity files')
.helpful()
.completable()
.arg()
.name('entity')
.title('entity')
.val(function(value) {
if (bemNaming.validate(value)) {
return bemNaming.parse(value);
} else {
return this.reject('Passed argument is not valid BEM entity');
}
})
.arr()
.end()
.opt()
.name('level')
.title('Name of level(s)')
.short('l')
.long('level')
.arr()
.end()
.opt()
.name('block')
.title('Name of block(s)')
.short('b')
.long('block')
.arr()
.end()
.opt()
.name('element')
.title('Name of element(s)')
.short('e')
.long('element')
.arr()
.end()
.opt()
.name('modifier')
.title('Name of modifier(s)')
.short('m')
.long('mod')
.arr()
.end()
.opt()
.name('tech')
.title('Name of tech(s)')
.short('t')
.long('tech')
.arr()
.end()
.act(execute);
};