-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.js
154 lines (149 loc) · 3.39 KB
/
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
var readline = require('readline'),
fs = require('fs'),
mkdirp = require('mkdirp'),
config_obj = {},
finalArg = process.argv[process.argv.length - 1],
configPath = __dirname+'/config/'; // '/config/test/' implement some sort of testing flag
if(!fs.existsSync(configPath)){
mkdirp.sync(configPath);
}
var rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
var twilioQuestions = [
{
title:'Account SID',
desc: '(Found in your Twilio account information)',
json_key:'accountSid',
'default': null,
action: null
},
{
title:'Auth Token',
desc: '(Found in your Twilio account information)',
json_key:'authToken',
'default': null,
action: null
},
{
title:'Twilio Phone Number',
desc: '(Found in your Twilio account information MAKE SURE TO ADD A +1 for US)',
json_key:'twilioNumber',
'default': null,
action: null
},
{
title:'unique passphrase',
desc: '(what you\'ll prepend to every text)',
json_key:'password',
'default': null,
action: null
},
{
title:'list of valid phone numbers',
desc: '(phone numbers you allow to communicate with your server MAKE SURE TO ADD A +1 for US country code and add spaces between each phone number)',
json_key:'validPhones',
'default': [],
action: function(a){
if(a.length > 0){
return a.split(' ');
}
}
}
]
var sendhubQuestions = [
{
title:'SendHub API key',
desc: '(found on the account settings page at www.sendhub.com)',
json_key:'sh_api',
'default': 'https://api.sendhub.com',
action: null
},
{
title:'SendHub account phone number',
desc: '(the number you used to sign up)',
json_key:'phone_number',
'default': null,
action: null
},
{
title:'API Version',
desc: '(most likely v1)',
json_key:'api_ver',
'default': 'v1',
action: null
},
{
title:'API Key',
desc: '(Found in the settings page as well)',
json_key:'api_key',
'default': null,
action: null
},
{
title:'unique passphrase',
desc: '(what you\'ll prepend to every text)',
json_key:'password',
'default': null,
action: null
},
{
title:'list of valid phone numbers',
desc: '(phone numbers you allow to communicate with your server MAKE SURE TO ADD A +1 for US country code and add spaces between each phone number)',
json_key:'valid_phones',
'default': [],
action: function(a){
if(a.length > 0){
return a.split(' ');
}
}
}
];
var i = 0;
var q = [];
var configFile = '';
configure();
function configure(){
if(finalArg == 'twilio'){
configFile = configPath+'twilio_config.json';
q = twilioQuestions;
ask(i);
} else if(finalArg == 'sendhub'){
configFile = configPath+'sendhub_config.json';
q = sendhubQuestions;
ask(i);
} else{
console.log('No valid option...use \'node config.js twilio\' or \'node config.js sendhub\'');
process.exit();
}
}
function ask(i){
if(i == q.length){
console.log('CONFIGURATION COMPLETE');
rl.close();
writeConfigFile(config_obj);
} else{
rl.question(q[i].title+' '+q[i].desc+': ', function(answer) {
if(answer.length == 0 && q[i].default != null){
answer = q[i].default;
}
if(q[i].action !== null){
answer = q[i].action(answer);
}
config_obj[q[i].json_key] = answer;
i++;
ask(i);
});
}
}
function writeConfigFile(obj){
var json = JSON.stringify(obj);
fs.writeFile(configFile, json, function(err){
if(err){
console.log(err);
} else{
console.log("Successfully wrote config file");
}
});
}