-
Notifications
You must be signed in to change notification settings - Fork 309
/
init.js
74 lines (65 loc) · 2.12 KB
/
init.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
const inquirer = require('inquirer');
const fs = require('fs');
const path = './config/userconfig.js';
const goodchars = /^[1-9a-km-zA-HJ-NP-Z]+$/;
const questions = [
{
type: 'input',
name: 'ipaddr',
message: 'What is your Flux IP address?',
},
{
type: 'input',
name: 'zelid',
message: 'Flux uses FluxID system for authentication and verification purposes. What is your FluxID?',
},
];
function showQuestions() {
if (fs.existsSync(path)) {
console.log('Configuration file found. You can change your configuration in ./config/userconfig.js');
console.log('Starting Flux...');
return;
}
inquirer.prompt(questions).then((answers) => {
console.log(`IP address: ${answers.ipaddr}`);
console.log(`FluxID: ${answers.zelid}`);
if (answers.ipaddr.length < 5 || (answers.ipaddr.indexOf('.') === -1 && answers.ipaddr.indexOf(':') === -1)) {
console.log('IP address is NOT valid!');
return showQuestions();
}
if (!goodchars.test(answers.zelid) || answers.zelid[0] !== '1' || answers.zelid.length > 34 || answers.zelid.length < 25) {
console.log('FluxID is NOT valid!');
return showQuestions();
}
if (answers.ipaddr.includes(':')) {
if (!answers.ipaddr.includes('[')) {
// eslint-disable-next-line no-param-reassign
answers.ipaddr = `[${answers.ipaddr}`;
}
if (!answers.ipaddr.includes(']')) {
// eslint-disable-next-line no-param-reassign
answers.ipaddr = `${answers.ipaddr}]`;
}
}
const dataToWrite = `module.exports = {
initial: {
ipaddress: '${answers.ipaddr}',
zelid: '${answers.zelid}',
testnet: false,
development: false,
apiport: 16127,
pgpPrivateKey: '',
pgpPublicKey: '',
}
}`;
const userconfig = fs.createWriteStream(path);
userconfig.once('open', () => {
userconfig.write(dataToWrite);
userconfig.end();
});
console.log('Configuration successful. The values have saved and can be changed in ./config/userconfig.js');
console.log('Starting Flux...');
return 0;
});
}
showQuestions();