1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 | _fs = require 'fs-extra'
|
7 | _jsonl = require 'json-literal'
|
8 | _ = require 'lodash'
|
9 |
|
10 | _utils = require './utils'
|
11 |
|
12 |
|
13 | readConfig = (isGlobal)->
|
14 | configFile = if isGlobal then _utils.globalConfigFile() else _utils.localConfigFile()
|
15 | console.log configFile
|
16 | if not _fs.existsSync configFile
|
17 | message = "没有找到配置文件"
|
18 | message += ",请检查当前目录是否为合法的的Silky项目" if not isGlobal
|
19 | console.log message.red
|
20 | return false
|
21 |
|
22 | configFile
|
23 |
|
24 |
|
25 | exports.set = (xPath, value, isGlobal)->
|
26 | return console.log "要配置的键不能为空".red if not xPath
|
27 |
|
28 |
|
29 | return if not file = readConfig isGlobal
|
30 | config = require file
|
31 | _utils.xPathSetValue xPath, config, value
|
32 | _utils.saveObjectAsCode config, file
|
33 |
|
34 | if value
|
35 | console.log "#配置成功 -> #{xPath}: #{value}".green
|
36 | else
|
37 | console.log "删除配置成功 -> #{xPath}".green
|
38 |
|
39 |
|
40 | exports.get = (xPath, isGlobal)->
|
41 | return if not file = readConfig isGlobal
|
42 | config = require file
|
43 | value = _utils.xPathMapValue xPath, config
|
44 | value = JSON.stringify value if typeof(value) is 'object'
|
45 |
|
46 | xPathStr = xPath || "All"
|
47 | console.log "#{xPathStr.green} -> #{value}"
|
48 |
|
49 |
|
50 | exports.setAsHoney = ()->
|
51 | return if not file = readConfig true
|
52 | config = require file
|
53 |
|
54 | for key, value of _utils.honeyConfig
|
55 | _utils.xPathSetValue "custom.#{key}", config, value
|
56 |
|
57 | _utils.saveObjectAsCode config, file
|
58 | console.log "Silky自定义配置成功"
|