starlight-cli 1.0.8 → 1.0.10

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
@@ -2396,6 +2396,14 @@ module.exports = require("os");
2396
2396
  "use strict";
2397
2397
  module.exports = require("path");
2398
2398
 
2399
+ /***/ }),
2400
+
2401
+ /***/ 785:
2402
+ /***/ ((module) => {
2403
+
2404
+ "use strict";
2405
+ module.exports = require("readline");
2406
+
2399
2407
  /***/ })
2400
2408
 
2401
2409
  /******/ });
@@ -2446,7 +2454,7 @@ const Lexer = __nccwpck_require__(211);
2446
2454
  const Parser = __nccwpck_require__(222);
2447
2455
  const Evaluator = __nccwpck_require__(112);
2448
2456
 
2449
- const VERSION = '1.0.8';
2457
+ const VERSION = '1.0.10';
2450
2458
 
2451
2459
  const COLOR = {
2452
2460
  reset: '\x1b[0m',
@@ -2493,11 +2501,12 @@ if (args.length === 0) {
2493
2501
  Starlight Programming Language
2494
2502
 
2495
2503
  Usage:
2496
- starlight <file.sl> Run a Starlight program
2497
- starlight -v Show version
2498
- starlight --help Show help
2499
- starlight --learn Open learning guide
2500
- 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
2501
2510
  `);
2502
2511
  process.exit(0);
2503
2512
  }
@@ -2512,46 +2521,99 @@ if (args[0] === '--help') {
2512
2521
  Starlight CLI Help
2513
2522
 
2514
2523
  Commands:
2515
- starlight file.sl Run a Starlight program
2516
- starlight -v Show version
2517
- starlight --learn Open learning guide
2518
- 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
2519
2529
  `);
2520
2530
  process.exit(0);
2521
2531
  }
2532
+
2522
2533
  if (args[0] === '--learn') {
2523
2534
  console.log(COLOR.cyan + 'Opening Starlight Learning Guide...' + COLOR.reset);
2524
2535
  exec('start https://programming-lang.pages.dev/learning-guide');
2525
2536
  process.exit(0);
2526
2537
  }
2527
2538
 
2528
- if (args[0] === '--writedirectly') {
2529
- console.log(COLOR.green + 'Write your Starlight code below.' + COLOR.reset);
2530
- console.log(COLOR.gray + 'Press CTRL + Z then ENTER to run.\n' + COLOR.reset);
2539
+ if (args[0] === '--viewfilelist') {
2540
+ const readline = __nccwpck_require__(552);
2541
+ let folderPath = readline.question(COLOR.cyan + 'Paste folder path to search .sl files: ' + COLOR.reset).trim();
2542
+ if (!folderPath) return waitAndExit(0);
2531
2543
 
2532
- let input = '';
2544
+ if (!fs.existsSync(folderPath) || !fs.lstatSync(folderPath).isDirectory()) {
2545
+ return fatal('Invalid folder path.');
2546
+ }
2533
2547
 
2534
- process.stdin.resume();
2535
- process.stdin.setEncoding('utf8');
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
+
2557
+ if (args[0] === '--writedirectly') {
2558
+ const readline = __nccwpck_require__(785);
2559
+ const tempFile = path.join(os.tmpdir(), `starlight-temp-${Date.now()}.sl`);
2560
+
2561
+ console.log(COLOR.green + 'Interactive Starlight Editor' + COLOR.reset);
2562
+ console.log(COLOR.gray + 'Type your code. Enter ":run" on a new line to execute.\n' + COLOR.reset);
2536
2563
 
2537
- process.stdin.on('data', chunk => {
2538
- input += chunk;
2564
+ const rl = readline.createInterface({
2565
+ input: process.stdin,
2566
+ output: process.stdout,
2567
+ prompt: COLOR.cyan + '> ' + COLOR.reset
2539
2568
  });
2540
2569
 
2541
- process.stdin.on('end', () => {
2542
- const tempFile = path.join(
2543
- os.tmpdir(),
2544
- `starlight-temp-${Date.now()}.sl`
2545
- );
2570
+ let lines = [];
2571
+ rl.prompt();
2546
2572
 
2547
- fs.writeFileSync(tempFile, input, 'utf8');
2573
+ rl.on('line', (line) => {
2574
+ if (line.trim() === ':run') {
2575
+ rl.close();
2576
+ fs.writeFileSync(tempFile, lines.join('\n'), 'utf8');
2577
+ runFile(tempFile, true, () => saveTempFilePrompt(lines));
2578
+ return;
2579
+ }
2580
+
2581
+ let coloredLine = line
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);
2548
2584
 
2549
- runFile(tempFile, true);
2585
+ console.log(coloredLine);
2586
+
2587
+ lines.push(line);
2588
+ rl.prompt();
2550
2589
  });
2551
2590
 
2552
2591
  return;
2553
2592
  }
2554
- function runFile(filePath, isTemp = false) {
2593
+
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) {
2555
2617
  if (!fs.existsSync(filePath)) {
2556
2618
  return fatal(`File not found: ${filePath}`);
2557
2619
  }
@@ -2571,11 +2633,7 @@ function runFile(filePath, isTemp = false) {
2571
2633
  console.error(COLOR.red + COLOR.bold + 'Starlight Lexer Error' + COLOR.reset);
2572
2634
  console.error(COLOR.cyan + `File: ${filePath}` + COLOR.reset);
2573
2635
  console.error(COLOR.yellow + `Message: ${err.message}` + COLOR.reset);
2574
-
2575
- if (err.line && err.column) {
2576
- printSourceContext(code, err.line, err.column);
2577
- }
2578
-
2636
+ if (err.line && err.column) printSourceContext(code, err.line, err.column);
2579
2637
  return waitAndExit(1);
2580
2638
  }
2581
2639
 
@@ -2587,11 +2645,7 @@ function runFile(filePath, isTemp = false) {
2587
2645
  console.error(COLOR.red + COLOR.bold + 'Starlight Parser Error' + COLOR.reset);
2588
2646
  console.error(COLOR.cyan + `File: ${filePath}` + COLOR.reset);
2589
2647
  console.error(COLOR.yellow + `Message: ${err.message}` + COLOR.reset);
2590
-
2591
- if (err.token && err.token.line && err.token.column) {
2592
- printSourceContext(code, err.token.line, err.token.column);
2593
- }
2594
-
2648
+ if (err.token && err.token.line && err.token.column) printSourceContext(code, err.token.line, err.token.column);
2595
2649
  return waitAndExit(1);
2596
2650
  }
2597
2651
 
@@ -2602,19 +2656,13 @@ function runFile(filePath, isTemp = false) {
2602
2656
  console.error(COLOR.red + COLOR.bold + 'Starlight Runtime Error' + COLOR.reset);
2603
2657
  console.error(COLOR.cyan + `File: ${filePath}` + COLOR.reset);
2604
2658
  console.error(COLOR.yellow + `Message: ${err.message}` + COLOR.reset);
2605
-
2606
- if (err.line && err.column) {
2607
- printSourceContext(code, err.line, err.column);
2608
- }
2609
-
2659
+ if (err.line && err.column) printSourceContext(code, err.line, err.column);
2610
2660
  return waitAndExit(1);
2611
2661
  }
2612
2662
 
2613
- console.log(
2614
- COLOR.green +
2615
- '\nProgram finished successfully.' +
2616
- COLOR.reset
2617
- );
2663
+ console.log(COLOR.green + '\nProgram finished successfully.' + COLOR.reset);
2664
+
2665
+ if (callback) callback();
2618
2666
 
2619
2667
  if (isTemp) {
2620
2668
  try { fs.unlinkSync(filePath); } catch {}
@@ -2622,6 +2670,7 @@ function runFile(filePath, isTemp = false) {
2622
2670
 
2623
2671
  waitAndExit(0);
2624
2672
  }
2673
+
2625
2674
  runFile(path.resolve(args[0]));
2626
2675
 
2627
2676
  module.exports = __webpack_exports__;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "starlight-cli",
3
- "version": "1.0.8",
3
+ "version": "1.0.10",
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.8';
10
+ const VERSION = '1.0.10';
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,46 +74,99 @@ 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
 
89
- if (args[0] === '--writedirectly') {
90
- console.log(COLOR.green + 'Write your Starlight code below.' + COLOR.reset);
91
- console.log(COLOR.gray + 'Press CTRL + Z then ENTER to run.\n' + COLOR.reset);
92
+ if (args[0] === '--viewfilelist') {
93
+ const readline = require('readline-sync');
94
+ let folderPath = readline.question(COLOR.cyan + 'Paste folder path to search .sl files: ' + COLOR.reset).trim();
95
+ if (!folderPath) return waitAndExit(0);
92
96
 
93
- let input = '';
97
+ if (!fs.existsSync(folderPath) || !fs.lstatSync(folderPath).isDirectory()) {
98
+ return fatal('Invalid folder path.');
99
+ }
94
100
 
95
- process.stdin.resume();
96
- process.stdin.setEncoding('utf8');
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
+
110
+ if (args[0] === '--writedirectly') {
111
+ const readline = require('readline');
112
+ const tempFile = path.join(os.tmpdir(), `starlight-temp-${Date.now()}.sl`);
113
+
114
+ console.log(COLOR.green + 'Interactive Starlight Editor' + COLOR.reset);
115
+ console.log(COLOR.gray + 'Type your code. Enter ":run" on a new line to execute.\n' + COLOR.reset);
97
116
 
98
- process.stdin.on('data', chunk => {
99
- input += chunk;
117
+ const rl = readline.createInterface({
118
+ input: process.stdin,
119
+ output: process.stdout,
120
+ prompt: COLOR.cyan + '> ' + COLOR.reset
100
121
  });
101
122
 
102
- process.stdin.on('end', () => {
103
- const tempFile = path.join(
104
- os.tmpdir(),
105
- `starlight-temp-${Date.now()}.sl`
106
- );
123
+ let lines = [];
124
+ rl.prompt();
107
125
 
108
- fs.writeFileSync(tempFile, input, 'utf8');
126
+ rl.on('line', (line) => {
127
+ if (line.trim() === ':run') {
128
+ rl.close();
129
+ fs.writeFileSync(tempFile, lines.join('\n'), 'utf8');
130
+ runFile(tempFile, true, () => saveTempFilePrompt(lines));
131
+ return;
132
+ }
133
+
134
+ let coloredLine = line
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);
109
137
 
110
- runFile(tempFile, true);
138
+ console.log(coloredLine);
139
+
140
+ lines.push(line);
141
+ rl.prompt();
111
142
  });
112
143
 
113
144
  return;
114
145
  }
115
- function runFile(filePath, isTemp = false) {
146
+
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) {
116
170
  if (!fs.existsSync(filePath)) {
117
171
  return fatal(`File not found: ${filePath}`);
118
172
  }
@@ -132,11 +186,7 @@ function runFile(filePath, isTemp = false) {
132
186
  console.error(COLOR.red + COLOR.bold + 'Starlight Lexer Error' + COLOR.reset);
133
187
  console.error(COLOR.cyan + `File: ${filePath}` + COLOR.reset);
134
188
  console.error(COLOR.yellow + `Message: ${err.message}` + COLOR.reset);
135
-
136
- if (err.line && err.column) {
137
- printSourceContext(code, err.line, err.column);
138
- }
139
-
189
+ if (err.line && err.column) printSourceContext(code, err.line, err.column);
140
190
  return waitAndExit(1);
141
191
  }
142
192
 
@@ -148,11 +198,7 @@ function runFile(filePath, isTemp = false) {
148
198
  console.error(COLOR.red + COLOR.bold + 'Starlight Parser Error' + COLOR.reset);
149
199
  console.error(COLOR.cyan + `File: ${filePath}` + COLOR.reset);
150
200
  console.error(COLOR.yellow + `Message: ${err.message}` + COLOR.reset);
151
-
152
- if (err.token && err.token.line && err.token.column) {
153
- printSourceContext(code, err.token.line, err.token.column);
154
- }
155
-
201
+ if (err.token && err.token.line && err.token.column) printSourceContext(code, err.token.line, err.token.column);
156
202
  return waitAndExit(1);
157
203
  }
158
204
 
@@ -163,19 +209,13 @@ function runFile(filePath, isTemp = false) {
163
209
  console.error(COLOR.red + COLOR.bold + 'Starlight Runtime Error' + COLOR.reset);
164
210
  console.error(COLOR.cyan + `File: ${filePath}` + COLOR.reset);
165
211
  console.error(COLOR.yellow + `Message: ${err.message}` + COLOR.reset);
166
-
167
- if (err.line && err.column) {
168
- printSourceContext(code, err.line, err.column);
169
- }
170
-
212
+ if (err.line && err.column) printSourceContext(code, err.line, err.column);
171
213
  return waitAndExit(1);
172
214
  }
173
215
 
174
- console.log(
175
- COLOR.green +
176
- '\nProgram finished successfully.' +
177
- COLOR.reset
178
- );
216
+ console.log(COLOR.green + '\nProgram finished successfully.' + COLOR.reset);
217
+
218
+ if (callback) callback();
179
219
 
180
220
  if (isTemp) {
181
221
  try { fs.unlinkSync(filePath); } catch {}
@@ -183,4 +223,5 @@ function runFile(filePath, isTemp = false) {
183
223
 
184
224
  waitAndExit(0);
185
225
  }
226
+
186
227
  runFile(path.resolve(args[0]));