config.js
1.83 KB
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
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
function _react() {
const data = _interopRequireDefault(require("react"));
_react = function _react() {
return data;
};
return data;
}
function _utils() {
const data = require("@umijs/utils");
_utils = function _utils() {
return data;
};
return data;
}
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var _default = api => {
api.registerCommand({
name: 'config',
description: 'umi config cli',
details: `
# List configs
$ umi config list
# List the specific config
$ umi config list --name history
`.trim(),
fn({
args
}) {
const command = args._[0];
switch (command) {
case 'list':
list();
break;
default:
throw new Error(`Unsupported sub command ${command} for umi config.`);
}
function list() {
const getValue = value => {
if (typeof value !== 'function') {
return value;
}
return _utils().chalk.yellow('The value data type does not support the view');
};
const print = key => {
console.log(` - ${_utils().chalk.blue(`[key: ${key}]`)}`, getValue(api.config[key]));
console.log();
};
console.log();
console.log(` Configs:`);
console.log();
if (args.name) {
if (!api.config[args.name]) {
// current key not existed
throw new Error(`key ${args.name} not found`);
}
print(args.name);
} else {
// list all
Object.keys(api.config).forEach(key => {
print(key);
});
}
console.log();
}
}
});
};
exports.default = _default;