@open-discord-bots/framework 0.0.7 → 0.1.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/dist/api/modules/console.d.ts +3 -1
- package/dist/api/modules/console.js +9 -4
- package/dist/cli/editConfig.d.ts +2 -2
- package/dist/cli/editConfig.js +146 -112
- package/dist/cli/{cli.d.ts → index.d.ts} +1 -1
- package/dist/index.d.ts +0 -3
- package/dist/index.js +1 -37
- package/dist/startup/compilation.d.ts +1 -1
- package/dist/startup/dump.d.ts +1 -1
- package/dist/startup/dump.js +2 -2
- package/dist/startup/errorHandling.d.ts +1 -1
- package/dist/startup/errorHandling.js +35 -2
- package/dist/startup/pluginLauncher.d.ts +1 -1
- package/dist/startup/pluginLauncher.js +61 -28
- package/dist/{api/utils.d.ts → utilities/index.d.ts} +1 -1
- package/dist/{api/utils.js → utilities/index.js} +1 -1
- package/package.json +6 -1
- package/src/api/modules/console.ts +8 -4
- package/src/cli/editConfig.ts +3 -2
- package/src/cli/{cli.ts → index.ts} +2 -1
- package/src/index.ts +0 -4
- package/src/startup/compilation.ts +1 -1
- package/src/startup/dump.ts +2 -1
- package/src/startup/errorHandling.ts +2 -1
- package/src/startup/pluginLauncher.ts +2 -1
- package/src/{api/utils.ts → utilities/index.ts} +1 -1
- /package/dist/api/{api.d.ts → index.d.ts} +0 -0
- /package/dist/api/{api.js → index.js} +0 -0
- /package/dist/cli/{cli.js → index.js} +0 -0
- /package/src/api/{api.ts → index.ts} +0 -0
package/dist/cli/editConfig.js
CHANGED
|
@@ -1,13 +1,47 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
2
35
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
36
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
37
|
};
|
|
5
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
39
|
exports.ODCliEditConfigInstance = void 0;
|
|
7
|
-
const
|
|
40
|
+
const api = __importStar(require("../api/index"));
|
|
41
|
+
const utilities = __importStar(require("../utilities/index"));
|
|
8
42
|
const terminal_kit_1 = require("terminal-kit");
|
|
9
43
|
const ansis_1 = __importDefault(require("ansis"));
|
|
10
|
-
const
|
|
44
|
+
const _1 = require(".");
|
|
11
45
|
class ODCliEditConfigInstance {
|
|
12
46
|
opts;
|
|
13
47
|
opendiscord;
|
|
@@ -16,11 +50,11 @@ class ODCliEditConfigInstance {
|
|
|
16
50
|
this.opendiscord = opendiscord;
|
|
17
51
|
}
|
|
18
52
|
async renderEditConfig(backFn) {
|
|
19
|
-
(0,
|
|
53
|
+
(0, _1.renderHeader)(this.opts, []);
|
|
20
54
|
(0, terminal_kit_1.terminal)(ansis_1.default.bold.green("Please select which config you would like to edit.\n") + ansis_1.default.italic.gray("(use arrow keys to navigate, go back using escape)\n"));
|
|
21
55
|
const checkerList = this.opendiscord.checkers.getAll();
|
|
22
56
|
const checkerNameList = checkerList.map((checker) => (checker.options.cliDisplayName ? checker.options.cliDisplayName + " (" + checker.config.file + ")" : checker.config.file));
|
|
23
|
-
const checkerNameLength =
|
|
57
|
+
const checkerNameLength = utilities.getLongestLength(checkerNameList);
|
|
24
58
|
const finalCheckerNameList = checkerNameList.map((name, index) => name.padEnd(checkerNameLength + 5, " ") + ansis_1.default.gray(checkerList[index].options.cliDisplayDescription ? "=> " + checkerList[index].options.cliDisplayDescription : ""));
|
|
25
59
|
const answer = await terminal_kit_1.terminal.singleColumnMenu(finalCheckerNameList, {
|
|
26
60
|
leftPadding: "> ",
|
|
@@ -37,31 +71,31 @@ class ODCliEditConfigInstance {
|
|
|
37
71
|
await this.chooseConfigStructure(checker, async () => { await this.renderEditConfig(backFn); }, checker.structure, configData, {}, NaN, ["(" + checker.config.path + ")"]);
|
|
38
72
|
}
|
|
39
73
|
async chooseConfigStructure(checker, backFn, structure, data, parent, parentIndex, path) {
|
|
40
|
-
if (structure instanceof
|
|
74
|
+
if (structure instanceof api.ODCheckerObjectStructure && typeof data == "object" && !Array.isArray(data) && data)
|
|
41
75
|
await this.renderConfigObjectStructureSelector(checker, backFn, structure, data, parent, parentIndex, path);
|
|
42
|
-
else if (structure instanceof
|
|
76
|
+
else if (structure instanceof api.ODCheckerEnabledObjectStructure && typeof data == "object" && !Array.isArray(data) && data)
|
|
43
77
|
await this.renderConfigEnabledObjectStructureSelector(checker, backFn, structure, data, parent, parentIndex, path);
|
|
44
|
-
else if (structure instanceof
|
|
78
|
+
else if (structure instanceof api.ODCheckerObjectSwitchStructure && typeof data == "object" && !Array.isArray(data) && data)
|
|
45
79
|
await this.renderConfigObjectSwitchStructureSelector(checker, backFn, structure, data, parent, parentIndex, path);
|
|
46
|
-
else if (structure instanceof
|
|
80
|
+
else if (structure instanceof api.ODCheckerArrayStructure && Array.isArray(data))
|
|
47
81
|
await this.renderConfigArrayStructureSelector(checker, backFn, structure, data, parent, parentIndex, path);
|
|
48
|
-
else if (structure instanceof
|
|
82
|
+
else if (structure instanceof api.ODCheckerBooleanStructure && typeof data == "boolean")
|
|
49
83
|
await this.renderConfigBooleanStructureEditor(checker, backFn, structure, data, parent, parentIndex, path);
|
|
50
|
-
else if (structure instanceof
|
|
84
|
+
else if (structure instanceof api.ODCheckerNumberStructure && typeof data == "number")
|
|
51
85
|
await this.renderConfigNumberStructureEditor(checker, backFn, structure, data, parent, parentIndex, path);
|
|
52
|
-
else if (structure instanceof
|
|
86
|
+
else if (structure instanceof api.ODCheckerStringStructure && typeof data == "string")
|
|
53
87
|
await this.renderConfigStringStructureEditor(checker, backFn, structure, data, parent, parentIndex, path);
|
|
54
|
-
else if (structure instanceof
|
|
88
|
+
else if (structure instanceof api.ODCheckerNullStructure && data === null)
|
|
55
89
|
await this.renderConfigNullStructureEditor(checker, backFn, structure, data, parent, parentIndex, path);
|
|
56
|
-
else if (structure instanceof
|
|
90
|
+
else if (structure instanceof api.ODCheckerTypeSwitchStructure)
|
|
57
91
|
await this.renderConfigTypeSwitchStructureEditor(checker, backFn, structure, data, parent, parentIndex, path);
|
|
58
92
|
else
|
|
59
93
|
terminal_kit_1.terminal.red.bold("❌ Unable to detect type of variable! Please try to edit this property in the JSON file itself!");
|
|
60
94
|
}
|
|
61
95
|
async renderConfigObjectStructureSelector(checker, backFn, structure, data, parent, parentIndex, path) {
|
|
62
96
|
if (typeof data != "object" || Array.isArray(data))
|
|
63
|
-
throw new
|
|
64
|
-
(0,
|
|
97
|
+
throw new api.ODSystemError("OD CLI => Property is not of the type 'object'. Please check your config for possible errors. (index: " + parentIndex + ", path: " + path.join(".") + ")");
|
|
98
|
+
(0, _1.renderHeader)(this.opts, path);
|
|
65
99
|
(0, terminal_kit_1.terminal)(ansis_1.default.bold.green("Please select which variable you would like to edit.\n") + ansis_1.default.italic.gray("(use arrow keys to navigate, go back using escape)\n"));
|
|
66
100
|
if (!structure.options.children)
|
|
67
101
|
return await backFn();
|
|
@@ -71,7 +105,7 @@ class ODCliEditConfigInstance {
|
|
|
71
105
|
}
|
|
72
106
|
const list = structure.options.children.filter((child) => !child.cliHideInEditMode);
|
|
73
107
|
const nameList = list.map((child) => (child.checker.options.cliDisplayName ? child.checker.options.cliDisplayName : child.key));
|
|
74
|
-
const nameLength =
|
|
108
|
+
const nameLength = utilities.getLongestLength(nameList);
|
|
75
109
|
const finalnameList = nameList.map((name, index) => name.padEnd(nameLength + 5, " ") + ansis_1.default.gray((!list[index].checker.options.cliHideDescriptionInParent && list[index].checker.options.cliDisplayDescription) ? "=> " + list[index].checker.options.cliDisplayDescription : ""));
|
|
76
110
|
const answer = await terminal_kit_1.terminal.singleColumnMenu(finalnameList, {
|
|
77
111
|
leftPadding: "> ",
|
|
@@ -89,24 +123,24 @@ class ODCliEditConfigInstance {
|
|
|
89
123
|
}
|
|
90
124
|
async renderConfigEnabledObjectStructureSelector(checker, backFn, structure, data, parent, parentIndex, path) {
|
|
91
125
|
if (typeof data != "object" || Array.isArray(data))
|
|
92
|
-
throw new
|
|
126
|
+
throw new api.ODSystemError("OD CLI => Property is not of the type 'object'. Please check your config for possible errors. (index: " + parentIndex + ", path: " + path.join(".") + ")");
|
|
93
127
|
const enabledProperty = structure.options.property;
|
|
94
128
|
const subStructure = structure.options.checker;
|
|
95
129
|
if (!enabledProperty || !subStructure || !subStructure.options.children)
|
|
96
130
|
return await backFn();
|
|
97
131
|
if (!subStructure.options.children.find((child) => child.key === structure.options.property)) {
|
|
98
132
|
if (typeof structure.options.enabledValue == "string")
|
|
99
|
-
subStructure.options.children.unshift({ key: enabledProperty, optional: false, priority: 1, checker: new
|
|
133
|
+
subStructure.options.children.unshift({ key: enabledProperty, optional: false, priority: 1, checker: new api.ODCheckerStringStructure("opendiscord:CLI-checker-enabled-object-structure", {}) });
|
|
100
134
|
else if (typeof structure.options.enabledValue == "number")
|
|
101
|
-
subStructure.options.children.unshift({ key: enabledProperty, optional: false, priority: 1, checker: new
|
|
135
|
+
subStructure.options.children.unshift({ key: enabledProperty, optional: false, priority: 1, checker: new api.ODCheckerNumberStructure("opendiscord:CLI-checker-enabled-object-structure", {}) });
|
|
102
136
|
else if (typeof structure.options.enabledValue == "boolean")
|
|
103
|
-
subStructure.options.children.unshift({ key: enabledProperty, optional: false, priority: 1, checker: new
|
|
137
|
+
subStructure.options.children.unshift({ key: enabledProperty, optional: false, priority: 1, checker: new api.ODCheckerBooleanStructure("opendiscord:CLI-checker-enabled-object-structure", {}) });
|
|
104
138
|
}
|
|
105
139
|
await this.chooseConfigStructure(checker, backFn, subStructure, data, parent, parentIndex, path);
|
|
106
140
|
}
|
|
107
141
|
async renderConfigObjectSwitchStructureSelector(checker, backFn, structure, data, parent, parentIndex, path) {
|
|
108
142
|
if (typeof data != "object" || Array.isArray(data))
|
|
109
|
-
throw new
|
|
143
|
+
throw new api.ODSystemError("OD CLI => Property is not of the type 'object'. Please check your config for possible errors. (index: " + parentIndex + ", path: " + path.join(".") + ")");
|
|
110
144
|
if (!structure.options.objects)
|
|
111
145
|
return await backFn();
|
|
112
146
|
let didMatch = false;
|
|
@@ -119,12 +153,12 @@ class ODCliEditConfigInstance {
|
|
|
119
153
|
}
|
|
120
154
|
}
|
|
121
155
|
if (!didMatch)
|
|
122
|
-
throw new
|
|
156
|
+
throw new api.ODSystemError("OD CLI => Unable to detect type of object in the object switch. Please check your config for possible errors. (index: " + parentIndex + ", path: " + path.join(".") + ")");
|
|
123
157
|
}
|
|
124
158
|
async renderConfigArrayStructureSelector(checker, backFn, structure, data, parent, parentIndex, path) {
|
|
125
159
|
if (!Array.isArray(data))
|
|
126
|
-
throw new
|
|
127
|
-
(0,
|
|
160
|
+
throw new api.ODSystemError("OD CLI => Property is not of the type 'array'. Please check your config for possible errors. (index: " + parentIndex + ", path: " + path.join(".") + ")");
|
|
161
|
+
(0, _1.renderHeader)(this.opts, path);
|
|
128
162
|
(0, terminal_kit_1.terminal)(ansis_1.default.bold.green("Please select what you would like to do.\n") + ansis_1.default.italic.gray("(use arrow keys to navigate, go back using escape)\n"));
|
|
129
163
|
if (!structure.options.propertyChecker)
|
|
130
164
|
return await backFn();
|
|
@@ -167,7 +201,7 @@ class ODCliEditConfigInstance {
|
|
|
167
201
|
}
|
|
168
202
|
async renderConfigArrayStructureEditSelector(checker, backFn, arrayStructure, structure, data, parent, parentIndex, path) {
|
|
169
203
|
const propertyName = arrayStructure.options.cliDisplayPropertyName ?? "index";
|
|
170
|
-
(0,
|
|
204
|
+
(0, _1.renderHeader)(this.opts, path);
|
|
171
205
|
(0, terminal_kit_1.terminal)(ansis_1.default.bold.green("Please select the " + propertyName + " you would like to edit.\n") + ansis_1.default.italic.gray("(use arrow keys to navigate, go back using escape)\n"));
|
|
172
206
|
const longestDataListName = Math.max(...data.map((d, i) => this.getArrayPreviewStructureNameLength(structure, d, data, i)));
|
|
173
207
|
const dataList = data.map((d, i) => (i + 1) + ". " + this.getArrayPreviewFromStructure(structure, d, data, i, longestDataListName));
|
|
@@ -186,7 +220,7 @@ class ODCliEditConfigInstance {
|
|
|
186
220
|
}
|
|
187
221
|
async renderConfigArrayStructureMoveSelector(checker, backFn, arrayStructure, structure, data, parent, parentIndex, path) {
|
|
188
222
|
const propertyName = arrayStructure.options.cliDisplayPropertyName ?? "index";
|
|
189
|
-
(0,
|
|
223
|
+
(0, _1.renderHeader)(this.opts, path);
|
|
190
224
|
(0, terminal_kit_1.terminal)(ansis_1.default.bold.green("Please select the " + propertyName + " you would like to move.\n") + ansis_1.default.italic.gray("(use arrow keys to navigate, go back using escape)\n"));
|
|
191
225
|
const longestDataListName = Math.max(...data.map((d, i) => this.getArrayPreviewStructureNameLength(structure, d, data, i)));
|
|
192
226
|
const dataList = data.map((d, i) => (i + 1) + ". " + this.getArrayPreviewFromStructure(structure, d, data, i, longestDataListName));
|
|
@@ -200,7 +234,7 @@ class ODCliEditConfigInstance {
|
|
|
200
234
|
}).promise;
|
|
201
235
|
if (dataAnswer.canceled)
|
|
202
236
|
return await backFn();
|
|
203
|
-
(0,
|
|
237
|
+
(0, _1.renderHeader)(this.opts, [...path, dataAnswer.selectedIndex]);
|
|
204
238
|
(0, terminal_kit_1.terminal)(ansis_1.default.bold.green("Please select the position you would like to move to.\n") + ansis_1.default.italic.gray("(use arrow keys to navigate, go back using escape)\n"));
|
|
205
239
|
const moveAnswer = await terminal_kit_1.terminal.singleColumnMenu(data.map((d, i) => "Position " + (i + 1)), {
|
|
206
240
|
leftPadding: "> ",
|
|
@@ -218,12 +252,12 @@ class ODCliEditConfigInstance {
|
|
|
218
252
|
insertedData.forEach((d, i) => data[i] = d);
|
|
219
253
|
await checker.config.save();
|
|
220
254
|
terminal_kit_1.terminal.bold.blue("\n\n✅ Property moved succesfully!");
|
|
221
|
-
await
|
|
255
|
+
await utilities.timer(400);
|
|
222
256
|
await backFn();
|
|
223
257
|
}
|
|
224
258
|
async renderConfigArrayStructureRemoveSelector(checker, backFn, arrayStructure, structure, data, parent, parentIndex, path) {
|
|
225
259
|
const propertyName = arrayStructure.options.cliDisplayPropertyName ?? "index";
|
|
226
|
-
(0,
|
|
260
|
+
(0, _1.renderHeader)(this.opts, path);
|
|
227
261
|
(0, terminal_kit_1.terminal)(ansis_1.default.bold.green("Please select the " + propertyName + " you would like to delete.\n") + ansis_1.default.italic.gray("(use arrow keys to navigate, go back using escape)\n"));
|
|
228
262
|
const longestDataListName = Math.max(...data.map((d, i) => this.getArrayPreviewStructureNameLength(structure, d, data, i)));
|
|
229
263
|
const dataList = data.map((d, i) => (i + 1) + ". " + this.getArrayPreviewFromStructure(structure, d, data, i, longestDataListName));
|
|
@@ -240,12 +274,12 @@ class ODCliEditConfigInstance {
|
|
|
240
274
|
data.splice(dataAnswer.selectedIndex, 1);
|
|
241
275
|
await checker.config.save();
|
|
242
276
|
terminal_kit_1.terminal.bold.blue("\n\n✅ Property deleted succesfully!");
|
|
243
|
-
await
|
|
277
|
+
await utilities.timer(400);
|
|
244
278
|
await backFn();
|
|
245
279
|
}
|
|
246
280
|
async renderConfigArrayStructureDuplicateSelector(checker, backFn, arrayStructure, structure, data, parent, parentIndex, path) {
|
|
247
281
|
const propertyName = arrayStructure.options.cliDisplayPropertyName ?? "index";
|
|
248
|
-
(0,
|
|
282
|
+
(0, _1.renderHeader)(this.opts, path);
|
|
249
283
|
(0, terminal_kit_1.terminal)(ansis_1.default.bold.green("Please select the " + propertyName + " you would like to duplicate.\n") + ansis_1.default.italic.gray("(use arrow keys to navigate, go back using escape)\n"));
|
|
250
284
|
const longestDataListName = Math.max(...data.map((d, i) => this.getArrayPreviewStructureNameLength(structure, d, data, i)));
|
|
251
285
|
const dataList = data.map((d, i) => (i + 1) + ". " + this.getArrayPreviewFromStructure(structure, d, data, i, longestDataListName));
|
|
@@ -262,13 +296,13 @@ class ODCliEditConfigInstance {
|
|
|
262
296
|
data.push(JSON.parse(JSON.stringify(data[dataAnswer.selectedIndex])));
|
|
263
297
|
await checker.config.save();
|
|
264
298
|
terminal_kit_1.terminal.bold.blue("\n\n✅ Property duplicated succesfully!");
|
|
265
|
-
await
|
|
299
|
+
await utilities.timer(400);
|
|
266
300
|
await backFn();
|
|
267
301
|
}
|
|
268
302
|
async renderConfigBooleanStructureEditor(checker, backFn, structure, data, parent, parentIndex, path) {
|
|
269
303
|
if (typeof data != "boolean")
|
|
270
|
-
throw new
|
|
271
|
-
(0,
|
|
304
|
+
throw new api.ODSystemError("OD CLI => Property is not of the type 'boolean'. Please check your config for possible errors. (index: " + parentIndex + ", path: " + path.join(".") + ")");
|
|
305
|
+
(0, _1.renderHeader)(this.opts, path);
|
|
272
306
|
(0, terminal_kit_1.terminal)(ansis_1.default.bold.green("You are now editing " + (typeof parentIndex == "string" ? "the boolean property " + ansis_1.default.blue("\"" + parentIndex + "\"") : "boolean property " + ansis_1.default.blue("#" + (parentIndex + 1))) + ".\n") + ansis_1.default.italic.gray("(use arrow keys to navigate, go back using escape)\n"));
|
|
273
307
|
terminal_kit_1.terminal.gray("\nCurrent value: " + ansis_1.default.bold[data ? "green" : "red"](data.toString()) + "\n");
|
|
274
308
|
terminal_kit_1.terminal.gray("Description: " + ansis_1.default.bold(structure.options.cliDisplayDescription ?? "/") + "\n");
|
|
@@ -292,21 +326,21 @@ class ODCliEditConfigInstance {
|
|
|
292
326
|
parent[parentIndex] = newValue;
|
|
293
327
|
await checker.config.save();
|
|
294
328
|
terminal_kit_1.terminal.bold.blue("\n\n✅ Variable saved succesfully!");
|
|
295
|
-
await
|
|
329
|
+
await utilities.timer(400);
|
|
296
330
|
await backFn();
|
|
297
331
|
}
|
|
298
332
|
else {
|
|
299
333
|
const messages = checker.messages.map((msg) => "=> [" + msg.type.toUpperCase() + "] " + msg.message).join("\n");
|
|
300
334
|
terminal_kit_1.terminal.bold.blue("\n\n❌ Variable is invalid! Please try again!");
|
|
301
335
|
terminal_kit_1.terminal.gray("\n" + messages);
|
|
302
|
-
await
|
|
336
|
+
await utilities.timer(1000 + (2000 * checker.messages.length));
|
|
303
337
|
await this.renderConfigBooleanStructureEditor(checker, backFn, structure, data, parent, parentIndex, path);
|
|
304
338
|
}
|
|
305
339
|
}
|
|
306
340
|
async renderConfigNumberStructureEditor(checker, backFn, structure, data, parent, parentIndex, path, prefillValue) {
|
|
307
341
|
if (typeof data != "number")
|
|
308
|
-
throw new
|
|
309
|
-
(0,
|
|
342
|
+
throw new api.ODSystemError("OD CLI => Property is not of the type 'number'. Please check your config for possible errors. (index: " + parentIndex + ", path: " + path.join(".") + ")");
|
|
343
|
+
(0, _1.renderHeader)(this.opts, path);
|
|
310
344
|
(0, terminal_kit_1.terminal)(ansis_1.default.bold.green("You are now editing " + (typeof parentIndex == "string" ? "the number property " + ansis_1.default.blue("\"" + parentIndex + "\"") : "number property " + ansis_1.default.blue("#" + (parentIndex + 1))) + ".\n") + ansis_1.default.italic.gray("(insert a new value and press enter, go back using escape)\n"));
|
|
311
345
|
terminal_kit_1.terminal.gray("\nCurrent value: " + ansis_1.default.bold.blue(data.toString()) + "\n");
|
|
312
346
|
terminal_kit_1.terminal.gray("Description: " + ansis_1.default.bold(structure.options.cliDisplayDescription ?? "/") + "\n");
|
|
@@ -327,25 +361,25 @@ class ODCliEditConfigInstance {
|
|
|
327
361
|
parent[parentIndex] = newValue;
|
|
328
362
|
await checker.config.save();
|
|
329
363
|
terminal_kit_1.terminal.bold.blue("\n\n✅ Variable saved succesfully!");
|
|
330
|
-
await
|
|
364
|
+
await utilities.timer(400);
|
|
331
365
|
await backFn();
|
|
332
366
|
}
|
|
333
367
|
else {
|
|
334
368
|
const messages = checker.messages.map((msg) => "=> [" + msg.type.toUpperCase() + "] " + msg.message).join("\n");
|
|
335
369
|
terminal_kit_1.terminal.bold.blue("\n\n❌ Variable is invalid! Please try again!");
|
|
336
370
|
terminal_kit_1.terminal.red("\n" + messages);
|
|
337
|
-
await
|
|
371
|
+
await utilities.timer(1000 + (2000 * checker.messages.length));
|
|
338
372
|
await this.renderConfigNumberStructureEditor(checker, backFn, structure, data, parent, parentIndex, path, answer);
|
|
339
373
|
}
|
|
340
374
|
}
|
|
341
375
|
async renderConfigStringStructureEditor(checker, backFn, structure, data, parent, parentIndex, path, prefillValue) {
|
|
342
376
|
if (typeof data != "string")
|
|
343
|
-
throw new
|
|
344
|
-
(0,
|
|
377
|
+
throw new api.ODSystemError("OD CLI => Property is not of the type 'string'. Please check your config for possible errors. (index: " + parentIndex + ", path: " + path.join(".") + ")");
|
|
378
|
+
(0, _1.renderHeader)(this.opts, path);
|
|
345
379
|
(0, terminal_kit_1.terminal)(ansis_1.default.bold.green("You are now editing " + (typeof parentIndex == "string" ? "the string property " + ansis_1.default.blue("\"" + parentIndex + "\"") : "string property " + ansis_1.default.blue("#" + (parentIndex + 1))) + ".\n") + ansis_1.default.italic.gray("(insert a new value and press enter, go back using escape)\n"));
|
|
346
380
|
terminal_kit_1.terminal.gray("\nCurrent value:" + (data.includes("\n") ? "\n" : " \"") + ansis_1.default.bold.blue(data) + ansis_1.default.gray(!data.includes("\n") ? "\"\n" : "\n"));
|
|
347
381
|
terminal_kit_1.terminal.gray("Description: " + ansis_1.default.bold(structure.options.cliDisplayDescription ?? "/") + "\n");
|
|
348
|
-
const customExtraOptions = (structure instanceof
|
|
382
|
+
const customExtraOptions = (structure instanceof api.ODCheckerCustomStructure_DiscordId) ? structure.extraOptions : undefined;
|
|
349
383
|
const customAutocompleteFunc = structure.options.cliAutocompleteFunc ? await structure.options.cliAutocompleteFunc() : null;
|
|
350
384
|
const autocompleteList = ((customAutocompleteFunc ?? structure.options.cliAutocompleteList) ?? customExtraOptions) ?? structure.options.choices;
|
|
351
385
|
const autoCompleteMenuOpts = {
|
|
@@ -382,21 +416,21 @@ class ODCliEditConfigInstance {
|
|
|
382
416
|
parent[parentIndex] = newValue;
|
|
383
417
|
await checker.config.save();
|
|
384
418
|
terminal_kit_1.terminal.bold.blue("\n\n✅ Variable saved succesfully!");
|
|
385
|
-
await
|
|
419
|
+
await utilities.timer(400);
|
|
386
420
|
await backFn();
|
|
387
421
|
}
|
|
388
422
|
else {
|
|
389
423
|
const messages = checker.messages.map((msg) => "=> [" + msg.type.toUpperCase() + "] " + msg.message).join("\n");
|
|
390
424
|
terminal_kit_1.terminal.bold.blue("\n\n❌ Variable is invalid! Please try again!");
|
|
391
425
|
terminal_kit_1.terminal.red("\n" + messages);
|
|
392
|
-
await
|
|
426
|
+
await utilities.timer(1000 + (2000 * checker.messages.length));
|
|
393
427
|
await this.renderConfigStringStructureEditor(checker, backFn, structure, data, parent, parentIndex, path, answer);
|
|
394
428
|
}
|
|
395
429
|
}
|
|
396
430
|
async renderConfigNullStructureEditor(checker, backFn, structure, data, parent, parentIndex, path) {
|
|
397
431
|
if (data !== null)
|
|
398
|
-
throw new
|
|
399
|
-
(0,
|
|
432
|
+
throw new api.ODSystemError("OD CLI => Property is not of the type 'null'. Please check your config for possible errors. (index: " + parentIndex + ", path: " + path.join(".") + ")");
|
|
433
|
+
(0, _1.renderHeader)(this.opts, path);
|
|
400
434
|
(0, terminal_kit_1.terminal)(ansis_1.default.bold.green("You are now editing " + (typeof parentIndex == "string" ? "the null property " + ansis_1.default.blue("\"" + parentIndex + "\"") : "null property " + ansis_1.default.blue("#" + (parentIndex + 1))) + ".\n") + ansis_1.default.italic.gray("(use arrow keys to navigate, go back using escape)\n"));
|
|
401
435
|
terminal_kit_1.terminal.gray("\nCurrent value: " + ansis_1.default.bold.blue("null") + "\n");
|
|
402
436
|
terminal_kit_1.terminal.gray("Description: " + ansis_1.default.bold(structure.options.cliDisplayDescription ?? "/") + "\n");
|
|
@@ -420,19 +454,19 @@ class ODCliEditConfigInstance {
|
|
|
420
454
|
parent[parentIndex] = newValue;
|
|
421
455
|
await checker.config.save();
|
|
422
456
|
terminal_kit_1.terminal.bold.blue("\n\n✅ Variable saved succesfully!");
|
|
423
|
-
await
|
|
457
|
+
await utilities.timer(400);
|
|
424
458
|
await backFn();
|
|
425
459
|
}
|
|
426
460
|
else {
|
|
427
461
|
const messages = checker.messages.map((msg) => "=> [" + msg.type.toUpperCase() + "] " + msg.message).join("\n");
|
|
428
462
|
terminal_kit_1.terminal.bold.blue("\n\n❌ Variable is invalid! Please try again!");
|
|
429
463
|
terminal_kit_1.terminal.red("\n" + messages);
|
|
430
|
-
await
|
|
464
|
+
await utilities.timer(1000 + (2000 * checker.messages.length));
|
|
431
465
|
await this.renderConfigNullStructureEditor(checker, backFn, structure, data, parent, parentIndex, path);
|
|
432
466
|
}
|
|
433
467
|
}
|
|
434
468
|
async renderConfigTypeSwitchStructureEditor(checker, backFn, structure, data, parent, parentIndex, path) {
|
|
435
|
-
(0,
|
|
469
|
+
(0, _1.renderHeader)(this.opts, path);
|
|
436
470
|
(0, terminal_kit_1.terminal)(ansis_1.default.bold.green("You are now editing " + (typeof parentIndex == "string" ? "the property " + ansis_1.default.blue("\"" + parentIndex + "\"") : "property " + ansis_1.default.blue("#" + (parentIndex + 1))) + ".\n") + ansis_1.default.italic.gray("(use arrow keys to navigate, go back using escape)\n"));
|
|
437
471
|
terminal_kit_1.terminal.gray("\nCurrent value: " + ansis_1.default.bold.blue(data.toString()) + "\n");
|
|
438
472
|
terminal_kit_1.terminal.gray("Description: " + ansis_1.default.bold(structure.options.cliDisplayDescription ?? "/") + "\n");
|
|
@@ -474,29 +508,29 @@ class ODCliEditConfigInstance {
|
|
|
474
508
|
await this.renderConfigNullStructureEditor(checker, async () => { await this.renderConfigTypeSwitchStructureEditor(checker, backFn, structure, data, parent, parentIndex, path); }, structure.options.null, null, parent, parentIndex, path);
|
|
475
509
|
}
|
|
476
510
|
getArrayPreviewStructureNameLength(structure, data, parent, parentIndex) {
|
|
477
|
-
if (structure instanceof
|
|
511
|
+
if (structure instanceof api.ODCheckerBooleanStructure && typeof data == "boolean")
|
|
478
512
|
return data.toString().length;
|
|
479
|
-
else if (structure instanceof
|
|
513
|
+
else if (structure instanceof api.ODCheckerNumberStructure && typeof data == "number")
|
|
480
514
|
return data.toString().length;
|
|
481
|
-
else if (structure instanceof
|
|
515
|
+
else if (structure instanceof api.ODCheckerStringStructure && typeof data == "string")
|
|
482
516
|
return data.length;
|
|
483
|
-
else if (structure instanceof
|
|
517
|
+
else if (structure instanceof api.ODCheckerNullStructure && data === null)
|
|
484
518
|
return "Null".length;
|
|
485
|
-
else if (structure instanceof
|
|
519
|
+
else if (structure instanceof api.ODCheckerArrayStructure && Array.isArray(data))
|
|
486
520
|
return "Array".length;
|
|
487
|
-
else if (structure instanceof
|
|
521
|
+
else if (structure instanceof api.ODCheckerObjectStructure && typeof data == "object" && !Array.isArray(data) && data) {
|
|
488
522
|
if (!structure.options.cliDisplayKeyInParentArray)
|
|
489
523
|
return "Object".length;
|
|
490
524
|
else
|
|
491
525
|
return data[structure.options.cliDisplayKeyInParentArray].toString().length;
|
|
492
526
|
}
|
|
493
|
-
else if (structure instanceof
|
|
527
|
+
else if (structure instanceof api.ODCheckerEnabledObjectStructure && typeof data == "object" && !Array.isArray(data) && data) {
|
|
494
528
|
const subStructure = structure.options.checker;
|
|
495
529
|
if (!subStructure)
|
|
496
530
|
return "<unknown-property>".length;
|
|
497
531
|
return this.getArrayPreviewStructureNameLength(subStructure, data, parent, parentIndex);
|
|
498
532
|
}
|
|
499
|
-
else if (structure instanceof
|
|
533
|
+
else if (structure instanceof api.ODCheckerObjectSwitchStructure && typeof data == "object" && !Array.isArray(data) && data) {
|
|
500
534
|
for (const objectTemplate of (structure.options.objects ?? [])) {
|
|
501
535
|
if (objectTemplate.properties.every((prop) => data[prop.key] === prop.value)) {
|
|
502
536
|
//object template matches data
|
|
@@ -506,7 +540,7 @@ class ODCliEditConfigInstance {
|
|
|
506
540
|
}
|
|
507
541
|
return "<unknown-property>".length;
|
|
508
542
|
}
|
|
509
|
-
else if (structure instanceof
|
|
543
|
+
else if (structure instanceof api.ODCheckerTypeSwitchStructure) {
|
|
510
544
|
if (typeof data == "boolean" && structure.options.boolean)
|
|
511
545
|
return this.getArrayPreviewStructureNameLength(structure.options.boolean, data, parent, parentIndex);
|
|
512
546
|
else if (typeof data == "number" && structure.options.number)
|
|
@@ -526,30 +560,30 @@ class ODCliEditConfigInstance {
|
|
|
526
560
|
return "<unknown-property>".length;
|
|
527
561
|
}
|
|
528
562
|
getArrayPreviewFromStructure(structure, data, parent, parentIndex, nameLength) {
|
|
529
|
-
if (structure instanceof
|
|
563
|
+
if (structure instanceof api.ODCheckerBooleanStructure && typeof data == "boolean")
|
|
530
564
|
return data.toString();
|
|
531
|
-
else if (structure instanceof
|
|
565
|
+
else if (structure instanceof api.ODCheckerNumberStructure && typeof data == "number")
|
|
532
566
|
return data.toString();
|
|
533
|
-
else if (structure instanceof
|
|
567
|
+
else if (structure instanceof api.ODCheckerStringStructure && typeof data == "string")
|
|
534
568
|
return data;
|
|
535
|
-
else if (structure instanceof
|
|
569
|
+
else if (structure instanceof api.ODCheckerNullStructure && data === null)
|
|
536
570
|
return "Null";
|
|
537
|
-
else if (structure instanceof
|
|
571
|
+
else if (structure instanceof api.ODCheckerArrayStructure && Array.isArray(data))
|
|
538
572
|
return "Array";
|
|
539
|
-
else if (structure instanceof
|
|
573
|
+
else if (structure instanceof api.ODCheckerObjectStructure && typeof data == "object" && !Array.isArray(data) && data) {
|
|
540
574
|
const additionalKeys = (structure.options.cliDisplayAdditionalKeysInParentArray ?? []).map((key) => key + ": " + data[key].toString()).join(", ");
|
|
541
575
|
if (!structure.options.cliDisplayKeyInParentArray)
|
|
542
576
|
return "Object";
|
|
543
577
|
else
|
|
544
578
|
return data[structure.options.cliDisplayKeyInParentArray].toString().padEnd(nameLength + 5, " ") + ansis_1.default.gray(additionalKeys.length > 0 ? "(" + additionalKeys + ")" : "");
|
|
545
579
|
}
|
|
546
|
-
else if (structure instanceof
|
|
580
|
+
else if (structure instanceof api.ODCheckerEnabledObjectStructure && typeof data == "object" && !Array.isArray(data) && data) {
|
|
547
581
|
const subStructure = structure.options.checker;
|
|
548
582
|
if (!subStructure)
|
|
549
583
|
return "<unknown-property>";
|
|
550
584
|
return this.getArrayPreviewFromStructure(subStructure, data, parent, parentIndex, nameLength);
|
|
551
585
|
}
|
|
552
|
-
else if (structure instanceof
|
|
586
|
+
else if (structure instanceof api.ODCheckerObjectSwitchStructure && typeof data == "object" && !Array.isArray(data) && data) {
|
|
553
587
|
for (const objectTemplate of (structure.options.objects ?? [])) {
|
|
554
588
|
if (objectTemplate.properties.every((prop) => data[prop.key] === prop.value)) {
|
|
555
589
|
//object template matches data
|
|
@@ -559,7 +593,7 @@ class ODCliEditConfigInstance {
|
|
|
559
593
|
}
|
|
560
594
|
return "<unknown-property>";
|
|
561
595
|
}
|
|
562
|
-
else if (structure instanceof
|
|
596
|
+
else if (structure instanceof api.ODCheckerTypeSwitchStructure) {
|
|
563
597
|
if (typeof data == "boolean" && structure.options.boolean)
|
|
564
598
|
return this.getArrayPreviewFromStructure(structure.options.boolean, data, parent, parentIndex, nameLength);
|
|
565
599
|
else if (typeof data == "number" && structure.options.number)
|
|
@@ -579,23 +613,23 @@ class ODCliEditConfigInstance {
|
|
|
579
613
|
return "<unknown-property>";
|
|
580
614
|
}
|
|
581
615
|
async chooseAdditionConfigStructure(checker, backFn, nextFn, structure, parent, parentIndex, path, localPath) {
|
|
582
|
-
if (structure instanceof
|
|
616
|
+
if (structure instanceof api.ODCheckerObjectStructure)
|
|
583
617
|
await this.renderAdditionConfigObjectStructure(checker, backFn, nextFn, structure, parent, parentIndex, path, localPath);
|
|
584
|
-
else if (structure instanceof
|
|
618
|
+
else if (structure instanceof api.ODCheckerBooleanStructure)
|
|
585
619
|
await this.renderAdditionConfigBooleanStructure(checker, backFn, nextFn, structure, parent, parentIndex, path, localPath);
|
|
586
|
-
else if (structure instanceof
|
|
620
|
+
else if (structure instanceof api.ODCheckerNumberStructure)
|
|
587
621
|
await this.renderAdditionConfigNumberStructure(checker, backFn, nextFn, structure, parent, parentIndex, path, localPath);
|
|
588
|
-
else if (structure instanceof
|
|
622
|
+
else if (structure instanceof api.ODCheckerStringStructure)
|
|
589
623
|
await this.renderAdditionConfigStringStructure(checker, backFn, nextFn, structure, parent, parentIndex, path, localPath);
|
|
590
|
-
else if (structure instanceof
|
|
624
|
+
else if (structure instanceof api.ODCheckerNullStructure)
|
|
591
625
|
await this.renderAdditionConfigNullStructure(checker, backFn, nextFn, structure, parent, parentIndex, path, localPath);
|
|
592
|
-
else if (structure instanceof
|
|
626
|
+
else if (structure instanceof api.ODCheckerEnabledObjectStructure)
|
|
593
627
|
await this.renderAdditionConfigEnabledObjectStructure(checker, backFn, nextFn, structure, parent, parentIndex, path, localPath);
|
|
594
|
-
else if (structure instanceof
|
|
628
|
+
else if (structure instanceof api.ODCheckerObjectSwitchStructure)
|
|
595
629
|
await this.renderAdditionConfigObjectSwitchStructure(checker, backFn, nextFn, structure, parent, parentIndex, path, localPath);
|
|
596
|
-
else if (structure instanceof
|
|
630
|
+
else if (structure instanceof api.ODCheckerArrayStructure)
|
|
597
631
|
await this.renderAdditionConfigArrayStructureSelector(checker, backFn, nextFn, structure, parent, parentIndex, path, localPath);
|
|
598
|
-
else if (structure instanceof
|
|
632
|
+
else if (structure instanceof api.ODCheckerTypeSwitchStructure)
|
|
599
633
|
await this.renderAdditionConfigTypeSwitchStructure(checker, backFn, nextFn, structure, parent, parentIndex, path, localPath);
|
|
600
634
|
else
|
|
601
635
|
await backFn();
|
|
@@ -608,26 +642,26 @@ class ODCliEditConfigInstance {
|
|
|
608
642
|
const childStructure = children.find((c) => c.key == key);
|
|
609
643
|
if (childStructure) {
|
|
610
644
|
const defaultValue = childStructure.checker.options.cliInitDefaultValue;
|
|
611
|
-
if (childStructure.checker instanceof
|
|
645
|
+
if (childStructure.checker instanceof api.ODCheckerBooleanStructure)
|
|
612
646
|
localData[key] = (typeof defaultValue == "boolean" ? defaultValue : false);
|
|
613
|
-
else if (childStructure.checker instanceof
|
|
647
|
+
else if (childStructure.checker instanceof api.ODCheckerNumberStructure)
|
|
614
648
|
localData[key] = (typeof defaultValue == "number" ? defaultValue : 0);
|
|
615
|
-
else if (childStructure.checker instanceof
|
|
649
|
+
else if (childStructure.checker instanceof api.ODCheckerStringStructure)
|
|
616
650
|
localData[key] = (typeof defaultValue == "string" ? defaultValue : "");
|
|
617
|
-
else if (childStructure.checker instanceof
|
|
651
|
+
else if (childStructure.checker instanceof api.ODCheckerNullStructure)
|
|
618
652
|
localData[key] = (defaultValue === null ? defaultValue : null);
|
|
619
|
-
else if (childStructure.checker instanceof
|
|
653
|
+
else if (childStructure.checker instanceof api.ODCheckerArrayStructure)
|
|
620
654
|
localData[key] = (Array.isArray(defaultValue) ? JSON.parse(JSON.stringify(defaultValue)) : []);
|
|
621
|
-
else if (childStructure.checker instanceof
|
|
655
|
+
else if (childStructure.checker instanceof api.ODCheckerObjectStructure)
|
|
622
656
|
localData[key] = ((typeof defaultValue == "object" && !Array.isArray(defaultValue) && defaultValue) ? JSON.parse(JSON.stringify(defaultValue)) : {});
|
|
623
|
-
else if (childStructure.checker instanceof
|
|
657
|
+
else if (childStructure.checker instanceof api.ODCheckerObjectSwitchStructure)
|
|
624
658
|
localData[key] = ((typeof defaultValue == "object" && !Array.isArray(defaultValue) && defaultValue) ? JSON.parse(JSON.stringify(defaultValue)) : {});
|
|
625
|
-
else if (childStructure.checker instanceof
|
|
659
|
+
else if (childStructure.checker instanceof api.ODCheckerEnabledObjectStructure)
|
|
626
660
|
localData[key] = ((typeof defaultValue == "object" && !Array.isArray(defaultValue) && defaultValue) ? JSON.parse(JSON.stringify(defaultValue)) : {});
|
|
627
|
-
else if (childStructure.checker instanceof
|
|
661
|
+
else if (childStructure.checker instanceof api.ODCheckerTypeSwitchStructure && typeof defaultValue != "undefined")
|
|
628
662
|
localData[key] = JSON.parse(JSON.stringify(defaultValue));
|
|
629
663
|
else
|
|
630
|
-
throw new
|
|
664
|
+
throw new api.ODSystemError("OD CLI => Object skip key has an invalid checker structure! key: " + key);
|
|
631
665
|
}
|
|
632
666
|
}
|
|
633
667
|
//add properties that need to be configured
|
|
@@ -638,7 +672,7 @@ class ODCliEditConfigInstance {
|
|
|
638
672
|
}, async () => {
|
|
639
673
|
//finish setup
|
|
640
674
|
terminal_kit_1.terminal.bold.blue("\n\n✅ Variable saved succesfully!");
|
|
641
|
-
await
|
|
675
|
+
await utilities.timer(400);
|
|
642
676
|
await nextFn(localData);
|
|
643
677
|
});
|
|
644
678
|
}
|
|
@@ -667,11 +701,11 @@ class ODCliEditConfigInstance {
|
|
|
667
701
|
return await backFn();
|
|
668
702
|
let propertyStructure;
|
|
669
703
|
if (typeof enabledValue == "string")
|
|
670
|
-
propertyStructure = new
|
|
704
|
+
propertyStructure = new api.ODCheckerStringStructure("opendiscord:CLI-checker-enabled-object-structure", {});
|
|
671
705
|
else if (typeof enabledValue == "number")
|
|
672
|
-
propertyStructure = new
|
|
706
|
+
propertyStructure = new api.ODCheckerNumberStructure("opendiscord:CLI-checker-enabled-object-structure", {});
|
|
673
707
|
else if (typeof enabledValue == "boolean")
|
|
674
|
-
propertyStructure = new
|
|
708
|
+
propertyStructure = new api.ODCheckerBooleanStructure("opendiscord:CLI-checker-enabled-object-structure", {});
|
|
675
709
|
else
|
|
676
710
|
throw new Error("OD CLI => enabled object structure has an invalid type of enabledProperty. It must be a primitive boolean/number/string.");
|
|
677
711
|
const localData = {};
|
|
@@ -681,7 +715,7 @@ class ODCliEditConfigInstance {
|
|
|
681
715
|
else {
|
|
682
716
|
localData[enabledProperty] = data;
|
|
683
717
|
//copy old object checker to new object checker => all options get de-referenced (this is needed for the new object skip keys are temporary)
|
|
684
|
-
const newStructure = new
|
|
718
|
+
const newStructure = new api.ODCheckerObjectStructure(subStructure.id, { children: [] });
|
|
685
719
|
//copy all options over to the new checker
|
|
686
720
|
newStructure.options.children = [...subStructure.options.children];
|
|
687
721
|
newStructure.options.cliInitSkipKeys = subStructure.options.children.map((child) => child.key);
|
|
@@ -696,7 +730,7 @@ class ODCliEditConfigInstance {
|
|
|
696
730
|
}, propertyStructure, localData, enabledProperty, [...path, parentIndex], [...localPath, parentIndex]);
|
|
697
731
|
}
|
|
698
732
|
async renderAdditionConfigObjectSwitchStructure(checker, backFn, nextFn, structure, parent, parentIndex, path, localPath) {
|
|
699
|
-
(0,
|
|
733
|
+
(0, _1.renderHeader)(this.opts, [...path, parentIndex]);
|
|
700
734
|
(0, terminal_kit_1.terminal)(ansis_1.default.bold.green("What type of object would you like to add?\n") + ansis_1.default.italic.gray("(use arrow keys to navigate, go back using escape)\n"));
|
|
701
735
|
const answer = await terminal_kit_1.terminal.singleColumnMenu(structure.options.objects.map((obj) => obj.name), {
|
|
702
736
|
leftPadding: "> ",
|
|
@@ -711,7 +745,7 @@ class ODCliEditConfigInstance {
|
|
|
711
745
|
const objectTemplate = structure.options.objects[answer.selectedIndex];
|
|
712
746
|
//copy old object checker to new object checker => all options get de-referenced (this is needed for the new object switch properties which are temporary)
|
|
713
747
|
const oldStructure = objectTemplate.checker;
|
|
714
|
-
const newStructure = new
|
|
748
|
+
const newStructure = new api.ODCheckerObjectStructure(oldStructure.id, { children: [] });
|
|
715
749
|
//copy all options over to the new checker
|
|
716
750
|
newStructure.options.children = [...oldStructure.options.children];
|
|
717
751
|
newStructure.options.cliInitSkipKeys = [...(oldStructure.options.cliInitSkipKeys ?? [])];
|
|
@@ -730,17 +764,17 @@ class ODCliEditConfigInstance {
|
|
|
730
764
|
for (const prop of objectTemplate.properties) {
|
|
731
765
|
if (!newStructure.options.children.find((child) => child.key === prop.key)) {
|
|
732
766
|
if (typeof prop.value == "string")
|
|
733
|
-
newStructure.options.children.unshift({ key: prop.key, optional: false, priority: 1, checker: new
|
|
767
|
+
newStructure.options.children.unshift({ key: prop.key, optional: false, priority: 1, checker: new api.ODCheckerStringStructure("opendiscord:CLI-checker-object-switch-structure", { cliInitDefaultValue: prop.value }) });
|
|
734
768
|
else if (typeof prop.value == "number")
|
|
735
|
-
newStructure.options.children.unshift({ key: prop.key, optional: false, priority: 1, checker: new
|
|
769
|
+
newStructure.options.children.unshift({ key: prop.key, optional: false, priority: 1, checker: new api.ODCheckerNumberStructure("opendiscord:CLI-checker-object-switch-structure", { cliInitDefaultValue: prop.value }) });
|
|
736
770
|
else if (typeof prop.value == "boolean")
|
|
737
|
-
newStructure.options.children.unshift({ key: prop.key, optional: false, priority: 1, checker: new
|
|
771
|
+
newStructure.options.children.unshift({ key: prop.key, optional: false, priority: 1, checker: new api.ODCheckerBooleanStructure("opendiscord:CLI-checker-object-switch-structure", { cliInitDefaultValue: prop.value }) });
|
|
738
772
|
}
|
|
739
773
|
}
|
|
740
774
|
await this.chooseAdditionConfigStructure(checker, backFn, nextFn, newStructure, parent, parentIndex, path, localPath);
|
|
741
775
|
}
|
|
742
776
|
async renderAdditionConfigBooleanStructure(checker, backFn, nextFn, structure, parent, parentIndex, path, localPath) {
|
|
743
|
-
(0,
|
|
777
|
+
(0, _1.renderHeader)(this.opts, [...path, parentIndex]);
|
|
744
778
|
(0, terminal_kit_1.terminal)(ansis_1.default.bold.green("You are now creating " + (typeof parentIndex == "string" ? "the boolean property " + ansis_1.default.blue("\"" + parentIndex + "\"") : "boolean property " + ansis_1.default.blue("#" + (parentIndex + 1))) + ".\n") + ansis_1.default.italic.gray("(use arrow keys to navigate, go back using escape)\n"));
|
|
745
779
|
terminal_kit_1.terminal.gray("\nProperty: " + ansis_1.default.bold.blue(structure.options.cliDisplayName ?? [...localPath, parentIndex].join(".")) + "\n");
|
|
746
780
|
terminal_kit_1.terminal.gray("Description: " + ansis_1.default.bold(structure.options.cliDisplayDescription ?? "/") + "\n");
|
|
@@ -762,19 +796,19 @@ class ODCliEditConfigInstance {
|
|
|
762
796
|
const isDataValid = structure.check(checker, newValue, newPath);
|
|
763
797
|
if (isDataValid) {
|
|
764
798
|
terminal_kit_1.terminal.bold.blue("\n\n✅ Variable saved succesfully!");
|
|
765
|
-
await
|
|
799
|
+
await utilities.timer(400);
|
|
766
800
|
await nextFn(newValue);
|
|
767
801
|
}
|
|
768
802
|
else {
|
|
769
803
|
const messages = checker.messages.map((msg) => "=> [" + msg.type.toUpperCase() + "] " + msg.message).join("\n");
|
|
770
804
|
terminal_kit_1.terminal.bold.blue("\n\n❌ Variable is invalid! Please try again!");
|
|
771
805
|
terminal_kit_1.terminal.gray("\n" + messages);
|
|
772
|
-
await
|
|
806
|
+
await utilities.timer(1000 + (2000 * checker.messages.length));
|
|
773
807
|
await this.renderAdditionConfigBooleanStructure(checker, backFn, nextFn, structure, parent, parentIndex, path, localPath);
|
|
774
808
|
}
|
|
775
809
|
}
|
|
776
810
|
async renderAdditionConfigNumberStructure(checker, backFn, nextFn, structure, parent, parentIndex, path, localPath, prefillValue) {
|
|
777
|
-
(0,
|
|
811
|
+
(0, _1.renderHeader)(this.opts, [...path, parentIndex]);
|
|
778
812
|
(0, terminal_kit_1.terminal)(ansis_1.default.bold.green("You are now creating " + (typeof parentIndex == "string" ? "the number property " + ansis_1.default.blue("\"" + parentIndex + "\"") : "number property " + ansis_1.default.blue("#" + (parentIndex + 1))) + ".\n") + ansis_1.default.italic.gray("(insert a new value and press enter, go back using escape)\n"));
|
|
779
813
|
terminal_kit_1.terminal.gray("\nProperty: " + ansis_1.default.bold.blue(structure.options.cliDisplayName ?? [...localPath, parentIndex].join(".")) + "\n");
|
|
780
814
|
terminal_kit_1.terminal.gray("Description: " + ansis_1.default.bold(structure.options.cliDisplayDescription ?? "/") + "\n");
|
|
@@ -793,23 +827,23 @@ class ODCliEditConfigInstance {
|
|
|
793
827
|
const isDataValid = structure.check(checker, newValue, newPath);
|
|
794
828
|
if (isDataValid) {
|
|
795
829
|
terminal_kit_1.terminal.bold.blue("\n\n✅ Variable saved succesfully!");
|
|
796
|
-
await
|
|
830
|
+
await utilities.timer(400);
|
|
797
831
|
await nextFn(newValue);
|
|
798
832
|
}
|
|
799
833
|
else {
|
|
800
834
|
const messages = checker.messages.map((msg) => "=> [" + msg.type.toUpperCase() + "] " + msg.message).join("\n");
|
|
801
835
|
terminal_kit_1.terminal.bold.blue("\n\n❌ Variable is invalid! Please try again!");
|
|
802
836
|
terminal_kit_1.terminal.red("\n" + messages);
|
|
803
|
-
await
|
|
837
|
+
await utilities.timer(1000 + (2000 * checker.messages.length));
|
|
804
838
|
await this.renderAdditionConfigNumberStructure(checker, backFn, nextFn, structure, parent, parentIndex, path, localPath, answer);
|
|
805
839
|
}
|
|
806
840
|
}
|
|
807
841
|
async renderAdditionConfigStringStructure(checker, backFn, nextFn, structure, parent, parentIndex, path, localPath, prefillValue) {
|
|
808
|
-
(0,
|
|
842
|
+
(0, _1.renderHeader)(this.opts, [...path, parentIndex]);
|
|
809
843
|
(0, terminal_kit_1.terminal)(ansis_1.default.bold.green("You are now creating " + (typeof parentIndex == "string" ? "the string property " + ansis_1.default.blue("\"" + parentIndex + "\"") : "string property " + ansis_1.default.blue("#" + (parentIndex + 1))) + ".\n") + ansis_1.default.italic.gray("(insert a new value and press enter, go back using escape)\n"));
|
|
810
844
|
terminal_kit_1.terminal.gray("\nProperty: " + ansis_1.default.bold.blue(structure.options.cliDisplayName ?? [...localPath, parentIndex].join(".")) + "\n");
|
|
811
845
|
terminal_kit_1.terminal.gray("Description: " + ansis_1.default.bold(structure.options.cliDisplayDescription ?? "/") + "\n");
|
|
812
|
-
const customExtraOptions = (structure instanceof
|
|
846
|
+
const customExtraOptions = (structure instanceof api.ODCheckerCustomStructure_DiscordId) ? structure.extraOptions : undefined;
|
|
813
847
|
const customAutocompleteFunc = structure.options.cliAutocompleteFunc ? await structure.options.cliAutocompleteFunc() : null;
|
|
814
848
|
const autocompleteList = ((customAutocompleteFunc ?? structure.options.cliAutocompleteList) ?? customExtraOptions) ?? structure.options.choices;
|
|
815
849
|
const autoCompleteMenuOpts = {
|
|
@@ -844,19 +878,19 @@ class ODCliEditConfigInstance {
|
|
|
844
878
|
const isDataValid = structure.check(checker, newValue, newPath);
|
|
845
879
|
if (isDataValid) {
|
|
846
880
|
terminal_kit_1.terminal.bold.blue("\n\n✅ Variable saved succesfully!");
|
|
847
|
-
await
|
|
881
|
+
await utilities.timer(400);
|
|
848
882
|
await nextFn(newValue);
|
|
849
883
|
}
|
|
850
884
|
else {
|
|
851
885
|
const messages = checker.messages.map((msg) => "=> [" + msg.type.toUpperCase() + "] " + msg.message).join("\n");
|
|
852
886
|
terminal_kit_1.terminal.bold.blue("\n\n❌ Variable is invalid! Please try again!");
|
|
853
887
|
terminal_kit_1.terminal.red("\n" + messages);
|
|
854
|
-
await
|
|
888
|
+
await utilities.timer(1000 + (2000 * checker.messages.length));
|
|
855
889
|
await this.renderAdditionConfigStringStructure(checker, backFn, nextFn, structure, parent, parentIndex, path, localPath, answer);
|
|
856
890
|
}
|
|
857
891
|
}
|
|
858
892
|
async renderAdditionConfigNullStructure(checker, backFn, nextFn, structure, parent, parentIndex, path, localPath) {
|
|
859
|
-
(0,
|
|
893
|
+
(0, _1.renderHeader)(this.opts, [...path, parentIndex]);
|
|
860
894
|
(0, terminal_kit_1.terminal)(ansis_1.default.bold.green("You are now creating " + (typeof parentIndex == "string" ? "the null property " + ansis_1.default.blue("\"" + parentIndex + "\"") : "null property " + ansis_1.default.blue("#" + (parentIndex + 1))) + ".\n") + ansis_1.default.italic.gray("(use arrow keys to navigate, go back using escape)\n"));
|
|
861
895
|
terminal_kit_1.terminal.gray("\nProperty: " + ansis_1.default.bold.blue(structure.options.cliDisplayName ?? [...localPath, parentIndex].join(".")) + "\n");
|
|
862
896
|
terminal_kit_1.terminal.gray("Description: " + ansis_1.default.bold(structure.options.cliDisplayDescription ?? "/") + "\n");
|
|
@@ -878,19 +912,19 @@ class ODCliEditConfigInstance {
|
|
|
878
912
|
const isDataValid = structure.check(checker, newValue, newPath);
|
|
879
913
|
if (isDataValid) {
|
|
880
914
|
terminal_kit_1.terminal.bold.blue("\n\n✅ Variable saved succesfully!");
|
|
881
|
-
await
|
|
915
|
+
await utilities.timer(400);
|
|
882
916
|
await nextFn(newValue);
|
|
883
917
|
}
|
|
884
918
|
else {
|
|
885
919
|
const messages = checker.messages.map((msg) => "=> [" + msg.type.toUpperCase() + "] " + msg.message).join("\n");
|
|
886
920
|
terminal_kit_1.terminal.bold.blue("\n\n❌ Variable is invalid! Please try again!");
|
|
887
921
|
terminal_kit_1.terminal.red("\n" + messages);
|
|
888
|
-
await
|
|
922
|
+
await utilities.timer(1000 + (2000 * checker.messages.length));
|
|
889
923
|
await this.renderAdditionConfigNullStructure(checker, backFn, nextFn, structure, parent, parentIndex, path, localPath);
|
|
890
924
|
}
|
|
891
925
|
}
|
|
892
926
|
async renderAdditionConfigArrayStructureSelector(checker, backFn, nextFn, structure, parent, parentIndex, path, localPath, localData = []) {
|
|
893
|
-
(0,
|
|
927
|
+
(0, _1.renderHeader)(this.opts, [...path, parentIndex]);
|
|
894
928
|
(0, terminal_kit_1.terminal)(ansis_1.default.bold.green("Please select what you would like to do with the new array.\n") + ansis_1.default.italic.gray("(use arrow keys to navigate, go back using escape)\n"));
|
|
895
929
|
if (!structure.options.propertyChecker)
|
|
896
930
|
return await backFn();
|
|
@@ -932,7 +966,7 @@ class ODCliEditConfigInstance {
|
|
|
932
966
|
await this.renderConfigArrayStructureDuplicateSelector(checker, backFnFunc, structure, structure.options.propertyChecker, localData, parent, parentIndex, path);
|
|
933
967
|
}
|
|
934
968
|
async renderAdditionConfigTypeSwitchStructure(checker, backFn, nextFn, structure, parent, parentIndex, path, localPath) {
|
|
935
|
-
(0,
|
|
969
|
+
(0, _1.renderHeader)(this.opts, path);
|
|
936
970
|
(0, terminal_kit_1.terminal)(ansis_1.default.bold.green("You are now creating " + (typeof parentIndex == "string" ? "the property " + ansis_1.default.blue("\"" + parentIndex + "\"") : "property " + ansis_1.default.blue("#" + (parentIndex + 1))) + ".\n") + ansis_1.default.italic.gray("(use arrow keys to navigate, go back using escape)\n"));
|
|
937
971
|
terminal_kit_1.terminal.gray("\nProperty: " + ansis_1.default.bold.blue(structure.options.cliDisplayName ?? [...localPath, parentIndex].join(".")) + "\n");
|
|
938
972
|
terminal_kit_1.terminal.gray("Description: " + ansis_1.default.bold(structure.options.cliDisplayDescription ?? "/") + "\n");
|