starlight-cli 1.0.0 → 1.0.2

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.
Files changed (3) hide show
  1. package/index.js +2 -13
  2. package/install.js +54 -45
  3. package/package.json +4 -2
package/index.js CHANGED
@@ -1,18 +1,7 @@
1
1
  #!/usr/bin/env node
2
-
3
2
  const { spawn } = require('child_process');
4
- const path = require('path');
5
- const fs = require('fs');
6
-
7
- const exePath = 'C:\\Starlight\\starlight.exe';
8
-
9
- if (!fs.existsSync(exePath)) {
10
- console.error('Starlight is not installed correctly.');
11
- console.error('Please reinstall: npm install -g starlight-cli');
12
- process.exit(1);
13
- }
14
3
 
15
- spawn(exePath, process.argv.slice(2), {
4
+ spawn('starlight.exe', process.argv.slice(2), {
16
5
  stdio: 'inherit',
17
- windowsHide: false
6
+ shell: true
18
7
  });
package/install.js CHANGED
@@ -1,58 +1,67 @@
1
+ #!/usr/bin/env node
1
2
  const https = require('https');
2
3
  const fs = require('fs');
3
4
  const path = require('path');
4
- const { execSync } = require('child_process');
5
+ const { spawn, execSync } = require('child_process');
5
6
 
6
- const INSTALL_DIR = 'C:\\Starlight';
7
+ const DOWNLOAD_URL =
8
+ 'https://github.com/developerdominex/dominexmacedon/releases/download/programming/starlight.exe';
9
+
10
+ const INSTALL_DIR = 'C:\\Starlight\\bin';
7
11
  const EXE_PATH = path.join(INSTALL_DIR, 'starlight.exe');
8
- const EXE_URL = 'https://github.com/developerdominex/dominexmacedon/releases/download/programming/starlight.exe';
9
12
 
10
- function addToPath(dir) {
11
- try {
12
- const currentPath = execSync(
13
- 'powershell -Command "[Environment]::GetEnvironmentVariable(\'Path\', \'User\')"',
14
- { encoding: 'utf8' }
15
- ).trim();
16
-
17
- if (!currentPath.includes(dir)) {
18
- execSync(
19
- `powershell -Command "[Environment]::SetEnvironmentVariable('Path', '${currentPath};${dir}', 'User')"`
20
- );
21
- console.log('Added Starlight to PATH.');
22
- console.log('Restart your terminal to use it.');
23
- }
24
- } catch {
25
- console.warn('Could not modify PATH automatically.');
26
- }
27
- }
13
+ // Ensure install directory exists
14
+ fs.mkdirSync(INSTALL_DIR, { recursive: true });
28
15
 
29
- if (!fs.existsSync(INSTALL_DIR)) {
30
- fs.mkdirSync(INSTALL_DIR, { recursive: true });
31
- }
16
+ console.log('Downloading Starlight...');
17
+
18
+ function download(url, dest) {
19
+ return new Promise((resolve, reject) => {
20
+ https.get(url, res => {
21
+ if ([301, 302].includes(res.statusCode)) {
22
+ return download(res.headers.location, dest).then(resolve).catch(reject);
23
+ }
24
+ if (res.statusCode !== 200) {
25
+ reject(new Error(`HTTP ${res.statusCode}`));
26
+ return;
27
+ }
32
28
 
33
- if (fs.existsSync(EXE_PATH)) {
34
- console.log('Starlight already installed.');
35
- addToPath(INSTALL_DIR);
36
- process.exit(0);
29
+ const file = fs.createWriteStream(dest);
30
+ res.pipe(file);
31
+
32
+ file.on('finish', () => file.close(resolve));
33
+ file.on('error', err => {
34
+ fs.unlinkSync(dest);
35
+ reject(err);
36
+ });
37
+ }).on('error', reject);
38
+ });
37
39
  }
38
40
 
39
- console.log('Downloading Starlight...');
41
+ (async () => {
42
+ try {
43
+ await download(DOWNLOAD_URL, EXE_PATH);
44
+ console.log(`Downloaded to: ${EXE_PATH}`);
40
45
 
41
- https.get(EXE_URL, res => {
42
- if (res.statusCode !== 200) {
43
- console.error('Failed to download Starlight.');
44
- process.exit(1);
45
- }
46
+ // Add to PATH permanently
47
+ try {
48
+ execSync(`setx PATH "%PATH%;${INSTALL_DIR}"`, { stdio: 'ignore' });
49
+ console.log('PATH updated for future sessions.');
50
+ } catch {
51
+ console.warn('Could not update PATH permanently (may already exist or too long).');
52
+ }
46
53
 
47
- const file = fs.createWriteStream(EXE_PATH);
48
- res.pipe(file);
54
+ // Add to PATH for current session
55
+ process.env.PATH = `${INSTALL_DIR};${process.env.PATH}`;
56
+ console.log('PATH updated for current session.');
49
57
 
50
- file.on('finish', () => {
51
- file.close();
52
- console.log('Starlight installed to C:\\Starlight');
53
- addToPath(INSTALL_DIR);
54
- });
55
- }).on('error', err => {
56
- console.error('Download error:', err.message);
57
- process.exit(1);
58
- });
58
+ // Spawn starlight.exe with CLI arguments
59
+ const args = process.argv.slice(2);
60
+ const starlightProcess = spawn(EXE_PATH, args, { stdio: 'inherit', shell: true });
61
+
62
+ starlightProcess.on('exit', code => process.exit(code));
63
+ } catch (err) {
64
+ console.error('Download or installation failed:', err.message);
65
+ process.exit(1);
66
+ }
67
+ })();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "starlight-cli",
3
- "version": "1.0.0",
3
+ "version": "1.0.2",
4
4
  "description": "Starlight Programming Language CLI",
5
5
  "bin": {
6
6
  "starlight": "index.js"
@@ -10,5 +10,7 @@
10
10
  },
11
11
  "author": "Macedon",
12
12
  "license": "MIT",
13
- "os": ["win32"]
13
+ "os": [
14
+ "win32"
15
+ ]
14
16
  }