starlight-cli 1.0.1 → 1.0.3

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 (2) hide show
  1. package/install.js +24 -27
  2. package/package.json +1 -1
package/install.js CHANGED
@@ -1,3 +1,4 @@
1
+ #!/usr/bin/env node
1
2
  const https = require('https');
2
3
  const fs = require('fs');
3
4
  const path = require('path');
@@ -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
- // Handle GitHub redirects properly
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 (res.statusCode === 302 || res.statusCode === 301) {
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,27 @@ function download(url, dest) {
44
38
  });
45
39
  }
46
40
 
47
- download(DOWNLOAD_URL, EXE_PATH)
48
- .then(() => {
49
- console.log('Downloaded to:', EXE_PATH);
41
+ (async () => {
42
+ try {
43
+ await download(DOWNLOAD_URL, EXE_PATH);
44
+ console.log(`Downloaded to: ${EXE_PATH}`);
50
45
 
51
- // Add to PATH (Windows)
46
+ // Add to PATH permanently
52
47
  try {
53
- execSync(
54
- `setx PATH "%PATH%;${INSTALL_DIR}"`,
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.log('PATH update skipped (may already exist)');
51
+ console.warn('Could not update PATH permanently (may already exist or too long).');
60
52
  }
61
53
 
62
- console.log('Starlight installed successfully');
63
- })
64
- .catch(err => {
65
- console.error('Download error:', err.message);
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
+ console.log('Starlight installation completed successfully!');
59
+ process.exit(0);
60
+ } catch (err) {
61
+ console.error('Download or installation failed:', err.message);
66
62
  process.exit(1);
67
- });
63
+ }
64
+ })();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "starlight-cli",
3
- "version": "1.0.1",
3
+ "version": "1.0.3",
4
4
  "description": "Starlight Programming Language CLI",
5
5
  "bin": {
6
6
  "starlight": "index.js"