UNPKG

857 BJavaScriptView Raw
1#!/usr/bin/env node
2
3const path = require('path')
4const {
5 error,
6 info,
7 warn,
8} = require('./util')
9
10const globalConfigPath = path.join(__dirname, '../config/config.global.json')
11const globalConfig = require(globalConfigPath)
12
13if (!globalConfig) {
14 error('读取全局配置文件失败')
15
16 process.exit(1)
17}
18
19function getConfig(options) {
20 const {
21 all,
22 key
23 } = options
24
25 if (all || !key) {
26 info('~~~~~~~~~~~ All global config start ~~~~~~~~~~~')
27 console.log(JSON.stringify(globalConfig, null, 2))
28 info('~~~~~~~~~~~ All global config end ~~~~~~~~~~~')
29
30 process.exit(0)
31 }
32
33 const value = globalConfig[key]
34 const prefix = `Global config ${key}`
35
36 if (value) {
37 info(`\n${prefix}: ${value}\n`)
38 } else {
39 warn(`\n${prefix}: no exixt\n`)
40 }
41
42 process.exit(0)
43}
44
45module.exports = (options) => getConfig(options)