@yamato-daiwa/es-extensions-nodejs 0.0.2 → 1.5.0-alpha.2
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/Distributable/ConsoleApplicationLogger.d.ts +47 -0
- package/Distributable/ConsoleApplicationLogger.js +422 -0
- package/Distributable/ConsoleCommandsParser/ConsoleCommandsParser.d.ts +160 -0
- package/Distributable/ConsoleCommandsParser/ConsoleCommandsParser.js +495 -0
- package/Distributable/ConsoleCommandsParser/ConsoleCommandsParserLocalization.english.d.ts +3 -0
- package/Distributable/ConsoleCommandsParser/ConsoleCommandsParserLocalization.english.js +51 -0
- package/Distributable/DateTime/NodeJS_Timer.d.ts +1 -1
- package/Distributable/DateTime/NodeJS_Timer.js +7 -4
- package/Distributable/Logging/Errors/InvalidConsoleCommandError.d.ts +23 -0
- package/Distributable/Logging/Errors/InvalidConsoleCommandError.js +27 -0
- package/Distributable/Logging/Errors/InvalidConsoleCommandErrorLocalization__English.d.ts +3 -0
- package/Distributable/Logging/Errors/InvalidConsoleCommandErrorLocalization__English.js +11 -0
- package/Distributable/index.d.ts +5 -3
- package/Distributable/index.js +15 -3
- package/README.md +12 -1
- package/package.json +25 -13
- package/tsconfig.test.json +0 -4
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { ErrorLog, ThrownErrorLog, InfoLog, SuccessLog, WarningLog, Log, Logger } from "@yamato-daiwa/es-extensions";
|
|
2
|
+
declare abstract class ConsoleApplicationLogger {
|
|
3
|
+
private static localization;
|
|
4
|
+
static setLocalization(localization: Logger.Localization): typeof ConsoleApplicationLogger;
|
|
5
|
+
static throwErrorAndLog<CustomError extends Error>(errorLog: ThrownErrorLog<CustomError>): never;
|
|
6
|
+
static logError(errorLog: ErrorLog): void;
|
|
7
|
+
static logErrorLikeMessage(errorLikeLog: Log): void;
|
|
8
|
+
static logWarning(warningLog: WarningLog): void;
|
|
9
|
+
static logSuccess(successLog: SuccessLog): void;
|
|
10
|
+
static logInfo(infoLog: InfoLog): void;
|
|
11
|
+
static highlightText(targetString: string): string;
|
|
12
|
+
static generateConsoleMethodParametersForFormattedOutput(formattedOutputData: ConsoleApplicationLogger.FormattedOutputData): Array<string>;
|
|
13
|
+
static generateRedGreenBlueForegroundColorControlSequence(colorDefinition: ConsoleApplicationLogger.RedGreenBlue): string;
|
|
14
|
+
static generateRedGreenBlueBackgroundColorControlSequence(colorDefinition: ConsoleApplicationLogger.RedGreenBlue): string;
|
|
15
|
+
}
|
|
16
|
+
declare namespace ConsoleApplicationLogger {
|
|
17
|
+
type FormattedOutputData = Array<[string, Formatting]>;
|
|
18
|
+
type Formatting = {
|
|
19
|
+
foregroundColor?: FourBitColours | RedGreenBlue;
|
|
20
|
+
bold?: boolean;
|
|
21
|
+
bright?: boolean;
|
|
22
|
+
dim?: boolean;
|
|
23
|
+
underscore?: boolean;
|
|
24
|
+
blink?: boolean;
|
|
25
|
+
reverse?: boolean;
|
|
26
|
+
hidden?: boolean;
|
|
27
|
+
underlined?: boolean;
|
|
28
|
+
backgroundColor?: FourBitColours | RedGreenBlue;
|
|
29
|
+
};
|
|
30
|
+
enum FourBitColours {
|
|
31
|
+
black = "BLACK",
|
|
32
|
+
white = "WHITE",
|
|
33
|
+
red = "RED",
|
|
34
|
+
green = "GREEN",
|
|
35
|
+
blue = "BLUE",
|
|
36
|
+
yellow = "YELLOW",
|
|
37
|
+
magenta = "MAGENTA",
|
|
38
|
+
cyan = "CYAN"
|
|
39
|
+
}
|
|
40
|
+
type RedGreenBlue = {
|
|
41
|
+
red: number;
|
|
42
|
+
green: number;
|
|
43
|
+
blue: number;
|
|
44
|
+
};
|
|
45
|
+
function isRegGreenBlue(rawValue: unknown): rawValue is RedGreenBlue;
|
|
46
|
+
}
|
|
47
|
+
export default ConsoleApplicationLogger;
|
|
@@ -0,0 +1,422 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const es_extensions_1 = require("@yamato-daiwa/es-extensions");
|
|
4
|
+
class ConsoleApplicationLogger {
|
|
5
|
+
static setLocalization(localization) {
|
|
6
|
+
ConsoleApplicationLogger.localization = localization;
|
|
7
|
+
return ConsoleApplicationLogger;
|
|
8
|
+
}
|
|
9
|
+
static throwErrorAndLog(errorLog) {
|
|
10
|
+
if ("errorInstance" in errorLog) {
|
|
11
|
+
errorLog.errorInstance.message = `${errorLog.title}\n${errorLog.errorInstance.message}` +
|
|
12
|
+
`\n\n${ConsoleApplicationLogger.localization.occurrenceLocation}: ${errorLog.occurrenceLocation}` +
|
|
13
|
+
`${(0, es_extensions_1.insertSubstringIf)(`\n\n${ConsoleApplicationLogger.localization.wrappableError}:` +
|
|
14
|
+
`\n${(0, es_extensions_1.stringifyAndFormatArbitraryValue)(errorLog.wrappableError)}`, (0, es_extensions_1.isNotUndefined)(errorLog.wrappableError))}` +
|
|
15
|
+
`${(0, es_extensions_1.insertSubstringIf)(`\n\n${ConsoleApplicationLogger.localization.appendedData}:` +
|
|
16
|
+
`\n${(0, es_extensions_1.stringifyAndFormatArbitraryValue)(errorLog.additionalData)}`, (0, es_extensions_1.isNotUndefined)(errorLog.additionalData))}` +
|
|
17
|
+
"\n";
|
|
18
|
+
throw errorLog.errorInstance;
|
|
19
|
+
}
|
|
20
|
+
const errorWillBeThrown = new Error(errorLog.description);
|
|
21
|
+
errorWillBeThrown.name = errorLog.errorType;
|
|
22
|
+
throw errorWillBeThrown;
|
|
23
|
+
}
|
|
24
|
+
static logError(errorLog) {
|
|
25
|
+
console.error(...ConsoleApplicationLogger.generateConsoleMethodParametersForFormattedOutput([
|
|
26
|
+
[
|
|
27
|
+
` ${errorLog.customBadgeText ?? ConsoleApplicationLogger.localization.badgesDefaultTitles.error} `,
|
|
28
|
+
{
|
|
29
|
+
bold: true,
|
|
30
|
+
foregroundColor: { red: 255, green: 255, blue: 255 },
|
|
31
|
+
backgroundColor: { red: 192, green: 57, blue: 43 }
|
|
32
|
+
}
|
|
33
|
+
],
|
|
34
|
+
[
|
|
35
|
+
` ${errorLog.title}\n`,
|
|
36
|
+
{
|
|
37
|
+
bold: true,
|
|
38
|
+
foregroundColor: { red: 192, green: 57, blue: 43 }
|
|
39
|
+
}
|
|
40
|
+
],
|
|
41
|
+
[
|
|
42
|
+
`${errorLog.description}`,
|
|
43
|
+
{
|
|
44
|
+
foregroundColor: { red: 231, green: 76, blue: 60 }
|
|
45
|
+
}
|
|
46
|
+
],
|
|
47
|
+
[
|
|
48
|
+
`\n\n${ConsoleApplicationLogger.localization.errorType}: `,
|
|
49
|
+
{
|
|
50
|
+
bold: true,
|
|
51
|
+
foregroundColor: { red: 231, green: 76, blue: 60 }
|
|
52
|
+
}
|
|
53
|
+
],
|
|
54
|
+
[
|
|
55
|
+
`${errorLog.errorType}`,
|
|
56
|
+
{
|
|
57
|
+
foregroundColor: { red: 231, green: 76, blue: 60 }
|
|
58
|
+
}
|
|
59
|
+
],
|
|
60
|
+
[
|
|
61
|
+
`\n${ConsoleApplicationLogger.localization.occurrenceLocation}: `,
|
|
62
|
+
{
|
|
63
|
+
bold: true,
|
|
64
|
+
foregroundColor: { red: 231, green: 76, blue: 60 }
|
|
65
|
+
}
|
|
66
|
+
],
|
|
67
|
+
[
|
|
68
|
+
`${errorLog.occurrenceLocation}: `,
|
|
69
|
+
{
|
|
70
|
+
foregroundColor: { red: 231, green: 76, blue: 60 }
|
|
71
|
+
}
|
|
72
|
+
],
|
|
73
|
+
...("caughtError" in errorLog ? [
|
|
74
|
+
[
|
|
75
|
+
`\n\n${ConsoleApplicationLogger.localization.caughtError}:`,
|
|
76
|
+
{
|
|
77
|
+
bold: true,
|
|
78
|
+
foregroundColor: { red: 231, green: 76, blue: 60 }
|
|
79
|
+
}
|
|
80
|
+
],
|
|
81
|
+
[
|
|
82
|
+
errorLog.caughtError instanceof Error ? `\n${errorLog.caughtError.stack}` :
|
|
83
|
+
`\n${(0, es_extensions_1.stringifyAndFormatArbitraryValue)(errorLog.caughtError)}`,
|
|
84
|
+
{
|
|
85
|
+
foregroundColor: { red: 231, green: 76, blue: 60 }
|
|
86
|
+
}
|
|
87
|
+
]
|
|
88
|
+
] : []),
|
|
89
|
+
...("additionalData" in errorLog ? [
|
|
90
|
+
[
|
|
91
|
+
`\n\n${ConsoleApplicationLogger.localization.appendedData}:`,
|
|
92
|
+
{
|
|
93
|
+
bold: true,
|
|
94
|
+
foregroundColor: { red: 231, green: 76, blue: 60 }
|
|
95
|
+
}
|
|
96
|
+
],
|
|
97
|
+
[
|
|
98
|
+
`\n${(0, es_extensions_1.stringifyAndFormatArbitraryValue)(errorLog.additionalData)}`,
|
|
99
|
+
{
|
|
100
|
+
foregroundColor: { red: 231, green: 76, blue: 60 }
|
|
101
|
+
}
|
|
102
|
+
]
|
|
103
|
+
] : [])
|
|
104
|
+
]));
|
|
105
|
+
}
|
|
106
|
+
static logErrorLikeMessage(errorLikeLog) {
|
|
107
|
+
console.error(...ConsoleApplicationLogger.generateConsoleMethodParametersForFormattedOutput([
|
|
108
|
+
[
|
|
109
|
+
` ${errorLikeLog.customBadgeText ?? ConsoleApplicationLogger.localization.badgesDefaultTitles.error} `,
|
|
110
|
+
{
|
|
111
|
+
bold: true,
|
|
112
|
+
foregroundColor: { red: 255, green: 255, blue: 255 },
|
|
113
|
+
backgroundColor: { red: 192, green: 57, blue: 43 }
|
|
114
|
+
}
|
|
115
|
+
],
|
|
116
|
+
[
|
|
117
|
+
` ${errorLikeLog.title}\n`,
|
|
118
|
+
{
|
|
119
|
+
bold: true,
|
|
120
|
+
foregroundColor: { red: 192, green: 57, blue: 43 }
|
|
121
|
+
}
|
|
122
|
+
],
|
|
123
|
+
[
|
|
124
|
+
`${errorLikeLog.description}`,
|
|
125
|
+
{
|
|
126
|
+
foregroundColor: { red: 231, green: 76, blue: 60 }
|
|
127
|
+
}
|
|
128
|
+
],
|
|
129
|
+
...("additionalData" in errorLikeLog ? [
|
|
130
|
+
[
|
|
131
|
+
`\n\n${ConsoleApplicationLogger.localization.appendedData}:`,
|
|
132
|
+
{
|
|
133
|
+
bold: true,
|
|
134
|
+
foregroundColor: { red: 231, green: 76, blue: 60 }
|
|
135
|
+
}
|
|
136
|
+
],
|
|
137
|
+
[
|
|
138
|
+
`\n${(0, es_extensions_1.stringifyAndFormatArbitraryValue)(errorLikeLog.additionalData)}`,
|
|
139
|
+
{
|
|
140
|
+
foregroundColor: { red: 231, green: 76, blue: 60 }
|
|
141
|
+
}
|
|
142
|
+
]
|
|
143
|
+
] : [])
|
|
144
|
+
]));
|
|
145
|
+
}
|
|
146
|
+
static logWarning(warningLog) {
|
|
147
|
+
console.warn(...ConsoleApplicationLogger.generateConsoleMethodParametersForFormattedOutput([
|
|
148
|
+
[
|
|
149
|
+
` ${warningLog.customBadgeText ?? ConsoleApplicationLogger.localization.badgesDefaultTitles.warning} `,
|
|
150
|
+
{
|
|
151
|
+
bold: true,
|
|
152
|
+
foregroundColor: { red: 255, green: 255, blue: 255 },
|
|
153
|
+
backgroundColor: { red: 211, green: 84, blue: 0 }
|
|
154
|
+
}
|
|
155
|
+
],
|
|
156
|
+
[
|
|
157
|
+
` ${warningLog.title}\n`,
|
|
158
|
+
{
|
|
159
|
+
bold: true,
|
|
160
|
+
foregroundColor: { red: 211, green: 84, blue: 0 }
|
|
161
|
+
}
|
|
162
|
+
],
|
|
163
|
+
[
|
|
164
|
+
`${warningLog.description}`,
|
|
165
|
+
{
|
|
166
|
+
foregroundColor: { red: 230, green: 126, blue: 34 }
|
|
167
|
+
}
|
|
168
|
+
],
|
|
169
|
+
...("occurrenceLocation" in warningLog ? [
|
|
170
|
+
[
|
|
171
|
+
`\n\n${ConsoleApplicationLogger.localization.occurrenceLocation}: `,
|
|
172
|
+
{
|
|
173
|
+
bold: true,
|
|
174
|
+
foregroundColor: { red: 230, green: 126, blue: 34 }
|
|
175
|
+
}
|
|
176
|
+
],
|
|
177
|
+
[
|
|
178
|
+
`${warningLog.occurrenceLocation}`,
|
|
179
|
+
{
|
|
180
|
+
foregroundColor: { red: 230, green: 126, blue: 34 }
|
|
181
|
+
}
|
|
182
|
+
]
|
|
183
|
+
] : []),
|
|
184
|
+
...("additionalData" in warningLog ? [
|
|
185
|
+
[
|
|
186
|
+
`\n\n${ConsoleApplicationLogger.localization.appendedData}:`,
|
|
187
|
+
{
|
|
188
|
+
"font-weight": "bold",
|
|
189
|
+
foregroundColor: { red: 230, green: 126, blue: 34 }
|
|
190
|
+
}
|
|
191
|
+
],
|
|
192
|
+
[
|
|
193
|
+
`\n${(0, es_extensions_1.stringifyAndFormatArbitraryValue)(warningLog.additionalData)}`,
|
|
194
|
+
{
|
|
195
|
+
foregroundColor: { red: 230, green: 126, blue: 34 }
|
|
196
|
+
}
|
|
197
|
+
]
|
|
198
|
+
] : [])
|
|
199
|
+
]));
|
|
200
|
+
}
|
|
201
|
+
static logSuccess(successLog) {
|
|
202
|
+
console.log(...ConsoleApplicationLogger.generateConsoleMethodParametersForFormattedOutput([
|
|
203
|
+
[
|
|
204
|
+
` ${successLog.customBadgeText ?? ConsoleApplicationLogger.localization.badgesDefaultTitles.success} `,
|
|
205
|
+
{
|
|
206
|
+
bold: true,
|
|
207
|
+
foregroundColor: { red: 255, green: 255, blue: 255 },
|
|
208
|
+
backgroundColor: { red: 39, green: 174, blue: 96 }
|
|
209
|
+
}
|
|
210
|
+
],
|
|
211
|
+
[
|
|
212
|
+
` ${successLog.title}\n`,
|
|
213
|
+
{
|
|
214
|
+
bold: true,
|
|
215
|
+
foregroundColor: { red: 39, green: 174, blue: 96 }
|
|
216
|
+
}
|
|
217
|
+
],
|
|
218
|
+
[
|
|
219
|
+
`${successLog.description}`,
|
|
220
|
+
{
|
|
221
|
+
foregroundColor: { red: 46, green: 204, blue: 113 }
|
|
222
|
+
}
|
|
223
|
+
],
|
|
224
|
+
...("additionalData" in successLog ? [
|
|
225
|
+
[
|
|
226
|
+
`\n\n${ConsoleApplicationLogger.localization.appendedData}:`,
|
|
227
|
+
{
|
|
228
|
+
bold: true,
|
|
229
|
+
foregroundColor: { red: 46, green: 204, blue: 113 }
|
|
230
|
+
}
|
|
231
|
+
],
|
|
232
|
+
[
|
|
233
|
+
`\n${(0, es_extensions_1.stringifyAndFormatArbitraryValue)(successLog.additionalData)}`,
|
|
234
|
+
{
|
|
235
|
+
foregroundColor: { red: 46, green: 204, blue: 113 }
|
|
236
|
+
}
|
|
237
|
+
]
|
|
238
|
+
] : [])
|
|
239
|
+
]));
|
|
240
|
+
}
|
|
241
|
+
static logInfo(infoLog) {
|
|
242
|
+
console.log(...ConsoleApplicationLogger.generateConsoleMethodParametersForFormattedOutput([
|
|
243
|
+
[
|
|
244
|
+
` ${infoLog.customBadgeText ?? ConsoleApplicationLogger.localization.badgesDefaultTitles.info} `,
|
|
245
|
+
{
|
|
246
|
+
bold: true,
|
|
247
|
+
foregroundColor: { red: 255, green: 255, blue: 255 },
|
|
248
|
+
backgroundColor: { red: 41, green: 128, blue: 185 }
|
|
249
|
+
}
|
|
250
|
+
],
|
|
251
|
+
[
|
|
252
|
+
` ${infoLog.title}\n`,
|
|
253
|
+
{
|
|
254
|
+
foregroundColor: { red: 41, green: 128, blue: 185 },
|
|
255
|
+
bold: true
|
|
256
|
+
}
|
|
257
|
+
],
|
|
258
|
+
[
|
|
259
|
+
`${infoLog.description}`,
|
|
260
|
+
{
|
|
261
|
+
foregroundColor: { red: 52, green: 152, blue: 219 }
|
|
262
|
+
}
|
|
263
|
+
],
|
|
264
|
+
...("additionalData" in infoLog ? [
|
|
265
|
+
[
|
|
266
|
+
`\n\n${ConsoleApplicationLogger.localization.appendedData}:`,
|
|
267
|
+
{
|
|
268
|
+
bold: true,
|
|
269
|
+
foregroundColor: { red: 52, green: 152, blue: 219 }
|
|
270
|
+
}
|
|
271
|
+
],
|
|
272
|
+
[
|
|
273
|
+
`\n${(0, es_extensions_1.stringifyAndFormatArbitraryValue)(infoLog.additionalData)}`,
|
|
274
|
+
{
|
|
275
|
+
foregroundColor: { red: 52, green: 152, blue: 219 }
|
|
276
|
+
}
|
|
277
|
+
]
|
|
278
|
+
] : [])
|
|
279
|
+
]));
|
|
280
|
+
}
|
|
281
|
+
static highlightText(targetString) {
|
|
282
|
+
return `\x1b[43m${targetString}\x1b[0m`;
|
|
283
|
+
}
|
|
284
|
+
static generateConsoleMethodParametersForFormattedOutput(formattedOutputData) {
|
|
285
|
+
const logsTextings = [];
|
|
286
|
+
const templatesWithFormattings = [];
|
|
287
|
+
for (const singleFormattedOutputData of formattedOutputData) {
|
|
288
|
+
let templateWithFormatting = "";
|
|
289
|
+
const formatting = singleFormattedOutputData[1];
|
|
290
|
+
switch (formatting.foregroundColor) {
|
|
291
|
+
case ConsoleApplicationLogger.FourBitColours.black: {
|
|
292
|
+
templateWithFormatting = `${templateWithFormatting}\x1b[30m`;
|
|
293
|
+
break;
|
|
294
|
+
}
|
|
295
|
+
case ConsoleApplicationLogger.FourBitColours.red: {
|
|
296
|
+
templateWithFormatting = `${templateWithFormatting}\x1b[31m`;
|
|
297
|
+
break;
|
|
298
|
+
}
|
|
299
|
+
case ConsoleApplicationLogger.FourBitColours.green: {
|
|
300
|
+
templateWithFormatting = `${templateWithFormatting}\x1b[32m`;
|
|
301
|
+
break;
|
|
302
|
+
}
|
|
303
|
+
case ConsoleApplicationLogger.FourBitColours.yellow: {
|
|
304
|
+
templateWithFormatting = `${templateWithFormatting}\x1b[33m`;
|
|
305
|
+
break;
|
|
306
|
+
}
|
|
307
|
+
case ConsoleApplicationLogger.FourBitColours.blue: {
|
|
308
|
+
templateWithFormatting = `${templateWithFormatting}\x1b[34m`;
|
|
309
|
+
break;
|
|
310
|
+
}
|
|
311
|
+
case ConsoleApplicationLogger.FourBitColours.magenta: {
|
|
312
|
+
templateWithFormatting = `${templateWithFormatting}\x1b[35m`;
|
|
313
|
+
break;
|
|
314
|
+
}
|
|
315
|
+
case ConsoleApplicationLogger.FourBitColours.cyan: {
|
|
316
|
+
templateWithFormatting = `${templateWithFormatting}\x1b[36m`;
|
|
317
|
+
break;
|
|
318
|
+
}
|
|
319
|
+
case ConsoleApplicationLogger.FourBitColours.white: {
|
|
320
|
+
templateWithFormatting = `${templateWithFormatting}\x1b[37m`;
|
|
321
|
+
break;
|
|
322
|
+
}
|
|
323
|
+
default: {
|
|
324
|
+
if (ConsoleApplicationLogger.isRegGreenBlue(formatting.foregroundColor)) {
|
|
325
|
+
templateWithFormatting = `${templateWithFormatting}${ConsoleApplicationLogger.generateRedGreenBlueForegroundColorControlSequence(formatting.foregroundColor)}`;
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
switch (formatting.backgroundColor) {
|
|
330
|
+
case ConsoleApplicationLogger.FourBitColours.black: {
|
|
331
|
+
templateWithFormatting = `${templateWithFormatting}\x1b[40m`;
|
|
332
|
+
break;
|
|
333
|
+
}
|
|
334
|
+
case ConsoleApplicationLogger.FourBitColours.red: {
|
|
335
|
+
templateWithFormatting = `${templateWithFormatting}\x1b[41m`;
|
|
336
|
+
break;
|
|
337
|
+
}
|
|
338
|
+
case ConsoleApplicationLogger.FourBitColours.green: {
|
|
339
|
+
templateWithFormatting = `${templateWithFormatting}\x1b[42m`;
|
|
340
|
+
break;
|
|
341
|
+
}
|
|
342
|
+
case ConsoleApplicationLogger.FourBitColours.yellow: {
|
|
343
|
+
templateWithFormatting = `${templateWithFormatting}\x1b[43m`;
|
|
344
|
+
break;
|
|
345
|
+
}
|
|
346
|
+
case ConsoleApplicationLogger.FourBitColours.blue: {
|
|
347
|
+
templateWithFormatting = `${templateWithFormatting}\x1b[44m`;
|
|
348
|
+
break;
|
|
349
|
+
}
|
|
350
|
+
case ConsoleApplicationLogger.FourBitColours.magenta: {
|
|
351
|
+
templateWithFormatting = `${templateWithFormatting}\x1b[45m`;
|
|
352
|
+
break;
|
|
353
|
+
}
|
|
354
|
+
case ConsoleApplicationLogger.FourBitColours.cyan: {
|
|
355
|
+
templateWithFormatting = `${templateWithFormatting}\x1b[46m`;
|
|
356
|
+
break;
|
|
357
|
+
}
|
|
358
|
+
case ConsoleApplicationLogger.FourBitColours.white: {
|
|
359
|
+
templateWithFormatting = `${templateWithFormatting}\x1b[47m`;
|
|
360
|
+
break;
|
|
361
|
+
}
|
|
362
|
+
default: {
|
|
363
|
+
if (ConsoleApplicationLogger.isRegGreenBlue(formatting.backgroundColor)) {
|
|
364
|
+
templateWithFormatting = `${templateWithFormatting}${ConsoleApplicationLogger.generateRedGreenBlueBackgroundColorControlSequence(formatting.backgroundColor)}`;
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
if (formatting.bold === true) {
|
|
369
|
+
templateWithFormatting = `${templateWithFormatting}\x1b[1m`;
|
|
370
|
+
}
|
|
371
|
+
if (formatting.underlined === true || formatting.underscore === true) {
|
|
372
|
+
templateWithFormatting = `${templateWithFormatting}\x1b[4m`;
|
|
373
|
+
}
|
|
374
|
+
if (formatting.bright === true) {
|
|
375
|
+
templateWithFormatting = `${templateWithFormatting}\x1b[1m`;
|
|
376
|
+
}
|
|
377
|
+
if (formatting.dim === true) {
|
|
378
|
+
templateWithFormatting = `${templateWithFormatting}\x1b[2m`;
|
|
379
|
+
}
|
|
380
|
+
if (formatting.blink === true) {
|
|
381
|
+
templateWithFormatting = `${templateWithFormatting}\x1b[5m`;
|
|
382
|
+
}
|
|
383
|
+
if (formatting.reverse === true) {
|
|
384
|
+
templateWithFormatting = `${templateWithFormatting}\x1b[7m`;
|
|
385
|
+
}
|
|
386
|
+
if (formatting.hidden === true) {
|
|
387
|
+
templateWithFormatting = `${templateWithFormatting}\x1b[8m`;
|
|
388
|
+
}
|
|
389
|
+
logsTextings.push(singleFormattedOutputData[0]);
|
|
390
|
+
templatesWithFormattings.push(templateWithFormatting);
|
|
391
|
+
}
|
|
392
|
+
return [`${templatesWithFormattings.join("%s\x1b[0m")}%s\x1b[0m`].concat(logsTextings);
|
|
393
|
+
}
|
|
394
|
+
static generateRedGreenBlueForegroundColorControlSequence(colorDefinition) {
|
|
395
|
+
return `\x1b[38;2;${colorDefinition.red};${colorDefinition.green};${colorDefinition.blue}m`;
|
|
396
|
+
}
|
|
397
|
+
static generateRedGreenBlueBackgroundColorControlSequence(colorDefinition) {
|
|
398
|
+
return `\x1b[48;2;${colorDefinition.red};${colorDefinition.green};${colorDefinition.blue}m`;
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
ConsoleApplicationLogger.localization = es_extensions_1.LoggerLocalization__English;
|
|
402
|
+
(function (ConsoleApplicationLogger) {
|
|
403
|
+
let FourBitColours;
|
|
404
|
+
(function (FourBitColours) {
|
|
405
|
+
FourBitColours["black"] = "BLACK";
|
|
406
|
+
FourBitColours["white"] = "WHITE";
|
|
407
|
+
FourBitColours["red"] = "RED";
|
|
408
|
+
FourBitColours["green"] = "GREEN";
|
|
409
|
+
FourBitColours["blue"] = "BLUE";
|
|
410
|
+
FourBitColours["yellow"] = "YELLOW";
|
|
411
|
+
FourBitColours["magenta"] = "MAGENTA";
|
|
412
|
+
FourBitColours["cyan"] = "CYAN";
|
|
413
|
+
})(FourBitColours = ConsoleApplicationLogger.FourBitColours || (ConsoleApplicationLogger.FourBitColours = {}));
|
|
414
|
+
function isRegGreenBlue(rawValue) {
|
|
415
|
+
return (0, es_extensions_1.isArbitraryObject)(rawValue) &&
|
|
416
|
+
(0, es_extensions_1.isNonNegativeInteger)(rawValue.red) &&
|
|
417
|
+
(0, es_extensions_1.isNonNegativeInteger)(rawValue.green) &&
|
|
418
|
+
(0, es_extensions_1.isNonNegativeInteger)(rawValue.blue);
|
|
419
|
+
}
|
|
420
|
+
ConsoleApplicationLogger.isRegGreenBlue = isRegGreenBlue;
|
|
421
|
+
})(ConsoleApplicationLogger || (ConsoleApplicationLogger = {}));
|
|
422
|
+
exports.default = ConsoleApplicationLogger;
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
import { ParsedJSON, RawObjectDataProcessor } from "@yamato-daiwa/es-extensions";
|
|
2
|
+
declare class ConsoleCommandsParser<TargetCommandsAndOptionsCombinations extends ConsoleCommandsParser.GeneralizedCommandsAndOptionsCombinations> {
|
|
3
|
+
private static readonly MINIMAL_ARGUMENTS_IN_VALID_CONSOLE_COMMAND;
|
|
4
|
+
private static localization;
|
|
5
|
+
private readonly applicationName;
|
|
6
|
+
private readonly targetCommandPhrase?;
|
|
7
|
+
private readonly targetCommandOptions?;
|
|
8
|
+
private readonly targetCommandOptions__eachOneWillBeRemovedOnceProcessed;
|
|
9
|
+
private readonly targetCommandOptionsSpecification?;
|
|
10
|
+
static parse<TargetCommandsAndOptionsCombinations extends ConsoleCommandsParser.GeneralizedCommandsAndOptionsCombinations>(argumentsVector: unknown, commandLineInterfaceSpecification: ConsoleCommandsParser.CommandLineInterfaceSpecification): ConsoleCommandsParser.ParsedCommand<TargetCommandsAndOptionsCombinations>;
|
|
11
|
+
static setLocalization(newLocalization: ConsoleCommandsParser.Localization): void;
|
|
12
|
+
private constructor();
|
|
13
|
+
private getParsedOptionsAndParameters;
|
|
14
|
+
private processStringTypeOptionValue;
|
|
15
|
+
private processNumberTypeOptionValue;
|
|
16
|
+
private extractAndValidateParsedJSON5_ParameterValue;
|
|
17
|
+
private static isCommandArgumentTheOption;
|
|
18
|
+
private static generateFullHelpReference;
|
|
19
|
+
private static generateSingleCommendHelpReference;
|
|
20
|
+
}
|
|
21
|
+
declare namespace ConsoleCommandsParser {
|
|
22
|
+
type ParsedCommand<TargetCommandsAndOptionsCombinations extends GeneralizedCommandsAndOptionsCombinations> = {
|
|
23
|
+
NodeJS_InterpreterAbsolutePath: string;
|
|
24
|
+
executableFileAbsolutePath: string;
|
|
25
|
+
phrase?: string;
|
|
26
|
+
} & TargetCommandsAndOptionsCombinations;
|
|
27
|
+
type GeneralizedCommandsAndOptionsCombinations = {
|
|
28
|
+
[name: string]: string | number | boolean | ParsedJSON;
|
|
29
|
+
};
|
|
30
|
+
type CommandLineInterfaceSpecification = {
|
|
31
|
+
applicationName: string;
|
|
32
|
+
defaultCommand?: CommandOptionsSpecification;
|
|
33
|
+
commandPhrases?: {
|
|
34
|
+
[commandPhrase: string]: CommandOptionsSpecification | undefined;
|
|
35
|
+
};
|
|
36
|
+
};
|
|
37
|
+
type CommandOptionsSpecification = {
|
|
38
|
+
[optionKey: string]: OptionSpecification;
|
|
39
|
+
};
|
|
40
|
+
type OptionSpecification = StringOptionSpecification | NumberOptionSpecification | BooleanParameterSpecification | JSON5_ParameterSpecification;
|
|
41
|
+
type ParameterSpecification__CommonProperties = {
|
|
42
|
+
shortcut?: string;
|
|
43
|
+
};
|
|
44
|
+
type StringOptionSpecification = ParameterSpecification__CommonProperties & {
|
|
45
|
+
type: ParametersTypes.string;
|
|
46
|
+
required: boolean;
|
|
47
|
+
allowedAlternatives?: Array<string>;
|
|
48
|
+
newName?: string;
|
|
49
|
+
};
|
|
50
|
+
type NumberOptionSpecification = ParameterSpecification__CommonProperties & {
|
|
51
|
+
type: ParametersTypes.number;
|
|
52
|
+
required: boolean;
|
|
53
|
+
numbersSet: RawObjectDataProcessor.NumbersSets;
|
|
54
|
+
minimalValue?: number;
|
|
55
|
+
maximalValue?: number;
|
|
56
|
+
newName?: string;
|
|
57
|
+
};
|
|
58
|
+
type BooleanParameterSpecification = ParameterSpecification__CommonProperties & {
|
|
59
|
+
type: ParametersTypes.boolean;
|
|
60
|
+
newName?: string;
|
|
61
|
+
};
|
|
62
|
+
type JSON5_ParameterSpecification = ParameterSpecification__CommonProperties & {
|
|
63
|
+
type: ParametersTypes.JSON5;
|
|
64
|
+
required: boolean;
|
|
65
|
+
newName?: string;
|
|
66
|
+
validValueSpecification: RawObjectDataProcessor.ObjectDataSpecification;
|
|
67
|
+
};
|
|
68
|
+
enum ParametersTypes {
|
|
69
|
+
string = "string",
|
|
70
|
+
number = "number",
|
|
71
|
+
boolean = "boolean",
|
|
72
|
+
JSON5 = "JSON5"
|
|
73
|
+
}
|
|
74
|
+
type Localization = {
|
|
75
|
+
generateArgumentsVectorIsNotArrayErrorMessage: (argumentsVector: unknown) => string;
|
|
76
|
+
generateArgumentsVectorHasNotEnoughElementsErrorMessage: (parameter: Localization.RawArgumentsVectorHasNotEnoughElementsErrorMessageParameters) => string;
|
|
77
|
+
generateArgumentsVectorHasNonStringElementsErrorMessage: (nonStringArguments: Array<unknown>) => string;
|
|
78
|
+
generateNoDefaultCommandPhraseAvailableErrorMessage: (helpReference: string) => string;
|
|
79
|
+
generateFirstParameterLooksLikeCommandPhraseWhileNoCommandPhrasesAvailableErrorMessage: (parametersObject: Localization.FirstParameterLooksLikeCommandPhraseWhileNoCommandPhrasesAvailableErrorMessageParameters) => string;
|
|
80
|
+
generateUnknownCommandPhraseErrorMessage: (parametersObject: Localization.UnknownCommandPhraseErrorMessageParameters) => string;
|
|
81
|
+
generateUnknownOptionsFoundForSpecificCommandErrorMessage: (parametersObject: Localization.UnknownOptionsFoundForSpecificCommandErrorMessageParameters) => string;
|
|
82
|
+
generateInvalidOptionTypeErrorMessage: (parametersObject: {
|
|
83
|
+
optionName: string;
|
|
84
|
+
}) => string;
|
|
85
|
+
generateRequiredOptionKeyIsMissingErrorMessage: (parametersObject: Localization.RequiredOptionKeyIsMissingErrorMessageParameters) => string;
|
|
86
|
+
generateNoValueFollowingTheKeyOfNonBooleanOptionErrorMessage: (parametersObject: Localization.NoValueFollowingTheKeyOfNonBooleanOptionErrorMessageParameters) => string;
|
|
87
|
+
generateOptionValueIsNotAmongAllowedAlternativesErrorMessage: (parametersObject: Localization.OptionValueIsNotAmongAllowedAlternativesErrorMessageParameters) => string;
|
|
88
|
+
generateUnparsableNumericOptionValueErrorMessage: (parametersObject: Localization.UnparsableNumericOptionValueErrorMessageErrorMessageParameters) => string;
|
|
89
|
+
generatedNumericOptionValueIsNotBelongToExpectedNumbersSetErrorMessage: (parametersObject: Localization.NumericOptionValueIsNotBelongToExpectedNumbersSetErrorMessageParameters) => string;
|
|
90
|
+
generateReadableNumbersSet: (numberSet: RawObjectDataProcessor.NumbersSets) => string;
|
|
91
|
+
generateNumericValueIsSmallerThanRequiredMinimumErrorMessage: (parametersObject: Localization.NumericValueIsSmallerThanRequiredMinimumErrorMessageParameters) => string;
|
|
92
|
+
generateNumericValueIsGreaterThanAllowedMaximumErrorMessage: (parametersObject: Localization.NumericValueIsGreaterThanAllowedMaximumErrorMessageParameters) => string;
|
|
93
|
+
generateMalformedJSON5_OptionErrorMessage: (parametersObject: Localization.MalformedJSON5_OptionErrorMessageParameters) => string;
|
|
94
|
+
generateJSON5_OptionDoesNotMatchWithValidDataSchemaErrorMessage: (parametersObject: Localization.JSON5_OptionDoesNotMatchWithValidDataSchemaErrorMessageParameters) => string;
|
|
95
|
+
};
|
|
96
|
+
namespace Localization {
|
|
97
|
+
type RawArgumentsVectorHasNotEnoughElementsErrorMessageParameters = {
|
|
98
|
+
arrayedConsoleCommand: Array<unknown>;
|
|
99
|
+
minimalElementsCount: number;
|
|
100
|
+
};
|
|
101
|
+
type FirstParameterLooksLikeCommandPhraseWhileNoCommandPhrasesAvailableErrorMessageParameters = {
|
|
102
|
+
commandPhraseLikeArgument: string;
|
|
103
|
+
helpReference: string;
|
|
104
|
+
};
|
|
105
|
+
type UnknownCommandPhraseErrorMessageParameters = {
|
|
106
|
+
inputtedCommandPhrase: string;
|
|
107
|
+
helpReference: string;
|
|
108
|
+
};
|
|
109
|
+
type UnknownOptionsFoundForSpecificCommandErrorMessageParameters = {
|
|
110
|
+
commandPhrase?: string;
|
|
111
|
+
commandReference: string;
|
|
112
|
+
};
|
|
113
|
+
type RequiredOptionKeyIsMissingErrorMessageParameters = {
|
|
114
|
+
commandPhrase?: string;
|
|
115
|
+
missingOptionKey: string;
|
|
116
|
+
commandHelpReference: string;
|
|
117
|
+
};
|
|
118
|
+
type NoValueFollowingTheKeyOfNonBooleanOptionErrorMessageParameters = {
|
|
119
|
+
targetOptionKey: string;
|
|
120
|
+
commandHelpReference: string;
|
|
121
|
+
};
|
|
122
|
+
type OptionValueIsNotAmongAllowedAlternativesErrorMessageParameters = {
|
|
123
|
+
targetOptionKey: string;
|
|
124
|
+
actualOptionValue: string;
|
|
125
|
+
commandReference: string;
|
|
126
|
+
};
|
|
127
|
+
type UnparsableNumericOptionValueErrorMessageErrorMessageParameters = {
|
|
128
|
+
targetOptionKey: string;
|
|
129
|
+
actualOptionValue: string;
|
|
130
|
+
commandReference: string;
|
|
131
|
+
};
|
|
132
|
+
type NumericOptionValueIsNotBelongToExpectedNumbersSetErrorMessageParameters = {
|
|
133
|
+
targetOptionKey: string;
|
|
134
|
+
expectedNumbersSet: RawObjectDataProcessor.NumbersSets;
|
|
135
|
+
actualOptionValue: string;
|
|
136
|
+
commandReference: string;
|
|
137
|
+
};
|
|
138
|
+
type NumericValueIsSmallerThanRequiredMinimumErrorMessageParameters = {
|
|
139
|
+
targetOptionKey: string;
|
|
140
|
+
requiredMinimum: number;
|
|
141
|
+
actualOptionValue: string;
|
|
142
|
+
commandReference: string;
|
|
143
|
+
};
|
|
144
|
+
type NumericValueIsGreaterThanAllowedMaximumErrorMessageParameters = {
|
|
145
|
+
targetOptionKey: string;
|
|
146
|
+
allowedMaximum: number;
|
|
147
|
+
actualOptionValue: string;
|
|
148
|
+
commandReference: string;
|
|
149
|
+
};
|
|
150
|
+
type MalformedJSON5_OptionErrorMessageParameters = {
|
|
151
|
+
targetOptionKey: string;
|
|
152
|
+
commandReference: string;
|
|
153
|
+
};
|
|
154
|
+
type JSON5_OptionDoesNotMatchWithValidDataSchemaErrorMessageParameters = {
|
|
155
|
+
targetOptionKey: string;
|
|
156
|
+
formattedValidationErrorsMessages: string;
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
export default ConsoleCommandsParser;
|