aionix 1.0.5 → 1.0.7

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 CHANGED
@@ -2,7 +2,13 @@
2
2
  'use strict';
3
3
 
4
4
  const chalk = require('chalk');
5
- const net = require('net');
5
+ const readline = require('readline');
6
+ const fs = require('fs');
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,35 +17,75 @@ console.log(chalk.cyan.bold(`
11
17
  +==============================+
12
18
  `));
13
19
 
14
- // Check which ports are in use
15
- async function checkPort(port) {
16
- return new Promise((resolve) => {
17
- const server = net.createServer();
18
- server.listen(port, () => {
19
- server.close(() => resolve(false)); // free
20
- });
21
- server.on('error', () => resolve(true)); // in use
22
- });
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));
23
32
  }
24
33
 
25
- async function showPortStatus() {
26
- const ports = [3000, 3001, 3002, 3003, 3004];
27
- console.log(chalk.yellow('\nšŸ“” Port Status:'));
28
- for (const port of ports) {
29
- const inUse = await checkPort(port);
30
- if (inUse) {
31
- console.log(chalk.red(` ā— ${port} — IN USE`));
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'));
32
67
  } else {
33
- console.log(chalk.green(` ā—‹ ${port} — free`));
68
+ console.log(chalk.cyan(` echo "alias ${finalAlias}='aionix'" >> ~/.bashrc && source ~/.bashrc\n`));
34
69
  }
35
70
  }
36
- console.log('');
37
- }
38
71
 
39
- async function main() {
40
- await showPortStatus();
41
- console.log(chalk.green('Starting server...'));
42
- require('../server/app');
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
+ });
43
89
  }
44
90
 
45
- main();
91
+ setup().catch(e => { console.error(e); rl.close(); process.exit(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); });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "aionix",
3
- "version": "1.0.5",
3
+ "version": "1.0.7",
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
- getPort(3000).then(PORT => {
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
- console.log(chalk.yellow('Opening browser...'));
42
- await open(`http://localhost:${PORT}`);
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