@@ -123,6 +123,16 @@ module.exports = require('coa').Cmd()
123
123
124
124
}
125
125
126
+ // --disable
127
+ if ( opts . disable ) {
128
+ config = changePluginsState ( opts . disable , false , config ) ;
129
+ }
130
+
131
+ // --enable
132
+ if ( opts . enable ) {
133
+ config = changePluginsState ( opts . enable , true , config ) ;
134
+ }
135
+
126
136
// --pretty
127
137
if ( opts . pretty ) {
128
138
@@ -139,7 +149,7 @@ module.exports = require('coa').Cmd()
139
149
return ;
140
150
}
141
151
142
- // --inpput
152
+ // --input
143
153
if ( input ) {
144
154
145
155
// STDIN
@@ -249,6 +259,81 @@ function printProfitInfo(inBytes, outBytes) {
249
259
250
260
}
251
261
262
+ /**
263
+ * Change plugins state by names array.
264
+ *
265
+ * @param {Array } names plugins names
266
+ * @param {Boolean } state active state
267
+ * @param {Object } config original config
268
+ * @return {Object } changed config
269
+ */
270
+ function changePluginsState ( names , state , config ) {
271
+
272
+ // extend config
273
+ if ( config && config . plugins ) {
274
+
275
+ names . forEach ( function ( name ) {
276
+
277
+ var matched ,
278
+ key ;
279
+
280
+ config . plugins . forEach ( function ( plugin ) {
281
+
282
+ // get plugin name
283
+ if ( typeof plugin === 'object' ) {
284
+ key = Object . keys ( plugin ) [ 0 ] ;
285
+ } else {
286
+ key = plugin ;
287
+ }
288
+
289
+ // if there are such plugin name
290
+ if ( key === name ) {
291
+ // do not replace plugin's params with true
292
+ if ( typeof plugin [ key ] !== 'object' || ! state ) {
293
+ plugin [ key ] = state ;
294
+ }
295
+
296
+ // mark it as matched
297
+ matched = true ;
298
+ }
299
+
300
+ } ) ;
301
+
302
+ // if not matched and current config is not full
303
+ if ( ! matched && ! config . full ) {
304
+
305
+ var obj = { } ;
306
+
307
+ obj [ name ] = state ;
308
+
309
+ // push new plugin Object
310
+ config . plugins . push ( obj ) ;
311
+
312
+ matched = true ;
313
+
314
+ }
315
+
316
+ } ) ;
317
+
318
+ // just push
319
+ } else {
320
+
321
+ config = { plugins : [ ] } ;
322
+
323
+ names . forEach ( function ( name ) {
324
+ var obj = { } ;
325
+
326
+ obj [ name ] = state ;
327
+
328
+ config . plugins . push ( obj ) ;
329
+ } ) ;
330
+
331
+ }
332
+
333
+ return config ;
334
+
335
+ }
336
+
252
337
function optimizeFolder ( path , config ) {
253
338
254
339
var svgo = new SVGO ( config ) ;
0 commit comments