-
Notifications
You must be signed in to change notification settings - Fork 0
/
scflog-configure.js
executable file
·49 lines (42 loc) · 1.3 KB
/
scflog-configure.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
#!/usr/bin/env node
const program = require('commander')
const path = require('path')
const fs = require('fs')
const os = require('os')
program
.option('-w, --websocket [websocket]', 'Websocket地址')
.option('-r, --region [region]', '常用函数的区域(非必选,默认ap-guangzhou)')
.option('-n, --namespace [namespace]', '常用函数的命名空间(非必选,默认default)')
.parse(process.argv);
const configurePath = path.join(os.homedir(), ".scf_python_logs")
let configureData
if (fs.existsSync(configurePath)) {
try {
configureData = JSON.parse(fs.readFileSync(configurePath, 'utf-8'))
} catch (e) {
}
}
if (!configureData) {
configureData = {
websocket: "",
region: 'ap-guangzhou',
namespace: 'default'
}
}
if (program.websocket) {
configureData.websocket = program.websocket
console.log("更新websocket成功")
}
if (program.region) {
configureData.region = program.region
console.log("更新region成功")
}
if (program.namespace) {
configureData.namespace = program.namespace
console.log("更新namespace成功")
}
fs.writeFileSync(configurePath, JSON.stringify(configureData))
console.log("目前配置:")
console.log(` websocket: ${configureData.websocket}`)
console.log(` region: ${configureData.region}`)
console.log(` namespace: ${configureData.namespace}`)