-
Notifications
You must be signed in to change notification settings - Fork 1
/
install.js
81 lines (63 loc) · 2.41 KB
/
install.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
'use strict';
const exec = require(`child_process`).exec;
const readline = require(`readline`);
const spinner = {
interval: null,
text:``,
start: (text) => {
const symbols = [`⠋`, `⠙`, `⠹`, `⠸`, `⠼`, `⠴`, `⠦`, `⠧`, `⠇`, `⠏`];
spinner.text = text;
spinner.interval = setInterval(() => {
symbols.push(symbols.shift());
readline.clearLine(process.stdout, 0);
readline.cursorTo(process.stdout, 0);
process.stdout.write(`${symbols[0]} ${text}`);
}, 100)
},
stop: (symbol = '', text = spinner.text) => {;
clearInterval(spinner.interval);
readline.clearLine(process.stdout, 0);
readline.cursorTo(process.stdout, 0);
process.stdout.write(`${symbol} ${text}\n`);
},
succeed: (text) => {
spinner.stop('✔', text);
},
fail: (text) => {
spinner.stop('✘', text);
}
};
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
rl.question(`What is the name of your instance?\n`, (name) => {
spinner.start('Installing');
exec(`npm install`, (err, stdout, stderr) => {
spinner.succeed(`Installed core`);
spinner.start('Doing initial setup of core');
const nedb = require(`nedb`);
exec(`node index.js --upgrade-only`, (err, stdout, stderr) => {
if (stderr) {
spinner.fail(`Setup failed. Error: ${stderr}`);
rl.close();
} else {
spinner.succeed(`Core setup`);
spinner.start('Setting name');
const basePrefData = new nedb({ filename: 'base-prefs.db', autoload: true });
basePrefData.update({name: `name`}, {$set: {value: name}}, function() {
spinner.succeed(`Name set`);
spinner.start('Installing shell client');
exec(`cd interface/shell; npm install -g`, (err, stdout, stderr) => {
if (stderr) {
spinner.fail(`Shell client install failed. You may need to run \`sudo npm install -g\` inside the \`interface/shell\` directory`);
} else {
spinner.succeed(`Client installed`);
}
rl.close();
});
})
}
});
});
});