-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
69 lines (54 loc) · 1.22 KB
/
index.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
'use strict'
const os = require('os')
const path = require('path')
const fs = require('fs')
const userRoot = os.homedir()
const globalConfigPath = path.resolve(userRoot, './.legoflow_config')
const defaultConfig = {
// 开发者
user: '',
// 自动打开 chrome
autoOpenChrome: true,
// 启动端口号
port: 3000,
// 常用编辑器
editor: 'VSCode',
// 是否打开 实验室 功能
lab: false,
// node bin 绝对路径
nodeBin: '',
// 自定义项目类型本地绝对路径
customProjectPath: '',
// 加载 npm legoflow 模板
loadNPMLegoFlowTemplate: false
}
let config = defaultConfig
const writeConfig = () => {
fs.writeFileSync(globalConfigPath, JSON.stringify(config), 'utf8')
}
const readConfig = () => {
config = JSON.parse(fs.readFileSync(globalConfigPath, 'utf8'))
return config
}
if (!fs.existsSync(globalConfigPath)) {
writeConfig()
} else {
readConfig()
}
exports.set = (name, value) => {
value == 'true' && (value = true)
value == 'false' && (value = false)
config[ name ] = value
writeConfig()
}
exports.get = (name) => {
if (!name) {
return readConfig()
} else {
return config[ name ]
}
}
exports.clean = () => {
config = defaultConfig
writeConfig()
}