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,421 @@
1
+ # Project Snapshot
2
+
3
+ ## Structure
4
+
5
+ ```
6
+ .
7
+ ```
8
+
9
+ ## ./.default/BScript/$arg.js
10
+
11
+ ```javascript
12
+ module.exports = {
13
+ name: '$arg',
14
+ description: '',
15
+ syntax: '',
16
+ perms: [999],
17
+ async execute(argNumber) {
18
+ return this.getScope().$arg[argNumber.val]
19
+ }
20
+ }
21
+ ```
22
+
23
+ ## ./.default/BScript/$val.js
24
+
25
+ ```javascript
26
+ module.exports = {
27
+ name: '$val',
28
+ description: '',
29
+ syntax: '',
30
+ perms: [999],
31
+ execute(bsarg0, bsarg1) {
32
+ if(bsarg0?.type == "ref") {
33
+ const refVal = bsarg0.get();
34
+ return refVal;
35
+ }
36
+ if(bsarg0.val == "exist"){
37
+ return { type: "bool", val: this.getScope().$val[bsarg1.val] ? 1 : 0 }
38
+ }
39
+
40
+ bsarg0 = this.getScope().$val[bsarg0.val];
41
+
42
+ return bsarg0? !bsarg0.type && !bsarg0.val? new this.Type(bsarg0) : bsarg0 : null;
43
+ }
44
+ }
45
+ ```
46
+
47
+ ## ./.default/BScript/bool.js
48
+
49
+ ```javascript
50
+ const Helpers = require('@beiser/bscript-runner').Helpers;
51
+
52
+ module.exports = {
53
+ name: 'bool',
54
+ description: '',
55
+ syntax: '',
56
+ perms: [999],
57
+ execute: ({ val }) => Helpers.Boolean(val)
58
+ }
59
+ ```
60
+
61
+ ## ./.default/BScript/delay.js
62
+
63
+ ```javascript
64
+ const { delay } = require("./SRC/utils/utils.js")
65
+ module.exports = {
66
+ name: 'delay',
67
+ description: '',
68
+ syntax: '',
69
+ perms: [999],
70
+ async execute(ms) {
71
+ return await delay(ms);
72
+ }
73
+ }
74
+ ```
75
+
76
+ ## ./.default/BScript/eval.js
77
+
78
+ ```javascript
79
+ module.exports = {
80
+ name: ['eval', 'evaluate'],
81
+ description: '',
82
+ syntax: '',
83
+ perms: [999],
84
+ async execute(code) {
85
+ return eval(code.val);
86
+ }
87
+ }
88
+ ```
89
+
90
+ ## ./.default/BScript/import.js
91
+
92
+ ```javascript
93
+ const fs = require('fs')
94
+ const path = require('path')
95
+ const Runner = require('@beiser/bscript-runner').Runner;
96
+
97
+ module.exports = {
98
+ name: 'import',
99
+ description: '',
100
+ syntax: '',
101
+ perms: [999],
102
+ async execute({ val: scriptPath }) {
103
+ const imported = fs.readFileSync(path.join(this.__baseDir, scriptPath), { encoding: 'utf8', flag: 'r' });
104
+ const bScriptRunner = new Runner(this.cmdEnviroment)
105
+ bScriptRunner.Create(imported)
106
+ await bScriptRunner.executer()
107
+ return await bScriptRunner.commandExecute({ commandName: "$val", args: [new this.Type("export")], options: bScriptRunner.options })
108
+ }
109
+ }
110
+ ```
111
+
112
+ ## ./.default/BScript/Input.js
113
+
114
+ ```javascript
115
+ module.exports = {
116
+ name: 'Input',
117
+ description: '',
118
+ syntax: '',
119
+ perms: [999],
120
+ async execute(prefix) {
121
+ const test = await this.cmdEnviroment.Input(prefix.val);
122
+ return test
123
+ }
124
+ }
125
+ ```
126
+
127
+ ## ./.default/BScript/js_new.js
128
+
129
+ ```javascript
130
+ module.exports = {
131
+ name: 'js_new',
132
+ description: '',
133
+ syntax: '',
134
+ perms: [999],
135
+ execute: (jsTypeClass, ...args) => {
136
+ return new jsTypeClass.val(...args.map(x=>x?.val??x))
137
+ }
138
+ }
139
+ ```
140
+
141
+ ## ./.default/BScript/js_require.js
142
+
143
+ ```javascript
144
+ module.exports = {
145
+ name: 'js',
146
+ description: '',
147
+ syntax: '',
148
+ perms: [999],
149
+ execute: (req) => {
150
+ return require(req.val)
151
+ }
152
+ }
153
+ ```
154
+
155
+ ## ./.default/BScript/jstype.js
156
+
157
+ ```javascript
158
+ module.exports = {
159
+ name: 'jstype',
160
+ description: '',
161
+ syntax: '',
162
+ perms: [999],
163
+ execute: (bsval) => {
164
+ return { type: "jstype", val: bsval?.type == "ref" ? bsval.get() : bsval.val}
165
+ }
166
+ }
167
+ ```
168
+
169
+ ## ./.default/BScript/num.js
170
+
171
+ ```javascript
172
+ const Helpers = require('@beiser/bscript-runner').Helpers;
173
+
174
+ module.exports = {
175
+ name: 'num',
176
+ description: '',
177
+ syntax: '',
178
+ perms: [999],
179
+ execute: ({ val }) => Helpers.Number(val)
180
+ }
181
+ ```
182
+
183
+ ## ./.default/BScript/object.js
184
+
185
+ ```javascript
186
+ const Helpers = require('@beiser/bscript-runner').Helpers;
187
+
188
+ module.exports = {
189
+ name: 'object',
190
+ description: '',
191
+ syntax: '',
192
+ perms: [999],
193
+ execute(bsval) {
194
+ const obj = {}
195
+ if(bsval?.type == 'array') {
196
+ bsval.val.map(x => {
197
+ obj[x.name] = x.val;
198
+ })
199
+ } else {
200
+ obj[bsval.name] = bsval.val
201
+ }
202
+ return Helpers.Object(obj)
203
+ }
204
+ }
205
+ ```
206
+
207
+ ## ./.default/BScript/print.js
208
+
209
+ ```javascript
210
+ module.exports = {
211
+ name: 'print',
212
+ description: '',
213
+ syntax: '',
214
+ perms: [999],
215
+ execute(...args) {
216
+ this.cmdEnviroment.commandController.Print(...args.map(x=>x.GetDisplayType()))
217
+ }
218
+ }
219
+ ```
220
+
221
+ ## ./.default/BScript/raw.js
222
+
223
+ ```javascript
224
+ module.exports = {
225
+ name: 'raw',
226
+ description: '',
227
+ syntax: '',
228
+ perms: [999],
229
+ execute(bsval) {
230
+ return new this.Type(bsval.val)
231
+ }
232
+ }
233
+ ```
234
+
235
+ ## ./.default/BScript/ref.js
236
+
237
+ ```javascript
238
+ function setValue(obj, path, value) {
239
+ const parts = Array.isArray(path)
240
+ ? path
241
+ : path.split(".");
242
+
243
+ parts.shift();
244
+
245
+ let current = obj;
246
+
247
+ for (let i = 0; i < parts.length - 1; i++) {
248
+ const key = parts[i];
249
+
250
+ if (current.val[key] == null)
251
+ current.val[key] = {};
252
+
253
+ current = current.val[key];
254
+ }
255
+
256
+ current.val[parts.at(-1)] = value;
257
+ }
258
+
259
+ function deepValue(obj, path) {
260
+ for (const key of path) {
261
+ if (obj == null)
262
+ return undefined;
263
+
264
+ obj = obj.val?.[key];
265
+ }
266
+
267
+ return obj;
268
+ }
269
+
270
+ module.exports = {
271
+ name: "ref",
272
+ description: "",
273
+ syntax: "",
274
+ perms: [999],
275
+
276
+ execute: function (bsarg, ...props) {
277
+ const path =
278
+ (bsarg?.type === "object" || bsarg?.type === "jstype")
279
+ ? props.flatMap(x => x.val.split("."))
280
+ : [bsarg, ...props].flatMap(x => x.val.split("."));
281
+
282
+ const root =
283
+ (bsarg?.type === "object" || bsarg?.type === "jstype")
284
+ ? bsarg
285
+ : this;
286
+
287
+ const bsref = new this.Type({
288
+ type: "ref",
289
+
290
+ prop: path,
291
+
292
+ get: () => deepValue(root, path),
293
+
294
+ set: value => {
295
+ if (root?.val)
296
+ setValue(root, path, value);
297
+ }
298
+ });
299
+
300
+ return bsref;
301
+ }
302
+ };
303
+ ```
304
+
305
+ ## ./.default/BScript/run.js
306
+
307
+ ```javascript
308
+ module.exports = {
309
+ name: 'run',
310
+ description: '',
311
+ syntax: '',
312
+ perms: [999],
313
+ async execute(func, ...args) {
314
+ if(func.type == this.Type.FuncionType){
315
+ return func.isAsync ? new this.Type({ type: this.Type.PromiseType, val: func.val(...args.map(arg=>arg.val)) }) : await func.val(...args.map(arg=>arg.val));
316
+ }
317
+ }
318
+ }
319
+ ```
320
+
321
+ ## ./.default/BScript/run-with-await.js
322
+
323
+ ```javascript
324
+ module.exports = {
325
+ name: 'await',
326
+ description: '',
327
+ syntax: '',
328
+ perms: [999],
329
+ async execute(arg1, arg2) {
330
+ if(arg1?.type == 'promise') {
331
+ return await arg1.val
332
+ } if(arg1?.val == "run") {
333
+ return await await this.commandExecute.bind(this)({ commandName: "run", args: [arg2] }).then(x => x?.val)
334
+ }
335
+ }
336
+ }
337
+ ```
338
+
339
+ ## ./.default/BScript/script.js
340
+
341
+ ```javascript
342
+ const fs = require('fs')
343
+ const path = require('path')
344
+
345
+ module.exports = {
346
+ name: 'script',
347
+ description: '',
348
+ syntax: '',
349
+ perms: [999],
350
+ async execute({ val: scriptPath }) {
351
+ const imported = fs.readFileSync(path.join(this.__baseDir, scriptPath), { encoding: 'utf8', flag: 'r' });
352
+ await this.cmdEnviroment.bscript(imported)()
353
+ }
354
+ }
355
+ ```
356
+
357
+ ## ./.default/BScript/str.js
358
+
359
+ ```javascript
360
+ const Helpers = require('@beiser/bscript-runner').Helpers;
361
+
362
+ module.exports = {
363
+ name: 'str',
364
+ description: '',
365
+ syntax: '',
366
+ perms: [999],
367
+ execute: (...bsvals) => Helpers.Text(bsvals.filter(x=>x).map(x=>x.val).join(""))
368
+ }
369
+ ```
370
+
371
+ ## ./.default/DebugOnly/clear.js
372
+
373
+ ```javascript
374
+ module.exports = {
375
+ name: 'clear',
376
+ description: 'Очищает комадную строку.',
377
+ syntax: 'clear',
378
+ execute() {
379
+ this.cmdEnviroment.commandController.ClearConsole();
380
+ }
381
+ }
382
+ ```
383
+
384
+ ## ./.default/DebugOnly/update-commands.js
385
+
386
+ ```javascript
387
+ module.exports = {
388
+ name: 'update-commands',
389
+ description: 'Обновить все команды.',
390
+ syntax: 'update-commands',
391
+ async execute() {
392
+ this.cmdEnviroment._updateCommands();
393
+ }
394
+ }
395
+ ```
396
+
397
+ ## ./.default/help.js
398
+
399
+ ```javascript
400
+ var descriptions = {
401
+
402
+ }
403
+
404
+ module.exports = {
405
+ name: 'help',
406
+ description: 'Выводит все команды одним списком.',
407
+ syntax: 'help',
408
+ execute() {
409
+ this.cmdEnviroment.commandController.Print(
410
+ Object.keys(this.cmdEnviroment.commandController.CMD._commands).map(key =>
411
+ `\n\
412
+ Command: ${key}\n\
413
+ Desciption: ${this.cmdEnviroment.commandController.CMD._commands[key].description}\n\
414
+ Declaration: ${this.cmdEnviroment.commandController.CMD._commands[key].syntax}\n\
415
+ `
416
+ ).join("\n")
417
+ );
418
+ }
419
+ }
420
+ ```
421
+
package/index.js ADDED
@@ -0,0 +1,8 @@
1
+ const BScript = require("./BScript")
2
+ const TerminalCommandController = require("./TerminalCommandController")
3
+ const utils = require("./SRC/utils/utils")
4
+ module.exports = {
5
+ BScript,
6
+ TCC: TerminalCommandController,
7
+ utils
8
+ }
package/package.json ADDED
@@ -0,0 +1,12 @@
1
+ {
2
+ "name": "bscript-cli",
3
+ "version": "1.0.0",
4
+ "main": "index.js",
5
+ "license": "MIT",
6
+ "dependencies": {
7
+ "@beiser/bscript-runner": "^1.0.1"
8
+ },
9
+ "bin": {
10
+ "bscript": "./bin/bscript.js"
11
+ }
12
+ }
package/postinstall.js ADDED
@@ -0,0 +1,12 @@
1
+ // const saveFile = require('fs').writeFileSync;
2
+
3
+ // const pkgJsonPath = process.argv[2] + "/package.json";
4
+
5
+ // const json = require(pkgJsonPath);
6
+ // if (!json.hasOwnProperty('scripts')) {
7
+ // json.scripts = {};
8
+ // }
9
+
10
+ // json.scripts['cmd'] = "node " + process.cwd() + "/RunCMD.js";
11
+
12
+ // saveFile(pkgJsonPath, JSON.stringify(json, null, 2));