@open-discord-bots/framework 0.2.12 → 0.2.14
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/index.d.ts +26 -26
- package/dist/api/index.js +26 -42
- package/dist/api/main.d.ts +24 -24
- package/dist/api/main.js +7 -11
- package/dist/api/modules/action.d.ts +3 -3
- package/dist/api/modules/action.js +8 -14
- package/dist/api/modules/base.d.ts +2 -2
- package/dist/api/modules/base.js +14 -63
- package/dist/api/modules/builder.d.ts +3 -3
- package/dist/api/modules/builder.js +61 -122
- package/dist/api/modules/checker.d.ts +4 -4
- package/dist/api/modules/checker.js +55 -87
- package/dist/api/modules/client.d.ts +4 -4
- package/dist/api/modules/client.js +71 -118
- package/dist/api/modules/code.d.ts +2 -2
- package/dist/api/modules/code.js +3 -8
- package/dist/api/modules/config.d.ts +2 -2
- package/dist/api/modules/config.js +21 -63
- package/dist/api/modules/console.d.ts +2 -2
- package/dist/api/modules/console.js +45 -67
- package/dist/api/modules/cooldown.d.ts +2 -2
- package/dist/api/modules/cooldown.js +13 -23
- package/dist/api/modules/database.d.ts +2 -2
- package/dist/api/modules/database.js +19 -29
- package/dist/api/modules/event.d.ts +2 -2
- package/dist/api/modules/event.js +6 -11
- package/dist/api/modules/flag.d.ts +2 -2
- package/dist/api/modules/flag.js +3 -8
- package/dist/api/modules/fuse.js +2 -7
- package/dist/api/modules/helpmenu.d.ts +2 -2
- package/dist/api/modules/helpmenu.js +8 -16
- package/dist/api/modules/language.d.ts +2 -2
- package/dist/api/modules/language.js +12 -21
- package/dist/api/modules/permission.d.ts +3 -3
- package/dist/api/modules/permission.js +9 -47
- package/dist/api/modules/plugin.d.ts +2 -2
- package/dist/api/modules/plugin.js +10 -19
- package/dist/api/modules/post.d.ts +3 -3
- package/dist/api/modules/post.js +3 -8
- package/dist/api/modules/progressbar.d.ts +2 -2
- package/dist/api/modules/progressbar.js +13 -26
- package/dist/api/modules/responder.d.ts +5 -5
- package/dist/api/modules/responder.js +66 -125
- package/dist/api/modules/session.d.ts +2 -2
- package/dist/api/modules/session.js +4 -42
- package/dist/api/modules/startscreen.d.ts +4 -4
- package/dist/api/modules/startscreen.js +28 -44
- package/dist/api/modules/statistic.d.ts +3 -3
- package/dist/api/modules/statistic.js +11 -20
- package/dist/api/modules/verifybar.d.ts +5 -5
- package/dist/api/modules/verifybar.js +6 -11
- package/dist/api/modules/worker.d.ts +1 -1
- package/dist/api/modules/worker.js +6 -11
- package/dist/cli/editConfig.d.ts +2 -2
- package/dist/cli/editConfig.js +189 -229
- package/dist/cli/index.d.ts +2 -2
- package/dist/cli/index.js +37 -62
- package/dist/index.d.ts +4 -4
- package/dist/index.js +6 -13
- package/dist/startup/compilation.d.ts +1 -1
- package/dist/startup/compilation.js +36 -43
- package/dist/startup/dump.d.ts +1 -1
- package/dist/startup/dump.js +4 -41
- package/dist/startup/errorHandling.d.ts +1 -1
- package/dist/startup/errorHandling.js +2 -38
- package/dist/startup/pluginLauncher.d.ts +1 -1
- package/dist/startup/pluginLauncher.js +9 -49
- package/dist/utilities/index.d.ts +1 -1
- package/dist/utilities/index.js +21 -72
- package/package.json +2 -1
- package/src/api/index.ts +26 -26
- package/src/api/main.ts +25 -25
- package/src/api/modules/action.ts +3 -3
- package/src/api/modules/base.ts +2 -2
- package/src/api/modules/builder.ts +3 -3
- package/src/api/modules/checker.ts +4 -4
- package/src/api/modules/client.ts +4 -4
- package/src/api/modules/code.ts +2 -2
- package/src/api/modules/component.txt +3 -3
- package/src/api/modules/config.ts +2 -2
- package/src/api/modules/console.ts +2 -2
- package/src/api/modules/cooldown.ts +2 -2
- package/src/api/modules/database.ts +2 -2
- package/src/api/modules/event.ts +2 -2
- package/src/api/modules/flag.ts +2 -2
- package/src/api/modules/helpmenu.ts +2 -2
- package/src/api/modules/language.ts +2 -2
- package/src/api/modules/permission.ts +3 -3
- package/src/api/modules/plugin.ts +4 -4
- package/src/api/modules/post.ts +3 -3
- package/src/api/modules/progressbar.ts +2 -2
- package/src/api/modules/responder.ts +5 -5
- package/src/api/modules/session.ts +2 -2
- package/src/api/modules/startscreen.ts +4 -4
- package/src/api/modules/statistic.ts +3 -3
- package/src/api/modules/verifybar.ts +5 -5
- package/src/api/modules/worker.ts +1 -1
- package/src/cli/editConfig.ts +3 -3
- package/src/cli/index.ts +3 -3
- package/src/index.ts +5 -5
- package/src/startup/compilation.ts +2 -2
- package/src/startup/dump.ts +2 -2
- package/src/startup/errorHandling.ts +2 -2
- package/src/startup/pluginLauncher.ts +2 -2
- package/src/utilities/index.ts +2 -2
- package/tools/cleanup.js +1 -1
- package/tsconfig.json +1 -1
package/dist/cli/editConfig.js
CHANGED
|
@@ -1,48 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
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
|
-
})();
|
|
35
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
|
-
};
|
|
38
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
exports.ODCliEditConfigInstance = void 0;
|
|
40
|
-
const api = __importStar(require("../api/index"));
|
|
41
|
-
const utilities = __importStar(require("../utilities/index"));
|
|
42
|
-
const terminal_kit_1 = require("terminal-kit");
|
|
43
|
-
const ansis_1 = __importDefault(require("ansis"));
|
|
44
|
-
const _1 = require(".");
|
|
45
|
-
class ODCliEditConfigInstance {
|
|
1
|
+
import * as api from "../api/index.js";
|
|
2
|
+
import * as utilities from "../utilities/index.js";
|
|
3
|
+
import { terminal } from "terminal-kit";
|
|
4
|
+
import ansis from "ansis";
|
|
5
|
+
import { renderHeader } from "./index.js";
|
|
6
|
+
export class ODCliEditConfigInstance {
|
|
46
7
|
opts;
|
|
47
8
|
opendiscord;
|
|
48
9
|
constructor(opts, opendiscord) {
|
|
@@ -50,17 +11,17 @@ class ODCliEditConfigInstance {
|
|
|
50
11
|
this.opendiscord = opendiscord;
|
|
51
12
|
}
|
|
52
13
|
async renderEditConfig(backFn) {
|
|
53
|
-
|
|
54
|
-
|
|
14
|
+
renderHeader(this.opts, []);
|
|
15
|
+
terminal(ansis.bold.green("Please select which config you would like to edit.\n") + ansis.italic.gray("(use arrow keys to navigate, go back using escape)\n"));
|
|
55
16
|
const checkerList = this.opendiscord.checkers.getAll();
|
|
56
17
|
const checkerNameList = checkerList.map((checker) => (checker.options.cliDisplayName ? checker.options.cliDisplayName + " (" + checker.config.file + ")" : checker.config.file));
|
|
57
18
|
const checkerNameLength = utilities.getLongestLength(checkerNameList);
|
|
58
|
-
const finalCheckerNameList = checkerNameList.map((name, index) => name.padEnd(checkerNameLength + 5, " ") +
|
|
59
|
-
const answer = await
|
|
19
|
+
const finalCheckerNameList = checkerNameList.map((name, index) => name.padEnd(checkerNameLength + 5, " ") + ansis.gray(checkerList[index].options.cliDisplayDescription ? "=> " + checkerList[index].options.cliDisplayDescription : ""));
|
|
20
|
+
const answer = await terminal.singleColumnMenu(finalCheckerNameList, {
|
|
60
21
|
leftPadding: "> ",
|
|
61
|
-
style:
|
|
62
|
-
selectedStyle:
|
|
63
|
-
submittedStyle:
|
|
22
|
+
style: terminal.cyan,
|
|
23
|
+
selectedStyle: terminal.bgDefaultColor.bold,
|
|
24
|
+
submittedStyle: terminal.bgBlue,
|
|
64
25
|
extraLines: 2,
|
|
65
26
|
cancelable: true
|
|
66
27
|
}).promise;
|
|
@@ -90,28 +51,28 @@ class ODCliEditConfigInstance {
|
|
|
90
51
|
else if (structure instanceof api.ODCheckerTypeSwitchStructure)
|
|
91
52
|
await this.renderConfigTypeSwitchStructureEditor(checker, backFn, structure, data, parent, parentIndex, path);
|
|
92
53
|
else
|
|
93
|
-
|
|
54
|
+
terminal.red.bold("❌ Unable to detect type of variable! Please try to edit this property in the JSON file itself!");
|
|
94
55
|
}
|
|
95
56
|
async renderConfigObjectStructureSelector(checker, backFn, structure, data, parent, parentIndex, path) {
|
|
96
57
|
if (typeof data != "object" || Array.isArray(data))
|
|
97
58
|
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
|
-
|
|
99
|
-
|
|
59
|
+
renderHeader(this.opts, path);
|
|
60
|
+
terminal(ansis.bold.green("Please select which variable you would like to edit.\n") + ansis.italic.gray("(use arrow keys to navigate, go back using escape)\n"));
|
|
100
61
|
if (!structure.options.children)
|
|
101
62
|
return await backFn();
|
|
102
63
|
if (structure.options.cliDisplayName) {
|
|
103
|
-
|
|
104
|
-
|
|
64
|
+
terminal.gray("\nProperty: " + ansis.bold.blue(structure.options.cliDisplayName) + "\n");
|
|
65
|
+
terminal.gray("Description: " + ansis.bold(structure.options.cliDisplayDescription ?? "/") + "\n");
|
|
105
66
|
}
|
|
106
67
|
const list = structure.options.children.filter((child) => !child.cliHideInEditMode);
|
|
107
68
|
const nameList = list.map((child) => (child.checker.options.cliDisplayName ? child.checker.options.cliDisplayName : child.key));
|
|
108
69
|
const nameLength = utilities.getLongestLength(nameList);
|
|
109
|
-
const finalnameList = nameList.map((name, index) => name.padEnd(nameLength + 5, " ") +
|
|
110
|
-
const answer = await
|
|
70
|
+
const finalnameList = nameList.map((name, index) => name.padEnd(nameLength + 5, " ") + ansis.gray((!list[index].checker.options.cliHideDescriptionInParent && list[index].checker.options.cliDisplayDescription) ? "=> " + list[index].checker.options.cliDisplayDescription : ""));
|
|
71
|
+
const answer = await terminal.singleColumnMenu(finalnameList, {
|
|
111
72
|
leftPadding: "> ",
|
|
112
|
-
style:
|
|
113
|
-
selectedStyle:
|
|
114
|
-
submittedStyle:
|
|
73
|
+
style: terminal.cyan,
|
|
74
|
+
selectedStyle: terminal.bgDefaultColor.bold.defaultColor,
|
|
75
|
+
submittedStyle: terminal.bgBlue,
|
|
115
76
|
extraLines: 2,
|
|
116
77
|
cancelable: true
|
|
117
78
|
}).promise;
|
|
@@ -158,16 +119,16 @@ class ODCliEditConfigInstance {
|
|
|
158
119
|
async renderConfigArrayStructureSelector(checker, backFn, structure, data, parent, parentIndex, path) {
|
|
159
120
|
if (!Array.isArray(data))
|
|
160
121
|
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
|
-
|
|
162
|
-
|
|
122
|
+
renderHeader(this.opts, path);
|
|
123
|
+
terminal(ansis.bold.green("Please select what you would like to do.\n") + ansis.italic.gray("(use arrow keys to navigate, go back using escape)\n"));
|
|
163
124
|
if (!structure.options.propertyChecker)
|
|
164
125
|
return await backFn();
|
|
165
126
|
if (structure.options.cliDisplayName || typeof parentIndex == "string" || !isNaN(parentIndex)) {
|
|
166
|
-
|
|
167
|
-
|
|
127
|
+
terminal.gray("\nProperty: " + ansis.bold.blue(structure.options.cliDisplayName ?? parentIndex.toString()) + "\n");
|
|
128
|
+
terminal.gray("Description: " + ansis.bold(structure.options.cliDisplayDescription ?? "/") + "\n");
|
|
168
129
|
}
|
|
169
130
|
const propertyName = structure.options.cliDisplayPropertyName ?? "index";
|
|
170
|
-
const answer = await
|
|
131
|
+
const answer = await terminal.singleColumnMenu(data.length < 1 ? ["Add " + propertyName] : [
|
|
171
132
|
"Add " + propertyName,
|
|
172
133
|
"Edit " + propertyName,
|
|
173
134
|
"Move " + propertyName,
|
|
@@ -175,9 +136,9 @@ class ODCliEditConfigInstance {
|
|
|
175
136
|
"Duplicate " + propertyName
|
|
176
137
|
], {
|
|
177
138
|
leftPadding: "> ",
|
|
178
|
-
style:
|
|
179
|
-
selectedStyle:
|
|
180
|
-
submittedStyle:
|
|
139
|
+
style: terminal.cyan,
|
|
140
|
+
selectedStyle: terminal.bgDefaultColor.bold,
|
|
141
|
+
submittedStyle: terminal.bgBlue,
|
|
181
142
|
extraLines: 2,
|
|
182
143
|
cancelable: true
|
|
183
144
|
}).promise;
|
|
@@ -201,15 +162,15 @@ class ODCliEditConfigInstance {
|
|
|
201
162
|
}
|
|
202
163
|
async renderConfigArrayStructureEditSelector(checker, backFn, arrayStructure, structure, data, parent, parentIndex, path) {
|
|
203
164
|
const propertyName = arrayStructure.options.cliDisplayPropertyName ?? "index";
|
|
204
|
-
|
|
205
|
-
|
|
165
|
+
renderHeader(this.opts, path);
|
|
166
|
+
terminal(ansis.bold.green("Please select the " + propertyName + " you would like to edit.\n") + ansis.italic.gray("(use arrow keys to navigate, go back using escape)\n"));
|
|
206
167
|
const longestDataListName = Math.max(...data.map((d, i) => this.getArrayPreviewStructureNameLength(structure, d, data, i)));
|
|
207
168
|
const dataList = data.map((d, i) => (i + 1) + ". " + this.getArrayPreviewFromStructure(structure, d, data, i, longestDataListName));
|
|
208
|
-
const dataAnswer = await
|
|
169
|
+
const dataAnswer = await terminal.singleColumnMenu(dataList, {
|
|
209
170
|
leftPadding: "> ",
|
|
210
|
-
style:
|
|
211
|
-
selectedStyle:
|
|
212
|
-
submittedStyle:
|
|
171
|
+
style: terminal.cyan,
|
|
172
|
+
selectedStyle: terminal.bgDefaultColor.bold,
|
|
173
|
+
submittedStyle: terminal.bgBlue,
|
|
213
174
|
extraLines: 2,
|
|
214
175
|
cancelable: true
|
|
215
176
|
}).promise;
|
|
@@ -220,27 +181,27 @@ class ODCliEditConfigInstance {
|
|
|
220
181
|
}
|
|
221
182
|
async renderConfigArrayStructureMoveSelector(checker, backFn, arrayStructure, structure, data, parent, parentIndex, path) {
|
|
222
183
|
const propertyName = arrayStructure.options.cliDisplayPropertyName ?? "index";
|
|
223
|
-
|
|
224
|
-
|
|
184
|
+
renderHeader(this.opts, path);
|
|
185
|
+
terminal(ansis.bold.green("Please select the " + propertyName + " you would like to move.\n") + ansis.italic.gray("(use arrow keys to navigate, go back using escape)\n"));
|
|
225
186
|
const longestDataListName = Math.max(...data.map((d, i) => this.getArrayPreviewStructureNameLength(structure, d, data, i)));
|
|
226
187
|
const dataList = data.map((d, i) => (i + 1) + ". " + this.getArrayPreviewFromStructure(structure, d, data, i, longestDataListName));
|
|
227
|
-
const dataAnswer = await
|
|
188
|
+
const dataAnswer = await terminal.singleColumnMenu(dataList, {
|
|
228
189
|
leftPadding: "> ",
|
|
229
|
-
style:
|
|
230
|
-
selectedStyle:
|
|
231
|
-
submittedStyle:
|
|
190
|
+
style: terminal.cyan,
|
|
191
|
+
selectedStyle: terminal.bgDefaultColor.bold,
|
|
192
|
+
submittedStyle: terminal.bgBlue,
|
|
232
193
|
extraLines: 2,
|
|
233
194
|
cancelable: true
|
|
234
195
|
}).promise;
|
|
235
196
|
if (dataAnswer.canceled)
|
|
236
197
|
return await backFn();
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
const moveAnswer = await
|
|
198
|
+
renderHeader(this.opts, [...path, dataAnswer.selectedIndex]);
|
|
199
|
+
terminal(ansis.bold.green("Please select the position you would like to move to.\n") + ansis.italic.gray("(use arrow keys to navigate, go back using escape)\n"));
|
|
200
|
+
const moveAnswer = await terminal.singleColumnMenu(data.map((d, i) => "Position " + (i + 1)), {
|
|
240
201
|
leftPadding: "> ",
|
|
241
|
-
style:
|
|
242
|
-
selectedStyle:
|
|
243
|
-
submittedStyle:
|
|
202
|
+
style: terminal.cyan,
|
|
203
|
+
selectedStyle: terminal.bgDefaultColor.bold,
|
|
204
|
+
submittedStyle: terminal.bgBlue,
|
|
244
205
|
extraLines: 2,
|
|
245
206
|
cancelable: true
|
|
246
207
|
}).promise;
|
|
@@ -251,21 +212,21 @@ class ODCliEditConfigInstance {
|
|
|
251
212
|
const insertedData = [...slicedData.slice(0, moveAnswer.selectedIndex), subData, ...slicedData.slice(moveAnswer.selectedIndex)];
|
|
252
213
|
insertedData.forEach((d, i) => data[i] = d);
|
|
253
214
|
await checker.config.save();
|
|
254
|
-
|
|
215
|
+
terminal.bold.blue("\n\n✅ Property moved succesfully!");
|
|
255
216
|
await utilities.timer(400);
|
|
256
217
|
await backFn();
|
|
257
218
|
}
|
|
258
219
|
async renderConfigArrayStructureRemoveSelector(checker, backFn, arrayStructure, structure, data, parent, parentIndex, path) {
|
|
259
220
|
const propertyName = arrayStructure.options.cliDisplayPropertyName ?? "index";
|
|
260
|
-
|
|
261
|
-
|
|
221
|
+
renderHeader(this.opts, path);
|
|
222
|
+
terminal(ansis.bold.green("Please select the " + propertyName + " you would like to delete.\n") + ansis.italic.gray("(use arrow keys to navigate, go back using escape)\n"));
|
|
262
223
|
const longestDataListName = Math.max(...data.map((d, i) => this.getArrayPreviewStructureNameLength(structure, d, data, i)));
|
|
263
224
|
const dataList = data.map((d, i) => (i + 1) + ". " + this.getArrayPreviewFromStructure(structure, d, data, i, longestDataListName));
|
|
264
|
-
const dataAnswer = await
|
|
225
|
+
const dataAnswer = await terminal.singleColumnMenu(dataList, {
|
|
265
226
|
leftPadding: "> ",
|
|
266
|
-
style:
|
|
267
|
-
selectedStyle:
|
|
268
|
-
submittedStyle:
|
|
227
|
+
style: terminal.cyan,
|
|
228
|
+
selectedStyle: terminal.bgDefaultColor.bold,
|
|
229
|
+
submittedStyle: terminal.bgBlue,
|
|
269
230
|
extraLines: 2,
|
|
270
231
|
cancelable: true
|
|
271
232
|
}).promise;
|
|
@@ -273,21 +234,21 @@ class ODCliEditConfigInstance {
|
|
|
273
234
|
return await backFn();
|
|
274
235
|
data.splice(dataAnswer.selectedIndex, 1);
|
|
275
236
|
await checker.config.save();
|
|
276
|
-
|
|
237
|
+
terminal.bold.blue("\n\n✅ Property deleted succesfully!");
|
|
277
238
|
await utilities.timer(400);
|
|
278
239
|
await backFn();
|
|
279
240
|
}
|
|
280
241
|
async renderConfigArrayStructureDuplicateSelector(checker, backFn, arrayStructure, structure, data, parent, parentIndex, path) {
|
|
281
242
|
const propertyName = arrayStructure.options.cliDisplayPropertyName ?? "index";
|
|
282
|
-
|
|
283
|
-
|
|
243
|
+
renderHeader(this.opts, path);
|
|
244
|
+
terminal(ansis.bold.green("Please select the " + propertyName + " you would like to duplicate.\n") + ansis.italic.gray("(use arrow keys to navigate, go back using escape)\n"));
|
|
284
245
|
const longestDataListName = Math.max(...data.map((d, i) => this.getArrayPreviewStructureNameLength(structure, d, data, i)));
|
|
285
246
|
const dataList = data.map((d, i) => (i + 1) + ". " + this.getArrayPreviewFromStructure(structure, d, data, i, longestDataListName));
|
|
286
|
-
const dataAnswer = await
|
|
247
|
+
const dataAnswer = await terminal.singleColumnMenu(dataList, {
|
|
287
248
|
leftPadding: "> ",
|
|
288
|
-
style:
|
|
289
|
-
selectedStyle:
|
|
290
|
-
submittedStyle:
|
|
249
|
+
style: terminal.cyan,
|
|
250
|
+
selectedStyle: terminal.bgDefaultColor.bold,
|
|
251
|
+
submittedStyle: terminal.bgBlue,
|
|
291
252
|
extraLines: 2,
|
|
292
253
|
cancelable: true
|
|
293
254
|
}).promise;
|
|
@@ -295,22 +256,22 @@ class ODCliEditConfigInstance {
|
|
|
295
256
|
return await backFn();
|
|
296
257
|
data.push(JSON.parse(JSON.stringify(data[dataAnswer.selectedIndex])));
|
|
297
258
|
await checker.config.save();
|
|
298
|
-
|
|
259
|
+
terminal.bold.blue("\n\n✅ Property duplicated succesfully!");
|
|
299
260
|
await utilities.timer(400);
|
|
300
261
|
await backFn();
|
|
301
262
|
}
|
|
302
263
|
async renderConfigBooleanStructureEditor(checker, backFn, structure, data, parent, parentIndex, path) {
|
|
303
264
|
if (typeof data != "boolean")
|
|
304
265
|
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
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
const answer = await
|
|
266
|
+
renderHeader(this.opts, path);
|
|
267
|
+
terminal(ansis.bold.green("You are now editing " + (typeof parentIndex == "string" ? "the boolean property " + ansis.blue("\"" + parentIndex + "\"") : "boolean property " + ansis.blue("#" + (parentIndex + 1))) + ".\n") + ansis.italic.gray("(use arrow keys to navigate, go back using escape)\n"));
|
|
268
|
+
terminal.gray("\nCurrent value: " + ansis.bold[data ? "green" : "red"](data.toString()) + "\n");
|
|
269
|
+
terminal.gray("Description: " + ansis.bold(structure.options.cliDisplayDescription ?? "/") + "\n");
|
|
270
|
+
const answer = await terminal.singleColumnMenu(["false (Disabled)", "true (Enabled)"], {
|
|
310
271
|
leftPadding: "> ",
|
|
311
|
-
style:
|
|
312
|
-
selectedStyle:
|
|
313
|
-
submittedStyle:
|
|
272
|
+
style: terminal.cyan,
|
|
273
|
+
selectedStyle: terminal.bgDefaultColor.bold,
|
|
274
|
+
submittedStyle: terminal.bgBlue,
|
|
314
275
|
extraLines: 2,
|
|
315
276
|
cancelable: true
|
|
316
277
|
}).promise;
|
|
@@ -325,14 +286,14 @@ class ODCliEditConfigInstance {
|
|
|
325
286
|
if (isDataValid) {
|
|
326
287
|
parent[parentIndex] = newValue;
|
|
327
288
|
await checker.config.save();
|
|
328
|
-
|
|
289
|
+
terminal.bold.blue("\n\n✅ Variable saved succesfully!");
|
|
329
290
|
await utilities.timer(400);
|
|
330
291
|
await backFn();
|
|
331
292
|
}
|
|
332
293
|
else {
|
|
333
294
|
const messages = checker.messages.map((msg) => "=> [" + msg.type.toUpperCase() + "] " + msg.message).join("\n");
|
|
334
|
-
|
|
335
|
-
|
|
295
|
+
terminal.bold.blue("\n\n❌ Variable is invalid! Please try again!");
|
|
296
|
+
terminal.gray("\n" + messages);
|
|
336
297
|
await utilities.timer(1000 + (2000 * checker.messages.length));
|
|
337
298
|
await this.renderConfigBooleanStructureEditor(checker, backFn, structure, data, parent, parentIndex, path);
|
|
338
299
|
}
|
|
@@ -340,13 +301,13 @@ class ODCliEditConfigInstance {
|
|
|
340
301
|
async renderConfigNumberStructureEditor(checker, backFn, structure, data, parent, parentIndex, path, prefillValue) {
|
|
341
302
|
if (typeof data != "number")
|
|
342
303
|
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
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
const answer = await
|
|
304
|
+
renderHeader(this.opts, path);
|
|
305
|
+
terminal(ansis.bold.green("You are now editing " + (typeof parentIndex == "string" ? "the number property " + ansis.blue("\"" + parentIndex + "\"") : "number property " + ansis.blue("#" + (parentIndex + 1))) + ".\n") + ansis.italic.gray("(insert a new value and press enter, go back using escape)\n"));
|
|
306
|
+
terminal.gray("\nCurrent value: " + ansis.bold.blue(data.toString()) + "\n");
|
|
307
|
+
terminal.gray("Description: " + ansis.bold(structure.options.cliDisplayDescription ?? "/") + "\n");
|
|
308
|
+
const answer = await terminal.inputField({
|
|
348
309
|
default: prefillValue,
|
|
349
|
-
style:
|
|
310
|
+
style: terminal.cyan,
|
|
350
311
|
cancelable: true
|
|
351
312
|
}).promise;
|
|
352
313
|
if (typeof answer != "string")
|
|
@@ -360,14 +321,14 @@ class ODCliEditConfigInstance {
|
|
|
360
321
|
if (isDataValid) {
|
|
361
322
|
parent[parentIndex] = newValue;
|
|
362
323
|
await checker.config.save();
|
|
363
|
-
|
|
324
|
+
terminal.bold.blue("\n\n✅ Variable saved succesfully!");
|
|
364
325
|
await utilities.timer(400);
|
|
365
326
|
await backFn();
|
|
366
327
|
}
|
|
367
328
|
else {
|
|
368
329
|
const messages = checker.messages.map((msg) => "=> [" + msg.type.toUpperCase() + "] " + msg.message).join("\n");
|
|
369
|
-
|
|
370
|
-
|
|
330
|
+
terminal.bold.blue("\n\n❌ Variable is invalid! Please try again!");
|
|
331
|
+
terminal.red("\n" + messages);
|
|
371
332
|
await utilities.timer(1000 + (2000 * checker.messages.length));
|
|
372
333
|
await this.renderConfigNumberStructureEditor(checker, backFn, structure, data, parent, parentIndex, path, answer);
|
|
373
334
|
}
|
|
@@ -375,35 +336,35 @@ class ODCliEditConfigInstance {
|
|
|
375
336
|
async renderConfigStringStructureEditor(checker, backFn, structure, data, parent, parentIndex, path, prefillValue) {
|
|
376
337
|
if (typeof data != "string")
|
|
377
338
|
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
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
339
|
+
renderHeader(this.opts, path);
|
|
340
|
+
terminal(ansis.bold.green("You are now editing " + (typeof parentIndex == "string" ? "the string property " + ansis.blue("\"" + parentIndex + "\"") : "string property " + ansis.blue("#" + (parentIndex + 1))) + ".\n") + ansis.italic.gray("(insert a new value and press enter, go back using escape)\n"));
|
|
341
|
+
terminal.gray("\nCurrent value:" + (data.includes("\n") ? "\n" : " \"") + ansis.bold.blue(data) + ansis.gray(!data.includes("\n") ? "\"\n" : "\n"));
|
|
342
|
+
terminal.gray("Description: " + ansis.bold(structure.options.cliDisplayDescription ?? "/") + "\n");
|
|
382
343
|
const customExtraOptions = (structure instanceof api.ODCheckerCustomStructure_DiscordId) ? structure.extraOptions : undefined;
|
|
383
344
|
const customAutocompleteFunc = structure.options.cliAutocompleteFunc ? await structure.options.cliAutocompleteFunc() : null;
|
|
384
345
|
const autocompleteList = ((customAutocompleteFunc ?? structure.options.cliAutocompleteList) ?? customExtraOptions) ?? structure.options.choices;
|
|
385
346
|
const autoCompleteMenuOpts = {
|
|
386
|
-
style:
|
|
387
|
-
selectedStyle:
|
|
347
|
+
style: terminal.white,
|
|
348
|
+
selectedStyle: terminal.bgBlue.white
|
|
388
349
|
};
|
|
389
|
-
const input =
|
|
350
|
+
const input = terminal.inputField({
|
|
390
351
|
default: prefillValue,
|
|
391
|
-
style:
|
|
392
|
-
hintStyle:
|
|
352
|
+
style: terminal.cyan,
|
|
353
|
+
hintStyle: terminal.gray,
|
|
393
354
|
cancelable: false,
|
|
394
355
|
autoComplete: autocompleteList,
|
|
395
356
|
autoCompleteHint: (!!autocompleteList),
|
|
396
357
|
autoCompleteMenu: (autocompleteList) ? autoCompleteMenuOpts : false
|
|
397
358
|
});
|
|
398
|
-
|
|
359
|
+
terminal.on("key", async (name, matches, data) => {
|
|
399
360
|
if (name == "ESCAPE") {
|
|
400
|
-
|
|
361
|
+
terminal.removeListener("key", "cli-render-string-structure-edit");
|
|
401
362
|
input.abort();
|
|
402
363
|
await backFn();
|
|
403
364
|
}
|
|
404
365
|
}, { id: "cli-render-string-structure-edit" });
|
|
405
366
|
const answer = await input.promise;
|
|
406
|
-
|
|
367
|
+
terminal.removeListener("key", "cli-render-string-structure-edit");
|
|
407
368
|
if (typeof answer != "string")
|
|
408
369
|
return;
|
|
409
370
|
//run config checker
|
|
@@ -415,14 +376,14 @@ class ODCliEditConfigInstance {
|
|
|
415
376
|
if (isDataValid) {
|
|
416
377
|
parent[parentIndex] = newValue;
|
|
417
378
|
await checker.config.save();
|
|
418
|
-
|
|
379
|
+
terminal.bold.blue("\n\n✅ Variable saved succesfully!");
|
|
419
380
|
await utilities.timer(400);
|
|
420
381
|
await backFn();
|
|
421
382
|
}
|
|
422
383
|
else {
|
|
423
384
|
const messages = checker.messages.map((msg) => "=> [" + msg.type.toUpperCase() + "] " + msg.message).join("\n");
|
|
424
|
-
|
|
425
|
-
|
|
385
|
+
terminal.bold.blue("\n\n❌ Variable is invalid! Please try again!");
|
|
386
|
+
terminal.red("\n" + messages);
|
|
426
387
|
await utilities.timer(1000 + (2000 * checker.messages.length));
|
|
427
388
|
await this.renderConfigStringStructureEditor(checker, backFn, structure, data, parent, parentIndex, path, answer);
|
|
428
389
|
}
|
|
@@ -430,15 +391,15 @@ class ODCliEditConfigInstance {
|
|
|
430
391
|
async renderConfigNullStructureEditor(checker, backFn, structure, data, parent, parentIndex, path) {
|
|
431
392
|
if (data !== null)
|
|
432
393
|
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
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
const answer = await
|
|
394
|
+
renderHeader(this.opts, path);
|
|
395
|
+
terminal(ansis.bold.green("You are now editing " + (typeof parentIndex == "string" ? "the null property " + ansis.blue("\"" + parentIndex + "\"") : "null property " + ansis.blue("#" + (parentIndex + 1))) + ".\n") + ansis.italic.gray("(use arrow keys to navigate, go back using escape)\n"));
|
|
396
|
+
terminal.gray("\nCurrent value: " + ansis.bold.blue("null") + "\n");
|
|
397
|
+
terminal.gray("Description: " + ansis.bold(structure.options.cliDisplayDescription ?? "/") + "\n");
|
|
398
|
+
const answer = await terminal.singleColumnMenu(["null"], {
|
|
438
399
|
leftPadding: "> ",
|
|
439
|
-
style:
|
|
440
|
-
selectedStyle:
|
|
441
|
-
submittedStyle:
|
|
400
|
+
style: terminal.cyan,
|
|
401
|
+
selectedStyle: terminal.bgDefaultColor.bold,
|
|
402
|
+
submittedStyle: terminal.bgBlue,
|
|
442
403
|
extraLines: 2,
|
|
443
404
|
cancelable: true
|
|
444
405
|
}).promise;
|
|
@@ -453,23 +414,23 @@ class ODCliEditConfigInstance {
|
|
|
453
414
|
if (isDataValid) {
|
|
454
415
|
parent[parentIndex] = newValue;
|
|
455
416
|
await checker.config.save();
|
|
456
|
-
|
|
417
|
+
terminal.bold.blue("\n\n✅ Variable saved succesfully!");
|
|
457
418
|
await utilities.timer(400);
|
|
458
419
|
await backFn();
|
|
459
420
|
}
|
|
460
421
|
else {
|
|
461
422
|
const messages = checker.messages.map((msg) => "=> [" + msg.type.toUpperCase() + "] " + msg.message).join("\n");
|
|
462
|
-
|
|
463
|
-
|
|
423
|
+
terminal.bold.blue("\n\n❌ Variable is invalid! Please try again!");
|
|
424
|
+
terminal.red("\n" + messages);
|
|
464
425
|
await utilities.timer(1000 + (2000 * checker.messages.length));
|
|
465
426
|
await this.renderConfigNullStructureEditor(checker, backFn, structure, data, parent, parentIndex, path);
|
|
466
427
|
}
|
|
467
428
|
}
|
|
468
429
|
async renderConfigTypeSwitchStructureEditor(checker, backFn, structure, data, parent, parentIndex, path) {
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
430
|
+
renderHeader(this.opts, path);
|
|
431
|
+
terminal(ansis.bold.green("You are now editing " + (typeof parentIndex == "string" ? "the property " + ansis.blue("\"" + parentIndex + "\"") : "property " + ansis.blue("#" + (parentIndex + 1))) + ".\n") + ansis.italic.gray("(use arrow keys to navigate, go back using escape)\n"));
|
|
432
|
+
terminal.gray("\nCurrent value: " + ansis.bold.blue(data.toString()) + "\n");
|
|
433
|
+
terminal.gray("Description: " + ansis.bold(structure.options.cliDisplayDescription ?? "/") + "\n");
|
|
473
434
|
const actionsList = [];
|
|
474
435
|
if (structure.options.boolean)
|
|
475
436
|
actionsList.push("Edit as boolean");
|
|
@@ -483,11 +444,11 @@ class ODCliEditConfigInstance {
|
|
|
483
444
|
actionsList.push("Edit as array/list");
|
|
484
445
|
if (structure.options.null)
|
|
485
446
|
actionsList.push("Edit as null");
|
|
486
|
-
const answer = await
|
|
447
|
+
const answer = await terminal.singleColumnMenu(actionsList, {
|
|
487
448
|
leftPadding: "> ",
|
|
488
|
-
style:
|
|
489
|
-
selectedStyle:
|
|
490
|
-
submittedStyle:
|
|
449
|
+
style: terminal.cyan,
|
|
450
|
+
selectedStyle: terminal.bgDefaultColor.bold,
|
|
451
|
+
submittedStyle: terminal.bgBlue,
|
|
491
452
|
extraLines: 2,
|
|
492
453
|
cancelable: true
|
|
493
454
|
}).promise;
|
|
@@ -575,7 +536,7 @@ class ODCliEditConfigInstance {
|
|
|
575
536
|
if (!structure.options.cliDisplayKeyInParentArray)
|
|
576
537
|
return "Object";
|
|
577
538
|
else
|
|
578
|
-
return data[structure.options.cliDisplayKeyInParentArray]?.toString().padEnd(nameLength + 5, " ") +
|
|
539
|
+
return data[structure.options.cliDisplayKeyInParentArray]?.toString().padEnd(nameLength + 5, " ") + ansis.gray(additionalKeys.length > 0 ? "(" + additionalKeys + ")" : "");
|
|
579
540
|
}
|
|
580
541
|
else if (structure instanceof api.ODCheckerEnabledObjectStructure && typeof data == "object" && !Array.isArray(data) && data) {
|
|
581
542
|
const subStructure = structure.options.checker;
|
|
@@ -671,7 +632,7 @@ class ODCliEditConfigInstance {
|
|
|
671
632
|
await backFn();
|
|
672
633
|
}, async () => {
|
|
673
634
|
//finish setup
|
|
674
|
-
|
|
635
|
+
terminal.bold.blue("\n\n✅ Variable saved succesfully!");
|
|
675
636
|
await utilities.timer(400);
|
|
676
637
|
await nextFn(localData);
|
|
677
638
|
});
|
|
@@ -723,13 +684,13 @@ class ODCliEditConfigInstance {
|
|
|
723
684
|
}, propertyStructure, localData, enabledProperty, [...path, parentIndex], [...localPath, parentIndex]);
|
|
724
685
|
}
|
|
725
686
|
async renderAdditionConfigObjectSwitchStructure(checker, backFn, nextFn, structure, parent, parentIndex, path, localPath) {
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
const answer = await
|
|
687
|
+
renderHeader(this.opts, [...path, parentIndex]);
|
|
688
|
+
terminal(ansis.bold.green("What type of object would you like to add?\n") + ansis.italic.gray("(use arrow keys to navigate, go back using escape)\n"));
|
|
689
|
+
const answer = await terminal.singleColumnMenu(structure.options.objects.map((obj) => obj.name), {
|
|
729
690
|
leftPadding: "> ",
|
|
730
|
-
style:
|
|
731
|
-
selectedStyle:
|
|
732
|
-
submittedStyle:
|
|
691
|
+
style: terminal.cyan,
|
|
692
|
+
selectedStyle: terminal.bgDefaultColor.bold,
|
|
693
|
+
submittedStyle: terminal.bgBlue,
|
|
733
694
|
extraLines: 2,
|
|
734
695
|
cancelable: true
|
|
735
696
|
}).promise;
|
|
@@ -760,15 +721,15 @@ class ODCliEditConfigInstance {
|
|
|
760
721
|
await this.chooseAdditionConfigStructure(checker, backFn, nextFn, newStructure, parent, parentIndex, path, localPath);
|
|
761
722
|
}
|
|
762
723
|
async renderAdditionConfigBooleanStructure(checker, backFn, nextFn, structure, parent, parentIndex, path, localPath) {
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
const answer = await
|
|
724
|
+
renderHeader(this.opts, [...path, parentIndex]);
|
|
725
|
+
terminal(ansis.bold.green("You are now creating " + (typeof parentIndex == "string" ? "the boolean property " + ansis.blue("\"" + parentIndex + "\"") : "boolean property " + ansis.blue("#" + (parentIndex + 1))) + ".\n") + ansis.italic.gray("(use arrow keys to navigate, go back using escape)\n"));
|
|
726
|
+
terminal.gray("\nProperty: " + ansis.bold.blue(structure.options.cliDisplayName ?? [...localPath, parentIndex].join(".")) + "\n");
|
|
727
|
+
terminal.gray("Description: " + ansis.bold(structure.options.cliDisplayDescription ?? "/") + "\n");
|
|
728
|
+
const answer = await terminal.singleColumnMenu(["false (Disabled)", "true (Enabled)"], {
|
|
768
729
|
leftPadding: "> ",
|
|
769
|
-
style:
|
|
770
|
-
selectedStyle:
|
|
771
|
-
submittedStyle:
|
|
730
|
+
style: terminal.cyan,
|
|
731
|
+
selectedStyle: terminal.bgDefaultColor.bold,
|
|
732
|
+
submittedStyle: terminal.bgBlue,
|
|
772
733
|
extraLines: 2,
|
|
773
734
|
cancelable: true
|
|
774
735
|
}).promise;
|
|
@@ -781,26 +742,26 @@ class ODCliEditConfigInstance {
|
|
|
781
742
|
checker.messages = []; //manually clear previous messages
|
|
782
743
|
const isDataValid = structure.check(checker, newValue, newPath);
|
|
783
744
|
if (isDataValid) {
|
|
784
|
-
|
|
745
|
+
terminal.bold.blue("\n\n✅ Variable saved succesfully!");
|
|
785
746
|
await utilities.timer(400);
|
|
786
747
|
await nextFn(newValue);
|
|
787
748
|
}
|
|
788
749
|
else {
|
|
789
750
|
const messages = checker.messages.map((msg) => "=> [" + msg.type.toUpperCase() + "] " + msg.message).join("\n");
|
|
790
|
-
|
|
791
|
-
|
|
751
|
+
terminal.bold.blue("\n\n❌ Variable is invalid! Please try again!");
|
|
752
|
+
terminal.gray("\n" + messages);
|
|
792
753
|
await utilities.timer(1000 + (2000 * checker.messages.length));
|
|
793
754
|
await this.renderAdditionConfigBooleanStructure(checker, backFn, nextFn, structure, parent, parentIndex, path, localPath);
|
|
794
755
|
}
|
|
795
756
|
}
|
|
796
757
|
async renderAdditionConfigNumberStructure(checker, backFn, nextFn, structure, parent, parentIndex, path, localPath, prefillValue) {
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
const answer = await
|
|
758
|
+
renderHeader(this.opts, [...path, parentIndex]);
|
|
759
|
+
terminal(ansis.bold.green("You are now creating " + (typeof parentIndex == "string" ? "the number property " + ansis.blue("\"" + parentIndex + "\"") : "number property " + ansis.blue("#" + (parentIndex + 1))) + ".\n") + ansis.italic.gray("(insert a new value and press enter, go back using escape)\n"));
|
|
760
|
+
terminal.gray("\nProperty: " + ansis.bold.blue(structure.options.cliDisplayName ?? [...localPath, parentIndex].join(".")) + "\n");
|
|
761
|
+
terminal.gray("Description: " + ansis.bold(structure.options.cliDisplayDescription ?? "/") + "\n");
|
|
762
|
+
const answer = await terminal.inputField({
|
|
802
763
|
default: prefillValue,
|
|
803
|
-
style:
|
|
764
|
+
style: terminal.cyan,
|
|
804
765
|
cancelable: true
|
|
805
766
|
}).promise;
|
|
806
767
|
if (typeof answer != "string")
|
|
@@ -812,48 +773,48 @@ class ODCliEditConfigInstance {
|
|
|
812
773
|
checker.messages = []; //manually clear previous messages
|
|
813
774
|
const isDataValid = structure.check(checker, newValue, newPath);
|
|
814
775
|
if (isDataValid) {
|
|
815
|
-
|
|
776
|
+
terminal.bold.blue("\n\n✅ Variable saved succesfully!");
|
|
816
777
|
await utilities.timer(400);
|
|
817
778
|
await nextFn(newValue);
|
|
818
779
|
}
|
|
819
780
|
else {
|
|
820
781
|
const messages = checker.messages.map((msg) => "=> [" + msg.type.toUpperCase() + "] " + msg.message).join("\n");
|
|
821
|
-
|
|
822
|
-
|
|
782
|
+
terminal.bold.blue("\n\n❌ Variable is invalid! Please try again!");
|
|
783
|
+
terminal.red("\n" + messages);
|
|
823
784
|
await utilities.timer(1000 + (2000 * checker.messages.length));
|
|
824
785
|
await this.renderAdditionConfigNumberStructure(checker, backFn, nextFn, structure, parent, parentIndex, path, localPath, answer);
|
|
825
786
|
}
|
|
826
787
|
}
|
|
827
788
|
async renderAdditionConfigStringStructure(checker, backFn, nextFn, structure, parent, parentIndex, path, localPath, prefillValue) {
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
789
|
+
renderHeader(this.opts, [...path, parentIndex]);
|
|
790
|
+
terminal(ansis.bold.green("You are now creating " + (typeof parentIndex == "string" ? "the string property " + ansis.blue("\"" + parentIndex + "\"") : "string property " + ansis.blue("#" + (parentIndex + 1))) + ".\n") + ansis.italic.gray("(insert a new value and press enter, go back using escape)\n"));
|
|
791
|
+
terminal.gray("\nProperty: " + ansis.bold.blue(structure.options.cliDisplayName ?? [...localPath, parentIndex].join(".")) + "\n");
|
|
792
|
+
terminal.gray("Description: " + ansis.bold(structure.options.cliDisplayDescription ?? "/") + "\n");
|
|
832
793
|
const customExtraOptions = (structure instanceof api.ODCheckerCustomStructure_DiscordId) ? structure.extraOptions : undefined;
|
|
833
794
|
const customAutocompleteFunc = structure.options.cliAutocompleteFunc ? await structure.options.cliAutocompleteFunc() : null;
|
|
834
795
|
const autocompleteList = ((customAutocompleteFunc ?? structure.options.cliAutocompleteList) ?? customExtraOptions) ?? structure.options.choices;
|
|
835
796
|
const autoCompleteMenuOpts = {
|
|
836
|
-
style:
|
|
837
|
-
selectedStyle:
|
|
797
|
+
style: terminal.white,
|
|
798
|
+
selectedStyle: terminal.bgBlue.white
|
|
838
799
|
};
|
|
839
|
-
const input =
|
|
800
|
+
const input = terminal.inputField({
|
|
840
801
|
default: prefillValue,
|
|
841
|
-
style:
|
|
842
|
-
hintStyle:
|
|
802
|
+
style: terminal.cyan,
|
|
803
|
+
hintStyle: terminal.gray,
|
|
843
804
|
cancelable: false,
|
|
844
805
|
autoComplete: autocompleteList,
|
|
845
806
|
autoCompleteHint: (!!autocompleteList),
|
|
846
807
|
autoCompleteMenu: (autocompleteList) ? autoCompleteMenuOpts : false
|
|
847
808
|
});
|
|
848
|
-
|
|
809
|
+
terminal.on("key", async (name, matches, data) => {
|
|
849
810
|
if (name == "ESCAPE") {
|
|
850
|
-
|
|
811
|
+
terminal.removeListener("key", "cli-render-string-structure-add");
|
|
851
812
|
input.abort();
|
|
852
813
|
await backFn();
|
|
853
814
|
}
|
|
854
815
|
}, { id: "cli-render-string-structure-add" });
|
|
855
816
|
const answer = await input.promise;
|
|
856
|
-
|
|
817
|
+
terminal.removeListener("key", "cli-render-string-structure-add");
|
|
857
818
|
if (typeof answer != "string")
|
|
858
819
|
return;
|
|
859
820
|
//run config checker
|
|
@@ -863,28 +824,28 @@ class ODCliEditConfigInstance {
|
|
|
863
824
|
checker.messages = []; //manually clear previous messages
|
|
864
825
|
const isDataValid = structure.check(checker, newValue, newPath);
|
|
865
826
|
if (isDataValid) {
|
|
866
|
-
|
|
827
|
+
terminal.bold.blue("\n\n✅ Variable saved succesfully!");
|
|
867
828
|
await utilities.timer(400);
|
|
868
829
|
await nextFn(newValue);
|
|
869
830
|
}
|
|
870
831
|
else {
|
|
871
832
|
const messages = checker.messages.map((msg) => "=> [" + msg.type.toUpperCase() + "] " + msg.message).join("\n");
|
|
872
|
-
|
|
873
|
-
|
|
833
|
+
terminal.bold.blue("\n\n❌ Variable is invalid! Please try again!");
|
|
834
|
+
terminal.red("\n" + messages);
|
|
874
835
|
await utilities.timer(1000 + (2000 * checker.messages.length));
|
|
875
836
|
await this.renderAdditionConfigStringStructure(checker, backFn, nextFn, structure, parent, parentIndex, path, localPath, answer);
|
|
876
837
|
}
|
|
877
838
|
}
|
|
878
839
|
async renderAdditionConfigNullStructure(checker, backFn, nextFn, structure, parent, parentIndex, path, localPath) {
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
const answer = await
|
|
840
|
+
renderHeader(this.opts, [...path, parentIndex]);
|
|
841
|
+
terminal(ansis.bold.green("You are now creating " + (typeof parentIndex == "string" ? "the null property " + ansis.blue("\"" + parentIndex + "\"") : "null property " + ansis.blue("#" + (parentIndex + 1))) + ".\n") + ansis.italic.gray("(use arrow keys to navigate, go back using escape)\n"));
|
|
842
|
+
terminal.gray("\nProperty: " + ansis.bold.blue(structure.options.cliDisplayName ?? [...localPath, parentIndex].join(".")) + "\n");
|
|
843
|
+
terminal.gray("Description: " + ansis.bold(structure.options.cliDisplayDescription ?? "/") + "\n");
|
|
844
|
+
const answer = await terminal.singleColumnMenu(["null"], {
|
|
884
845
|
leftPadding: "> ",
|
|
885
|
-
style:
|
|
886
|
-
selectedStyle:
|
|
887
|
-
submittedStyle:
|
|
846
|
+
style: terminal.cyan,
|
|
847
|
+
selectedStyle: terminal.bgDefaultColor.bold,
|
|
848
|
+
submittedStyle: terminal.bgBlue,
|
|
888
849
|
extraLines: 2,
|
|
889
850
|
cancelable: true
|
|
890
851
|
}).promise;
|
|
@@ -897,28 +858,28 @@ class ODCliEditConfigInstance {
|
|
|
897
858
|
checker.messages = []; //manually clear previous messages
|
|
898
859
|
const isDataValid = structure.check(checker, newValue, newPath);
|
|
899
860
|
if (isDataValid) {
|
|
900
|
-
|
|
861
|
+
terminal.bold.blue("\n\n✅ Variable saved succesfully!");
|
|
901
862
|
await utilities.timer(400);
|
|
902
863
|
await nextFn(newValue);
|
|
903
864
|
}
|
|
904
865
|
else {
|
|
905
866
|
const messages = checker.messages.map((msg) => "=> [" + msg.type.toUpperCase() + "] " + msg.message).join("\n");
|
|
906
|
-
|
|
907
|
-
|
|
867
|
+
terminal.bold.blue("\n\n❌ Variable is invalid! Please try again!");
|
|
868
|
+
terminal.red("\n" + messages);
|
|
908
869
|
await utilities.timer(1000 + (2000 * checker.messages.length));
|
|
909
870
|
await this.renderAdditionConfigNullStructure(checker, backFn, nextFn, structure, parent, parentIndex, path, localPath);
|
|
910
871
|
}
|
|
911
872
|
}
|
|
912
873
|
async renderAdditionConfigArrayStructureSelector(checker, backFn, nextFn, structure, parent, parentIndex, path, localPath, localData = []) {
|
|
913
|
-
|
|
914
|
-
|
|
874
|
+
renderHeader(this.opts, [...path, parentIndex]);
|
|
875
|
+
terminal(ansis.bold.green("Please select what you would like to do with the new array.\n") + ansis.italic.gray("(use arrow keys to navigate, go back using escape)\n"));
|
|
915
876
|
if (!structure.options.propertyChecker)
|
|
916
877
|
return await backFn();
|
|
917
|
-
|
|
918
|
-
|
|
878
|
+
terminal.gray("\nProperty: " + ansis.bold.blue(structure.options.cliDisplayName ?? [...localPath, parentIndex].join(".")) + "\n");
|
|
879
|
+
terminal.gray("Description: " + ansis.bold(structure.options.cliDisplayDescription ?? "/") + "\n");
|
|
919
880
|
const propertyName = structure.options.cliDisplayPropertyName ?? "index";
|
|
920
|
-
const answer = await
|
|
921
|
-
|
|
881
|
+
const answer = await terminal.singleColumnMenu(localData.length < 1 ? [ansis.magenta("-> Continue to next variable"), "Add " + propertyName] : [
|
|
882
|
+
ansis.magenta("-> Continue to next variable"),
|
|
922
883
|
"Add " + propertyName,
|
|
923
884
|
"Edit " + propertyName,
|
|
924
885
|
"Move " + propertyName,
|
|
@@ -926,9 +887,9 @@ class ODCliEditConfigInstance {
|
|
|
926
887
|
"Duplicate " + propertyName,
|
|
927
888
|
], {
|
|
928
889
|
leftPadding: "> ",
|
|
929
|
-
style:
|
|
930
|
-
selectedStyle:
|
|
931
|
-
submittedStyle:
|
|
890
|
+
style: terminal.cyan,
|
|
891
|
+
selectedStyle: terminal.bgDefaultColor.bold,
|
|
892
|
+
submittedStyle: terminal.bgBlue,
|
|
932
893
|
extraLines: 2,
|
|
933
894
|
cancelable: true
|
|
934
895
|
}).promise;
|
|
@@ -952,10 +913,10 @@ class ODCliEditConfigInstance {
|
|
|
952
913
|
await this.renderConfigArrayStructureDuplicateSelector(checker, backFnFunc, structure, structure.options.propertyChecker, localData, parent, parentIndex, path);
|
|
953
914
|
}
|
|
954
915
|
async renderAdditionConfigTypeSwitchStructure(checker, backFn, nextFn, structure, parent, parentIndex, path, localPath) {
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
916
|
+
renderHeader(this.opts, path);
|
|
917
|
+
terminal(ansis.bold.green("You are now creating " + (typeof parentIndex == "string" ? "the property " + ansis.blue("\"" + parentIndex + "\"") : "property " + ansis.blue("#" + (parentIndex + 1))) + ".\n") + ansis.italic.gray("(use arrow keys to navigate, go back using escape)\n"));
|
|
918
|
+
terminal.gray("\nProperty: " + ansis.bold.blue(structure.options.cliDisplayName ?? [...localPath, parentIndex].join(".")) + "\n");
|
|
919
|
+
terminal.gray("Description: " + ansis.bold(structure.options.cliDisplayDescription ?? "/") + "\n");
|
|
959
920
|
const actionsList = [];
|
|
960
921
|
if (structure.options.boolean)
|
|
961
922
|
actionsList.push("Create as boolean");
|
|
@@ -969,11 +930,11 @@ class ODCliEditConfigInstance {
|
|
|
969
930
|
actionsList.push("Create as array/list");
|
|
970
931
|
if (structure.options.null)
|
|
971
932
|
actionsList.push("Create as null");
|
|
972
|
-
const answer = await
|
|
933
|
+
const answer = await terminal.singleColumnMenu(actionsList, {
|
|
973
934
|
leftPadding: "> ",
|
|
974
|
-
style:
|
|
975
|
-
selectedStyle:
|
|
976
|
-
submittedStyle:
|
|
935
|
+
style: terminal.cyan,
|
|
936
|
+
selectedStyle: terminal.bgDefaultColor.bold,
|
|
937
|
+
submittedStyle: terminal.bgBlue,
|
|
977
938
|
extraLines: 2,
|
|
978
939
|
cancelable: true
|
|
979
940
|
}).promise;
|
|
@@ -994,4 +955,3 @@ class ODCliEditConfigInstance {
|
|
|
994
955
|
await this.renderAdditionConfigNullStructure(checker, async () => { await this.renderAdditionConfigTypeSwitchStructure(checker, backFn, nextFn, structure, parent, parentIndex, path, localPath); }, nextFn, structure.options.null, parent, parentIndex, path, localPath);
|
|
995
956
|
}
|
|
996
957
|
}
|
|
997
|
-
exports.ODCliEditConfigInstance = ODCliEditConfigInstance;
|