aionix 1.0.6 ā 1.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/install.js +89 -0
- package/package.json +1 -1
package/bin/install.js
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
const chalk = require('chalk');
|
|
5
|
+
const readline = require('readline');
|
|
6
|
+
const fs = require('fs');
|
|
7
|
+
const os = require('os');
|
|
8
|
+
const path = require('path');
|
|
9
|
+
|
|
10
|
+
const CONFIG_DIR = path.join(os.homedir(), '.aionix');
|
|
11
|
+
const CONFIG_FILE = path.join(CONFIG_DIR, 'config.json');
|
|
12
|
+
|
|
13
|
+
console.log(chalk.cyan.bold(`
|
|
14
|
+
+==============================+
|
|
15
|
+
| š AIONIX |
|
|
16
|
+
| Offline Developer Toolkit |
|
|
17
|
+
+==============================+
|
|
18
|
+
`));
|
|
19
|
+
|
|
20
|
+
console.log(chalk.green('ā
AIONIX successfully installed!\n'));
|
|
21
|
+
|
|
22
|
+
let config = {};
|
|
23
|
+
try {
|
|
24
|
+
if (fs.existsSync(CONFIG_FILE)) {
|
|
25
|
+
config = JSON.parse(fs.readFileSync(CONFIG_FILE, 'utf8'));
|
|
26
|
+
}
|
|
27
|
+
} catch(e) {}
|
|
28
|
+
|
|
29
|
+
const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
|
|
30
|
+
function question(q) {
|
|
31
|
+
return new Promise(resolve => rl.question(q, resolve));
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
async function setup() {
|
|
35
|
+
console.log(chalk.yellow('āļø Quick Setup\n'));
|
|
36
|
+
|
|
37
|
+
const name = await question(chalk.white('š¤ Your name: '));
|
|
38
|
+
const port = await question(chalk.white('š Preferred port (default 3000): '));
|
|
39
|
+
const alias = await question(chalk.white('ā” Custom command alias (default: aionix): '));
|
|
40
|
+
const autoOpen = await question(chalk.white('š Auto open browser? (y/n, default y): '));
|
|
41
|
+
|
|
42
|
+
const finalPort = port.trim() || '3000';
|
|
43
|
+
const finalAlias = alias.trim() || 'aionix';
|
|
44
|
+
const finalName = name.trim() || 'Developer';
|
|
45
|
+
const finalAutoOpen = autoOpen.trim().toLowerCase() !== 'n';
|
|
46
|
+
|
|
47
|
+
config = {
|
|
48
|
+
name: finalName,
|
|
49
|
+
port: parseInt(finalPort),
|
|
50
|
+
alias: finalAlias,
|
|
51
|
+
autoOpen: finalAutoOpen,
|
|
52
|
+
installedAt: new Date().toISOString()
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
if (!fs.existsSync(CONFIG_DIR)) fs.mkdirSync(CONFIG_DIR, { recursive: true });
|
|
56
|
+
fs.writeFileSync(CONFIG_FILE, JSON.stringify(config, null, 2));
|
|
57
|
+
|
|
58
|
+
console.log(chalk.green('\nā
Config saved!'));
|
|
59
|
+
console.log(chalk.gray(`š ${CONFIG_FILE}\n`));
|
|
60
|
+
|
|
61
|
+
if (finalAlias !== 'aionix') {
|
|
62
|
+
console.log(chalk.yellow(`š” To use "${finalAlias}" as your command:`));
|
|
63
|
+
const isWindows = process.platform === 'win32';
|
|
64
|
+
if (isWindows) {
|
|
65
|
+
console.log(chalk.cyan(` doskey ${finalAlias}=aionix`));
|
|
66
|
+
} else {
|
|
67
|
+
console.log(chalk.cyan(` echo "alias ${finalAlias}='aionix'" >> ~/.bashrc && source ~/.bashrc\n`));
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
rl.close();
|
|
72
|
+
|
|
73
|
+
const rl2 = readline.createInterface({ input: process.stdin, output: process.stdout });
|
|
74
|
+
rl2.question(chalk.yellow('\nš Launch AIONIX now? (y/n, default y): '), (ans) => {
|
|
75
|
+
rl2.close();
|
|
76
|
+
if (ans.trim().toLowerCase() !== 'n') {
|
|
77
|
+
console.log(chalk.green('\nStarting server...'));
|
|
78
|
+
process.env.AIONIX_PORT = config.port || 3000;
|
|
79
|
+
process.env.AIONIX_AUTO_OPEN = config.autoOpen ? 'true' : 'false';
|
|
80
|
+
require('../server/app');
|
|
81
|
+
} else {
|
|
82
|
+
console.log(chalk.cyan('\nš Run anytime:'), chalk.white.bold('aionix'));
|
|
83
|
+
console.log(chalk.cyan('āļø Edit config:'), chalk.white.bold('aionix --config\n'));
|
|
84
|
+
process.exit(0);
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
setup().catch(e => { console.error(e); rl.close(); process.exit(1); });
|