starlight-cli 1.0.9 → 1.0.11

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/dist/index.js CHANGED
@@ -2454,7 +2454,7 @@ const Lexer = __nccwpck_require__(211);
2454
2454
  const Parser = __nccwpck_require__(222);
2455
2455
  const Evaluator = __nccwpck_require__(112);
2456
2456
 
2457
- const VERSION = '1.0.9';
2457
+ const VERSION = '1.0.11';
2458
2458
 
2459
2459
  const COLOR = {
2460
2460
  reset: '\x1b[0m',
@@ -2501,11 +2501,12 @@ if (args.length === 0) {
2501
2501
  Starlight Programming Language
2502
2502
 
2503
2503
  Usage:
2504
- starlight <file.sl> Run a Starlight program
2505
- starlight -v Show version
2506
- starlight --help Show help
2507
- starlight --learn Open learning guide
2508
- starlight --writedirectly Write and run temporary code
2504
+ starlight <file.sl> Run a Starlight program
2505
+ starlight -v Show version
2506
+ starlight --help Show help
2507
+ starlight --learn Open learning guide
2508
+ starlight --writedirectly Write and run temporary code
2509
+ starlight --viewfilelist View SL files in a folder
2509
2510
  `);
2510
2511
  process.exit(0);
2511
2512
  }
@@ -2520,19 +2521,39 @@ if (args[0] === '--help') {
2520
2521
  Starlight CLI Help
2521
2522
 
2522
2523
  Commands:
2523
- starlight file.sl Run a Starlight program
2524
- starlight -v Show version
2525
- starlight --learn Open learning guide
2526
- starlight --writedirectly Write & run temporary code
2524
+ starlight file.sl Run a Starlight program
2525
+ starlight -v Show version
2526
+ starlight --learn Open learning guide
2527
+ starlight --writedirectly Write & run temporary code
2528
+ starlight --viewfilelist View SL files in a folder
2527
2529
  `);
2528
2530
  process.exit(0);
2529
2531
  }
2532
+
2530
2533
  if (args[0] === '--learn') {
2531
2534
  console.log(COLOR.cyan + 'Opening Starlight Learning Guide...' + COLOR.reset);
2532
2535
  exec('start https://programming-lang.pages.dev/learning-guide');
2533
2536
  process.exit(0);
2534
2537
  }
2535
2538
 
2539
+ if (args[0] === '--viewfilelist') {
2540
+ const readlineSync = __nccwpck_require__(552);
2541
+ let folderPath = readlineSync.question(COLOR.cyan + 'Paste folder path to search .sl files: ' + COLOR.reset).trim();
2542
+ if (!folderPath) return waitAndExit(0);
2543
+
2544
+ if (!fs.existsSync(folderPath) || !fs.lstatSync(folderPath).isDirectory()) {
2545
+ return fatal('Invalid folder path.');
2546
+ }
2547
+
2548
+ const files = fs.readdirSync(folderPath).filter(f => f.endsWith('.sl'));
2549
+ if (files.length === 0) console.log(COLOR.yellow + 'No .sl files found in folder.' + COLOR.reset);
2550
+ else {
2551
+ console.log(COLOR.green + `Found ${files.length} .sl files:` + COLOR.reset);
2552
+ files.forEach(f => console.log(' ' + f));
2553
+ }
2554
+ return waitAndExit(0);
2555
+ }
2556
+
2536
2557
  if (args[0] === '--writedirectly') {
2537
2558
  const readline = __nccwpck_require__(785);
2538
2559
  const tempFile = path.join(os.tmpdir(), `starlight-temp-${Date.now()}.sl`);
@@ -2547,20 +2568,19 @@ if (args[0] === '--writedirectly') {
2547
2568
  });
2548
2569
 
2549
2570
  let lines = [];
2550
-
2551
2571
  rl.prompt();
2552
2572
 
2553
2573
  rl.on('line', (line) => {
2554
2574
  if (line.trim() === ':run') {
2555
2575
  rl.close();
2556
2576
  fs.writeFileSync(tempFile, lines.join('\n'), 'utf8');
2557
- runFile(tempFile, true);
2577
+ runFile(tempFile, true, () => saveTempFilePrompt(lines));
2558
2578
  return;
2559
2579
  }
2560
2580
 
2561
2581
  let coloredLine = line
2562
- .replace(/"(.*?)"/g, COLOR.yellow + '"$1"' + COLOR.reset)
2563
- .replace(/\b(sldeploy|import|from|const|let|var|if|else|for|while)\b/g, COLOR.blue + '$1' + COLOR.reset);
2582
+ .replace(/"(.*?)"/g, COLOR.yellow + '"$1"' + COLOR.reset)
2583
+ .replace(/\b(sldeploy|import|from|const|let|var|if|else|for|while|func|return|break|continue|define|ask)\b/g, COLOR.blue + '$1' + COLOR.reset);
2564
2584
 
2565
2585
  console.log(coloredLine);
2566
2586
 
@@ -2571,7 +2591,29 @@ if (args[0] === '--writedirectly') {
2571
2591
  return;
2572
2592
  }
2573
2593
 
2574
- function runFile(filePath, isTemp = false) {
2594
+ function saveTempFilePrompt(lines) {
2595
+ const readlineSync = __nccwpck_require__(552);
2596
+ let saveChoice = readlineSync.question(COLOR.cyan + 'Do you want to save this code? (y/n): ' + COLOR.reset).trim().toLowerCase();
2597
+ if (saveChoice !== 'y') return;
2598
+
2599
+ let folderPath = readlineSync.question(COLOR.cyan + 'Paste folder path to save (C:/ or D:/...): ' + COLOR.reset).trim();
2600
+ if (!folderPath || !fs.existsSync(folderPath) || !fs.lstatSync(folderPath).isDirectory()) return console.log(COLOR.yellow + 'Skipping save.' + COLOR.reset);
2601
+
2602
+ let fileName = readlineSync.question(COLOR.cyan + 'Enter file name (without extension): ' + COLOR.reset).trim();
2603
+ if (!fileName) return console.log(COLOR.yellow + 'Skipping save.' + COLOR.reset);
2604
+
2605
+ let fullPath = path.join(folderPath, fileName.endsWith('.sl') ? fileName : fileName + '.sl');
2606
+ while (fs.existsSync(fullPath)) {
2607
+ fileName = readlineSync.question(COLOR.red + 'File exists! Enter a new name (or leave blank to cancel): ' + COLOR.reset).trim();
2608
+ if (!fileName) return console.log(COLOR.yellow + 'Skipping save.' + COLOR.reset);
2609
+ fullPath = path.join(folderPath, fileName.endsWith('.sl') ? fileName : fileName + '.sl');
2610
+ }
2611
+
2612
+ fs.writeFileSync(fullPath, lines.join('\n'), 'utf8');
2613
+ console.log(COLOR.green + `Saved to ${fullPath}` + COLOR.reset);
2614
+ }
2615
+
2616
+ function runFile(filePath, isTemp = false, callback = null) {
2575
2617
  if (!fs.existsSync(filePath)) {
2576
2618
  return fatal(`File not found: ${filePath}`);
2577
2619
  }
@@ -2591,11 +2633,7 @@ function runFile(filePath, isTemp = false) {
2591
2633
  console.error(COLOR.red + COLOR.bold + 'Starlight Lexer Error' + COLOR.reset);
2592
2634
  console.error(COLOR.cyan + `File: ${filePath}` + COLOR.reset);
2593
2635
  console.error(COLOR.yellow + `Message: ${err.message}` + COLOR.reset);
2594
-
2595
- if (err.line && err.column) {
2596
- printSourceContext(code, err.line, err.column);
2597
- }
2598
-
2636
+ if (err.line && err.column) printSourceContext(code, err.line, err.column);
2599
2637
  return waitAndExit(1);
2600
2638
  }
2601
2639
 
@@ -2607,11 +2645,7 @@ function runFile(filePath, isTemp = false) {
2607
2645
  console.error(COLOR.red + COLOR.bold + 'Starlight Parser Error' + COLOR.reset);
2608
2646
  console.error(COLOR.cyan + `File: ${filePath}` + COLOR.reset);
2609
2647
  console.error(COLOR.yellow + `Message: ${err.message}` + COLOR.reset);
2610
-
2611
- if (err.token && err.token.line && err.token.column) {
2612
- printSourceContext(code, err.token.line, err.token.column);
2613
- }
2614
-
2648
+ if (err.token && err.token.line && err.token.column) printSourceContext(code, err.token.line, err.token.column);
2615
2649
  return waitAndExit(1);
2616
2650
  }
2617
2651
 
@@ -2622,19 +2656,13 @@ function runFile(filePath, isTemp = false) {
2622
2656
  console.error(COLOR.red + COLOR.bold + 'Starlight Runtime Error' + COLOR.reset);
2623
2657
  console.error(COLOR.cyan + `File: ${filePath}` + COLOR.reset);
2624
2658
  console.error(COLOR.yellow + `Message: ${err.message}` + COLOR.reset);
2625
-
2626
- if (err.line && err.column) {
2627
- printSourceContext(code, err.line, err.column);
2628
- }
2629
-
2659
+ if (err.line && err.column) printSourceContext(code, err.line, err.column);
2630
2660
  return waitAndExit(1);
2631
2661
  }
2632
2662
 
2633
- console.log(
2634
- COLOR.green +
2635
- '\nProgram finished successfully.' +
2636
- COLOR.reset
2637
- );
2663
+ console.log(COLOR.green + '\nProgram finished successfully.' + COLOR.reset);
2664
+
2665
+ if (callback) callback();
2638
2666
 
2639
2667
  if (isTemp) {
2640
2668
  try { fs.unlinkSync(filePath); } catch {}
@@ -2642,7 +2670,10 @@ function runFile(filePath, isTemp = false) {
2642
2670
 
2643
2671
  waitAndExit(0);
2644
2672
  }
2645
- runFile(path.resolve(args[0]));
2673
+
2674
+ if (!['--writedirectly', '--viewfilelist', '--learn', '--help', '-v', '--version'].includes(args[0])) {
2675
+ runFile(path.resolve(args[0]));
2676
+ }
2646
2677
 
2647
2678
  module.exports = __webpack_exports__;
2648
2679
  /******/ })()
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "starlight-cli",
3
- "version": "1.0.9",
3
+ "version": "1.0.11",
4
4
  "description": "Starlight Programming Language CLI",
5
5
  "bin": {
6
6
  "starlight": "index.js"
package/src/starlight.js CHANGED
@@ -7,7 +7,7 @@ const Lexer = require('./lexer');
7
7
  const Parser = require('./parser');
8
8
  const Evaluator = require('./evaluator');
9
9
 
10
- const VERSION = '1.0.9';
10
+ const VERSION = '1.0.11';
11
11
 
12
12
  const COLOR = {
13
13
  reset: '\x1b[0m',
@@ -54,11 +54,12 @@ if (args.length === 0) {
54
54
  Starlight Programming Language
55
55
 
56
56
  Usage:
57
- starlight <file.sl> Run a Starlight program
58
- starlight -v Show version
59
- starlight --help Show help
60
- starlight --learn Open learning guide
61
- starlight --writedirectly Write and run temporary code
57
+ starlight <file.sl> Run a Starlight program
58
+ starlight -v Show version
59
+ starlight --help Show help
60
+ starlight --learn Open learning guide
61
+ starlight --writedirectly Write and run temporary code
62
+ starlight --viewfilelist View SL files in a folder
62
63
  `);
63
64
  process.exit(0);
64
65
  }
@@ -73,19 +74,39 @@ if (args[0] === '--help') {
73
74
  Starlight CLI Help
74
75
 
75
76
  Commands:
76
- starlight file.sl Run a Starlight program
77
- starlight -v Show version
78
- starlight --learn Open learning guide
79
- starlight --writedirectly Write & run temporary code
77
+ starlight file.sl Run a Starlight program
78
+ starlight -v Show version
79
+ starlight --learn Open learning guide
80
+ starlight --writedirectly Write & run temporary code
81
+ starlight --viewfilelist View SL files in a folder
80
82
  `);
81
83
  process.exit(0);
82
84
  }
85
+
83
86
  if (args[0] === '--learn') {
84
87
  console.log(COLOR.cyan + 'Opening Starlight Learning Guide...' + COLOR.reset);
85
88
  exec('start https://programming-lang.pages.dev/learning-guide');
86
89
  process.exit(0);
87
90
  }
88
91
 
92
+ if (args[0] === '--viewfilelist') {
93
+ const readlineSync = require('readline-sync');
94
+ let folderPath = readlineSync.question(COLOR.cyan + 'Paste folder path to search .sl files: ' + COLOR.reset).trim();
95
+ if (!folderPath) return waitAndExit(0);
96
+
97
+ if (!fs.existsSync(folderPath) || !fs.lstatSync(folderPath).isDirectory()) {
98
+ return fatal('Invalid folder path.');
99
+ }
100
+
101
+ const files = fs.readdirSync(folderPath).filter(f => f.endsWith('.sl'));
102
+ if (files.length === 0) console.log(COLOR.yellow + 'No .sl files found in folder.' + COLOR.reset);
103
+ else {
104
+ console.log(COLOR.green + `Found ${files.length} .sl files:` + COLOR.reset);
105
+ files.forEach(f => console.log(' ' + f));
106
+ }
107
+ return waitAndExit(0);
108
+ }
109
+
89
110
  if (args[0] === '--writedirectly') {
90
111
  const readline = require('readline');
91
112
  const tempFile = path.join(os.tmpdir(), `starlight-temp-${Date.now()}.sl`);
@@ -100,20 +121,19 @@ if (args[0] === '--writedirectly') {
100
121
  });
101
122
 
102
123
  let lines = [];
103
-
104
124
  rl.prompt();
105
125
 
106
126
  rl.on('line', (line) => {
107
127
  if (line.trim() === ':run') {
108
128
  rl.close();
109
129
  fs.writeFileSync(tempFile, lines.join('\n'), 'utf8');
110
- runFile(tempFile, true);
130
+ runFile(tempFile, true, () => saveTempFilePrompt(lines));
111
131
  return;
112
132
  }
113
133
 
114
134
  let coloredLine = line
115
- .replace(/"(.*?)"/g, COLOR.yellow + '"$1"' + COLOR.reset)
116
- .replace(/\b(sldeploy|import|from|const|let|var|if|else|for|while)\b/g, COLOR.blue + '$1' + COLOR.reset);
135
+ .replace(/"(.*?)"/g, COLOR.yellow + '"$1"' + COLOR.reset)
136
+ .replace(/\b(sldeploy|import|from|const|let|var|if|else|for|while|func|return|break|continue|define|ask)\b/g, COLOR.blue + '$1' + COLOR.reset);
117
137
 
118
138
  console.log(coloredLine);
119
139
 
@@ -124,7 +144,29 @@ if (args[0] === '--writedirectly') {
124
144
  return;
125
145
  }
126
146
 
127
- function runFile(filePath, isTemp = false) {
147
+ function saveTempFilePrompt(lines) {
148
+ const readlineSync = require('readline-sync');
149
+ let saveChoice = readlineSync.question(COLOR.cyan + 'Do you want to save this code? (y/n): ' + COLOR.reset).trim().toLowerCase();
150
+ if (saveChoice !== 'y') return;
151
+
152
+ let folderPath = readlineSync.question(COLOR.cyan + 'Paste folder path to save (C:/ or D:/...): ' + COLOR.reset).trim();
153
+ if (!folderPath || !fs.existsSync(folderPath) || !fs.lstatSync(folderPath).isDirectory()) return console.log(COLOR.yellow + 'Skipping save.' + COLOR.reset);
154
+
155
+ let fileName = readlineSync.question(COLOR.cyan + 'Enter file name (without extension): ' + COLOR.reset).trim();
156
+ if (!fileName) return console.log(COLOR.yellow + 'Skipping save.' + COLOR.reset);
157
+
158
+ let fullPath = path.join(folderPath, fileName.endsWith('.sl') ? fileName : fileName + '.sl');
159
+ while (fs.existsSync(fullPath)) {
160
+ fileName = readlineSync.question(COLOR.red + 'File exists! Enter a new name (or leave blank to cancel): ' + COLOR.reset).trim();
161
+ if (!fileName) return console.log(COLOR.yellow + 'Skipping save.' + COLOR.reset);
162
+ fullPath = path.join(folderPath, fileName.endsWith('.sl') ? fileName : fileName + '.sl');
163
+ }
164
+
165
+ fs.writeFileSync(fullPath, lines.join('\n'), 'utf8');
166
+ console.log(COLOR.green + `Saved to ${fullPath}` + COLOR.reset);
167
+ }
168
+
169
+ function runFile(filePath, isTemp = false, callback = null) {
128
170
  if (!fs.existsSync(filePath)) {
129
171
  return fatal(`File not found: ${filePath}`);
130
172
  }
@@ -144,11 +186,7 @@ function runFile(filePath, isTemp = false) {
144
186
  console.error(COLOR.red + COLOR.bold + 'Starlight Lexer Error' + COLOR.reset);
145
187
  console.error(COLOR.cyan + `File: ${filePath}` + COLOR.reset);
146
188
  console.error(COLOR.yellow + `Message: ${err.message}` + COLOR.reset);
147
-
148
- if (err.line && err.column) {
149
- printSourceContext(code, err.line, err.column);
150
- }
151
-
189
+ if (err.line && err.column) printSourceContext(code, err.line, err.column);
152
190
  return waitAndExit(1);
153
191
  }
154
192
 
@@ -160,11 +198,7 @@ function runFile(filePath, isTemp = false) {
160
198
  console.error(COLOR.red + COLOR.bold + 'Starlight Parser Error' + COLOR.reset);
161
199
  console.error(COLOR.cyan + `File: ${filePath}` + COLOR.reset);
162
200
  console.error(COLOR.yellow + `Message: ${err.message}` + COLOR.reset);
163
-
164
- if (err.token && err.token.line && err.token.column) {
165
- printSourceContext(code, err.token.line, err.token.column);
166
- }
167
-
201
+ if (err.token && err.token.line && err.token.column) printSourceContext(code, err.token.line, err.token.column);
168
202
  return waitAndExit(1);
169
203
  }
170
204
 
@@ -175,19 +209,13 @@ function runFile(filePath, isTemp = false) {
175
209
  console.error(COLOR.red + COLOR.bold + 'Starlight Runtime Error' + COLOR.reset);
176
210
  console.error(COLOR.cyan + `File: ${filePath}` + COLOR.reset);
177
211
  console.error(COLOR.yellow + `Message: ${err.message}` + COLOR.reset);
178
-
179
- if (err.line && err.column) {
180
- printSourceContext(code, err.line, err.column);
181
- }
182
-
212
+ if (err.line && err.column) printSourceContext(code, err.line, err.column);
183
213
  return waitAndExit(1);
184
214
  }
185
215
 
186
- console.log(
187
- COLOR.green +
188
- '\nProgram finished successfully.' +
189
- COLOR.reset
190
- );
216
+ console.log(COLOR.green + '\nProgram finished successfully.' + COLOR.reset);
217
+
218
+ if (callback) callback();
191
219
 
192
220
  if (isTemp) {
193
221
  try { fs.unlinkSync(filePath); } catch {}
@@ -195,4 +223,7 @@ function runFile(filePath, isTemp = false) {
195
223
 
196
224
  waitAndExit(0);
197
225
  }
198
- runFile(path.resolve(args[0]));
226
+
227
+ if (!['--writedirectly', '--viewfilelist', '--learn', '--help', '-v', '--version'].includes(args[0])) {
228
+ runFile(path.resolve(args[0]));
229
+ }