bscript-cli 1.0.0

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 (47) hide show
  1. package/BScript.js +233 -0
  2. package/Docs/BScript/BSCRIPT-REFERENCE-CLI.md +502 -0
  3. package/Docs/Images/BScript-baner.png +0 -0
  4. package/Docs/Images/BooleanType.png +0 -0
  5. package/Docs/Images/FuncionType.png +0 -0
  6. package/Docs/Images/Logo.png +0 -0
  7. package/Docs/Images/NumberType.png +0 -0
  8. package/Docs/Images/ObjectType.png +0 -0
  9. package/Docs/Images/PromiseType.png +0 -0
  10. package/Docs/Images/RawType.png +0 -0
  11. package/Docs/Images/RefType.png +0 -0
  12. package/Docs/Images/TextType.png +0 -0
  13. package/Docs/README.md +157 -0
  14. package/Docs/REFERENCE.md +602 -0
  15. package/Docs/TECHNICAL.md +1143 -0
  16. package/Docs/TUTORIAL.md +604 -0
  17. package/SRC/BScriptHistory.js +98 -0
  18. package/SRC/CMDPermissions.js +4 -0
  19. package/SRC/utils/utils.js +63 -0
  20. package/TerminalCommandController.js +193 -0
  21. package/bin/bscript.js +94 -0
  22. package/commands/.default/BScript/$arg.js +9 -0
  23. package/commands/.default/BScript/$val.js +19 -0
  24. package/commands/.default/BScript/Input.js +10 -0
  25. package/commands/.default/BScript/bool.js +9 -0
  26. package/commands/.default/BScript/delay.js +10 -0
  27. package/commands/.default/BScript/eval.js +9 -0
  28. package/commands/.default/BScript/import.js +17 -0
  29. package/commands/.default/BScript/js_new.js +9 -0
  30. package/commands/.default/BScript/js_require.js +9 -0
  31. package/commands/.default/BScript/jstype.js +9 -0
  32. package/commands/.default/BScript/num.js +9 -0
  33. package/commands/.default/BScript/object.js +19 -0
  34. package/commands/.default/BScript/print.js +9 -0
  35. package/commands/.default/BScript/raw.js +9 -0
  36. package/commands/.default/BScript/ref.js +65 -0
  37. package/commands/.default/BScript/run-with-await.js +13 -0
  38. package/commands/.default/BScript/run.js +11 -0
  39. package/commands/.default/BScript/script.js +13 -0
  40. package/commands/.default/BScript/str.js +9 -0
  41. package/commands/.default/DebugOnly/clear.js +8 -0
  42. package/commands/.default/DebugOnly/update-commands.js +8 -0
  43. package/commands/.default/help.js +20 -0
  44. package/commands/snapshot.md +421 -0
  45. package/index.js +8 -0
  46. package/package.json +12 -0
  47. package/postinstall.js +12 -0
@@ -0,0 +1,602 @@
1
+ # API Reference
2
+
3
+ Here are described all **public** modules, classes, functions, constants, and other exported declarations available for developers.
4
+
5
+ ---
6
+
7
+ ## Guide
8
+
9
+ <details>
10
+ <summary>BScript</summary>
11
+
12
+ ## Parent
13
+ [BScript.BScript](#BScriptBScript)
14
+
15
+ ### Constants
16
+ - [perrmissionsKeys](#BScriptBScriptperrmissionsKeys)
17
+
18
+ ### Properties
19
+ - [cmdRootPermissions](#BScriptBScriptcmdRootPermissions)
20
+ - [commandHistory](#BScriptBScriptcommandHistory)
21
+ - [returnCode](#BScriptBScriptreturnCode)
22
+
23
+ ### Methods
24
+ - [bscript()](#BScriptBScriptbscript)
25
+ - [Start()](#BScriptBScriptStart)
26
+ - [updateCommands()](#BScriptBScriptupdateCommands)
27
+ - [createCommand()](#BScriptBScriptcreateCommand)
28
+ - [executeCommand()](#BScriptBScriptexecuteCommand)
29
+
30
+ </details>
31
+
32
+ <details>
33
+ <summary>TerminalCommandController</summary>
34
+
35
+ ## Parent
36
+ [TerminalCommandController.TerminalCommandController](#TerminalCommandControllerTerminalCommandController)
37
+
38
+ ### Methods
39
+ - [ClearConsole()](#TerminalCommandControllerClearConsole)
40
+ - [InitInput()](#TerminalCommandControllerInitInput)
41
+ - [Write()](#TerminalCommandControllerWrite)
42
+ - [Print()](#TerminalCommandControllerPrint)
43
+ - [SetStdinListener()](#TerminalCommandControllerSetStdinListener)
44
+ - [RemoveStdinListener()](#TerminalCommandControllerRemoveStdinListener)
45
+
46
+ </details>
47
+
48
+ ---
49
+
50
+ ## Modules
51
+
52
+ <a id="BScriptBScript"></a>
53
+
54
+ ## BScript.BScript
55
+
56
+ ### Opportunities
57
+
58
+ - Create interactive CLI applications with minimal setup
59
+ - Implement role-based command access control
60
+ - Build extensible command systems with dynamic loading
61
+ - Execute scripts with custom sandboxed contexts
62
+ - Manage command history and navigation
63
+
64
+ ### Declaration
65
+
66
+ ```javascript
67
+ class BScript extends EventEmitter
68
+ ```
69
+
70
+ BScript is the main class for creating interactive command-line interfaces. It extends Node.js EventEmitter, allowing you to listen to and emit custom events. Use it to manage commands, control permissions, handle script execution, and interact with users through the terminal.
71
+
72
+ ---
73
+
74
+ ## Constants
75
+
76
+ <table>
77
+ <thead>
78
+ <tr>
79
+ <td>
80
+ <h4>About Constant</h4>
81
+ </td>
82
+ <td>
83
+ <h4>Example</h4>
84
+ </td>
85
+ </tr>
86
+ </thead>
87
+
88
+ <tbody>
89
+
90
+ <a id="BScriptBScriptperrmissionsKeys"></a>
91
+
92
+ <tr>
93
+ <td width="70%">
94
+
95
+ <h5>perrmissionsKeys</h5>
96
+
97
+ ```javascript
98
+ const perrmissionsKeys = {
99
+ default: 0,
100
+ script: 999
101
+ }
102
+ ```
103
+
104
+ Predefined permission levels used for command access control. `default` (0) is for normal user commands, while `script` (999) is for high-privilege script execution contexts.
105
+
106
+ </td>
107
+
108
+ <td width="30%">
109
+ <pre><code>
110
+ const cmd = new BScript();
111
+ console.log(cmd.perrmissionsKeys.default);
112
+ // Output: 0
113
+ console.log(cmd.perrmissionsKeys.script);
114
+ // Output: 999
115
+ </code></pre>
116
+ </td>
117
+
118
+ </tr>
119
+
120
+ </tbody>
121
+ </table>
122
+
123
+ ---
124
+
125
+ ## Properties
126
+
127
+ <table>
128
+ <thead>
129
+ <tr>
130
+ <td>
131
+ <h4>About Property</h4>
132
+ </td>
133
+ <td>
134
+ <h4>Example</h4>
135
+ </td>
136
+ </tr>
137
+ </thead>
138
+
139
+ <tbody>
140
+
141
+ <a id="BScriptBScriptcmdRootPermissions"></a>
142
+
143
+ <tr>
144
+ <td width="70%">
145
+
146
+ <h5>cmdRootPermissions</h5>
147
+
148
+ ```javascript
149
+ cmd.cmdRootPermissions
150
+ ```
151
+
152
+ An array of permission levels that determine which commands are available in the current context. Modify this array to control access to commands based on user roles.
153
+
154
+ </td>
155
+
156
+ <td width="30%">
157
+ <pre><code>
158
+ const cmd = new BScript();
159
+ cmd.cmdRootPermissions = [
160
+ cmd.perrmissionsKeys.default
161
+ ];
162
+ cmd.updateCommands();
163
+ </code></pre>
164
+ </td>
165
+
166
+ </tr>
167
+
168
+ <a id="BScriptBScriptcommandHistory"></a>
169
+
170
+ <tr>
171
+ <td width="70%">
172
+
173
+ <h5>commandHistory</h5>
174
+
175
+ ```javascript
176
+ cmd.commandHistory
177
+ ```
178
+
179
+ An array containing the history of executed commands. Persisted across sessions and navigable during interactive mode using arrow keys.
180
+
181
+ </td>
182
+
183
+ <td width="30%">
184
+ <pre><code>
185
+ const cmd = new BScript();
186
+ cmd.Start();
187
+ // After executing commands, access history:
188
+ console.log(cmd.commandHistory);
189
+ </code></pre>
190
+ </td>
191
+
192
+ </tr>
193
+
194
+ <a id="BScriptBScriptreturnCode"></a>
195
+
196
+ <tr>
197
+ <td width="70%">
198
+
199
+ <h5>returnCode</h5>
200
+
201
+ ```javascript
202
+ cmd.returnCode
203
+ ```
204
+
205
+ Current return code of the script execution (-1 = loading, 1 = ready, other = error). Used to track the state of async operations.
206
+
207
+ </td>
208
+
209
+ <td width="30%">
210
+ <pre><code>
211
+ const cmd = new BScript();
212
+ cmd.loader(async (done) => {
213
+ // When done, returnCode becomes 1
214
+ done();
215
+ });
216
+ </code></pre>
217
+ </td>
218
+
219
+ </tr>
220
+
221
+ </tbody>
222
+ </table>
223
+
224
+ ---
225
+
226
+ ## Methods
227
+
228
+ <table>
229
+ <thead>
230
+ <tr>
231
+ <td>
232
+ <h4>About Method</h4>
233
+ </td>
234
+ <td>
235
+ <h4>Example</h4>
236
+ </td>
237
+ </tr>
238
+ </thead>
239
+
240
+ <tbody>
241
+
242
+ <a id="BScriptBScriptbscript"></a>
243
+
244
+ <tr>
245
+ <td width="70%">
246
+
247
+ <h5>bscript()</h5>
248
+
249
+ ```javascript
250
+ bscript(scriptCode)
251
+ ```
252
+
253
+ Parses and returns an executable function for the given script code. Supports inline execution of BScript code. The returned function can be immediately invoked with `()`.
254
+
255
+ </td>
256
+
257
+ <td width="30%">
258
+ <pre><code>
259
+ const cmd = new BScript();
260
+ cmd.cmdRootPermissions = [
261
+ cmd.perrmissionsKeys.default,
262
+ cmd.perrmissionsKeys.script
263
+ ];
264
+ cmd.updateCommands();
265
+
266
+ const scriptFn = cmd.bscript(
267
+ 'echo "Hello World"'
268
+ );
269
+ scriptFn();
270
+ </code></pre>
271
+ </td>
272
+
273
+ </tr>
274
+
275
+ <a id="BScriptBScriptStart"></a>
276
+
277
+ <tr>
278
+ <td width="70%">
279
+
280
+ <h5>Start()</h5>
281
+
282
+ ```javascript
283
+ Start()
284
+ ```
285
+
286
+ Initializes and starts the interactive command-line interface. Displays the command prompt and listens for user input. Commands are processed and executed in real-time.
287
+
288
+ </td>
289
+
290
+ <td width="30%">
291
+ <pre><code>
292
+ const cmd = new BScript();
293
+ cmd.cmdRootPermissions = [
294
+ cmd.perrmissionsKeys.default
295
+ ];
296
+ cmd.updateCommands();
297
+
298
+ cmd.Start();
299
+ // Interactive mode begins
300
+ </code></pre>
301
+ </td>
302
+
303
+ </tr>
304
+
305
+ <a id="BScriptBScriptupdateCommands"></a>
306
+
307
+ <tr>
308
+ <td width="70%">
309
+
310
+ <h5>updateCommands()</h5>
311
+
312
+ ```javascript
313
+ updateCommands()
314
+ ```
315
+
316
+ Scans command directories and loads all command files. Respects permission settings and filters commands accordingly. Call this after changing permissions or adding new command files.
317
+
318
+ </td>
319
+
320
+ <td width="30%">
321
+ <pre><code>
322
+ const cmd = new BScript({
323
+ commandsPaths: [
324
+ './my-commands'
325
+ ]
326
+ });
327
+
328
+ cmd.cmdRootPermissions = [
329
+ cmd.perrmissionsKeys.default
330
+ ];
331
+
332
+ cmd.updateCommands();
333
+ </code></pre>
334
+ </td>
335
+
336
+ </tr>
337
+
338
+ <a id="BScriptBScriptcreateCommand"></a>
339
+
340
+ <tr>
341
+ <td width="70%">
342
+
343
+ <h5>createCommand()</h5>
344
+
345
+ ```javascript
346
+ createCommand({
347
+ name,
348
+ execute,
349
+ description,
350
+ syntax
351
+ })
352
+ ```
353
+
354
+ Registers a new command in the system. Typically called internally when loading commands, but can be used to programmatically add commands at runtime.
355
+
356
+ </td>
357
+
358
+ <td width="30%">
359
+ <pre><code>
360
+ const cmd = new BScript();
361
+
362
+ cmd.createCommand({
363
+ name: 'greet',
364
+ execute: (args) => {
365
+ console.log(`Hello, ${args[0]}!`);
366
+ },
367
+ description: 'Greet a user',
368
+ syntax: 'greet [name]'
369
+ });
370
+ </code></pre>
371
+ </td>
372
+
373
+ </tr>
374
+
375
+ <a id="BScriptBScriptexecuteCommand"></a>
376
+
377
+ <tr>
378
+ <td width="70%">
379
+
380
+ <h5>executeCommand()</h5>
381
+
382
+ ```javascript
383
+ executeCommand(commandString)
384
+ ```
385
+
386
+ Parses and executes a command string. Handles command routing, argument passing, and output. Called automatically during interactive mode.
387
+
388
+ </td>
389
+
390
+ <td width="30%">
391
+ <pre><code>
392
+ const cmd = new BScript();
393
+ cmd.cmdRootPermissions = [
394
+ cmd.perrmissionsKeys.default
395
+ ];
396
+ cmd.updateCommands();
397
+
398
+ cmd.executeCommand('help');
399
+ </code></pre>
400
+ </td>
401
+
402
+ </tr>
403
+
404
+ </tbody>
405
+ </table>
406
+
407
+ ---
408
+
409
+ <a id="TerminalCommandControllerTerminalCommandController"></a>
410
+
411
+ ## TerminalCommandController.TerminalCommandController
412
+
413
+ ### Declaration
414
+
415
+ ```javascript
416
+ class TerminalCommandController
417
+ ```
418
+
419
+ Handles low-level terminal I/O operations. Manages cursor positioning, text output, input handling, and terminal formatting. Works closely with BScript to provide the interactive interface experience.
420
+
421
+ ---
422
+
423
+ ## Methods
424
+
425
+ <table>
426
+ <thead>
427
+ <tr>
428
+ <td>
429
+ <h4>About Method</h4>
430
+ </td>
431
+ <td>
432
+ <h4>Example</h4>
433
+ </td>
434
+ </tr>
435
+ </thead>
436
+
437
+ <tbody>
438
+
439
+ <a id="TerminalCommandControllerClearConsole"></a>
440
+
441
+ <tr>
442
+ <td width="70%">
443
+
444
+ <h5>ClearConsole()</h5>
445
+
446
+ ```javascript
447
+ ClearConsole()
448
+ ```
449
+
450
+ Clears the entire terminal screen and resets the cursor to the top-left position.
451
+
452
+ </td>
453
+
454
+ <td width="30%">
455
+ <pre><code>
456
+ const cmd = new BScript();
457
+ cmd.commandController.ClearConsole();
458
+ </code></pre>
459
+ </td>
460
+
461
+ </tr>
462
+
463
+ <a id="TerminalCommandControllerInitInput"></a>
464
+
465
+ <tr>
466
+ <td width="70%">
467
+
468
+ <h5>InitInput()</h5>
469
+
470
+ ```javascript
471
+ InitInput(rawMode)
472
+ ```
473
+
474
+ Initializes stdin for raw input mode. Set `rawMode` to `true` for character-by-character input, `false` for line-based input.
475
+
476
+ </td>
477
+
478
+ <td width="30%">
479
+ <pre><code>
480
+ const cmd = new BScript();
481
+ cmd.commandController
482
+ .InitInput(true);
483
+ </code></pre>
484
+ </td>
485
+
486
+ </tr>
487
+
488
+ <a id="TerminalCommandControllerWrite"></a>
489
+
490
+ <tr>
491
+ <td width="70%">
492
+
493
+ <h5>Write()</h5>
494
+
495
+ ```javascript
496
+ Write(text)
497
+ ```
498
+
499
+ Writes text to stdout without a newline. Useful for prompts and inline output.
500
+
501
+ </td>
502
+
503
+ <td width="30%">
504
+ <pre><code>
505
+ const cmd = new BScript();
506
+ cmd.commandController
507
+ .Write("Enter command: ");
508
+ </code></pre>
509
+ </td>
510
+
511
+ </tr>
512
+
513
+ <a id="TerminalCommandControllerPrint"></a>
514
+
515
+ <tr>
516
+ <td width="70%">
517
+
518
+ <h5>Print()</h5>
519
+
520
+ ```javascript
521
+ Print(...text)
522
+ ```
523
+
524
+ Prints one or more values to stdout with automatic formatting. Equivalent to `console.log()`.
525
+
526
+ </td>
527
+
528
+ <td width="30%">
529
+ <pre><code>
530
+ const cmd = new BScript();
531
+ cmd.commandController
532
+ .Print("Command executed", 42);
533
+ </code></pre>
534
+ </td>
535
+
536
+ </tr>
537
+
538
+ <a id="TerminalCommandControllerSetStdinListener"></a>
539
+
540
+ <tr>
541
+ <td width="70%">
542
+
543
+ <h5>SetStdinListener()</h5>
544
+
545
+ ```javascript
546
+ SetStdinListener(eventName, callback)
547
+ ```
548
+
549
+ Registers an event listener on stdin for the specified event. Useful for custom input handling.
550
+
551
+ </td>
552
+
553
+ <td width="30%">
554
+ <pre><code>
555
+ const cmd = new BScript();
556
+ cmd.commandController
557
+ .SetStdinListener('data', (chunk) => {
558
+ console.log("Input:", chunk);
559
+ });
560
+ </code></pre>
561
+ </td>
562
+
563
+ </tr>
564
+
565
+ <a id="TerminalCommandControllerRemoveStdinListener"></a>
566
+
567
+ <tr>
568
+ <td width="70%">
569
+
570
+ <h5>RemoveStdinListener()</h5>
571
+
572
+ ```javascript
573
+ RemoveStdinListener(eventName, callback)
574
+ ```
575
+
576
+ Removes a previously registered stdin event listener.
577
+
578
+ </td>
579
+
580
+ <td width="30%">
581
+ <pre><code>
582
+ const cmd = new BScript();
583
+ const handler = (chunk) => {
584
+ console.log("Input:", chunk);
585
+ };
586
+ cmd.commandController
587
+ .SetStdinListener('data', handler);
588
+
589
+ // Later:
590
+ cmd.commandController
591
+ .RemoveStdinListener('data', handler);
592
+ </code></pre>
593
+ </td>
594
+
595
+ </tr>
596
+
597
+ </tbody>
598
+ </table>
599
+
600
+ ---
601
+
602
+ **Made with ❤️ for the Node.js ecosystem**