-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtarsius-sql-config.js
48 lines (45 loc) · 1.48 KB
/
tarsius-sql-config.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 p = require('commander');
const pkg = require('./package.json');
const s = require('shelljs');
const logger = require('./utils').log;
const writeFile = require('./utils').writeFile;
const fs = require('fs');
const os = require('os');
const i = require('inquirer');
const tshome = os.homedir() + "/.tarsius";
const tsdbconfig = tshome + "/db.json"
p
.version(pkg.version)
.parse(process.argv)
let prompt = (conf=null)=>{
if(!conf){
conf = {"host":"127.0.0.1","user":"root","password":"","port":26257,"database":"tarsius"}
}
let questions = [
{ type: 'input', name: 'host', message: 'hostname :', default: conf.host },
{ type: 'input', name: 'user', message: 'user :', default: conf.user },
{ type: 'input', name: 'password', message: 'password :', default: conf.password },
{ type: 'input', name: 'port', message: 'port :', default: conf.port },
{ type: 'input', name: 'database', message: 'db name :', default: conf.database }
]
i
.prompt(questions)
.then(function (answers) {
try{
console.log(logger.green("Write db config file to "+tsdbconfig));
writeFile(tsdbconfig,JSON.stringify(answers));
}
catch(e){
console.log(e)
}
})
}
if (!fs.existsSync(tshome)) s.mkdir("-p", tshome)
if (!fs.existsSync(tsdbconfig)) {
prompt()
}
else{
let conf = require(tsdbconfig);
prompt(conf)
}