forked from RunOnFlux/flux
-
Notifications
You must be signed in to change notification settings - Fork 0
/
init.js
73 lines (65 loc) · 2.1 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
const inquirer = require('inquirer');
const fs = require('fs');
const path = './config/userconfig.js';
const goodchars = /^[1-9a-km-zA-HJ-NP-Z]+$/;
if (fs.existsSync(path)) {
console.log('Configuration file found. You can change your configuration in ./config/userconfig.js');
console.log('Starting Flux...');
return;
}
const questions = [
{
type: 'input',
name: 'ipaddr',
message: 'What is your Flux IP address?',
},
{
type: 'input',
name: 'zelid',
message: 'Flux uses ZelID system for authentication and verification purposes. What is your ZelID?',
},
];
function showQuestions() {
inquirer.prompt(questions).then((answers) => {
console.log(`IP address: ${answers.ipaddr}`);
console.log(`ZelID: ${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('ZelID 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();