@yamato-daiwa/es-extensions-nodejs 1.7.0-alpha.2 → 1.7.0-alpha.3

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.
@@ -1,20 +1,20 @@
1
- import type { Logger, ErrorLog, ThrownErrorLog, InfoLog, SuccessLog, WarningLog, Log } from "@yamato-daiwa/es-extensions";
1
+ import type { Logger, ErrorLog, InfoLog, SuccessLog, WarningLog, Log } from "@yamato-daiwa/es-extensions";
2
2
  declare abstract class ConsoleApplicationLogger {
3
3
  private static localization;
4
4
  static setLocalization(localization: Logger.Localization): typeof ConsoleApplicationLogger;
5
- static throwErrorAndLog<CustomError extends Error>(errorLog: ThrownErrorLog<CustomError>): never;
6
5
  static logError(errorLog: ErrorLog): void;
7
6
  static logErrorLikeMessage(errorLikeLog: Log): void;
8
7
  static logWarning(warningLog: WarningLog): void;
9
8
  static logSuccess(successLog: SuccessLog): void;
10
9
  static logInfo(infoLog: InfoLog): void;
10
+ static logGeneric(genericLog: Log): void;
11
11
  static highlightText(targetString: string): string;
12
12
  static generateConsoleMethodParametersForFormattedOutput(formattedOutputData: ConsoleApplicationLogger.FormattedOutputData): Array<string>;
13
13
  static generateRedGreenBlueForegroundColorControlSequence(colorDefinition: ConsoleApplicationLogger.RedGreenBlue): string;
14
14
  static generateRedGreenBlueBackgroundColorControlSequence(colorDefinition: ConsoleApplicationLogger.RedGreenBlue): string;
15
15
  }
16
16
  declare namespace ConsoleApplicationLogger {
17
- type FormattedOutputData = Array<[string, Formatting]>;
17
+ type FormattedOutputData = Array<[string | null, Formatting]>;
18
18
  type Formatting = {
19
19
  foregroundColor?: FourBitColours | RedGreenBlue;
20
20
  bold?: boolean;
@@ -6,25 +6,11 @@ class ConsoleApplicationLogger {
6
6
  ConsoleApplicationLogger.localization = localization;
7
7
  return ConsoleApplicationLogger;
8
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
9
  static logError(errorLog) {
25
10
  console.error(...ConsoleApplicationLogger.generateConsoleMethodParametersForFormattedOutput([
26
11
  [
27
- ` ${errorLog.customBadgeText ?? ConsoleApplicationLogger.localization.badgesDefaultTitles.error} `,
12
+ errorLog.badge === false ?
13
+ null : ` ${errorLog.badge?.customText ?? ConsoleApplicationLogger.localization.badgesDefaultTitles.error} `,
28
14
  {
29
15
  bold: true,
30
16
  foregroundColor: { red: 255, green: 255, blue: 255 },
@@ -32,14 +18,14 @@ class ConsoleApplicationLogger {
32
18
  }
33
19
  ],
34
20
  [
35
- ` ${errorLog.title}\n`,
21
+ `${(0, es_extensions_1.insertSubstringIf)(" ", errorLog.badge !== false)}${errorLog.title}`,
36
22
  {
37
23
  bold: true,
38
24
  foregroundColor: { red: 192, green: 57, blue: 43 }
39
25
  }
40
26
  ],
41
27
  [
42
- `${errorLog.description}`,
28
+ `${errorLog.compactLayout === true ? " " : "\n"}${errorLog.description}`,
43
29
  {
44
30
  foregroundColor: { red: 231, green: 76, blue: 60 }
45
31
  }
@@ -106,7 +92,8 @@ class ConsoleApplicationLogger {
106
92
  static logErrorLikeMessage(errorLikeLog) {
107
93
  console.error(...ConsoleApplicationLogger.generateConsoleMethodParametersForFormattedOutput([
108
94
  [
109
- ` ${errorLikeLog.customBadgeText ?? ConsoleApplicationLogger.localization.badgesDefaultTitles.error} `,
95
+ errorLikeLog.badge === false ?
96
+ null : ` ${errorLikeLog.badge?.customText ?? ConsoleApplicationLogger.localization.badgesDefaultTitles.error} `,
110
97
  {
111
98
  bold: true,
112
99
  foregroundColor: { red: 255, green: 255, blue: 255 },
@@ -114,14 +101,14 @@ class ConsoleApplicationLogger {
114
101
  }
115
102
  ],
116
103
  [
117
- ` ${errorLikeLog.title}\n`,
104
+ `${(0, es_extensions_1.insertSubstringIf)(" ", errorLikeLog.badge !== false)}${errorLikeLog.title}`,
118
105
  {
119
106
  bold: true,
120
107
  foregroundColor: { red: 192, green: 57, blue: 43 }
121
108
  }
122
109
  ],
123
110
  [
124
- `${errorLikeLog.description}`,
111
+ `${errorLikeLog.compactLayout === true ? " " : "\n"}${errorLikeLog.description}`,
125
112
  {
126
113
  foregroundColor: { red: 231, green: 76, blue: 60 }
127
114
  }
@@ -146,7 +133,8 @@ class ConsoleApplicationLogger {
146
133
  static logWarning(warningLog) {
147
134
  console.warn(...ConsoleApplicationLogger.generateConsoleMethodParametersForFormattedOutput([
148
135
  [
149
- ` ${warningLog.customBadgeText ?? ConsoleApplicationLogger.localization.badgesDefaultTitles.warning} `,
136
+ warningLog.badge === false ?
137
+ null : ` ${warningLog.badge?.customText ?? ConsoleApplicationLogger.localization.badgesDefaultTitles.warning} `,
150
138
  {
151
139
  bold: true,
152
140
  foregroundColor: { red: 255, green: 255, blue: 255 },
@@ -154,14 +142,14 @@ class ConsoleApplicationLogger {
154
142
  }
155
143
  ],
156
144
  [
157
- ` ${warningLog.title}\n`,
145
+ `${(0, es_extensions_1.insertSubstringIf)(" ", warningLog.badge !== false)}${warningLog.title}`,
158
146
  {
159
147
  bold: true,
160
148
  foregroundColor: { red: 211, green: 84, blue: 0 }
161
149
  }
162
150
  ],
163
151
  [
164
- `${warningLog.description}`,
152
+ `${warningLog.compactLayout === true ? " " : "\n"}${warningLog.description}`,
165
153
  {
166
154
  foregroundColor: { red: 230, green: 126, blue: 34 }
167
155
  }
@@ -201,7 +189,8 @@ class ConsoleApplicationLogger {
201
189
  static logSuccess(successLog) {
202
190
  console.log(...ConsoleApplicationLogger.generateConsoleMethodParametersForFormattedOutput([
203
191
  [
204
- ` ${successLog.customBadgeText ?? ConsoleApplicationLogger.localization.badgesDefaultTitles.success} `,
192
+ successLog.badge === false ?
193
+ null : ` ${successLog.badge?.customText ?? ConsoleApplicationLogger.localization.badgesDefaultTitles.success} `,
205
194
  {
206
195
  bold: true,
207
196
  foregroundColor: { red: 255, green: 255, blue: 255 },
@@ -209,14 +198,14 @@ class ConsoleApplicationLogger {
209
198
  }
210
199
  ],
211
200
  [
212
- ` ${successLog.title}\n`,
201
+ `${(0, es_extensions_1.insertSubstringIf)(" ", successLog.badge !== false)}${successLog.title}`,
213
202
  {
214
203
  bold: true,
215
204
  foregroundColor: { red: 39, green: 174, blue: 96 }
216
205
  }
217
206
  ],
218
207
  [
219
- `${successLog.description}`,
208
+ `${successLog.compactLayout === true ? " " : "\n"}${successLog.description}`,
220
209
  {
221
210
  foregroundColor: { red: 46, green: 204, blue: 113 }
222
211
  }
@@ -241,7 +230,8 @@ class ConsoleApplicationLogger {
241
230
  static logInfo(infoLog) {
242
231
  console.log(...ConsoleApplicationLogger.generateConsoleMethodParametersForFormattedOutput([
243
232
  [
244
- ` ${infoLog.customBadgeText ?? ConsoleApplicationLogger.localization.badgesDefaultTitles.info} `,
233
+ infoLog.badge === false ?
234
+ null : ` ${infoLog.badge?.customText ?? ConsoleApplicationLogger.localization.badgesDefaultTitles.info} `,
245
235
  {
246
236
  bold: true,
247
237
  foregroundColor: { red: 255, green: 255, blue: 255 },
@@ -249,14 +239,14 @@ class ConsoleApplicationLogger {
249
239
  }
250
240
  ],
251
241
  [
252
- ` ${infoLog.title}\n`,
242
+ `${(0, es_extensions_1.insertSubstringIf)(" ", infoLog.badge !== false)}${infoLog.title}`,
253
243
  {
254
244
  foregroundColor: { red: 41, green: 128, blue: 185 },
255
245
  bold: true
256
246
  }
257
247
  ],
258
248
  [
259
- `${infoLog.description}`,
249
+ `${infoLog.compactLayout === true ? " " : "\n"}${infoLog.description}`,
260
250
  {
261
251
  foregroundColor: { red: 52, green: 152, blue: 219 }
262
252
  }
@@ -278,6 +268,47 @@ class ConsoleApplicationLogger {
278
268
  ] : [])
279
269
  ]));
280
270
  }
271
+ static logGeneric(genericLog) {
272
+ console.log(...ConsoleApplicationLogger.generateConsoleMethodParametersForFormattedOutput([
273
+ [
274
+ genericLog.badge === false ?
275
+ null : ` ${genericLog.badge?.customText ?? ConsoleApplicationLogger.localization.badgesDefaultTitles.info} `,
276
+ {
277
+ bold: true,
278
+ foregroundColor: { red: 0, green: 0, blue: 0 },
279
+ backgroundColor: { red: 255, green: 255, blue: 255 }
280
+ }
281
+ ],
282
+ [
283
+ `${(0, es_extensions_1.insertSubstringIf)(" ", genericLog.badge !== false)}${genericLog.title}`,
284
+ {
285
+ foregroundColor: { red: 255, green: 255, blue: 255 },
286
+ bold: true
287
+ }
288
+ ],
289
+ [
290
+ `${genericLog.compactLayout === true ? " " : "\n"}${genericLog.description}`,
291
+ {
292
+ foregroundColor: { red: 255, green: 255, blue: 255 }
293
+ }
294
+ ],
295
+ ...("additionalData" in genericLog ? [
296
+ [
297
+ `\n\n${ConsoleApplicationLogger.localization.appendedData}:`,
298
+ {
299
+ bold: true,
300
+ foregroundColor: { red: 255, green: 255, blue: 255 }
301
+ }
302
+ ],
303
+ [
304
+ `\n${(0, es_extensions_1.stringifyAndFormatArbitraryValue)(genericLog.additionalData)}`,
305
+ {
306
+ foregroundColor: { red: 255, green: 255, blue: 255 }
307
+ }
308
+ ]
309
+ ] : [])
310
+ ]));
311
+ }
281
312
  static highlightText(targetString) {
282
313
  return `\x1b[43m${targetString}\x1b[49m`;
283
314
  }
@@ -285,6 +316,9 @@ class ConsoleApplicationLogger {
285
316
  const logsTextings = [];
286
317
  const templatesWithFormattings = [];
287
318
  for (const singleFormattedOutputData of formattedOutputData) {
319
+ if ((0, es_extensions_1.isNull)(singleFormattedOutputData[0])) {
320
+ continue;
321
+ }
288
322
  let templateWithFormatting = "";
289
323
  const formatting = singleFormattedOutputData[1];
290
324
  switch (formatting.foregroundColor) {
@@ -398,7 +432,7 @@ class ConsoleApplicationLogger {
398
432
  return `\x1b[48;2;${colorDefinition.red};${colorDefinition.green};${colorDefinition.blue}m`;
399
433
  }
400
434
  }
401
- ConsoleApplicationLogger.localization = es_extensions_1.LoggerLocalization__English;
435
+ ConsoleApplicationLogger.localization = es_extensions_1.loggerLocalization__english;
402
436
  (function (ConsoleApplicationLogger) {
403
437
  let FourBitColours;
404
438
  (function (FourBitColours) {
@@ -216,8 +216,7 @@ declare namespace ConsoleCommandsParser {
216
216
  }
217
217
  namespace RequiredOptionKeyIsMissing {
218
218
  type TemplateVariables = Readonly<{
219
- commandPhrase: string;
220
- isDefaultCommandPhrase: boolean;
219
+ commandPhrase?: string;
221
220
  missingOptionKey: string;
222
221
  commandHelpReference: string;
223
222
  }>;
@@ -221,7 +221,6 @@ class ConsoleCommandsParser {
221
221
  applicationName: this.applicationName,
222
222
  messageSpecificPart: ConsoleCommandsParser.localization.errorsMessages.requiredOptionKeyIsMissing.generate({
223
223
  commandPhrase: this.targetCommandPhrase,
224
- isDefaultCommandPhrase: this.isTargetCommandPhraseDefault,
225
224
  missingOptionKey: optionKeyWithLeading2NDashes,
226
225
  commandHelpReference: ConsoleCommandsParser.generateSingleCommandPhraseHelpReference({
227
226
  commandPhrase: this.targetCommandPhrase,
@@ -58,8 +58,8 @@ const consoleCommandsParserLocalization__english = {
58
58
  `\n${helpReference}`
59
59
  },
60
60
  requiredOptionKeyIsMissing: {
61
- generate: ({ missingOptionKey, commandPhrase, isDefaultCommandPhrase, commandHelpReference }) => `The option "${missingOptionKey}" is required for the command "${commandPhrase}"` +
62
- `${(0, es_extensions_1.insertSubstringIf)(" (default command phrase)", isDefaultCommandPhrase)}. ` +
61
+ generate: ({ missingOptionKey, commandPhrase, commandHelpReference }) => `The option "${missingOptionKey}" is required for the ` +
62
+ `${(0, es_extensions_1.isNotUndefined)(commandPhrase) ? `command "${commandPhrase}"` : "default command"}. ` +
63
63
  `${consoleCommandsParserLocalization__english.generateCheckTheCommandReferenceAsking(commandHelpReference)}`
64
64
  },
65
65
  noValueFollowingTheKeyOfNonBooleanOption: {
@@ -3,8 +3,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- const glob_1 = __importDefault(require("glob"));
7
- const minimatch_1 = __importDefault(require("minimatch"));
6
+ const glob_1 = require("glob");
7
+ const minimatch_1 = require("minimatch");
8
8
  const es_extensions_1 = require("@yamato-daiwa/es-extensions");
9
9
  const appendCharacterIfItDoesNotPresentInLastPosition_1 = __importDefault(require("./Temporary/appendCharacterIfItDoesNotPresentInLastPosition"));
10
10
  class ImprovedGlob {
@@ -17,7 +17,7 @@ class ImprovedGlob {
17
17
  }
18
18
  const matchingFilesAbsolutePaths = [];
19
19
  for (const inclusiveGlobSelector of inclusiveGlobSelectors) {
20
- matchingFilesAbsolutePaths.push(...glob_1.default.sync(inclusiveGlobSelector, {
20
+ matchingFilesAbsolutePaths.push(...glob_1.glob.sync(inclusiveGlobSelector, {
21
21
  ignore: exclusiveGlobSelectors.map((globSelector) => (0, es_extensions_1.removeSpecificCharacterFromCertainPosition)({
22
22
  targetString: globSelector,
23
23
  fromFirstPosition: true,
@@ -31,12 +31,12 @@ class ImprovedGlob {
31
31
  return matchingFilesAbsolutePaths.map((fileAbsolutePath) => (0, es_extensions_1.replaceDoubleBackslashesWithForwardSlashes)(fileAbsolutePath));
32
32
  }
33
33
  static isFilePathMatchingWithGlobSelector(compoundParameter) {
34
- return (0, minimatch_1.default)(compoundParameter.filePath, compoundParameter.globSelector);
34
+ return (0, minimatch_1.minimatch)(compoundParameter.filePath, compoundParameter.globSelector);
35
35
  }
36
36
  static isFilePathMatchingWithAllGlobSelectors(compoundParameter) {
37
37
  return (Array.isArray(compoundParameter.globSelectors) ?
38
38
  compoundParameter.globSelectors : [compoundParameter.globSelectors]).
39
- every((globSelector) => (0, minimatch_1.default)(compoundParameter.filePath, globSelector));
39
+ every((globSelector) => (0, minimatch_1.minimatch)(compoundParameter.filePath, globSelector));
40
40
  }
41
41
  static isExcludingGlobSelector(globSelector) {
42
42
  return globSelector.startsWith("!");
@@ -58,7 +58,7 @@ class ImprovedGlob {
58
58
  targetString: (0, es_extensions_1.replaceDoubleBackslashesWithForwardSlashes)(compoundParameter.basicDirectoryPath),
59
59
  trailingCharacter: "/"
60
60
  }),
61
- "**/**",
61
+ "**/*",
62
62
  ...(0, es_extensions_1.isNonEmptyArray)(compoundParameter.fileNamesExtensions) ?
63
63
  [ImprovedGlob.createMultipleFilenameExtensionsGlobPostfix(compoundParameter.fileNamesExtensions)] : []
64
64
  ].join("");
@@ -70,7 +70,7 @@ class ImprovedGlob {
70
70
  targetString: (0, es_extensions_1.replaceDoubleBackslashesWithForwardSlashes)(targetDirectoryPath),
71
71
  trailingCharacter: "/"
72
72
  }),
73
- "**/**"
73
+ "**/*"
74
74
  ].join("");
75
75
  }
76
76
  static buildExcludingOfFilesWithSpecificPrefixesGlobSelector(compoundParameter) {
@@ -103,7 +103,7 @@ class ImprovedGlob {
103
103
  trailingCharacter: "/"
104
104
  }),
105
105
  "**/",
106
- `@(${compoundParameter.filesNamesPrefixes.join("|")})**`,
106
+ `@(${compoundParameter.filesNamesPrefixes.join("|")})*`,
107
107
  `${ImprovedGlob.createMultipleFilenameExtensionsGlobPostfix(compoundParameter.filesNamesExtensions)}`
108
108
  ].join("");
109
109
  }
@@ -127,7 +127,7 @@ class ImprovedGlob {
127
127
  trailingCharacter: "/"
128
128
  }),
129
129
  "**/",
130
- `@(${compoundParameter.subdirectoriesPrefixes.join("|")})**/**/**`,
130
+ `@(${compoundParameter.subdirectoriesPrefixes.join("|")})*/**/*`,
131
131
  ...(0, es_extensions_1.isNonEmptyArray)(compoundParameter.filesNamesExtensions) ?
132
132
  `${ImprovedGlob.createMultipleFilenameExtensionsGlobPostfix(compoundParameter.filesNamesExtensions)}` : []
133
133
  ].join("");
@@ -150,7 +150,7 @@ class ImprovedGlob {
150
150
  targetString: (0, es_extensions_1.replaceDoubleBackslashesWithForwardSlashes)(compoundParameter.basicDirectoryPath),
151
151
  trailingCharacter: "/"
152
152
  }),
153
- `@(${compoundParameter.subdirectoriesNames.join("|")})/**/**`,
153
+ `**/@(${compoundParameter.subdirectoriesNames.join("|")})/**/*`,
154
154
  ...(0, es_extensions_1.isNonEmptyArray)(compoundParameter.filesNamesExtensions) ?
155
155
  `${ImprovedGlob.createMultipleFilenameExtensionsGlobPostfix(compoundParameter.filesNamesExtensions)}` : []
156
156
  ].join("");
@@ -28,7 +28,7 @@ class ImprovedPath {
28
28
  errorInstance: new es_extensions_1.InvalidParameterValueError({ parameterName: "pathSegments", parameterNumber: 1 }),
29
29
  title: es_extensions_1.InvalidParameterValueError.localization.defaultTitle,
30
30
  occurrenceLocation: "ImprovedPath.joinPathSegments(pathSegments, options)",
31
- wrappableError: error
31
+ innerError: error
32
32
  });
33
33
  }
34
34
  }
@@ -60,7 +60,7 @@ class ImprovedPath {
60
60
  errorInstance: new es_extensions_1.InvalidParameterValueError({ parameterName: "pathSegments", parameterNumber: 1 }),
61
61
  title: es_extensions_1.InvalidParameterValueError.localization.defaultTitle,
62
62
  occurrenceLocation: "ImprovedPath.buildAbsolutePathFromCurrentWorkingDirectory(pathSegments, options)",
63
- wrappableError: error
63
+ innerError: error
64
64
  });
65
65
  }
66
66
  }
@@ -74,7 +74,7 @@ class ImprovedPath {
74
74
  errorInstance: new es_extensions_1.InvalidParameterValueError({ parameterName: "namedParameters", parameterNumber: 1 }),
75
75
  title: es_extensions_1.InvalidParameterValueError.localization.defaultTitle,
76
76
  occurrenceLocation: "ImprovedPath.computeRelativePath(namedParameters)",
77
- wrappableError: error
77
+ innerError: error
78
78
  });
79
79
  }
80
80
  return namedParameters.alwaysForwardSlashSeparators === true ?
@@ -107,7 +107,7 @@ class ObjectDataFilesProcessor {
107
107
  errorInstance: new FileNotFoundError_1.default({ filePath }),
108
108
  title: FileNotFoundError_1.default.localization.defaultTitle,
109
109
  occurrenceLocation: POTENTIAL_ERROR_OCCURRENCE_LOCATION,
110
- wrappableError: error
110
+ innerError: error
111
111
  });
112
112
  }
113
113
  throw error;
@@ -145,7 +145,7 @@ class ObjectDataFilesProcessor {
145
145
  errorInstance: new FileNotFoundError_1.default({ filePath }),
146
146
  title: FileNotFoundError_1.default.localization.defaultTitle,
147
147
  occurrenceLocation: POTENTIAL_ERROR_OCCURRENCE_LOCATION,
148
- wrappableError: error
148
+ innerError: error
149
149
  });
150
150
  }
151
151
  throw error;
@@ -194,7 +194,7 @@ class ObjectDataFilesProcessor {
194
194
  errorInstance: new es_extensions_1.InvalidExternalDataError({ mentionToExpectedData: filePathForLogging }),
195
195
  title: es_extensions_1.InvalidExternalDataError.localization.defaultTitle,
196
196
  occurrenceLocation: POTENTIAL_ERROR_OCCURRENCE_LOCATION,
197
- wrappableError: error
197
+ innerError: error
198
198
  });
199
199
  }
200
200
  if ((0, es_extensions_1.isUndefined)(validDataSpecification)) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yamato-daiwa/es-extensions-nodejs",
3
- "version": "1.7.0-alpha.2",
3
+ "version": "1.7.0-alpha.3",
4
4
  "description": "Additional to @yamato-daiwa/es-extensions functionality for Node.js environment. Helper functions and classes aimed to reduce the routine code. Build-in TypeScript type safety.",
5
5
  "keywords": [
6
6
  "nodejs",