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.
- package/BScript.js +233 -0
- package/Docs/BScript/BSCRIPT-REFERENCE-CLI.md +502 -0
- package/Docs/Images/BScript-baner.png +0 -0
- package/Docs/Images/BooleanType.png +0 -0
- package/Docs/Images/FuncionType.png +0 -0
- package/Docs/Images/Logo.png +0 -0
- package/Docs/Images/NumberType.png +0 -0
- package/Docs/Images/ObjectType.png +0 -0
- package/Docs/Images/PromiseType.png +0 -0
- package/Docs/Images/RawType.png +0 -0
- package/Docs/Images/RefType.png +0 -0
- package/Docs/Images/TextType.png +0 -0
- package/Docs/README.md +157 -0
- package/Docs/REFERENCE.md +602 -0
- package/Docs/TECHNICAL.md +1143 -0
- package/Docs/TUTORIAL.md +604 -0
- package/SRC/BScriptHistory.js +98 -0
- package/SRC/CMDPermissions.js +4 -0
- package/SRC/utils/utils.js +63 -0
- package/TerminalCommandController.js +193 -0
- package/bin/bscript.js +94 -0
- package/commands/.default/BScript/$arg.js +9 -0
- package/commands/.default/BScript/$val.js +19 -0
- package/commands/.default/BScript/Input.js +10 -0
- package/commands/.default/BScript/bool.js +9 -0
- package/commands/.default/BScript/delay.js +10 -0
- package/commands/.default/BScript/eval.js +9 -0
- package/commands/.default/BScript/import.js +17 -0
- package/commands/.default/BScript/js_new.js +9 -0
- package/commands/.default/BScript/js_require.js +9 -0
- package/commands/.default/BScript/jstype.js +9 -0
- package/commands/.default/BScript/num.js +9 -0
- package/commands/.default/BScript/object.js +19 -0
- package/commands/.default/BScript/print.js +9 -0
- package/commands/.default/BScript/raw.js +9 -0
- package/commands/.default/BScript/ref.js +65 -0
- package/commands/.default/BScript/run-with-await.js +13 -0
- package/commands/.default/BScript/run.js +11 -0
- package/commands/.default/BScript/script.js +13 -0
- package/commands/.default/BScript/str.js +9 -0
- package/commands/.default/DebugOnly/clear.js +8 -0
- package/commands/.default/DebugOnly/update-commands.js +8 -0
- package/commands/.default/help.js +20 -0
- package/commands/snapshot.md +421 -0
- package/index.js +8 -0
- package/package.json +12 -0
- package/postinstall.js +12 -0
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
const fs = require("fs")
|
|
2
|
+
const path = require("path")
|
|
3
|
+
|
|
4
|
+
module.exports = {}
|
|
5
|
+
|
|
6
|
+
module.exports.readDirRecursive = function(dir) {
|
|
7
|
+
var results = [];
|
|
8
|
+
var list = fs.readdirSync(dir);
|
|
9
|
+
list.forEach(function(file) {
|
|
10
|
+
file = dir + '/' + file;
|
|
11
|
+
var stat = fs.statSync(file);
|
|
12
|
+
if (stat && stat.isDirectory()) {
|
|
13
|
+
/* Recurse into a subdirectory */
|
|
14
|
+
results = results.concat(module.exports.readDirRecursive(file));
|
|
15
|
+
} else {
|
|
16
|
+
/* Is a file */
|
|
17
|
+
results.push(file);
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
return results;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
module.exports.getLeftWordIndex = (text, index) => {
|
|
24
|
+
if(index == 0)
|
|
25
|
+
return 0;
|
|
26
|
+
var words = text.split(" ");
|
|
27
|
+
var wordGlobalIndex = 0;
|
|
28
|
+
for(var i = 0; i < words.length; i++) {
|
|
29
|
+
if(wordGlobalIndex >= index) {
|
|
30
|
+
return wordGlobalIndex - words[i-1].length - 1;
|
|
31
|
+
}
|
|
32
|
+
wordGlobalIndex += words[i].length + 1;
|
|
33
|
+
}
|
|
34
|
+
return wordGlobalIndex - words[words.length-1].length - 1;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
module.exports.getRightWordIndex = (text, index) => {
|
|
38
|
+
var words = text.split(" ");
|
|
39
|
+
var wordGlobalIndex = 0;
|
|
40
|
+
for(var i = 0; i < words.length; i++) {
|
|
41
|
+
if(wordGlobalIndex >= index) {
|
|
42
|
+
return wordGlobalIndex + words[i].length;
|
|
43
|
+
}
|
|
44
|
+
wordGlobalIndex += words[i].length + 1;
|
|
45
|
+
}
|
|
46
|
+
return wordGlobalIndex;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
module.exports.delay = time => new Promise(res=>setTimeout(res,time))
|
|
50
|
+
|
|
51
|
+
module.exports.arraysIsEqual = (arr1, arr2) => JSON.stringify(arr1) == JSON.stringify(arr2);
|
|
52
|
+
|
|
53
|
+
module.exports.insert = function(str, index, string) {
|
|
54
|
+
if (index > 0)
|
|
55
|
+
{
|
|
56
|
+
return str.substring(0, index) + string + str.substring(index, str.length);
|
|
57
|
+
}
|
|
58
|
+
return string + str;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
module.exports.removeByIndex = function(str, index) {
|
|
62
|
+
return str.slice(0,index) + str.slice(index+1);
|
|
63
|
+
}
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
const { getLeftWordIndex, getRightWordIndex, removeByIndex, insert } = require('./SRC/utils/utils');
|
|
2
|
+
const BScriptHistory = require('./SRC/BScriptHistory')
|
|
3
|
+
|
|
4
|
+
// Terminal Command Controller
|
|
5
|
+
module.exports = class TCC {
|
|
6
|
+
constructor({ ...args }) {
|
|
7
|
+
this.stdinVal = args?.defaultCommandPrefix??0;
|
|
8
|
+
this.col = args?.col??0;
|
|
9
|
+
this.defaultCommandPrefix = args?.defaultCommandPrefix??"";
|
|
10
|
+
this.CMD = args?.CMD;
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
this.stdinEmmiter = args?.stdinEmmiter;
|
|
14
|
+
this.BScriptHistory = new BScriptHistory();
|
|
15
|
+
if(this.CMD) {
|
|
16
|
+
this.CMD.commandHistory = this.BScriptHistory.history;
|
|
17
|
+
|
|
18
|
+
process.on('exit', () => {
|
|
19
|
+
this.BScriptHistory.history = this.CMD.commandHistory;
|
|
20
|
+
this.BScriptHistory.save();
|
|
21
|
+
});
|
|
22
|
+
process.on('SIGINT', () => {
|
|
23
|
+
this.BScriptHistory.history = this.CMD.commandHistory;
|
|
24
|
+
this.BScriptHistory.save();
|
|
25
|
+
process.exit(0);
|
|
26
|
+
});
|
|
27
|
+
process.on('SIGTERM', () => {
|
|
28
|
+
this.BScriptHistory.history = this.CMD.commandHistory;
|
|
29
|
+
this.BScriptHistory.save();
|
|
30
|
+
process.exit(0);
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
ClearConsole() {
|
|
35
|
+
console.clear()
|
|
36
|
+
}
|
|
37
|
+
InitInput(rawMode) {
|
|
38
|
+
process.stdin.setRawMode(rawMode);
|
|
39
|
+
process.stdin.resume();
|
|
40
|
+
process.stdin.setEncoding('utf-8');
|
|
41
|
+
}
|
|
42
|
+
ClearLine() {
|
|
43
|
+
process.stdout.write("\r\x1b[K");
|
|
44
|
+
}
|
|
45
|
+
WriteCommand(cmd) {
|
|
46
|
+
process.stdout.write( `${this.defaultCommandPrefix}${cmd }`)
|
|
47
|
+
}
|
|
48
|
+
Write(text) {
|
|
49
|
+
process.stdout.write(text)
|
|
50
|
+
}
|
|
51
|
+
CursorTo(pos) {
|
|
52
|
+
process.stdout.cursorTo(pos);
|
|
53
|
+
}
|
|
54
|
+
Print(...text) {
|
|
55
|
+
console.log(...text);
|
|
56
|
+
}
|
|
57
|
+
SetStdinListener(lName, func) {
|
|
58
|
+
this.stdinEmmiter.on(lName, func);
|
|
59
|
+
}
|
|
60
|
+
RemoveStdinListener(lName, func) {
|
|
61
|
+
this.stdinEmmiter.removeListener(lName, func);
|
|
62
|
+
}
|
|
63
|
+
commandRender(inputStdin) {
|
|
64
|
+
let setCommand = (cmd) => {
|
|
65
|
+
this.col = cmd.length;
|
|
66
|
+
this.ClearLine();
|
|
67
|
+
this.WriteCommand(cmd);
|
|
68
|
+
this.stdinVal = cmd;
|
|
69
|
+
}
|
|
70
|
+
function toUnicode(theString) {
|
|
71
|
+
var unicodeString = '';
|
|
72
|
+
for (var i=0; i < theString.length; i++) {
|
|
73
|
+
var theUnicode = theString.charCodeAt(i).toString(16).toUpperCase();
|
|
74
|
+
while (theUnicode.length < 4) {
|
|
75
|
+
theUnicode = '0' + theUnicode;
|
|
76
|
+
}
|
|
77
|
+
theUnicode = '\\u' + theUnicode;
|
|
78
|
+
unicodeString += theUnicode;
|
|
79
|
+
}
|
|
80
|
+
return unicodeString;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
switch(inputStdin) {
|
|
84
|
+
case "\u0003":
|
|
85
|
+
process.stdout.write("\n");
|
|
86
|
+
process.exit();
|
|
87
|
+
return 1;
|
|
88
|
+
case "\u000D":
|
|
89
|
+
this.CursorTo(this.stdinVal.length-1);
|
|
90
|
+
this.Write("\n");
|
|
91
|
+
this.col = 0;
|
|
92
|
+
this.CMD._historyPos = -1;
|
|
93
|
+
return 1;
|
|
94
|
+
case "\u001B\u004F\u004D":
|
|
95
|
+
break;
|
|
96
|
+
case "\u001b[A":
|
|
97
|
+
if(this.CMD._historyPos != this.CMD.commandHistory.length-1) {
|
|
98
|
+
this.CMD._historyPos += 1;
|
|
99
|
+
setCommand(this.CMD.commandHistory[this.CMD.commandHistory.length-1 - this.CMD._historyPos]??"")
|
|
100
|
+
}
|
|
101
|
+
break;
|
|
102
|
+
case "\u001b[B":
|
|
103
|
+
if(this.CMD._historyPos != -1){
|
|
104
|
+
this.CMD._historyPos -= 1;
|
|
105
|
+
setCommand(this.CMD.commandHistory[this.CMD.commandHistory.length-1 - this.CMD._historyPos]??"")
|
|
106
|
+
}
|
|
107
|
+
break;
|
|
108
|
+
case "\u001b[C":
|
|
109
|
+
if(this.col < this.stdinVal.length) {
|
|
110
|
+
this.col += 1;
|
|
111
|
+
process.stdout.write("\u001b[C");
|
|
112
|
+
}
|
|
113
|
+
break;
|
|
114
|
+
case "\u001b[D":
|
|
115
|
+
if(this.col == 0){
|
|
116
|
+
process.stdout.cursorTo(this.defaultCommandPrefix.length);
|
|
117
|
+
return 0;
|
|
118
|
+
}
|
|
119
|
+
this.col -= 1;
|
|
120
|
+
process.stdout.write("\u001b[D");
|
|
121
|
+
break;
|
|
122
|
+
case "\u001b[3~":
|
|
123
|
+
this.stdinVal = removeByIndex(this.stdinVal, this.col);
|
|
124
|
+
this.ClearLine();
|
|
125
|
+
this.WriteCommand(this.stdinVal.replace("\r", "").replace("\n", ""));
|
|
126
|
+
process.stdout.cursorTo(this.col + this.defaultCommandPrefix.length);
|
|
127
|
+
break;
|
|
128
|
+
case "\x7F":
|
|
129
|
+
if(this.col == 0) {
|
|
130
|
+
break;
|
|
131
|
+
}
|
|
132
|
+
this.stdinVal = removeByIndex(this.stdinVal, this.col-1);
|
|
133
|
+
this.ClearLine();
|
|
134
|
+
this.WriteCommand(this.stdinVal.replace("\r", "").replace("\n", ""));
|
|
135
|
+
|
|
136
|
+
this.col -= 1;
|
|
137
|
+
process.stdout.cursorTo(this.col + this.defaultCommandPrefix.length);
|
|
138
|
+
break;
|
|
139
|
+
case "\\x7F":
|
|
140
|
+
break;
|
|
141
|
+
case "\b":
|
|
142
|
+
(()=> {
|
|
143
|
+
const delCount = this.col - (getLeftWordIndex(this.stdinVal, this.col)-1 > 0? getLeftWordIndex(this.stdinVal, this.col)-1: 0);
|
|
144
|
+
this.stdinVal = this.stdinVal.slice(0, (getLeftWordIndex(this.stdinVal, this.col)-1 > 0? getLeftWordIndex(this.stdinVal, this.col)-1: 0)) + this.stdinVal.slice(this.col, this.stdinVal.length);
|
|
145
|
+
this.col -= delCount;
|
|
146
|
+
this.ClearLine();
|
|
147
|
+
this.WriteCommand(this.stdinVal.replace("\r", "").replace("\n", ""));
|
|
148
|
+
})()
|
|
149
|
+
process.stdout.cursorTo(this.col + this.defaultCommandPrefix.length);
|
|
150
|
+
break;
|
|
151
|
+
case "\x1B[3;5~":
|
|
152
|
+
// (()=> {
|
|
153
|
+
// const delCount = (getLeftWordIndex(this.stdinVal, this.col)-1 > 0? getLeftWordIndex(this.stdinVal, this.col)-1: 0) - this.col;
|
|
154
|
+
// this.stdinVal = this.stdinVal.slice(0, this.col) + this.stdinVal.slice(getRightWordIndex(this.stdinVal, this.col), this.stdinVal.length);
|
|
155
|
+
// this.col -= delCount;
|
|
156
|
+
// process.stdout.write("\r\x1b[K");
|
|
157
|
+
// process.stdout.write( `${this.defaultCommandPrefix}${this.stdinVal.replace("\r", "").replace("\n", "")}` );
|
|
158
|
+
// process.stdout.cursorTo(this.col + this.defaultCommandPrefix.length);
|
|
159
|
+
// })()
|
|
160
|
+
break;
|
|
161
|
+
case "\x1B[1;5D":
|
|
162
|
+
this.col = getLeftWordIndex(this.stdinVal, this.col)-1 > 0? getLeftWordIndex(this.stdinVal, this.col)-1: 0;
|
|
163
|
+
process.stdout.cursorTo(this.col + this.defaultCommandPrefix.length);
|
|
164
|
+
break;
|
|
165
|
+
case "\x1B[1;5C":
|
|
166
|
+
if(this.col < this.stdinVal.length) {
|
|
167
|
+
this.col = getRightWordIndex(this.stdinVal, this.col);
|
|
168
|
+
process.stdout.cursorTo(this.col + this.defaultCommandPrefix.length);
|
|
169
|
+
}
|
|
170
|
+
// this.col += this.col - ;
|
|
171
|
+
// process.stdout.cursorTo(wordIndexByTextIndex(this.stdinVal.split(" "), this.col, 1) + this.defaultCommandPrefix.length);
|
|
172
|
+
break;
|
|
173
|
+
default:
|
|
174
|
+
if(this.col == this.stdinVal.length) {
|
|
175
|
+
this.col += inputStdin.length;
|
|
176
|
+
this.stdinVal += inputStdin;
|
|
177
|
+
this.ClearLine();
|
|
178
|
+
this.WriteCommand(this.stdinVal.replace("\r", "").replace("\n", ""));
|
|
179
|
+
} else {
|
|
180
|
+
this.stdinVal = insert(this.stdinVal, this.col, inputStdin);
|
|
181
|
+
this.col += inputStdin.length;
|
|
182
|
+
this.ClearLine();
|
|
183
|
+
this.WriteCommand(this.stdinVal.replace("\r", "").replace("\n", ""));
|
|
184
|
+
process.stdout.cursorTo(this.col + this.defaultCommandPrefix.length);
|
|
185
|
+
}
|
|
186
|
+
break;
|
|
187
|
+
}
|
|
188
|
+
return 0
|
|
189
|
+
}
|
|
190
|
+
OnData(inputStdin) {
|
|
191
|
+
return this.commandRender(inputStdin);
|
|
192
|
+
}
|
|
193
|
+
}
|
package/bin/bscript.js
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
#!/usr/bin/env -S node --no-warnings
|
|
2
|
+
|
|
3
|
+
const BScript = require("../BScript");
|
|
4
|
+
|
|
5
|
+
const args = process.argv.slice(2);
|
|
6
|
+
|
|
7
|
+
const options = {};
|
|
8
|
+
const positional = [];
|
|
9
|
+
|
|
10
|
+
for (let i = 0; i < args.length; i++) {
|
|
11
|
+
const arg = args[i];
|
|
12
|
+
|
|
13
|
+
if (arg.startsWith("--")) {
|
|
14
|
+
const key = arg.substring(2);
|
|
15
|
+
|
|
16
|
+
switch (key) {
|
|
17
|
+
case "eval":
|
|
18
|
+
options.eval = args[++i];
|
|
19
|
+
break;
|
|
20
|
+
|
|
21
|
+
case "help":
|
|
22
|
+
options.help = true;
|
|
23
|
+
break;
|
|
24
|
+
|
|
25
|
+
case "version":
|
|
26
|
+
options.version = true;
|
|
27
|
+
break;
|
|
28
|
+
|
|
29
|
+
default:
|
|
30
|
+
options[key] = true;
|
|
31
|
+
break;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
else if (arg.startsWith("-")) {
|
|
35
|
+
const key = arg.substring(1);
|
|
36
|
+
|
|
37
|
+
switch (key) {
|
|
38
|
+
case "e":
|
|
39
|
+
options.eval = args[++i];
|
|
40
|
+
break;
|
|
41
|
+
|
|
42
|
+
case "h":
|
|
43
|
+
options.help = true;
|
|
44
|
+
break;
|
|
45
|
+
|
|
46
|
+
case "v":
|
|
47
|
+
options.version = true;
|
|
48
|
+
break;
|
|
49
|
+
|
|
50
|
+
default:
|
|
51
|
+
options[key] = true;
|
|
52
|
+
break;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
positional.push(arg);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
const cmd = new BScript();
|
|
61
|
+
cmd.cmdRootPermissions = [
|
|
62
|
+
cmd.perrmissionsKeys.default,
|
|
63
|
+
cmd.perrmissionsKeys.script
|
|
64
|
+
];
|
|
65
|
+
cmd.updateCommands();
|
|
66
|
+
|
|
67
|
+
if (options.help) {
|
|
68
|
+
console.log(`
|
|
69
|
+
Usage:
|
|
70
|
+
bscript <file>
|
|
71
|
+
bscript -e "<script>"
|
|
72
|
+
|
|
73
|
+
Options:
|
|
74
|
+
-e, --eval Execute script text
|
|
75
|
+
-h, --help Show help
|
|
76
|
+
-v, --version Show version
|
|
77
|
+
`);
|
|
78
|
+
process.exit(0);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
if (options.version) {
|
|
82
|
+
console.log(require("../package.json").version);
|
|
83
|
+
process.exit(0);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
if (options.eval) {
|
|
87
|
+
cmd.bscript(options.eval)();
|
|
88
|
+
}
|
|
89
|
+
else if (positional.length > 0) {
|
|
90
|
+
cmd.bscript(`script ${positional[0]}`)();
|
|
91
|
+
}
|
|
92
|
+
else {
|
|
93
|
+
cmd.Start();
|
|
94
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
module.exports = {
|
|
2
|
+
name: '$val',
|
|
3
|
+
description: '',
|
|
4
|
+
syntax: '',
|
|
5
|
+
perms: [999],
|
|
6
|
+
execute(bsarg0, bsarg1) {
|
|
7
|
+
if(bsarg0?.type == "ref") {
|
|
8
|
+
const refVal = bsarg0.get();
|
|
9
|
+
return refVal;
|
|
10
|
+
}
|
|
11
|
+
if(bsarg0.val == "exist"){
|
|
12
|
+
return { type: "bool", val: this.getScope().$val[bsarg1.val] ? 1 : 0 }
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
bsarg0 = this.getScope().$val[bsarg0.val];
|
|
16
|
+
|
|
17
|
+
return bsarg0? !bsarg0.type && !bsarg0.val? new this.Type(bsarg0) : bsarg0 : null;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
const fs = require('fs')
|
|
2
|
+
const path = require('path')
|
|
3
|
+
const Runner = require('@beiser/bscript-runner').Runner;
|
|
4
|
+
|
|
5
|
+
module.exports = {
|
|
6
|
+
name: 'import',
|
|
7
|
+
description: '',
|
|
8
|
+
syntax: '',
|
|
9
|
+
perms: [999],
|
|
10
|
+
async execute({ val: scriptPath }) {
|
|
11
|
+
const imported = fs.readFileSync(path.join(this.__baseDir, scriptPath), { encoding: 'utf8', flag: 'r' });
|
|
12
|
+
const bScriptRunner = new Runner(this.cmdEnviroment)
|
|
13
|
+
bScriptRunner.Create(imported)
|
|
14
|
+
await bScriptRunner.executer()
|
|
15
|
+
return await bScriptRunner.commandExecute({ commandName: "$val", args: [new this.Type("export")], options: bScriptRunner.options })
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
const Helpers = require('@beiser/bscript-runner').Helpers;
|
|
2
|
+
|
|
3
|
+
module.exports = {
|
|
4
|
+
name: 'object',
|
|
5
|
+
description: '',
|
|
6
|
+
syntax: '',
|
|
7
|
+
perms: [999],
|
|
8
|
+
execute(bsval) {
|
|
9
|
+
const obj = {}
|
|
10
|
+
if(bsval?.type == 'array') {
|
|
11
|
+
bsval.val.map(x => {
|
|
12
|
+
obj[x.name] = x.val;
|
|
13
|
+
})
|
|
14
|
+
} else {
|
|
15
|
+
obj[bsval.name] = bsval.val
|
|
16
|
+
}
|
|
17
|
+
return Helpers.Object(obj)
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
function setValue(obj, path, value) {
|
|
2
|
+
const parts = Array.isArray(path)
|
|
3
|
+
? path
|
|
4
|
+
: path.split(".");
|
|
5
|
+
|
|
6
|
+
parts.shift();
|
|
7
|
+
|
|
8
|
+
let current = obj;
|
|
9
|
+
|
|
10
|
+
for (let i = 0; i < parts.length - 1; i++) {
|
|
11
|
+
const key = parts[i];
|
|
12
|
+
|
|
13
|
+
if (current.val[key] == null)
|
|
14
|
+
current.val[key] = {};
|
|
15
|
+
|
|
16
|
+
current = current.val[key];
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
current.val[parts.at(-1)] = value;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function deepValue(obj, path) {
|
|
23
|
+
for (const key of path) {
|
|
24
|
+
if (obj == null)
|
|
25
|
+
return undefined;
|
|
26
|
+
|
|
27
|
+
obj = obj.val?.[key];
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
return obj;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
module.exports = {
|
|
34
|
+
name: "ref",
|
|
35
|
+
description: "",
|
|
36
|
+
syntax: "",
|
|
37
|
+
perms: [999],
|
|
38
|
+
|
|
39
|
+
execute: function (bsarg, ...props) {
|
|
40
|
+
const path =
|
|
41
|
+
(bsarg?.type === "object" || bsarg?.type === "jstype")
|
|
42
|
+
? props.flatMap(x => x.val.split("."))
|
|
43
|
+
: [bsarg, ...props].flatMap(x => x.val.split("."));
|
|
44
|
+
|
|
45
|
+
const root =
|
|
46
|
+
(bsarg?.type === "object" || bsarg?.type === "jstype")
|
|
47
|
+
? bsarg
|
|
48
|
+
: this;
|
|
49
|
+
|
|
50
|
+
const bsref = new this.Type({
|
|
51
|
+
type: "ref",
|
|
52
|
+
|
|
53
|
+
prop: path,
|
|
54
|
+
|
|
55
|
+
get: () => deepValue(root, path),
|
|
56
|
+
|
|
57
|
+
set: value => {
|
|
58
|
+
if (root?.val)
|
|
59
|
+
setValue(root, path, value);
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
return bsref;
|
|
64
|
+
}
|
|
65
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
module.exports = {
|
|
2
|
+
name: 'await',
|
|
3
|
+
description: '',
|
|
4
|
+
syntax: '',
|
|
5
|
+
perms: [999],
|
|
6
|
+
async execute(arg1, arg2) {
|
|
7
|
+
if(arg1?.type == 'promise') {
|
|
8
|
+
return await arg1.val
|
|
9
|
+
} if(arg1?.val == "run") {
|
|
10
|
+
return await await this.commandExecute.bind(this)({ commandName: "run", args: [arg2] }).then(x => x?.val)
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
module.exports = {
|
|
2
|
+
name: 'run',
|
|
3
|
+
description: '',
|
|
4
|
+
syntax: '',
|
|
5
|
+
perms: [999],
|
|
6
|
+
async execute(func, ...args) {
|
|
7
|
+
if(func.type == this.Type.FuncionType){
|
|
8
|
+
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));
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
const fs = require('fs')
|
|
2
|
+
const path = require('path')
|
|
3
|
+
|
|
4
|
+
module.exports = {
|
|
5
|
+
name: 'script',
|
|
6
|
+
description: '',
|
|
7
|
+
syntax: '',
|
|
8
|
+
perms: [999],
|
|
9
|
+
async execute({ val: scriptPath }) {
|
|
10
|
+
const imported = fs.readFileSync(path.join(this.__baseDir, scriptPath), { encoding: 'utf8', flag: 'r' });
|
|
11
|
+
await this.cmdEnviroment.bscript(imported)()
|
|
12
|
+
}
|
|
13
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
var descriptions = {
|
|
2
|
+
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
module.exports = {
|
|
6
|
+
name: 'help',
|
|
7
|
+
description: 'Выводит все команды одним списком.',
|
|
8
|
+
syntax: 'help',
|
|
9
|
+
execute() {
|
|
10
|
+
this.cmdEnviroment.commandController.Print(
|
|
11
|
+
Object.keys(this.cmdEnviroment.commandController.CMD._commands).map(key =>
|
|
12
|
+
`\n\
|
|
13
|
+
Command: ${key}\n\
|
|
14
|
+
Desciption: ${this.cmdEnviroment.commandController.CMD._commands[key].description}\n\
|
|
15
|
+
Declaration: ${this.cmdEnviroment.commandController.CMD._commands[key].syntax}\n\
|
|
16
|
+
`
|
|
17
|
+
).join("\n")
|
|
18
|
+
);
|
|
19
|
+
}
|
|
20
|
+
}
|