starlight-cli 1.0.10 → 1.0.12

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.10';
2457
+ const VERSION = '1.0.12';
2458
2458
 
2459
2459
  const COLOR = {
2460
2460
  reset: '\x1b[0m',
@@ -2467,7 +2467,7 @@ const COLOR = {
2467
2467
  green: '\x1b[32m'
2468
2468
  };
2469
2469
 
2470
- function waitAndExit(code = 1) {
2470
+ function waitAndExit(code = 0) {
2471
2471
  console.error(COLOR.gray + '\nPress any key to exit...' + COLOR.reset);
2472
2472
  process.stdin.setRawMode(true);
2473
2473
  process.stdin.resume();
@@ -2484,14 +2484,8 @@ function printSourceContext(code, line, column) {
2484
2484
  const srcLine = lines[line - 1];
2485
2485
  if (!srcLine) return;
2486
2486
 
2487
- console.error(
2488
- COLOR.gray + `\n ${line} | ` + COLOR.reset + srcLine
2489
- );
2490
- console.error(
2491
- COLOR.gray + ' | ' +
2492
- COLOR.red + ' '.repeat(Math.max(0, column - 1)) + '^' +
2493
- COLOR.reset
2494
- );
2487
+ console.error(COLOR.gray + `\n ${line} | ` + COLOR.reset + srcLine);
2488
+ console.error(COLOR.gray + ' | ' + COLOR.red + ' '.repeat(Math.max(0, column - 1)) + '^' + COLOR.reset);
2495
2489
  }
2496
2490
 
2497
2491
  const args = process.argv.slice(2);
@@ -2537,14 +2531,10 @@ if (args[0] === '--learn') {
2537
2531
  }
2538
2532
 
2539
2533
  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();
2534
+ const readlineSync = __nccwpck_require__(552);
2535
+ const folderPath = readlineSync.question(COLOR.cyan + 'Paste folder path to search .sl files: ' + COLOR.reset).trim();
2542
2536
  if (!folderPath) return waitAndExit(0);
2543
-
2544
- if (!fs.existsSync(folderPath) || !fs.lstatSync(folderPath).isDirectory()) {
2545
- return fatal('Invalid folder path.');
2546
- }
2547
-
2537
+ if (!fs.existsSync(folderPath) || !fs.lstatSync(folderPath).isDirectory()) return fatal('Invalid folder path.');
2548
2538
  const files = fs.readdirSync(folderPath).filter(f => f.endsWith('.sl'));
2549
2539
  if (files.length === 0) console.log(COLOR.yellow + 'No .sl files found in folder.' + COLOR.reset);
2550
2540
  else {
@@ -2568,8 +2558,16 @@ if (args[0] === '--writedirectly') {
2568
2558
  });
2569
2559
 
2570
2560
  let lines = [];
2571
- rl.prompt();
2572
2561
 
2562
+ function highlightCode(line) {
2563
+ // Strings first
2564
+ line = line.replace(/"(.*?)"/g, COLOR.yellow + '"$1"' + COLOR.reset);
2565
+ // Keywords
2566
+ line = line.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);
2567
+ return line;
2568
+ }
2569
+
2570
+ rl.prompt();
2573
2571
  rl.on('line', (line) => {
2574
2572
  if (line.trim() === ':run') {
2575
2573
  rl.close();
@@ -2578,13 +2576,8 @@ if (args[0] === '--writedirectly') {
2578
2576
  return;
2579
2577
  }
2580
2578
 
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);
2584
-
2585
- console.log(coloredLine);
2586
-
2587
2579
  lines.push(line);
2580
+ console.log(COLOR.cyan + '> ' + COLOR.reset + highlightCode(line));
2588
2581
  rl.prompt();
2589
2582
  });
2590
2583
 
@@ -2593,11 +2586,14 @@ if (args[0] === '--writedirectly') {
2593
2586
 
2594
2587
  function saveTempFilePrompt(lines) {
2595
2588
  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;
2589
+ const saveChoice = readlineSync.question(COLOR.cyan + 'Do you want to save this code? (y/n): ' + COLOR.reset).trim().toLowerCase();
2590
+ if (saveChoice !== 'y') return waitAndExit(0);
2598
2591
 
2599
2592
  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);
2593
+ if (!folderPath || !fs.existsSync(folderPath) || !fs.lstatSync(folderPath).isDirectory()) {
2594
+ console.log(COLOR.yellow + 'Skipping save.' + COLOR.reset);
2595
+ return waitAndExit(0);
2596
+ }
2601
2597
 
2602
2598
  let fileName = readlineSync.question(COLOR.cyan + 'Enter file name (without extension): ' + COLOR.reset).trim();
2603
2599
  if (!fileName) return console.log(COLOR.yellow + 'Skipping save.' + COLOR.reset);
@@ -2605,25 +2601,24 @@ function saveTempFilePrompt(lines) {
2605
2601
  let fullPath = path.join(folderPath, fileName.endsWith('.sl') ? fileName : fileName + '.sl');
2606
2602
  while (fs.existsSync(fullPath)) {
2607
2603
  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);
2604
+ if (!fileName) {
2605
+ console.log(COLOR.yellow + 'Skipping save.' + COLOR.reset);
2606
+ return waitAndExit(0);
2607
+ }
2609
2608
  fullPath = path.join(folderPath, fileName.endsWith('.sl') ? fileName : fileName + '.sl');
2610
2609
  }
2611
2610
 
2612
2611
  fs.writeFileSync(fullPath, lines.join('\n'), 'utf8');
2613
2612
  console.log(COLOR.green + `Saved to ${fullPath}` + COLOR.reset);
2613
+ waitAndExit(0);
2614
2614
  }
2615
2615
 
2616
2616
  function runFile(filePath, isTemp = false, callback = null) {
2617
- if (!fs.existsSync(filePath)) {
2618
- return fatal(`File not found: ${filePath}`);
2619
- }
2617
+ if (!fs.existsSync(filePath)) return fatal(`File not found: ${filePath}`);
2620
2618
 
2621
2619
  let code;
2622
- try {
2623
- code = fs.readFileSync(filePath, 'utf-8');
2624
- } catch (err) {
2625
- return fatal(`Failed to read file: ${err.message}`);
2626
- }
2620
+ try { code = fs.readFileSync(filePath, 'utf-8'); }
2621
+ catch (err) { return fatal(`Failed to read file: ${err.message}`); }
2627
2622
 
2628
2623
  let tokens;
2629
2624
  try {
@@ -2661,17 +2656,12 @@ function runFile(filePath, isTemp = false, callback = null) {
2661
2656
  }
2662
2657
 
2663
2658
  console.log(COLOR.green + '\nProgram finished successfully.' + COLOR.reset);
2664
-
2665
2659
  if (callback) callback();
2666
-
2667
- if (isTemp) {
2668
- try { fs.unlinkSync(filePath); } catch {}
2669
- }
2670
-
2671
- waitAndExit(0);
2660
+ if (isTemp) { try { fs.unlinkSync(filePath); } catch {} }
2661
+ }
2662
+ if (!['--writedirectly', '--viewfilelist', '--learn', '--help', '-v', '--version'].includes(args[0])) {
2663
+ runFile(path.resolve(args[0]));
2672
2664
  }
2673
-
2674
- runFile(path.resolve(args[0]));
2675
2665
 
2676
2666
  module.exports = __webpack_exports__;
2677
2667
  /******/ })()
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "starlight-cli",
3
- "version": "1.0.10",
3
+ "version": "1.0.12",
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.10';
10
+ const VERSION = '1.0.12';
11
11
 
12
12
  const COLOR = {
13
13
  reset: '\x1b[0m',
@@ -20,7 +20,7 @@ const COLOR = {
20
20
  green: '\x1b[32m'
21
21
  };
22
22
 
23
- function waitAndExit(code = 1) {
23
+ function waitAndExit(code = 0) {
24
24
  console.error(COLOR.gray + '\nPress any key to exit...' + COLOR.reset);
25
25
  process.stdin.setRawMode(true);
26
26
  process.stdin.resume();
@@ -37,14 +37,8 @@ function printSourceContext(code, line, column) {
37
37
  const srcLine = lines[line - 1];
38
38
  if (!srcLine) return;
39
39
 
40
- console.error(
41
- COLOR.gray + `\n ${line} | ` + COLOR.reset + srcLine
42
- );
43
- console.error(
44
- COLOR.gray + ' | ' +
45
- COLOR.red + ' '.repeat(Math.max(0, column - 1)) + '^' +
46
- COLOR.reset
47
- );
40
+ console.error(COLOR.gray + `\n ${line} | ` + COLOR.reset + srcLine);
41
+ console.error(COLOR.gray + ' | ' + COLOR.red + ' '.repeat(Math.max(0, column - 1)) + '^' + COLOR.reset);
48
42
  }
49
43
 
50
44
  const args = process.argv.slice(2);
@@ -90,14 +84,10 @@ if (args[0] === '--learn') {
90
84
  }
91
85
 
92
86
  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();
87
+ const readlineSync = require('readline-sync');
88
+ const folderPath = readlineSync.question(COLOR.cyan + 'Paste folder path to search .sl files: ' + COLOR.reset).trim();
95
89
  if (!folderPath) return waitAndExit(0);
96
-
97
- if (!fs.existsSync(folderPath) || !fs.lstatSync(folderPath).isDirectory()) {
98
- return fatal('Invalid folder path.');
99
- }
100
-
90
+ if (!fs.existsSync(folderPath) || !fs.lstatSync(folderPath).isDirectory()) return fatal('Invalid folder path.');
101
91
  const files = fs.readdirSync(folderPath).filter(f => f.endsWith('.sl'));
102
92
  if (files.length === 0) console.log(COLOR.yellow + 'No .sl files found in folder.' + COLOR.reset);
103
93
  else {
@@ -121,8 +111,16 @@ if (args[0] === '--writedirectly') {
121
111
  });
122
112
 
123
113
  let lines = [];
124
- rl.prompt();
125
114
 
115
+ function highlightCode(line) {
116
+ // Strings first
117
+ line = line.replace(/"(.*?)"/g, COLOR.yellow + '"$1"' + COLOR.reset);
118
+ // Keywords
119
+ line = line.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);
120
+ return line;
121
+ }
122
+
123
+ rl.prompt();
126
124
  rl.on('line', (line) => {
127
125
  if (line.trim() === ':run') {
128
126
  rl.close();
@@ -131,13 +129,8 @@ if (args[0] === '--writedirectly') {
131
129
  return;
132
130
  }
133
131
 
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);
137
-
138
- console.log(coloredLine);
139
-
140
132
  lines.push(line);
133
+ console.log(COLOR.cyan + '> ' + COLOR.reset + highlightCode(line));
141
134
  rl.prompt();
142
135
  });
143
136
 
@@ -146,11 +139,14 @@ if (args[0] === '--writedirectly') {
146
139
 
147
140
  function saveTempFilePrompt(lines) {
148
141
  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;
142
+ const saveChoice = readlineSync.question(COLOR.cyan + 'Do you want to save this code? (y/n): ' + COLOR.reset).trim().toLowerCase();
143
+ if (saveChoice !== 'y') return waitAndExit(0);
151
144
 
152
145
  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);
146
+ if (!folderPath || !fs.existsSync(folderPath) || !fs.lstatSync(folderPath).isDirectory()) {
147
+ console.log(COLOR.yellow + 'Skipping save.' + COLOR.reset);
148
+ return waitAndExit(0);
149
+ }
154
150
 
155
151
  let fileName = readlineSync.question(COLOR.cyan + 'Enter file name (without extension): ' + COLOR.reset).trim();
156
152
  if (!fileName) return console.log(COLOR.yellow + 'Skipping save.' + COLOR.reset);
@@ -158,25 +154,24 @@ function saveTempFilePrompt(lines) {
158
154
  let fullPath = path.join(folderPath, fileName.endsWith('.sl') ? fileName : fileName + '.sl');
159
155
  while (fs.existsSync(fullPath)) {
160
156
  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);
157
+ if (!fileName) {
158
+ console.log(COLOR.yellow + 'Skipping save.' + COLOR.reset);
159
+ return waitAndExit(0);
160
+ }
162
161
  fullPath = path.join(folderPath, fileName.endsWith('.sl') ? fileName : fileName + '.sl');
163
162
  }
164
163
 
165
164
  fs.writeFileSync(fullPath, lines.join('\n'), 'utf8');
166
165
  console.log(COLOR.green + `Saved to ${fullPath}` + COLOR.reset);
166
+ waitAndExit(0);
167
167
  }
168
168
 
169
169
  function runFile(filePath, isTemp = false, callback = null) {
170
- if (!fs.existsSync(filePath)) {
171
- return fatal(`File not found: ${filePath}`);
172
- }
170
+ if (!fs.existsSync(filePath)) return fatal(`File not found: ${filePath}`);
173
171
 
174
172
  let code;
175
- try {
176
- code = fs.readFileSync(filePath, 'utf-8');
177
- } catch (err) {
178
- return fatal(`Failed to read file: ${err.message}`);
179
- }
173
+ try { code = fs.readFileSync(filePath, 'utf-8'); }
174
+ catch (err) { return fatal(`Failed to read file: ${err.message}`); }
180
175
 
181
176
  let tokens;
182
177
  try {
@@ -214,14 +209,9 @@ function runFile(filePath, isTemp = false, callback = null) {
214
209
  }
215
210
 
216
211
  console.log(COLOR.green + '\nProgram finished successfully.' + COLOR.reset);
217
-
218
212
  if (callback) callback();
219
-
220
- if (isTemp) {
221
- try { fs.unlinkSync(filePath); } catch {}
222
- }
223
-
224
- waitAndExit(0);
213
+ if (isTemp) { try { fs.unlinkSync(filePath); } catch {} }
214
+ }
215
+ if (!['--writedirectly', '--viewfilelist', '--learn', '--help', '-v', '--version'].includes(args[0])) {
216
+ runFile(path.resolve(args[0]));
225
217
  }
226
-
227
- runFile(path.resolve(args[0]));