-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
del.js
73 lines (67 loc) · 1.53 KB
/
del.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
'use strict';
var utils = require('../utils');
/**
* Delete a value from `app`.
*
* ```json
* # delete a value from package.json config (e.g. `verb` object)
* $ app --del=config.foo
* # delete a value from in-memory options
* $ app --del=option.foo
* # delete a property from the global config store
* $ app --del=globals.foo
* ```
* @name del
* @api public
*/
module.exports = function(app) {
return function(prop, key, config, next) {
if (typeof prop === 'undefined') {
next();
return;
}
if (utils.isObject(prop)) {
var temp = prop;
for (var k in temp) {
if (temp.hasOwnProperty(k)) {
prop = k + ':' + temp[k];
}
}
}
var keys = prop.split('.');
var init = keys.shift();
utils.assertPlugins(app, init);
prop = keys.join('.');
switch (init) {
case 'pkg':
app.pkg.del(prop);
app.pkg.save();
break;
case 'config':
app.pkg.del(app._name, prop);
app.pkg.save();
break;
case 'globals':
app.globals.del(prop);
break;
case 'store':
app.store.del(prop);
break;
case 'hints':
if (typeof app.questions !== 'undefined') {
app.questions.hints.del(Object.keys(app.questions.hints.data));
}
break;
case 'option':
app.del(['options', prop]);
break;
case 'data':
app.del(['cache.data', prop]);
break;
default:
app.del(prop);
break;
}
next();
};
};