starlight-cli 1.0.1 → 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.
- package/install.js +28 -28
- package/package.json +1 -1
package/install.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
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
7
|
const DOWNLOAD_URL =
|
|
7
8
|
'https://github.com/developerdominex/dominexmacedon/releases/download/programming/starlight.exe';
|
|
@@ -9,21 +10,17 @@ const DOWNLOAD_URL =
|
|
|
9
10
|
const INSTALL_DIR = 'C:\\Starlight\\bin';
|
|
10
11
|
const EXE_PATH = path.join(INSTALL_DIR, 'starlight.exe');
|
|
11
12
|
|
|
12
|
-
console.log('Downloading Starlight...');
|
|
13
|
-
|
|
14
13
|
// Ensure install directory exists
|
|
15
14
|
fs.mkdirSync(INSTALL_DIR, { recursive: true });
|
|
16
15
|
|
|
17
|
-
|
|
16
|
+
console.log('Downloading Starlight...');
|
|
17
|
+
|
|
18
18
|
function download(url, dest) {
|
|
19
19
|
return new Promise((resolve, reject) => {
|
|
20
20
|
https.get(url, res => {
|
|
21
|
-
if (
|
|
22
|
-
return download(res.headers.location, dest)
|
|
23
|
-
.then(resolve)
|
|
24
|
-
.catch(reject);
|
|
21
|
+
if ([301, 302].includes(res.statusCode)) {
|
|
22
|
+
return download(res.headers.location, dest).then(resolve).catch(reject);
|
|
25
23
|
}
|
|
26
|
-
|
|
27
24
|
if (res.statusCode !== 200) {
|
|
28
25
|
reject(new Error(`HTTP ${res.statusCode}`));
|
|
29
26
|
return;
|
|
@@ -32,10 +29,7 @@ function download(url, dest) {
|
|
|
32
29
|
const file = fs.createWriteStream(dest);
|
|
33
30
|
res.pipe(file);
|
|
34
31
|
|
|
35
|
-
file.on('finish', () =>
|
|
36
|
-
file.close(resolve);
|
|
37
|
-
});
|
|
38
|
-
|
|
32
|
+
file.on('finish', () => file.close(resolve));
|
|
39
33
|
file.on('error', err => {
|
|
40
34
|
fs.unlinkSync(dest);
|
|
41
35
|
reject(err);
|
|
@@ -44,24 +38,30 @@ function download(url, dest) {
|
|
|
44
38
|
});
|
|
45
39
|
}
|
|
46
40
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
41
|
+
(async () => {
|
|
42
|
+
try {
|
|
43
|
+
await download(DOWNLOAD_URL, EXE_PATH);
|
|
44
|
+
console.log(`Downloaded to: ${EXE_PATH}`);
|
|
50
45
|
|
|
51
|
-
// Add to PATH
|
|
46
|
+
// Add to PATH permanently
|
|
52
47
|
try {
|
|
53
|
-
execSync(
|
|
54
|
-
|
|
55
|
-
{ stdio: 'ignore' }
|
|
56
|
-
);
|
|
57
|
-
console.log('Added Starlight to PATH');
|
|
48
|
+
execSync(`setx PATH "%PATH%;${INSTALL_DIR}"`, { stdio: 'ignore' });
|
|
49
|
+
console.log('PATH updated for future sessions.');
|
|
58
50
|
} catch {
|
|
59
|
-
console.
|
|
51
|
+
console.warn('Could not update PATH permanently (may already exist or too long).');
|
|
60
52
|
}
|
|
61
53
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
54
|
+
// Add to PATH for current session
|
|
55
|
+
process.env.PATH = `${INSTALL_DIR};${process.env.PATH}`;
|
|
56
|
+
console.log('PATH updated for current session.');
|
|
57
|
+
|
|
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);
|
|
66
65
|
process.exit(1);
|
|
67
|
-
}
|
|
66
|
+
}
|
|
67
|
+
})();
|