-
Notifications
You must be signed in to change notification settings - Fork 1
/
initdb.js
61 lines (53 loc) · 1.48 KB
/
initdb.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
const applyOnDatabase=require("./src/applyOnDatabase")
const configurationService=require("./src/configuration")
const config= require("./config.json")
//start the application
configurationService.set(config,getConnection());
applyOnDatabase(getConnection(),config).then(report=>{
process.exit(0);
});
function getConnection(){
let connection;
if(process.argv.length>2){
console.log("creating connection via parameter")
if(!connection){
connection=splitString();
}
if(!connection){
connection=findAndParseOption("connection");
}
if(!connection){
connection={
user:findAndParseOption("user"),
password:findAndParseOption("password"),
connectString:findAndParseOption("connectionString")
}
}
}else{
connection= require("./connection.json");
}
return connection;
}
function splitString(){
try{
let arr1= process.argv[2].split("@");
let arr2= arr1[0].split(":");
return {
user:arr2[0],
password:arr2[1],
connectString:arr1[1]
}
}catch(e){
return null;
}
}
function findAndParseOption(option){
let foundOption=process.argv.find(e=>e.startsWith("-"+option));
if(foundOption){
let oparr= foundOption.split("=");
if(oparr.length>=2){
return oparr[1];
}
}
return null;
}