aionix 1.0.4 → 1.0.6
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/index.js +77 -2
- package/package.json +3 -2
- package/server/app.js +11 -8
package/bin/index.js
CHANGED
|
@@ -2,7 +2,13 @@
|
|
|
2
2
|
'use strict';
|
|
3
3
|
|
|
4
4
|
const chalk = require('chalk');
|
|
5
|
+
const readline = require('readline');
|
|
6
|
+
const fs = require('fs');
|
|
5
7
|
const path = require('path');
|
|
8
|
+
const os = require('os');
|
|
9
|
+
|
|
10
|
+
const CONFIG_DIR = path.join(os.homedir(), '.aionix');
|
|
11
|
+
const CONFIG_FILE = path.join(CONFIG_DIR, 'config.json');
|
|
6
12
|
|
|
7
13
|
console.log(chalk.cyan.bold(`
|
|
8
14
|
+==============================+
|
|
@@ -11,6 +17,75 @@ console.log(chalk.cyan.bold(`
|
|
|
11
17
|
+==============================+
|
|
12
18
|
`));
|
|
13
19
|
|
|
14
|
-
console.log(chalk.green('
|
|
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 on start? (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
|
+
console.log(chalk.gray(' (Run in terminal or add to AutoRun registry)\n'));
|
|
67
|
+
} else {
|
|
68
|
+
console.log(chalk.cyan(` echo "alias ${finalAlias}='aionix'" >> ~/.bashrc && source ~/.bashrc\n`));
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
rl.close();
|
|
73
|
+
|
|
74
|
+
// Ask to launch now
|
|
75
|
+
const rl2 = readline.createInterface({ input: process.stdin, output: process.stdout });
|
|
76
|
+
rl2.question(chalk.yellow(`🚀 Launch AIONIX now? (y/n, default y): `), (ans) => {
|
|
77
|
+
rl2.close();
|
|
78
|
+
if (ans.trim().toLowerCase() !== 'n') {
|
|
79
|
+
console.log(chalk.green('\nStarting server...'));
|
|
80
|
+
process.env.AIONIX_PORT = config.port || 3000;
|
|
81
|
+
process.env.AIONIX_AUTO_OPEN = config.autoOpen ? 'true' : 'false';
|
|
82
|
+
require('../server/app');
|
|
83
|
+
} else {
|
|
84
|
+
console.log(chalk.cyan('\n👉 Run anytime:'), chalk.white.bold('aionix'));
|
|
85
|
+
console.log(chalk.cyan('⚙️ Edit config:'), chalk.white.bold('aionix --config\n'));
|
|
86
|
+
process.exit(0);
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
}
|
|
15
90
|
|
|
16
|
-
|
|
91
|
+
setup().catch(e => { console.error(e); rl.close(); process.exit(1); });
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "aionix",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.6",
|
|
4
4
|
"description": "Offline Developer Toolkit - Learning, Tools & Productivity",
|
|
5
5
|
"main": "server/app.js",
|
|
6
6
|
"bin": {
|
|
@@ -30,6 +30,7 @@
|
|
|
30
30
|
"open": "^8.4.2"
|
|
31
31
|
},
|
|
32
32
|
"scripts": {
|
|
33
|
-
"start": "node ./bin/index.js"
|
|
33
|
+
"start": "node ./bin/index.js",
|
|
34
|
+
"postinstall": "node ./bin/install.js"
|
|
34
35
|
}
|
|
35
36
|
}
|
package/server/app.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
|
|
2
1
|
const express = require('express');
|
|
3
2
|
const path = require('path');
|
|
4
3
|
const open = require('open');
|
|
@@ -24,22 +23,26 @@ app.get('/', (req, res) => {
|
|
|
24
23
|
res.sendFile(path.join(__dirname, '../client/index.html'));
|
|
25
24
|
});
|
|
26
25
|
|
|
27
|
-
// Auto find available port
|
|
28
26
|
function getPort(start) {
|
|
29
27
|
return new Promise((resolve) => {
|
|
30
28
|
const server = net.createServer();
|
|
31
|
-
server.listen(start, () => {
|
|
32
|
-
server.close(() => resolve(start));
|
|
33
|
-
});
|
|
29
|
+
server.listen(start, () => { server.close(() => resolve(start)); });
|
|
34
30
|
server.on('error', () => resolve(getPort(start + 1)));
|
|
35
31
|
});
|
|
36
32
|
}
|
|
37
33
|
|
|
38
|
-
|
|
34
|
+
const preferredPort = parseInt(process.env.AIONIX_PORT) || 3000;
|
|
35
|
+
const autoOpen = process.env.AIONIX_AUTO_OPEN !== 'false';
|
|
36
|
+
|
|
37
|
+
getPort(preferredPort).then(PORT => {
|
|
39
38
|
app.listen(PORT, async () => {
|
|
40
39
|
console.log(chalk.green(`✅ Server running at http://localhost:${PORT}`));
|
|
41
|
-
|
|
42
|
-
|
|
40
|
+
if (autoOpen) {
|
|
41
|
+
console.log(chalk.yellow('Opening browser...'));
|
|
42
|
+
await open(`http://localhost:${PORT}`);
|
|
43
|
+
} else {
|
|
44
|
+
console.log(chalk.cyan(`👉 Open manually: http://localhost:${PORT}`));
|
|
45
|
+
}
|
|
43
46
|
});
|
|
44
47
|
});
|
|
45
48
|
|