forked from bem-tools/bem-tools-create
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcli.js
137 lines (121 loc) · 3.71 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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
'use strict';
var create = require('./');
function noOp() {};
var action = function(opts, args) {
var options = {};
args.entities = args.entities || [];
args.entities.forEach(function(file) {
braceExpansion(file).forEach(function(file) {
var splitted = file.split('.'),
entity = naming.parse(splitted.shift()),
tech = splitted.join('.'),
techs = [];
if (tech) {
techs = [tech];
} else if (opts.addTech) {
techs = opts.addTech;
}
create(entity, opts.level, techs, options);
});
});
var techs = opts.addTech || [];
if (opts.forceTech) {
options.onlyTech = opts.forceTech;
}
if (!opts.block) {
return reject('Block name required');
}
var result = create([{
block: opts.block[0],
elem: opts.elem && opts.elem[0],
modName: opts.mod && opts.mod[0],
modVal: opts.val && opts.val[0]
}], opts.level, techs, options);
result.catch(reject);
};
var reject = function(err) {
console.log('Not created:', err);
};
module.exports = function() {
this
.title('Create BEM entity').helpful()
.opt()
.name('level').short('l').long('level')
.title('level directory path')
.end()
.opt()
.name('block').short('b').long('block')
.title('block name, required')
.arr()
.end()
.opt()
.name('elem').short('e').long('elem')
.title('element name')
.arr()
.end()
.opt()
.name('mod').short('m').long('mod')
.title('modifier name')
.arr()
.end()
.opt()
.name('val').short('v').long('val')
.title('modifier value')
.arr()
.end()
.opt()
.name('addTech').short('t').long('add-tech')
.title('add tech')
.arr()
.end()
.opt()
.name('forceTech').short('T').long('force-tech')
.title('use only specified tech')
.arr()
.end()
.opt()
.name('noTech').short('n').long('no-tech')
.title('exclude tech')
.arr()
.end()
.opt()
.name('content').short('c').long('content')
.title('the content of the file')
.arr()
.end()
.opt()
.name('contentFile').short('cf').long('content-file')
.title('path to the template to use as a content of created file')
.arr()
.end()
.opt()
.name('force').short('f').long('force')
.title('force files creation')
.flag()
.end()
.arg()
.name('entities').title('Entities')
.arr()
.end()
.act(function(opts, args) {
var options = {},
techs = opts.addTech || [];
if (opts.forceTech) {
options.onlyTech = opts.forceTech;
}
if (args.entities) {
return create(args.entities, opts.level, techs, options).then(noOp);
};
var block = opts.block && opts.block[0],
elem = opts.elem && opts.elem[0],
modName = opts.mod && opts.mod[0],
modVal = opts.val && opts.val[0];
(block || elem || modName) && create([{
block: block,
elem: elem,
modName: modName,
modVal: modVal
}], opts.level, techs, options).then(noOp);
})
.end();
};