@yamato-daiwa/es-extensions-nodejs 0.0.2 → 0.10.0-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Distributable/ConsoleApplicationLogger.d.ts +68 -0
- package/Distributable/ConsoleApplicationLogger.js +435 -0
- package/Distributable/ConsoleCommandsParser/ConsoleCommandsParser.d.ts +289 -0
- package/Distributable/ConsoleCommandsParser/ConsoleCommandsParser.js +702 -0
- package/Distributable/ConsoleCommandsParser/ConsoleCommandsParserLocalization.english.d.ts +4 -0
- package/Distributable/ConsoleCommandsParser/ConsoleCommandsParserLocalization.english.js +118 -0
- package/Distributable/DateTime/NodeJS_Timer.d.ts +21 -7
- package/Distributable/DateTime/NodeJS_Timer.js +61 -13
- package/Distributable/DotEnvFilesGenerator.d.ts +13 -0
- package/Distributable/DotEnvFilesGenerator.js +21 -0
- package/Distributable/Errors/FileNotFoundError/FileNotFoundError.d.ts +25 -0
- package/Distributable/Errors/FileNotFoundError/FileNotFoundError.js +21 -0
- package/Distributable/Errors/FileNotFoundError/FileNotFoundErrorLocalization.english.d.ts +3 -0
- package/Distributable/Errors/FileNotFoundError/FileNotFoundErrorLocalization.english.js +7 -0
- package/Distributable/Errors/InvalidConsoleCommand/InvalidConsoleCommandError.d.ts +25 -0
- package/Distributable/Errors/InvalidConsoleCommand/InvalidConsoleCommandError.js +21 -0
- package/Distributable/Errors/InvalidConsoleCommand/InvalidConsoleCommandErrorLocalization.english.d.ts +3 -0
- package/Distributable/Errors/InvalidConsoleCommand/InvalidConsoleCommandErrorLocalization.english.js +7 -0
- package/Distributable/Errors/PathRefersToDirectoryNotFileError/PathRefersToDirectoryNotFileError.d.ts +25 -0
- package/Distributable/Errors/PathRefersToDirectoryNotFileError/PathRefersToDirectoryNotFileError.js +21 -0
- package/Distributable/Errors/PathRefersToDirectoryNotFileError/PathRefersToDirectoryNotFileErrorLocalization.english.d.ts +3 -0
- package/Distributable/Errors/PathRefersToDirectoryNotFileError/PathRefersToDirectoryNotFileErrorLocalization.english.js +7 -0
- package/Distributable/ImprovedFileSystem.d.ts +43 -0
- package/Distributable/ImprovedFileSystem.js +142 -0
- package/Distributable/ImprovedGlob.d.ts +57 -0
- package/Distributable/ImprovedGlob.js +275 -0
- package/Distributable/ImprovedPath/ImprovedPath.d.ts +59 -0
- package/Distributable/ImprovedPath/ImprovedPath.js +224 -0
- package/Distributable/ObjectDataFilesProcessor/ObjectDataFilesProcessor.d.ts +55 -0
- package/Distributable/ObjectDataFilesProcessor/ObjectDataFilesProcessor.js +228 -0
- package/Distributable/ObjectDataFilesProcessor/ObjectDataFilesProcessorLocalization.english.d.ts +4 -0
- package/Distributable/ObjectDataFilesProcessor/ObjectDataFilesProcessorLocalization.english.js +11 -0
- package/Distributable/Temporary/appendCharacterIfItDoesNotPresentInLastPosition.d.ts +4 -0
- package/Distributable/Temporary/appendCharacterIfItDoesNotPresentInLastPosition.js +7 -0
- package/Distributable/Temporary/extractLastExtensionOfFileName.d.ts +9 -0
- package/Distributable/Temporary/extractLastExtensionOfFileName.js +21 -0
- package/Distributable/index.d.ts +22 -7
- package/Distributable/index.js +45 -7
- package/Distributable/isErrnoException.d.ts +2 -0
- package/Distributable/isErrnoException.js +12 -0
- package/LICENSE +1 -1
- package/README.md +51 -3
- package/package.json +45 -15
- package/tsconfig.test.json +0 -4
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const es_extensions_1 = require("@yamato-daiwa/es-extensions");
|
|
4
|
+
const consoleCommandsParserLocalization__english = {
|
|
5
|
+
helpReference: {
|
|
6
|
+
defaultCommandPhrase__parenthetical: "(default command phrase)",
|
|
7
|
+
options: "Options",
|
|
8
|
+
shortcut: "Shortcut",
|
|
9
|
+
type: "Type",
|
|
10
|
+
isRequired: "Is Required",
|
|
11
|
+
defaultValue: "Default Value",
|
|
12
|
+
yes: "Yes",
|
|
13
|
+
no: "No",
|
|
14
|
+
allowedAlternatives: "Allowed Alternatives",
|
|
15
|
+
numbersSet: {
|
|
16
|
+
key: "Numbers Set",
|
|
17
|
+
generateValue: es_extensions_1.rawObjectDataProcessorLocalization__english.getLocalizedNumbersSet
|
|
18
|
+
},
|
|
19
|
+
minimalValue: "Minimal Value",
|
|
20
|
+
maximalValue: "Maximal Value",
|
|
21
|
+
objectTypeValuePropertiesSpecification: "Properties Specification"
|
|
22
|
+
},
|
|
23
|
+
generateCheckTheCommandReferenceAsking: (commandReference) => `Please check the reference for this command:\n${commandReference}`,
|
|
24
|
+
errorsMessages: {
|
|
25
|
+
argumentsVectorIsNotArray: {
|
|
26
|
+
generate: ({ stringifiedActualValueOfArgumentsVector }) => "Expected that the arguments vector be an array while actually it is not and actually has the value:\n" +
|
|
27
|
+
stringifiedActualValueOfArgumentsVector
|
|
28
|
+
},
|
|
29
|
+
argumentsVectorHasNotEnoughElements: {
|
|
30
|
+
generate: ({ minimalElementsCountInArgumentsVector, actualElementsCountInArgumentsVector, stringifiedArgumentsVector }) => `The valid arguments vector must be an array of at least ${minimalElementsCountInArgumentsVector} elements ` +
|
|
31
|
+
`while actually is has ${actualElementsCountInArgumentsVector} elements and value:\n` +
|
|
32
|
+
stringifiedArgumentsVector
|
|
33
|
+
},
|
|
34
|
+
argumentsVectorHasNonStringElements: {
|
|
35
|
+
generate: ({ stringifiedFormattedNonStringArguments }) => "The valid arguments vector must be an array of the strings while below arguments are not strings:\n" +
|
|
36
|
+
stringifiedFormattedNonStringArguments
|
|
37
|
+
},
|
|
38
|
+
moreThanOneCommandPhrasesMarkedAsDefault: {
|
|
39
|
+
generate: ({ formattedListOfCommandsPhrasesMarkedAsDefault }) => "More than one commands phrases has been marked as default. " +
|
|
40
|
+
"If you are the developer of the this console application, leave the \"default\" flag only on one of below " +
|
|
41
|
+
"command phrases:\n" +
|
|
42
|
+
`${formattedListOfCommandsPhrasesMarkedAsDefault}\n` +
|
|
43
|
+
"If you are the user of this console application, please consider the reporting about this issue to the " +
|
|
44
|
+
"developers."
|
|
45
|
+
},
|
|
46
|
+
noDefaultCommandPhraseAvailable: {
|
|
47
|
+
generate: (templateVariables) => "This application has no the default command. " +
|
|
48
|
+
"Please specify explicitly one of mentioned below command phrases.\n" +
|
|
49
|
+
templateVariables.helpReference
|
|
50
|
+
},
|
|
51
|
+
firstParameterLooksLikeCommandPhraseWhileNoCommandPhrasesAvailable: {
|
|
52
|
+
generate: ({ commandPhraseLikeArgument, helpReference }) => `"${commandPhraseLikeArgument}" seems like the command phrase while there is only the default command available ` +
|
|
53
|
+
"for this application:\n" +
|
|
54
|
+
helpReference
|
|
55
|
+
},
|
|
56
|
+
unknownCommandPhrase: {
|
|
57
|
+
generate: ({ inputtedCommandPhrase, helpReference }) => `The command phrase "${inputtedCommandPhrase}" is unknown. ` +
|
|
58
|
+
"Please input one of below available command phrases:" +
|
|
59
|
+
`\n${helpReference}`
|
|
60
|
+
},
|
|
61
|
+
requiredOptionKeyIsMissing: {
|
|
62
|
+
generate: ({ missingOptionKey, commandPhrase, isDefaultCommandPhrase, commandHelpReference }) => `The option "${missingOptionKey}" is required for the command "${commandPhrase}"` +
|
|
63
|
+
`${(0, es_extensions_1.insertSubstringIf)(" (default command phrase)", isDefaultCommandPhrase)}. ` +
|
|
64
|
+
consoleCommandsParserLocalization__english.generateCheckTheCommandReferenceAsking(commandHelpReference)
|
|
65
|
+
},
|
|
66
|
+
noValueFollowingTheKeyOfNonBooleanOption: {
|
|
67
|
+
generate: ({ targetOptionKey, commandHelpReference }) => `No value following the key "${targetOptionKey}" of non-boolean option has been specified. ` +
|
|
68
|
+
consoleCommandsParserLocalization__english.generateCheckTheCommandReferenceAsking(commandHelpReference)
|
|
69
|
+
},
|
|
70
|
+
invalidCommandOptionTypeAtSpecification: {
|
|
71
|
+
generate: ({ optionName, typeName }) => "Most likely, it is the bug from the side of the console application. " +
|
|
72
|
+
`The type "${typeName}" specified for the option "${optionName}" in the console command specification ` +
|
|
73
|
+
" is invalid. " +
|
|
74
|
+
"It is possible only when the console application has been written by JavaScript or the TypeScript type checking " +
|
|
75
|
+
"has been disabled. " +
|
|
76
|
+
"There is nothing you must to correct; however it is recommended to report about this issue to the developers " +
|
|
77
|
+
"of this application."
|
|
78
|
+
},
|
|
79
|
+
unknownOptionsFoundForSpecificCommand: {
|
|
80
|
+
generate: ({ commandPhrase, formattedUnknownOptions, commandHelpReference }) => "Below options are unknown for the " +
|
|
81
|
+
`${(0, es_extensions_1.isNotUndefined)(commandPhrase) ? `command "${commandPhrase}"` : "default command"}:\n` +
|
|
82
|
+
`${formattedUnknownOptions}\n` +
|
|
83
|
+
consoleCommandsParserLocalization__english.generateCheckTheCommandReferenceAsking(commandHelpReference)
|
|
84
|
+
},
|
|
85
|
+
optionValueIsNotAmongAllowedAlternatives: {
|
|
86
|
+
generate: ({ targetOptionKey, actualOptionValue, commandHelpReference }) => `The value "${actualOptionValue}" of the option "${targetOptionKey}" is not among allowed alternatives. ` +
|
|
87
|
+
consoleCommandsParserLocalization__english.generateCheckTheCommandReferenceAsking(commandHelpReference)
|
|
88
|
+
},
|
|
89
|
+
unparsableNumericOptionValue: {
|
|
90
|
+
generate: ({ actualOptionValue, targetOptionKey, commandHelpReference }) => `The value "${actualOptionValue}" of the numeric option "${targetOptionKey}" is not the valid numeric value.\n` +
|
|
91
|
+
consoleCommandsParserLocalization__english.generateCheckTheCommandReferenceAsking(commandHelpReference)
|
|
92
|
+
},
|
|
93
|
+
numericOptionValueIsNotBelongToExpectedNumbersSet: {
|
|
94
|
+
generate: ({ targetOptionKey, expectedNumbersSet, actualOptionValue, commandHelpReference }) => `The value "${actualOptionValue}" of the numeric option "${targetOptionKey}" is not belong to ` +
|
|
95
|
+
`"${es_extensions_1.rawObjectDataProcessorLocalization__english.getLocalizedNumbersSet(expectedNumbersSet)}" numbers set.\n` +
|
|
96
|
+
consoleCommandsParserLocalization__english.generateCheckTheCommandReferenceAsking(commandHelpReference)
|
|
97
|
+
},
|
|
98
|
+
numericValueIsSmallerThanRequiredMinimum: {
|
|
99
|
+
generate: ({ targetOptionKey, requiredMinimum, actualOptionValue, commandHelpReference }) => `The value "${actualOptionValue}" of the numeric option "${targetOptionKey}" is smaller than required ` +
|
|
100
|
+
`minimal value ${requiredMinimum}.\n` +
|
|
101
|
+
consoleCommandsParserLocalization__english.generateCheckTheCommandReferenceAsking(commandHelpReference)
|
|
102
|
+
},
|
|
103
|
+
numericValueIsGreaterThanAllowedMaximum: {
|
|
104
|
+
generate: ({ targetOptionKey, allowedMaximum, actualOptionValue, commandHelpReference }) => `The value "${actualOptionValue}" of the numeric option "${targetOptionKey}" is greater that allowed ` +
|
|
105
|
+
`maximal value ${allowedMaximum}.\n` +
|
|
106
|
+
consoleCommandsParserLocalization__english.generateCheckTheCommandReferenceAsking(commandHelpReference)
|
|
107
|
+
},
|
|
108
|
+
malformedJSON5_Option: {
|
|
109
|
+
generate: ({ targetOptionKey, commandHelpReference }) => `The value of the option "${targetOptionKey}" is not valid JSON5 string. ` +
|
|
110
|
+
consoleCommandsParserLocalization__english.generateCheckTheCommandReferenceAsking(commandHelpReference)
|
|
111
|
+
},
|
|
112
|
+
JSON5_OptionDoesNotMatchWithValidDataSchema: {
|
|
113
|
+
generate: ({ targetOptionKey, formattedValidationErrorsMessages }) => `The JSON5-type value of the option "${targetOptionKey}" does not match with valid data schema:\n` +
|
|
114
|
+
formattedValidationErrorsMessages
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
};
|
|
118
|
+
exports.default = consoleCommandsParserLocalization__english;
|
|
@@ -1,7 +1,21 @@
|
|
|
1
|
-
import { Timer } from "@yamato-daiwa/es-extensions";
|
|
2
|
-
export default class NodeJS_Timer extends Timer {
|
|
3
|
-
private
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
}
|
|
1
|
+
import { Timer } from "@yamato-daiwa/es-extensions";
|
|
2
|
+
export default class NodeJS_Timer extends Timer {
|
|
3
|
+
#private;
|
|
4
|
+
constructor(compoundParameter: Readonly<{
|
|
5
|
+
period__seconds: number;
|
|
6
|
+
onElapsed?: (outcome: Timer.Outcomes) => void;
|
|
7
|
+
}>);
|
|
8
|
+
countDown(compoundParameter?: Readonly<{
|
|
9
|
+
asynchronousCompletion?: Timer.AsynchronousCompletions.promise;
|
|
10
|
+
}>): Promise<Timer.Outcomes>;
|
|
11
|
+
countDown(compoundParameter: Readonly<{
|
|
12
|
+
asynchronousCompletion: Timer.AsynchronousCompletions.callback;
|
|
13
|
+
}>): void;
|
|
14
|
+
resetAndRestart(compoundParameter?: Readonly<{
|
|
15
|
+
asynchronousCompletion: Timer.AsynchronousCompletions.promise;
|
|
16
|
+
}>): Promise<Timer.Outcomes>;
|
|
17
|
+
resetAndRestart(compoundParameter: Readonly<{
|
|
18
|
+
asynchronousCompletion: Timer.AsynchronousCompletions.callback;
|
|
19
|
+
}>): void;
|
|
20
|
+
get isActive(): boolean;
|
|
21
|
+
}
|
|
@@ -1,13 +1,61 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const es_extensions_1 = require("@yamato-daiwa/es-extensions");
|
|
4
|
+
class NodeJS_Timer extends es_extensions_1.Timer {
|
|
5
|
+
#nativeTimeout;
|
|
6
|
+
#secondsLeft = this.period__seconds;
|
|
7
|
+
#isActive = false;
|
|
8
|
+
constructor(compoundParameter) {
|
|
9
|
+
super(compoundParameter);
|
|
10
|
+
}
|
|
11
|
+
countDown({ asynchronousCompletion = es_extensions_1.Timer.AsynchronousCompletions.promise } = {}) {
|
|
12
|
+
if (this.isActive) {
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
this.#isActive = true;
|
|
16
|
+
const promise = new Promise((resolve) => {
|
|
17
|
+
this.#nativeTimeout = setInterval(() => {
|
|
18
|
+
if (this.mustStop) {
|
|
19
|
+
this.#isActive = false;
|
|
20
|
+
window.clearInterval(this.#nativeTimeout);
|
|
21
|
+
resolve(es_extensions_1.Timer.Outcomes.stopped);
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
this.#secondsLeft = this.#secondsLeft - 1;
|
|
25
|
+
if (this.#secondsLeft === 0) {
|
|
26
|
+
this.#isActive = false;
|
|
27
|
+
this.#secondsLeft = this.period__seconds;
|
|
28
|
+
clearInterval(this.#nativeTimeout);
|
|
29
|
+
resolve(es_extensions_1.Timer.Outcomes.elapsed);
|
|
30
|
+
}
|
|
31
|
+
}, (0, es_extensions_1.secondsToMilliseconds)(1));
|
|
32
|
+
});
|
|
33
|
+
if (asynchronousCompletion === es_extensions_1.Timer.AsynchronousCompletions.promise) {
|
|
34
|
+
return promise;
|
|
35
|
+
}
|
|
36
|
+
promise.
|
|
37
|
+
then((outcome) => { this.onElapsed?.(outcome); }).
|
|
38
|
+
catch((error) => {
|
|
39
|
+
es_extensions_1.Logger.logError({
|
|
40
|
+
errorType: es_extensions_1.AlgorithmMismatchError.NAME,
|
|
41
|
+
title: es_extensions_1.AlgorithmMismatchError.localization.defaultTitle,
|
|
42
|
+
description: "Error occurred before times has elapsed.",
|
|
43
|
+
occurrenceLocation: "browserJS_Timer.countDown(parametersObject)",
|
|
44
|
+
caughtError: error
|
|
45
|
+
});
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
resetAndRestart({ asynchronousCompletion = es_extensions_1.Timer.AsynchronousCompletions.promise } = {}) {
|
|
49
|
+
clearInterval(this.#nativeTimeout);
|
|
50
|
+
this.#isActive = false;
|
|
51
|
+
this.#secondsLeft = this.period__seconds;
|
|
52
|
+
if (asynchronousCompletion === es_extensions_1.Timer.AsynchronousCompletions.promise) {
|
|
53
|
+
return this.countDown({ asynchronousCompletion: es_extensions_1.Timer.AsynchronousCompletions.promise });
|
|
54
|
+
}
|
|
55
|
+
this.countDown({ asynchronousCompletion: es_extensions_1.Timer.AsynchronousCompletions.callback });
|
|
56
|
+
}
|
|
57
|
+
get isActive() {
|
|
58
|
+
return this.#isActive;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
exports.default = NodeJS_Timer;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
declare abstract class DotEnvFilesGenerator {
|
|
2
|
+
static generate(order: DotEnvFilesGenerator.Order): typeof DotEnvFilesGenerator;
|
|
3
|
+
}
|
|
4
|
+
declare namespace DotEnvFilesGenerator {
|
|
5
|
+
type Order = Readonly<{
|
|
6
|
+
fileName: string;
|
|
7
|
+
directory: string;
|
|
8
|
+
variables: Readonly<{
|
|
9
|
+
[name: string]: string | number;
|
|
10
|
+
}>;
|
|
11
|
+
}>;
|
|
12
|
+
}
|
|
13
|
+
export default DotEnvFilesGenerator;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const ImprovedFileSystem_1 = __importDefault(require("./ImprovedFileSystem"));
|
|
7
|
+
const path_1 = __importDefault(require("path"));
|
|
8
|
+
class DotEnvFilesGenerator {
|
|
9
|
+
static generate(order) {
|
|
10
|
+
const fileContent = Object.entries(order.variables).
|
|
11
|
+
reduce((previousValue, [key, value]) => `${previousValue}${key}="${value}"\n`, "# [ Attention ] DON'T EDIT THIS FILE MANUALLY!!! \n" +
|
|
12
|
+
"# This file intended to be generated repeatedly thus the manual changes WILL BE LOST.\n\n");
|
|
13
|
+
ImprovedFileSystem_1.default.writeFileToPossiblyNotExistingDirectory({
|
|
14
|
+
content: fileContent,
|
|
15
|
+
filePath: path_1.default.join(order.directory, order.fileName),
|
|
16
|
+
synchronously: true
|
|
17
|
+
});
|
|
18
|
+
return DotEnvFilesGenerator;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
exports.default = DotEnvFilesGenerator;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
declare class FileNotFoundError extends Error {
|
|
2
|
+
static readonly NAME: string;
|
|
3
|
+
static localization: FileNotFoundError.Localization;
|
|
4
|
+
constructor(constructorParameter: FileNotFoundError.ConstructorParameter);
|
|
5
|
+
}
|
|
6
|
+
declare namespace FileNotFoundError {
|
|
7
|
+
type ConstructorParameter = Readonly<{
|
|
8
|
+
filePath: string;
|
|
9
|
+
messageSpecificPart?: string;
|
|
10
|
+
} | {
|
|
11
|
+
customMessage: string;
|
|
12
|
+
}>;
|
|
13
|
+
type Localization = Readonly<{
|
|
14
|
+
defaultTitle: string;
|
|
15
|
+
generateDescriptionCommonPart: (templateVariables: Localization.CommonDescription.TemplateVariables) => string;
|
|
16
|
+
}>;
|
|
17
|
+
namespace Localization {
|
|
18
|
+
namespace CommonDescription {
|
|
19
|
+
type TemplateVariables = Readonly<{
|
|
20
|
+
filePath: string;
|
|
21
|
+
}>;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
export default FileNotFoundError;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const FileNotFoundErrorLocalization_english_1 = __importDefault(require("./FileNotFoundErrorLocalization.english"));
|
|
7
|
+
const es_extensions_1 = require("@yamato-daiwa/es-extensions");
|
|
8
|
+
class FileNotFoundError extends Error {
|
|
9
|
+
static NAME = "FileNotFoundError";
|
|
10
|
+
static localization = FileNotFoundErrorLocalization_english_1.default;
|
|
11
|
+
constructor(constructorParameter) {
|
|
12
|
+
super();
|
|
13
|
+
this.name = FileNotFoundError.NAME;
|
|
14
|
+
this.message =
|
|
15
|
+
"customMessage" in constructorParameter ?
|
|
16
|
+
constructorParameter.customMessage :
|
|
17
|
+
FileNotFoundError.localization.generateDescriptionCommonPart(constructorParameter) +
|
|
18
|
+
(0, es_extensions_1.insertSubstring)(constructorParameter.messageSpecificPart, { modifier: (messageSpecificPart) => ` ${messageSpecificPart}` });
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
exports.default = FileNotFoundError;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const fileNotFoundErrorLocalization__english = {
|
|
4
|
+
defaultTitle: "File Not Found",
|
|
5
|
+
generateDescriptionCommonPart: ({ filePath }) => `File with path "${filePath}" not found.`
|
|
6
|
+
};
|
|
7
|
+
exports.default = fileNotFoundErrorLocalization__english;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
declare class InvalidConsoleCommandError extends Error {
|
|
2
|
+
static readonly NAME: string;
|
|
3
|
+
static localization: InvalidConsoleCommandError.Localization;
|
|
4
|
+
constructor(constructorParameter: InvalidConsoleCommandError.ConstructorParameter);
|
|
5
|
+
}
|
|
6
|
+
declare namespace InvalidConsoleCommandError {
|
|
7
|
+
type ConstructorParameter = Readonly<{
|
|
8
|
+
applicationName: string;
|
|
9
|
+
messageSpecificPart?: string;
|
|
10
|
+
} | {
|
|
11
|
+
customMessage: string;
|
|
12
|
+
}>;
|
|
13
|
+
type Localization = Readonly<{
|
|
14
|
+
defaultTitle: string;
|
|
15
|
+
generateDescriptionCommonPart: (templateVariables: Localization.CommonDescription.TemplateVariables) => string;
|
|
16
|
+
}>;
|
|
17
|
+
namespace Localization {
|
|
18
|
+
namespace CommonDescription {
|
|
19
|
+
type TemplateVariables = Readonly<{
|
|
20
|
+
applicationName: string;
|
|
21
|
+
}>;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
export default InvalidConsoleCommandError;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const InvalidConsoleCommandErrorLocalization_english_1 = __importDefault(require("./InvalidConsoleCommandErrorLocalization.english"));
|
|
7
|
+
const es_extensions_1 = require("@yamato-daiwa/es-extensions");
|
|
8
|
+
class InvalidConsoleCommandError extends Error {
|
|
9
|
+
static NAME = "InvalidConsoleCommandError";
|
|
10
|
+
static localization = InvalidConsoleCommandErrorLocalization_english_1.default;
|
|
11
|
+
constructor(constructorParameter) {
|
|
12
|
+
super();
|
|
13
|
+
this.name = InvalidConsoleCommandError.NAME;
|
|
14
|
+
this.message =
|
|
15
|
+
"customMessage" in constructorParameter ?
|
|
16
|
+
constructorParameter.customMessage :
|
|
17
|
+
InvalidConsoleCommandError.localization.generateDescriptionCommonPart(constructorParameter) +
|
|
18
|
+
(0, es_extensions_1.insertSubstring)(constructorParameter.messageSpecificPart, { modifier: (messageSpecificPart) => ` ${messageSpecificPart}` });
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
exports.default = InvalidConsoleCommandError;
|
package/Distributable/Errors/InvalidConsoleCommand/InvalidConsoleCommandErrorLocalization.english.js
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const invalidConsoleCommandErrorLocalization__english = {
|
|
4
|
+
defaultTitle: "Invalid Console Command",
|
|
5
|
+
generateDescriptionCommonPart: ({ applicationName }) => `Invalid console command for the application "${applicationName}".`
|
|
6
|
+
};
|
|
7
|
+
exports.default = invalidConsoleCommandErrorLocalization__english;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
declare class PathRefersToDirectoryNotFileError extends Error {
|
|
2
|
+
static readonly NAME: string;
|
|
3
|
+
static localization: PathRefersToDirectoryNotFileError.Localization;
|
|
4
|
+
constructor(constructorParameter: PathRefersToDirectoryNotFileError.ConstructorParameter);
|
|
5
|
+
}
|
|
6
|
+
declare namespace PathRefersToDirectoryNotFileError {
|
|
7
|
+
type ConstructorParameter = Readonly<{
|
|
8
|
+
targetPath: string;
|
|
9
|
+
messageSpecificPart?: string;
|
|
10
|
+
} | {
|
|
11
|
+
customMessage: string;
|
|
12
|
+
}>;
|
|
13
|
+
type Localization = Readonly<{
|
|
14
|
+
defaultTitle: string;
|
|
15
|
+
genericDescription: (templateVariables: Localization.CommonDescription.TemplateVariables) => string;
|
|
16
|
+
}>;
|
|
17
|
+
namespace Localization {
|
|
18
|
+
namespace CommonDescription {
|
|
19
|
+
type TemplateVariables = Readonly<{
|
|
20
|
+
targetPath: string;
|
|
21
|
+
}>;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
export default PathRefersToDirectoryNotFileError;
|
package/Distributable/Errors/PathRefersToDirectoryNotFileError/PathRefersToDirectoryNotFileError.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const PathRefersToDirectoryNotFileErrorLocalization_english_1 = __importDefault(require("./PathRefersToDirectoryNotFileErrorLocalization.english"));
|
|
7
|
+
const es_extensions_1 = require("@yamato-daiwa/es-extensions");
|
|
8
|
+
class PathRefersToDirectoryNotFileError extends Error {
|
|
9
|
+
static NAME = "PathRefersToDirectoryNotFileError";
|
|
10
|
+
static localization = PathRefersToDirectoryNotFileErrorLocalization_english_1.default;
|
|
11
|
+
constructor(constructorParameter) {
|
|
12
|
+
super();
|
|
13
|
+
this.name = PathRefersToDirectoryNotFileError.NAME;
|
|
14
|
+
this.message =
|
|
15
|
+
"customMessage" in constructorParameter ?
|
|
16
|
+
constructorParameter.customMessage :
|
|
17
|
+
PathRefersToDirectoryNotFileError.localization.genericDescription(constructorParameter) +
|
|
18
|
+
(0, es_extensions_1.insertSubstring)(constructorParameter.messageSpecificPart, { modifier: (messageSpecificPart) => ` ${messageSpecificPart}` });
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
exports.default = PathRefersToDirectoryNotFileError;
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type PathRefersToDirectoryNotFileError from "./PathRefersToDirectoryNotFileError";
|
|
2
|
+
declare const pathRefersToDirectoryNotFileErrorLocalization__english: PathRefersToDirectoryNotFileError.Localization;
|
|
3
|
+
export default pathRefersToDirectoryNotFileErrorLocalization__english;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const pathRefersToDirectoryNotFileErrorLocalization__english = {
|
|
4
|
+
defaultTitle: "Desired File Actually is the Directory",
|
|
5
|
+
genericDescription: ({ targetPath }) => `Contrary to expectations, path "${targetPath}" refers to directory, not file.`
|
|
6
|
+
};
|
|
7
|
+
exports.default = pathRefersToDirectoryNotFileErrorLocalization__english;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
export default class ImprovedFileSystem {
|
|
2
|
+
static isFileOrDirectoryExists(compoundParameter: Readonly<{
|
|
3
|
+
targetPath: string;
|
|
4
|
+
synchronously: false;
|
|
5
|
+
}>): Promise<boolean>;
|
|
6
|
+
static isFileOrDirectoryExists(compoundParameter: Readonly<{
|
|
7
|
+
targetPath: string;
|
|
8
|
+
synchronously: true;
|
|
9
|
+
}>): boolean;
|
|
10
|
+
static createDirectory(compoundParameter: Readonly<{
|
|
11
|
+
targetPath: string;
|
|
12
|
+
mustThrowErrorIfTargetDirectoryExists: boolean;
|
|
13
|
+
synchronously: false;
|
|
14
|
+
}>): Promise<void>;
|
|
15
|
+
static createDirectory(compoundParameter: Readonly<{
|
|
16
|
+
targetPath: string;
|
|
17
|
+
mustThrowErrorIfTargetDirectoryExists: boolean;
|
|
18
|
+
synchronously: true;
|
|
19
|
+
}>): void;
|
|
20
|
+
static ensureDirectoriesCreated(targetDirectoryPathOrMultipleOfThem: string | ReadonlyArray<string>): void;
|
|
21
|
+
static removeDirectoryWithFiles(compoundParameter: Readonly<{
|
|
22
|
+
targetPath: string;
|
|
23
|
+
mustThrowErrorIfOneOrMoreFilesCouldNotBeDeleted: boolean;
|
|
24
|
+
}>): void;
|
|
25
|
+
static removeFilesFromDirectory(compoundParameter: Readonly<{
|
|
26
|
+
directoryPath__absoluteOrRelative: string;
|
|
27
|
+
synchronously: true;
|
|
28
|
+
}>): void;
|
|
29
|
+
static removeFilesFromDirectory(compoundParameter: Readonly<{
|
|
30
|
+
directoryPath__absoluteOrRelative: string;
|
|
31
|
+
synchronously: false;
|
|
32
|
+
}>): Promise<void>;
|
|
33
|
+
static writeFileToPossiblyNotExistingDirectory(compoundParameter: Readonly<{
|
|
34
|
+
filePath: string;
|
|
35
|
+
content: string;
|
|
36
|
+
synchronously: true;
|
|
37
|
+
}>): void;
|
|
38
|
+
static writeFileToPossiblyNotExistingDirectory(compoundParameter: Readonly<{
|
|
39
|
+
filePath: string;
|
|
40
|
+
content: string;
|
|
41
|
+
synchronously: false;
|
|
42
|
+
}>): Promise<void>;
|
|
43
|
+
}
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const fs_1 = __importDefault(require("fs"));
|
|
7
|
+
const promises_1 = __importDefault(require("fs/promises"));
|
|
8
|
+
const path_1 = __importDefault(require("path"));
|
|
9
|
+
const ImprovedPath_1 = __importDefault(require("./ImprovedPath/ImprovedPath"));
|
|
10
|
+
const isErrnoException_1 = __importDefault(require("./isErrnoException"));
|
|
11
|
+
const es_extensions_1 = require("@yamato-daiwa/es-extensions");
|
|
12
|
+
class ImprovedFileSystem {
|
|
13
|
+
static isFileOrDirectoryExists({ targetPath, synchronously }) {
|
|
14
|
+
if (synchronously) {
|
|
15
|
+
return fs_1.default.existsSync(targetPath);
|
|
16
|
+
}
|
|
17
|
+
return new Promise((resolve, reject) => {
|
|
18
|
+
promises_1.default.access(targetPath).
|
|
19
|
+
then(() => { resolve(true); }).
|
|
20
|
+
catch((error) => {
|
|
21
|
+
if ((0, isErrnoException_1.default)(error) && error.code === "ENOENT") {
|
|
22
|
+
resolve(false);
|
|
23
|
+
}
|
|
24
|
+
reject(error);
|
|
25
|
+
});
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
static createDirectory({ targetPath, mustThrowErrorIfTargetDirectoryExists, synchronously }) {
|
|
29
|
+
if (synchronously) {
|
|
30
|
+
if (ImprovedFileSystem.isFileOrDirectoryExists({ targetPath, synchronously: true })) {
|
|
31
|
+
if (mustThrowErrorIfTargetDirectoryExists) {
|
|
32
|
+
es_extensions_1.Logger.throwErrorWithFormattedMessage({
|
|
33
|
+
errorType: "DirectoryAlreadyExistsError",
|
|
34
|
+
title: "Directory already exists",
|
|
35
|
+
description: `The directory "${targetPath}" is already exists.`,
|
|
36
|
+
occurrenceLocation: "ImprovedFileSystem.createDirectory(compoundParameter)"
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
fs_1.default.mkdirSync(targetPath, { recursive: true });
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
return ImprovedFileSystem.isFileOrDirectoryExists({ targetPath, synchronously: false }).
|
|
45
|
+
then(async (isTargetDirectoryAlreadyExists) => {
|
|
46
|
+
if (isTargetDirectoryAlreadyExists) {
|
|
47
|
+
if (mustThrowErrorIfTargetDirectoryExists) {
|
|
48
|
+
es_extensions_1.Logger.throwErrorWithFormattedMessage({
|
|
49
|
+
errorType: "DirectoryAlreadyExistsError",
|
|
50
|
+
title: "Directory already exists",
|
|
51
|
+
description: `The directory "${targetPath}" is already exists.`,
|
|
52
|
+
occurrenceLocation: "ImprovedFileSystem.createDirectory(compoundParameter)"
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
await promises_1.default.mkdir(targetPath, { recursive: true });
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
static ensureDirectoriesCreated(targetDirectoryPathOrMultipleOfThem) {
|
|
61
|
+
for (const targetDirectory of Array.isArray(targetDirectoryPathOrMultipleOfThem) ?
|
|
62
|
+
targetDirectoryPathOrMultipleOfThem : [targetDirectoryPathOrMultipleOfThem]) {
|
|
63
|
+
ImprovedFileSystem.createDirectory({
|
|
64
|
+
targetPath: targetDirectory,
|
|
65
|
+
synchronously: true,
|
|
66
|
+
mustThrowErrorIfTargetDirectoryExists: false
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
static removeDirectoryWithFiles(compoundParameter) {
|
|
71
|
+
const targetDirectoryPath = compoundParameter.targetPath;
|
|
72
|
+
if (!fs_1.default.existsSync(targetDirectoryPath)) {
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
for (const fileOrDirectoryPathRelativeToTargetDirectory of fs_1.default.readdirSync(targetDirectoryPath)) {
|
|
76
|
+
const fileOrChildDirectoryAbsolutePath = path_1.default.join(targetDirectoryPath, fileOrDirectoryPathRelativeToTargetDirectory);
|
|
77
|
+
if (fs_1.default.lstatSync(fileOrChildDirectoryAbsolutePath).isDirectory()) {
|
|
78
|
+
ImprovedFileSystem.removeDirectoryWithFiles({
|
|
79
|
+
targetPath: fileOrChildDirectoryAbsolutePath,
|
|
80
|
+
mustThrowErrorIfOneOrMoreFilesCouldNotBeDeleted: compoundParameter.mustThrowErrorIfOneOrMoreFilesCouldNotBeDeleted
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
else {
|
|
84
|
+
fs_1.default.unlinkSync(fileOrChildDirectoryAbsolutePath);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
fs_1.default.rmdirSync(targetDirectoryPath);
|
|
88
|
+
}
|
|
89
|
+
static removeFilesFromDirectory({ directoryPath__absoluteOrRelative, synchronously }) {
|
|
90
|
+
if (synchronously) {
|
|
91
|
+
fs_1.default.rmSync(directoryPath__absoluteOrRelative, { recursive: true, force: true });
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
return promises_1.default.rm(directoryPath__absoluteOrRelative, { recursive: true, force: true });
|
|
95
|
+
}
|
|
96
|
+
static writeFileToPossiblyNotExistingDirectory({ filePath, content, synchronously }) {
|
|
97
|
+
if (synchronously) {
|
|
98
|
+
try {
|
|
99
|
+
fs_1.default.writeFileSync(filePath, content);
|
|
100
|
+
}
|
|
101
|
+
catch (error) {
|
|
102
|
+
if ((0, isErrnoException_1.default)(error) && error.code === "ENOENT") {
|
|
103
|
+
ImprovedFileSystem.createDirectory({
|
|
104
|
+
targetPath: ImprovedPath_1.default.extractDirectoryFromFilePath({
|
|
105
|
+
targetPath: filePath,
|
|
106
|
+
ambiguitiesResolution: {
|
|
107
|
+
mustConsiderLastSegmentWithoutDotsAsFileNameWithoutExtension: true,
|
|
108
|
+
mustConsiderLastSegmentWithNonLeadingDotAsDirectory: false,
|
|
109
|
+
mustConsiderLastSegmentStartingWithDotAsDirectory: false
|
|
110
|
+
}
|
|
111
|
+
}),
|
|
112
|
+
synchronously: true,
|
|
113
|
+
mustThrowErrorIfTargetDirectoryExists: true
|
|
114
|
+
});
|
|
115
|
+
fs_1.default.writeFileSync(filePath, content);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
return promises_1.default.
|
|
121
|
+
writeFile(filePath, content).
|
|
122
|
+
catch(async (error) => {
|
|
123
|
+
if ((0, isErrnoException_1.default)(error) && error.code === "ENOENT") {
|
|
124
|
+
ImprovedFileSystem.createDirectory({
|
|
125
|
+
targetPath: ImprovedPath_1.default.extractDirectoryFromFilePath({
|
|
126
|
+
targetPath: filePath,
|
|
127
|
+
ambiguitiesResolution: {
|
|
128
|
+
mustConsiderLastSegmentWithoutDotsAsFileNameWithoutExtension: true,
|
|
129
|
+
mustConsiderLastSegmentWithNonLeadingDotAsDirectory: false,
|
|
130
|
+
mustConsiderLastSegmentStartingWithDotAsDirectory: false
|
|
131
|
+
}
|
|
132
|
+
}),
|
|
133
|
+
synchronously: true,
|
|
134
|
+
mustThrowErrorIfTargetDirectoryExists: true
|
|
135
|
+
});
|
|
136
|
+
return promises_1.default.writeFile(filePath, content);
|
|
137
|
+
}
|
|
138
|
+
throw error;
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
exports.default = ImprovedFileSystem;
|