@cenk1cenk2/oclif-common 6.3.30 → 6.4.1
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/commands/base.command.d.ts +43 -0
- package/dist/commands/base.command.js +156 -0
- package/dist/commands/index.js +1 -0
- package/dist/constants/file.constants.d.ts +6 -0
- package/dist/constants/file.constants.js +8 -0
- package/dist/constants/help-groups.constants.d.ts +6 -0
- package/dist/constants/help-groups.constants.js +8 -0
- package/dist/hooks/index.js +2 -0
- package/dist/hooks/not-found.hook.d.ts +6 -0
- package/dist/hooks/not-found.hook.js +18 -0
- package/dist/hooks/update-notifier.hook.d.ts +6 -0
- package/dist/hooks/update-notifier.hook.js +11 -0
- package/dist/index.d.ts +51 -450
- package/dist/index.js +42 -1361
- package/dist/interfaces/class.interface.d.ts +4 -0
- package/dist/interfaces/hooks.interface.d.ts +16 -0
- package/dist/interfaces/index.js +1 -0
- package/dist/interfaces/oclif.interface.d.ts +9 -0
- package/dist/interfaces/oclif.interface.js +3 -0
- package/dist/interfaces/type-helper.interface.d.ts +7 -0
- package/dist/lib/cli.interface.d.ts +8 -0
- package/dist/lib/cli.module.d.ts +11 -0
- package/dist/lib/cli.module.js +57 -0
- package/dist/lib/config/config.constants.js +12 -0
- package/dist/lib/config/config.interface.d.ts +21 -0
- package/dist/lib/config/config.module.d.ts +4 -0
- package/dist/lib/config/config.module.js +15 -0
- package/dist/lib/config/config.service.d.ts +32 -0
- package/dist/lib/config/config.service.js +152 -0
- package/dist/lib/config/index.js +2 -0
- package/dist/lib/fs/filesystem.interface.d.ts +2 -0
- package/dist/lib/fs/filesystem.module.d.ts +4 -0
- package/dist/lib/fs/filesystem.module.js +13 -0
- package/dist/lib/fs/filesystem.service.d.ts +31 -0
- package/dist/lib/fs/filesystem.service.js +141 -0
- package/dist/lib/fs/index.js +2 -0
- package/dist/lib/index.js +32 -0
- package/dist/lib/locker/index.js +2 -0
- package/dist/lib/locker/locker.interface.d.ts +28 -0
- package/dist/lib/locker/locker.module.d.ts +9 -0
- package/dist/lib/locker/locker.module.js +33 -0
- package/dist/lib/locker/locker.service.d.ts +41 -0
- package/dist/lib/locker/locker.service.js +170 -0
- package/dist/lib/logger/index.js +6 -0
- package/dist/lib/logger/logger.constants.d.ts +21 -0
- package/dist/lib/logger/logger.constants.js +24 -0
- package/dist/lib/logger/logger.interface.d.ts +13 -0
- package/dist/lib/logger/logger.module.d.ts +4 -0
- package/dist/lib/logger/logger.module.js +17 -0
- package/dist/lib/logger/logger.service.d.ts +31 -0
- package/dist/lib/logger/logger.service.js +70 -0
- package/dist/lib/logger/pipe/pipe-process-to-listr.d.ts +7 -0
- package/dist/lib/logger/pipe/pipe-process-to-listr.js +9 -0
- package/dist/lib/logger/pipe/pipe-process-to-logger.d.ts +12 -0
- package/dist/lib/logger/pipe/pipe-process-to-logger.interface.d.ts +19 -0
- package/dist/lib/logger/pipe/pipe-process-to-logger.js +54 -0
- package/dist/lib/logger/winston.service.d.ts +15 -0
- package/dist/lib/logger/winston.service.js +91 -0
- package/dist/lib/logo/index.js +3 -0
- package/dist/lib/logo/logo.constants.d.ts +6 -0
- package/dist/lib/logo/logo.constants.js +5 -0
- package/dist/lib/logo/logo.interface.d.ts +6 -0
- package/dist/lib/logo/logo.module.d.ts +4 -0
- package/dist/lib/logo/logo.module.js +13 -0
- package/dist/lib/logo/logo.service.d.ts +17 -0
- package/dist/lib/logo/logo.service.js +42 -0
- package/dist/lib/parser/fts/env-parser.service.d.ts +16 -0
- package/dist/lib/parser/fts/env-parser.service.js +42 -0
- package/dist/lib/parser/fts/index.js +3 -0
- package/dist/lib/parser/fts/json-parser.service.d.ts +15 -0
- package/dist/lib/parser/fts/json-parser.service.js +32 -0
- package/dist/lib/parser/fts/yaml-parser.service.d.ts +15 -0
- package/dist/lib/parser/fts/yaml-parser.service.js +33 -0
- package/dist/lib/parser/index.js +6 -0
- package/dist/lib/parser/parser.interface.d.ts +8 -0
- package/dist/lib/parser/parser.module.d.ts +4 -0
- package/dist/lib/parser/parser.module.js +16 -0
- package/dist/lib/parser/parser.service.d.ts +29 -0
- package/dist/lib/parser/parser.service.js +76 -0
- package/dist/lib/setup.d.ts +4 -0
- package/dist/lib/setup.js +16 -0
- package/dist/lib/validator/index.js +3 -0
- package/dist/lib/validator/validator.constants.d.ts +6 -0
- package/dist/lib/validator/validator.constants.js +5 -0
- package/dist/lib/validator/validator.interface.d.ts +10 -0
- package/dist/lib/validator/validator.module.d.ts +4 -0
- package/dist/lib/validator/validator.module.js +13 -0
- package/dist/lib/validator/validator.service.d.ts +19 -0
- package/dist/lib/validator/validator.service.js +76 -0
- package/dist/utils/defaults.d.ts +12 -0
- package/dist/utils/defaults.js +16 -0
- package/dist/utils/environment.d.ts +8 -0
- package/dist/utils/environment.js +16 -0
- package/dist/utils/guards.d.ts +9 -0
- package/dist/utils/guards.js +13 -0
- package/dist/utils/index.d.ts +7 -0
- package/dist/utils/index.js +8 -0
- package/dist/utils/merge.constants.d.ts +7 -0
- package/dist/utils/merge.constants.js +9 -0
- package/dist/utils/merge.d.ts +9 -0
- package/dist/utils/merge.js +15 -0
- package/package.json +27 -23
- package/dist/chunk-DzC9Nte8.js +0 -31
- package/dist/source-map-support-CuBekda-.js +0 -2435
package/dist/index.js
CHANGED
|
@@ -1,1363 +1,44 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import
|
|
12
|
-
import
|
|
13
|
-
import
|
|
14
|
-
import {
|
|
15
|
-
import {
|
|
16
|
-
import {
|
|
17
|
-
import {
|
|
18
|
-
import "
|
|
1
|
+
import { FileConstants } from "./constants/file.constants.js";
|
|
2
|
+
import { HelpGroups } from "./constants/help-groups.constants.js";
|
|
3
|
+
import { pipeProcessThroughListr } from "./lib/logger/pipe/pipe-process-to-listr.js";
|
|
4
|
+
import { LogFieldStatus, LogLevels } from "./lib/logger/logger.constants.js";
|
|
5
|
+
import { pipeProcessToLogger } from "./lib/logger/pipe/pipe-process-to-logger.js";
|
|
6
|
+
import { WinstonService } from "./lib/logger/winston.service.js";
|
|
7
|
+
import { LoggerService } from "./lib/logger/logger.service.js";
|
|
8
|
+
import { LoggerModule } from "./lib/logger/logger.module.js";
|
|
9
|
+
import { FileSystemService } from "./lib/fs/filesystem.service.js";
|
|
10
|
+
import { FilesystemModule } from "./lib/fs/filesystem.module.js";
|
|
11
|
+
import { ParserService } from "./lib/parser/parser.service.js";
|
|
12
|
+
import { setCtxAssign, setCtxDefaults } from "./utils/defaults.js";
|
|
13
|
+
import { isDebug, isSilent, isVerbose } from "./utils/environment.js";
|
|
14
|
+
import { isHookedWithRegister, isHookedWithShouldRunAfter, isHookedWithShouldRunBefore } from "./utils/guards.js";
|
|
15
|
+
import { MergeStrategy } from "./utils/merge.constants.js";
|
|
16
|
+
import { merge, uniqueArrayFilter } from "./utils/merge.js";
|
|
17
|
+
import { ux } from "./utils/index.js";
|
|
18
|
+
import { ConfigService } from "./lib/config/config.service.js";
|
|
19
|
+
import { ParserModule } from "./lib/parser/parser.module.js";
|
|
20
|
+
import { ConfigModule } from "./lib/config/config.module.js";
|
|
21
|
+
import { EnvironmentVariableParser } from "./lib/parser/fts/env-parser.service.js";
|
|
22
|
+
import { JsonParser } from "./lib/parser/fts/json-parser.service.js";
|
|
23
|
+
import { YamlParser } from "./lib/parser/fts/yaml-parser.service.js";
|
|
24
|
+
import { LockerService } from "./lib/locker/locker.service.js";
|
|
25
|
+
import { LockerModule } from "./lib/locker/locker.module.js";
|
|
26
|
+
import { TOKEN_LOGO_GENERATOR } from "./lib/logo/logo.constants.js";
|
|
27
|
+
import { LogoService } from "./lib/logo/logo.service.js";
|
|
28
|
+
import { LogoModule } from "./lib/logo/logo.module.js";
|
|
29
|
+
import { TOKEN_VALIDATOR_SERVICE_OPTIONS } from "./lib/validator/validator.constants.js";
|
|
30
|
+
import { ValidatorService } from "./lib/validator/validator.service.js";
|
|
31
|
+
import { ValidatorModule } from "./lib/validator/validator.module.js";
|
|
32
|
+
import { setup } from "./lib/setup.js";
|
|
33
|
+
import { CliModule } from "./lib/cli.module.js";
|
|
34
|
+
import "./lib/index.js";
|
|
35
|
+
import { Command } from "./commands/base.command.js";
|
|
36
|
+
import "./commands/index.js";
|
|
37
|
+
import { notFoundHook } from "./hooks/not-found.hook.js";
|
|
38
|
+
import { updateNotifierHook } from "./hooks/update-notifier.hook.js";
|
|
39
|
+
import "./hooks/index.js";
|
|
40
|
+
import { Args, Flags } from "./interfaces/oclif.interface.js";
|
|
41
|
+
import "./interfaces/index.js";
|
|
42
|
+
import { Inject } from "@nestjs/common";
|
|
19
43
|
|
|
20
|
-
//#region src/constants/file.constants.ts
|
|
21
|
-
let FileConstants = /* @__PURE__ */ function(FileConstants$1) {
|
|
22
|
-
FileConstants$1["CONFIG_SERVICE_DEFAULTS_DIR"] = "config";
|
|
23
|
-
return FileConstants$1;
|
|
24
|
-
}({});
|
|
25
|
-
|
|
26
|
-
//#endregion
|
|
27
|
-
//#region src/constants/help-groups.constants.ts
|
|
28
|
-
let HelpGroups = /* @__PURE__ */ function(HelpGroups$1) {
|
|
29
|
-
HelpGroups$1["CLI"] = "CLI";
|
|
30
|
-
return HelpGroups$1;
|
|
31
|
-
}({});
|
|
32
|
-
|
|
33
|
-
//#endregion
|
|
34
|
-
//#region src/lib/config/config.constants.ts
|
|
35
|
-
let ConfigEnvKeys = /* @__PURE__ */ function(ConfigEnvKeys$1) {
|
|
36
|
-
ConfigEnvKeys$1["NAME"] = "__name";
|
|
37
|
-
ConfigEnvKeys$1["PARSER"] = "__format";
|
|
38
|
-
ConfigEnvKeys$1["ELEMENT"] = "__element";
|
|
39
|
-
ConfigEnvKeys$1["ELEMENT_REPLACER"] = "${i}";
|
|
40
|
-
return ConfigEnvKeys$1;
|
|
41
|
-
}({});
|
|
42
|
-
const TOKEN_CONFIG_MODULE_OPTIONS = Symbol("TOKEN_CONFIG_MODULE_OPTIONS");
|
|
43
|
-
|
|
44
|
-
//#endregion
|
|
45
|
-
//#region src/utils/defaults.ts
|
|
46
|
-
function setCtxDefaults(ctx, ...defaults) {
|
|
47
|
-
defaults?.forEach((i) => {
|
|
48
|
-
if (typeof i === "object" && !Array.isArray(i)) Object.assign(ctx, i);
|
|
49
|
-
});
|
|
50
|
-
}
|
|
51
|
-
function setCtxAssign(ctx, ...assigns) {
|
|
52
|
-
assigns.forEach((assign) => {
|
|
53
|
-
assign?.keys.forEach((i) => {
|
|
54
|
-
if (assign.from[i]) ctx[i] = assign.from[i];
|
|
55
|
-
});
|
|
56
|
-
});
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
//#endregion
|
|
60
|
-
//#region src/lib/logger/pipe/pipe-process-to-listr.ts
|
|
61
|
-
function pipeProcessThroughListr(task, instance) {
|
|
62
|
-
instance.stdout.pipe(task.stdout());
|
|
63
|
-
instance.stderr.pipe(task.stdout());
|
|
64
|
-
return instance;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
//#endregion
|
|
68
|
-
//#region src/lib/logger/logger.constants.ts
|
|
69
|
-
let LogLevels = /* @__PURE__ */ function(LogLevels$1) {
|
|
70
|
-
LogLevels$1["SILENT"] = "SILENT";
|
|
71
|
-
LogLevels$1["DIRECT"] = "DIRECT";
|
|
72
|
-
LogLevels$1["FATAL"] = "FATAL";
|
|
73
|
-
LogLevels$1["ERROR"] = "ERROR";
|
|
74
|
-
LogLevels$1["WARN"] = "WARN";
|
|
75
|
-
LogLevels$1["INFO"] = "INFO";
|
|
76
|
-
LogLevels$1["VERBOSE"] = "VERBOSE";
|
|
77
|
-
LogLevels$1["DEBUG"] = "DEBUG";
|
|
78
|
-
LogLevels$1["TRACE"] = "TRACE";
|
|
79
|
-
return LogLevels$1;
|
|
80
|
-
}({});
|
|
81
|
-
let LogFieldStatus = /* @__PURE__ */ function(LogFieldStatus$1) {
|
|
82
|
-
LogFieldStatus$1["RUN"] = "run";
|
|
83
|
-
LogFieldStatus$1["END"] = "end";
|
|
84
|
-
LogFieldStatus$1["STAGE"] = "stage";
|
|
85
|
-
LogFieldStatus$1["EXIT"] = "exit";
|
|
86
|
-
LogFieldStatus$1["TERMINATE"] = "terminate";
|
|
87
|
-
return LogFieldStatus$1;
|
|
88
|
-
}({});
|
|
89
|
-
|
|
90
|
-
//#endregion
|
|
91
|
-
//#region src/lib/logger/pipe/pipe-process-to-logger.ts
|
|
92
|
-
/**
|
|
93
|
-
* Given the instance it will pipe process output through the logger to append prefixes such as the application name.
|
|
94
|
-
*/
|
|
95
|
-
function pipeProcessToLogger(logger, instance, options) {
|
|
96
|
-
options = {
|
|
97
|
-
start: LogLevels.INFO,
|
|
98
|
-
end: LogLevels.INFO,
|
|
99
|
-
stdout: LogLevels.INFO,
|
|
100
|
-
stderr: LogLevels.WARN,
|
|
101
|
-
...options
|
|
102
|
-
};
|
|
103
|
-
if (options.start) logger.run(instance.spawnargs.join(" "), {
|
|
104
|
-
level: options.start,
|
|
105
|
-
context: options.context
|
|
106
|
-
});
|
|
107
|
-
if (instance.stdout) {
|
|
108
|
-
const writable = new Writable();
|
|
109
|
-
writable.write = (chunk) => {
|
|
110
|
-
logger.log(options.stdout, chunk, { context: options.context });
|
|
111
|
-
return true;
|
|
112
|
-
};
|
|
113
|
-
instance.stdout.pipe(writable);
|
|
114
|
-
}
|
|
115
|
-
if (instance.stderr) {
|
|
116
|
-
const writable = new Writable();
|
|
117
|
-
writable.write = (chunk) => {
|
|
118
|
-
logger.log(options.stderr, chunk, { context: options.context });
|
|
119
|
-
return true;
|
|
120
|
-
};
|
|
121
|
-
instance.stderr.pipe(writable);
|
|
122
|
-
}
|
|
123
|
-
instance.on("exit", (code, signal) => {
|
|
124
|
-
const message = `Process ended with code ${code}${signal ? ` and signal ${signal}` : ""}.`;
|
|
125
|
-
logger.debug(message, { context: options.context });
|
|
126
|
-
if (options.end) logger.end(instance.spawnargs.join(" "), {
|
|
127
|
-
level: options.end,
|
|
128
|
-
context: options.context
|
|
129
|
-
});
|
|
130
|
-
if (options?.callback) options.callback();
|
|
131
|
-
});
|
|
132
|
-
instance.on("error", (error) => {
|
|
133
|
-
logger.fatal(error.message, { context: options.context });
|
|
134
|
-
logger.debug(error.stack, { context: options.context });
|
|
135
|
-
if (options?.callback) options.callback(error);
|
|
136
|
-
});
|
|
137
|
-
return instance;
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
//#endregion
|
|
141
|
-
//#region ../../node_modules/.pnpm/@oxc-project+runtime@0.77.2/node_modules/@oxc-project/runtime/src/helpers/typeof.js
|
|
142
|
-
var require_typeof = __commonJS({ "../../node_modules/.pnpm/@oxc-project+runtime@0.77.2/node_modules/@oxc-project/runtime/src/helpers/typeof.js"(exports, module) {
|
|
143
|
-
function _typeof$2(o) {
|
|
144
|
-
"@babel/helpers - typeof";
|
|
145
|
-
return module.exports = _typeof$2 = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o$1) {
|
|
146
|
-
return typeof o$1;
|
|
147
|
-
} : function(o$1) {
|
|
148
|
-
return o$1 && "function" == typeof Symbol && o$1.constructor === Symbol && o$1 !== Symbol.prototype ? "symbol" : typeof o$1;
|
|
149
|
-
}, module.exports.__esModule = true, module.exports["default"] = module.exports, _typeof$2(o);
|
|
150
|
-
}
|
|
151
|
-
module.exports = _typeof$2, module.exports.__esModule = true, module.exports["default"] = module.exports;
|
|
152
|
-
} });
|
|
153
|
-
|
|
154
|
-
//#endregion
|
|
155
|
-
//#region ../../node_modules/.pnpm/@oxc-project+runtime@0.77.2/node_modules/@oxc-project/runtime/src/helpers/toPrimitive.js
|
|
156
|
-
var require_toPrimitive = __commonJS({ "../../node_modules/.pnpm/@oxc-project+runtime@0.77.2/node_modules/@oxc-project/runtime/src/helpers/toPrimitive.js"(exports, module) {
|
|
157
|
-
var _typeof$1 = require_typeof()["default"];
|
|
158
|
-
function toPrimitive$1(t, r) {
|
|
159
|
-
if ("object" != _typeof$1(t) || !t) return t;
|
|
160
|
-
var e = t[Symbol.toPrimitive];
|
|
161
|
-
if (void 0 !== e) {
|
|
162
|
-
var i = e.call(t, r || "default");
|
|
163
|
-
if ("object" != _typeof$1(i)) return i;
|
|
164
|
-
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
165
|
-
}
|
|
166
|
-
return ("string" === r ? String : Number)(t);
|
|
167
|
-
}
|
|
168
|
-
module.exports = toPrimitive$1, module.exports.__esModule = true, module.exports["default"] = module.exports;
|
|
169
|
-
} });
|
|
170
|
-
|
|
171
|
-
//#endregion
|
|
172
|
-
//#region ../../node_modules/.pnpm/@oxc-project+runtime@0.77.2/node_modules/@oxc-project/runtime/src/helpers/toPropertyKey.js
|
|
173
|
-
var require_toPropertyKey = __commonJS({ "../../node_modules/.pnpm/@oxc-project+runtime@0.77.2/node_modules/@oxc-project/runtime/src/helpers/toPropertyKey.js"(exports, module) {
|
|
174
|
-
var _typeof = require_typeof()["default"];
|
|
175
|
-
var toPrimitive = require_toPrimitive();
|
|
176
|
-
function toPropertyKey$1(t) {
|
|
177
|
-
var i = toPrimitive(t, "string");
|
|
178
|
-
return "symbol" == _typeof(i) ? i : i + "";
|
|
179
|
-
}
|
|
180
|
-
module.exports = toPropertyKey$1, module.exports.__esModule = true, module.exports["default"] = module.exports;
|
|
181
|
-
} });
|
|
182
|
-
|
|
183
|
-
//#endregion
|
|
184
|
-
//#region ../../node_modules/.pnpm/@oxc-project+runtime@0.77.2/node_modules/@oxc-project/runtime/src/helpers/defineProperty.js
|
|
185
|
-
var require_defineProperty = __commonJS({ "../../node_modules/.pnpm/@oxc-project+runtime@0.77.2/node_modules/@oxc-project/runtime/src/helpers/defineProperty.js"(exports, module) {
|
|
186
|
-
var toPropertyKey = require_toPropertyKey();
|
|
187
|
-
function _defineProperty$12(e, r, t) {
|
|
188
|
-
return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
|
|
189
|
-
value: t,
|
|
190
|
-
enumerable: !0,
|
|
191
|
-
configurable: !0,
|
|
192
|
-
writable: !0
|
|
193
|
-
}) : e[r] = t, e;
|
|
194
|
-
}
|
|
195
|
-
module.exports = _defineProperty$12, module.exports.__esModule = true, module.exports["default"] = module.exports;
|
|
196
|
-
} });
|
|
197
|
-
|
|
198
|
-
//#endregion
|
|
199
|
-
//#region ../../node_modules/.pnpm/@oxc-project+runtime@0.77.2/node_modules/@oxc-project/runtime/src/helpers/decorate.js
|
|
200
|
-
var require_decorate = __commonJS({ "../../node_modules/.pnpm/@oxc-project+runtime@0.77.2/node_modules/@oxc-project/runtime/src/helpers/decorate.js"(exports, module) {
|
|
201
|
-
function __decorate(decorators, target, key, desc) {
|
|
202
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
203
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
204
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
205
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
206
|
-
}
|
|
207
|
-
module.exports = __decorate, module.exports.__esModule = true, module.exports["default"] = module.exports;
|
|
208
|
-
} });
|
|
209
|
-
|
|
210
|
-
//#endregion
|
|
211
|
-
//#region src/lib/logger/logger.service.ts
|
|
212
|
-
var import_defineProperty$11 = __toESM(require_defineProperty(), 1);
|
|
213
|
-
var import_decorate$17 = __toESM(require_decorate(), 1);
|
|
214
|
-
let LoggerService = class LoggerService$1 {
|
|
215
|
-
constructor(winston$1) {
|
|
216
|
-
this.winston = winston$1;
|
|
217
|
-
(0, import_defineProperty$11.default)(this, "context", void 0);
|
|
218
|
-
}
|
|
219
|
-
setup(context) {
|
|
220
|
-
this.context = context;
|
|
221
|
-
return this;
|
|
222
|
-
}
|
|
223
|
-
log(level, data, ...args) {
|
|
224
|
-
return this.parseMessage(level, data, args);
|
|
225
|
-
}
|
|
226
|
-
direct(data, ...args) {
|
|
227
|
-
return this.parseMessage(LogLevels.DIRECT, data, args);
|
|
228
|
-
}
|
|
229
|
-
fatal(data, ...args) {
|
|
230
|
-
return this.parseMessage(LogLevels.FATAL, data, args);
|
|
231
|
-
}
|
|
232
|
-
error(data, ...args) {
|
|
233
|
-
return this.parseMessage(LogLevels.ERROR, data, args);
|
|
234
|
-
}
|
|
235
|
-
warn(data, ...args) {
|
|
236
|
-
return this.parseMessage(LogLevels.WARN, data, args);
|
|
237
|
-
}
|
|
238
|
-
info(data, ...args) {
|
|
239
|
-
return this.parseMessage(LogLevels.INFO, data, args);
|
|
240
|
-
}
|
|
241
|
-
verbose(data, ...args) {
|
|
242
|
-
return this.parseMessage(LogLevels.VERBOSE, data, args);
|
|
243
|
-
}
|
|
244
|
-
debug(data, ...args) {
|
|
245
|
-
return this.parseMessage(LogLevels.DEBUG, data, args);
|
|
246
|
-
}
|
|
247
|
-
trace(data, ...args) {
|
|
248
|
-
return this.parseMessage(LogLevels.TRACE, data, args);
|
|
249
|
-
}
|
|
250
|
-
run(data, ...args) {
|
|
251
|
-
return this.parseMessage(LogLevels.INFO, data, args, { status: LogFieldStatus.RUN });
|
|
252
|
-
}
|
|
253
|
-
end(data, ...args) {
|
|
254
|
-
return this.parseMessage(LogLevels.INFO, data, args, { status: LogFieldStatus.END });
|
|
255
|
-
}
|
|
256
|
-
stage(data, ...args) {
|
|
257
|
-
return this.parseMessage(LogLevels.TRACE, data, args, { status: LogFieldStatus.STAGE });
|
|
258
|
-
}
|
|
259
|
-
splat(...args) {
|
|
260
|
-
const message = args.shift();
|
|
261
|
-
if (typeof message === "undefined") return "";
|
|
262
|
-
if (args.length === 0) return message;
|
|
263
|
-
return splat(message, args);
|
|
264
|
-
}
|
|
265
|
-
parseMessage(level, data, args, format$1) {
|
|
266
|
-
this.winston.instance.log(level, data.toString(), ...args ?? [], {
|
|
267
|
-
context: this.context,
|
|
268
|
-
...format$1 ?? {}
|
|
269
|
-
});
|
|
270
|
-
}
|
|
271
|
-
};
|
|
272
|
-
LoggerService = (0, import_decorate$17.default)([Injectable({ scope: Scope.TRANSIENT })], LoggerService);
|
|
273
|
-
|
|
274
|
-
//#endregion
|
|
275
|
-
//#region ../../node_modules/.pnpm/@oxc-project+runtime@0.77.2/node_modules/@oxc-project/runtime/src/helpers/decorateParam.js
|
|
276
|
-
var require_decorateParam = __commonJS({ "../../node_modules/.pnpm/@oxc-project+runtime@0.77.2/node_modules/@oxc-project/runtime/src/helpers/decorateParam.js"(exports, module) {
|
|
277
|
-
function __decorateParam(paramIndex, decorator) {
|
|
278
|
-
return function(target, key) {
|
|
279
|
-
decorator(target, key, paramIndex);
|
|
280
|
-
};
|
|
281
|
-
}
|
|
282
|
-
module.exports = __decorateParam, module.exports.__esModule = true, module.exports["default"] = module.exports;
|
|
283
|
-
} });
|
|
284
|
-
|
|
285
|
-
//#endregion
|
|
286
|
-
//#region src/lib/logger/winston.service.ts
|
|
287
|
-
var import_defineProperty$10 = __toESM(require_defineProperty(), 1);
|
|
288
|
-
var import_decorateParam$1 = __toESM(require_decorateParam(), 1);
|
|
289
|
-
var import_decorate$16 = __toESM(require_decorate(), 1);
|
|
290
|
-
let WinstonService = class WinstonService$1 {
|
|
291
|
-
constructor(options) {
|
|
292
|
-
this.options = options;
|
|
293
|
-
(0, import_defineProperty$10.default)(this, "instance", this.initiateLogger());
|
|
294
|
-
}
|
|
295
|
-
initiateLogger() {
|
|
296
|
-
const logFormat = format.printf(({ level, message, context, status }) => {
|
|
297
|
-
return message.split(EOL).filter((msg) => !msg || msg.trim() !== "").map((msg) => {
|
|
298
|
-
return this.logColoring({
|
|
299
|
-
level,
|
|
300
|
-
message: msg,
|
|
301
|
-
context,
|
|
302
|
-
status
|
|
303
|
-
});
|
|
304
|
-
}).join(EOL);
|
|
305
|
-
});
|
|
306
|
-
const logger = winston.createLogger({
|
|
307
|
-
level: this.options.config.logLevel,
|
|
308
|
-
format: format.combine(format.splat(), format.json({ space: 2 }), format.prettyPrint(), logFormat),
|
|
309
|
-
levels: Object.fromEntries(Object.values(LogLevels).map((level, i) => {
|
|
310
|
-
return [level, i];
|
|
311
|
-
})),
|
|
312
|
-
silent: this.options.config.logLevel === LogLevels.SILENT || this.options.config.isJson,
|
|
313
|
-
transports: [new transports.Console({ stderrLevels: [LogLevels.FATAL, LogLevels.ERROR] })]
|
|
314
|
-
});
|
|
315
|
-
logger.log(LogLevels.TRACE, "Initiated new winston with level: %s", this.options.config.logLevel, { context: this.constructor.name });
|
|
316
|
-
return logger;
|
|
317
|
-
}
|
|
318
|
-
logColoring({ level, message, context, status }) {
|
|
319
|
-
let icon;
|
|
320
|
-
let coloring = (input) => {
|
|
321
|
-
return input;
|
|
322
|
-
};
|
|
323
|
-
let msgColoring = (input) => {
|
|
324
|
-
return input;
|
|
325
|
-
};
|
|
326
|
-
switch (level) {
|
|
327
|
-
case LogLevels.DIRECT: return message;
|
|
328
|
-
case LogLevels.FATAL:
|
|
329
|
-
coloring = color.red;
|
|
330
|
-
msgColoring = color.red;
|
|
331
|
-
break;
|
|
332
|
-
case LogLevels.ERROR:
|
|
333
|
-
coloring = color.red;
|
|
334
|
-
icon = figures.cross;
|
|
335
|
-
break;
|
|
336
|
-
case LogLevels.WARN:
|
|
337
|
-
coloring = color.yellow;
|
|
338
|
-
icon = figures.warning;
|
|
339
|
-
break;
|
|
340
|
-
case LogLevels.INFO:
|
|
341
|
-
coloring = color.green;
|
|
342
|
-
icon = figures.pointerSmall;
|
|
343
|
-
break;
|
|
344
|
-
case LogLevels.VERBOSE:
|
|
345
|
-
coloring = color.dim;
|
|
346
|
-
break;
|
|
347
|
-
case LogLevels.DEBUG:
|
|
348
|
-
coloring = color.cyan;
|
|
349
|
-
msgColoring = color.dim;
|
|
350
|
-
break;
|
|
351
|
-
case LogLevels.TRACE:
|
|
352
|
-
coloring = color.magenta;
|
|
353
|
-
msgColoring = color.dim;
|
|
354
|
-
break;
|
|
355
|
-
}
|
|
356
|
-
if (!icon) icon = `[${level.at(0).toUpperCase()}]`;
|
|
357
|
-
return `${coloring(icon)}${context ? " " + coloring(`[${context}]`) : ""}${status ? " " + coloring(`[${status}]`) : ""} ${msgColoring(message)}`;
|
|
358
|
-
}
|
|
359
|
-
};
|
|
360
|
-
WinstonService = (0, import_decorate$16.default)([Injectable(), (0, import_decorateParam$1.default)(0, Inject$1(TOKEN_CONFIG_MODULE_OPTIONS))], WinstonService);
|
|
361
|
-
|
|
362
|
-
//#endregion
|
|
363
|
-
//#region src/lib/logger/logger.module.ts
|
|
364
|
-
var import_decorate$15 = __toESM(require_decorate(), 1);
|
|
365
|
-
let LoggerModule = class LoggerModule$1 {};
|
|
366
|
-
LoggerModule = (0, import_decorate$15.default)([Global(), Module({
|
|
367
|
-
providers: [WinstonService, LoggerService],
|
|
368
|
-
exports: [LoggerService]
|
|
369
|
-
})], LoggerModule);
|
|
370
|
-
|
|
371
|
-
//#endregion
|
|
372
|
-
//#region src/utils/environment.ts
|
|
373
|
-
function isVerbose(logLevel) {
|
|
374
|
-
return logLevel === LogLevels.VERBOSE;
|
|
375
|
-
}
|
|
376
|
-
function isDebug(logLevel) {
|
|
377
|
-
return [LogLevels.DEBUG, LogLevels.TRACE].includes(logLevel);
|
|
378
|
-
}
|
|
379
|
-
function isSilent(logLevel) {
|
|
380
|
-
return logLevel === LogLevels.SILENT;
|
|
381
|
-
}
|
|
382
|
-
|
|
383
|
-
//#endregion
|
|
384
|
-
//#region src/utils/guards.ts
|
|
385
|
-
function isHookedWithShouldRunBefore(command) {
|
|
386
|
-
return typeof command.shouldRunBefore === "function";
|
|
387
|
-
}
|
|
388
|
-
function isHookedWithShouldRunAfter(command) {
|
|
389
|
-
return typeof command.shouldRunAfter === "function";
|
|
390
|
-
}
|
|
391
|
-
function isHookedWithRegister(command) {
|
|
392
|
-
return typeof command.register === "function";
|
|
393
|
-
}
|
|
394
|
-
|
|
395
|
-
//#endregion
|
|
396
|
-
//#region src/utils/merge.constants.ts
|
|
397
|
-
let MergeStrategy = /* @__PURE__ */ function(MergeStrategy$1) {
|
|
398
|
-
MergeStrategy$1["OVERWRITE"] = "OVERWRITE";
|
|
399
|
-
MergeStrategy$1["EXTEND"] = "EXTEND";
|
|
400
|
-
return MergeStrategy$1;
|
|
401
|
-
}({});
|
|
402
|
-
|
|
403
|
-
//#endregion
|
|
404
|
-
//#region src/utils/merge.ts
|
|
405
|
-
/** Merge objects deep from overwriting the properties from source to target.
|
|
406
|
-
* Does not mutate the object */
|
|
407
|
-
function merge(strategy, ...source) {
|
|
408
|
-
return deepmerge.all(source, { arrayMerge: strategy === MergeStrategy.EXTEND ? (dest, src) => [...dest, ...src].filter(uniqueArrayFilter) : (_, src) => src });
|
|
409
|
-
}
|
|
410
|
-
function uniqueArrayFilter(value, index, self) {
|
|
411
|
-
return self.indexOf(value) === index;
|
|
412
|
-
}
|
|
413
|
-
|
|
414
|
-
//#endregion
|
|
415
|
-
//#region src/lib/config/config.service.ts
|
|
416
|
-
var import_defineProperty$9 = __toESM(require_defineProperty(), 1);
|
|
417
|
-
var import_decorateParam = __toESM(require_decorateParam(), 1);
|
|
418
|
-
var import_decorate$14 = __toESM(require_decorate(), 1);
|
|
419
|
-
let ConfigService = class ConfigService$1 {
|
|
420
|
-
constructor(parser, logger, options) {
|
|
421
|
-
this.parser = parser;
|
|
422
|
-
this.logger = logger;
|
|
423
|
-
(0, import_defineProperty$9.default)(this, "defaults", void 0);
|
|
424
|
-
(0, import_defineProperty$9.default)(this, "root", void 0);
|
|
425
|
-
(0, import_defineProperty$9.default)(this, "config", void 0);
|
|
426
|
-
(0, import_defineProperty$9.default)(this, "oclif", void 0);
|
|
427
|
-
(0, import_defineProperty$9.default)(this, "command", void 0);
|
|
428
|
-
this.root = options.oclif.root;
|
|
429
|
-
this.defaults = join(options.oclif.root, FileConstants.CONFIG_SERVICE_DEFAULTS_DIR);
|
|
430
|
-
this.oclif = options.oclif;
|
|
431
|
-
this.config = options.config;
|
|
432
|
-
this.command = options.command;
|
|
433
|
-
this.logger.setup(this.constructor.name);
|
|
434
|
-
}
|
|
435
|
-
get isVerbose() {
|
|
436
|
-
return isVerbose(this.config.logLevel);
|
|
437
|
-
}
|
|
438
|
-
get isDebug() {
|
|
439
|
-
return isDebug(this.config.logLevel);
|
|
440
|
-
}
|
|
441
|
-
get isSilent() {
|
|
442
|
-
return isSilent(this.config.logLevel);
|
|
443
|
-
}
|
|
444
|
-
get isJson() {
|
|
445
|
-
return this.config.isJson;
|
|
446
|
-
}
|
|
447
|
-
async read(path) {
|
|
448
|
-
const config = await this.parser.read(path);
|
|
449
|
-
this.logger.trace("Read config from: %s", path);
|
|
450
|
-
return config;
|
|
451
|
-
}
|
|
452
|
-
async extend(paths, strategy = MergeStrategy.OVERWRITE) {
|
|
453
|
-
this.logger.trace("Will generate config from: %o with %s", paths, strategy);
|
|
454
|
-
const configs = (await Promise.all(paths.map(async (path) => {
|
|
455
|
-
try {
|
|
456
|
-
const config = typeof path === "string" ? await this.parser.read(path) : path;
|
|
457
|
-
this.logger.trace("Extending config from: %s", path);
|
|
458
|
-
return config;
|
|
459
|
-
} catch (e) {
|
|
460
|
-
this.logger.trace("Failed to extend config from: %s", e.message);
|
|
461
|
-
}
|
|
462
|
-
}))).filter(Boolean);
|
|
463
|
-
return this.merge(configs, strategy);
|
|
464
|
-
}
|
|
465
|
-
merge(configs, strategy = MergeStrategy.OVERWRITE) {
|
|
466
|
-
if (configs.length === 0) throw new Error("Nothing to merge, configuration files are empty.");
|
|
467
|
-
return merge(strategy, ...configs);
|
|
468
|
-
}
|
|
469
|
-
async env(definition, config) {
|
|
470
|
-
const env = typeof definition === "string" ? await this.parser.read(definition) : definition;
|
|
471
|
-
this.logger.trace("Environment variable extensions read: %o", definition);
|
|
472
|
-
const iter = async (obj, parent) => {
|
|
473
|
-
const data = await Promise.all(Object.entries(obj).map(async ([key, value]) => {
|
|
474
|
-
const location = [...parent ?? [], key];
|
|
475
|
-
if (typeof value === "string") return [{
|
|
476
|
-
key: location,
|
|
477
|
-
env: value
|
|
478
|
-
}];
|
|
479
|
-
else if (typeof value === "object") {
|
|
480
|
-
let extensions;
|
|
481
|
-
if (ConfigEnvKeys.ELEMENT in value) {
|
|
482
|
-
extensions = await iter(value[ConfigEnvKeys.ELEMENT], [...location, ConfigEnvKeys.ELEMENT]);
|
|
483
|
-
this.logger.trace("Expanding location to elements: %s -> %s", location, extensions.map((extension) => extension.key.join(".")).join(", "));
|
|
484
|
-
}
|
|
485
|
-
if (ConfigEnvKeys.NAME in value && ConfigEnvKeys.PARSER in value) {
|
|
486
|
-
const variable = [{
|
|
487
|
-
key: location,
|
|
488
|
-
env: value[ConfigEnvKeys.NAME],
|
|
489
|
-
parser: value[ConfigEnvKeys.PARSER],
|
|
490
|
-
extensions
|
|
491
|
-
}];
|
|
492
|
-
return variable;
|
|
493
|
-
} else return iter(value, location);
|
|
494
|
-
}
|
|
495
|
-
}));
|
|
496
|
-
return data.flatMap((d) => d).filter(Boolean);
|
|
497
|
-
};
|
|
498
|
-
const parsed = await iter(env);
|
|
499
|
-
const cb = (config$1, variable, data) => {
|
|
500
|
-
if (variable.parser) try {
|
|
501
|
-
data = this.parser.parse(variable.parser, data);
|
|
502
|
-
} catch (e) {
|
|
503
|
-
this.logger.trace("Can not parse environment environment variable for config: %s -> %s with %s", variable.key.join("."), variable.env, variable.parser);
|
|
504
|
-
throw e;
|
|
505
|
-
}
|
|
506
|
-
this.logger.trace("Overwriting config with environment variable: %s -> %s", variable.key.join("."), variable.env);
|
|
507
|
-
return op.set(config$1, variable.key, data);
|
|
508
|
-
};
|
|
509
|
-
parsed.forEach((variable) => {
|
|
510
|
-
let data;
|
|
511
|
-
data = process.env[variable.env];
|
|
512
|
-
if (data) config = cb(config, variable, data);
|
|
513
|
-
if (variable.extensions && variable.extensions.length > 0) {
|
|
514
|
-
const timeout = 6e4;
|
|
515
|
-
const startedAt = Date.now();
|
|
516
|
-
for (let i = 0; i < Infinity; i++) {
|
|
517
|
-
if (Date.now() - startedAt > timeout) throw new Error(`Timed-out in ${timeout}ms while looking for element environment variables.`);
|
|
518
|
-
const extensions = variable.extensions.map((extension) => {
|
|
519
|
-
const clone = JSON.parse(JSON.stringify(extension));
|
|
520
|
-
clone.env = clone.env.replace(ConfigEnvKeys.ELEMENT_REPLACER, i.toString());
|
|
521
|
-
clone.key[clone.key.findIndex((value) => value === ConfigEnvKeys.ELEMENT)] = i.toString();
|
|
522
|
-
data = process.env[clone.env];
|
|
523
|
-
if (!data) {
|
|
524
|
-
this.logger.trace("No extension for environment variable: %s -> %s", clone.key.join("."), clone.env);
|
|
525
|
-
return;
|
|
526
|
-
}
|
|
527
|
-
config = cb(config, clone, data);
|
|
528
|
-
return true;
|
|
529
|
-
}).filter(Boolean);
|
|
530
|
-
if (extensions.length === 0) {
|
|
531
|
-
this.logger.trace("No more extensions for environment variables: %s -> %d", variable.key.join("."), i);
|
|
532
|
-
break;
|
|
533
|
-
}
|
|
534
|
-
}
|
|
535
|
-
}
|
|
536
|
-
});
|
|
537
|
-
return config;
|
|
538
|
-
}
|
|
539
|
-
async write(path, data) {
|
|
540
|
-
return this.parser.write(path, data);
|
|
541
|
-
}
|
|
542
|
-
};
|
|
543
|
-
ConfigService = (0, import_decorate$14.default)([Injectable(), (0, import_decorateParam.default)(2, Inject$1(TOKEN_CONFIG_MODULE_OPTIONS))], ConfigService);
|
|
544
|
-
|
|
545
|
-
//#endregion
|
|
546
|
-
//#region src/lib/parser/parser.service.ts
|
|
547
|
-
var import_defineProperty$8 = __toESM(require_defineProperty(), 1);
|
|
548
|
-
var import_decorate$13 = __toESM(require_decorate(), 1);
|
|
549
|
-
let ParserService = class ParserService$1 {
|
|
550
|
-
constructor(moduleRef, fs$1, logger) {
|
|
551
|
-
this.moduleRef = moduleRef;
|
|
552
|
-
this.fs = fs$1;
|
|
553
|
-
this.logger = logger;
|
|
554
|
-
(0, import_defineProperty$8.default)(this, "instances", []);
|
|
555
|
-
this.logger.setup(this.constructor.name);
|
|
556
|
-
}
|
|
557
|
-
byFt(file) {
|
|
558
|
-
const ext = (file.includes(".") ? this.fs.extname(file) : file).replace(/^\./, "");
|
|
559
|
-
const Parser = this.instances.find((parser) => parser.extensions.includes(ext));
|
|
560
|
-
if (!Parser) throw new Error(`Parser for the extension is not configured: ${ext}`);
|
|
561
|
-
return Parser;
|
|
562
|
-
}
|
|
563
|
-
fetch(Parser) {
|
|
564
|
-
const parser = this.instances.find((instance) => instance instanceof Parser);
|
|
565
|
-
if (!parser) throw new Error(`Specified parser has not been initiated: ${Parser.name}`);
|
|
566
|
-
return parser;
|
|
567
|
-
}
|
|
568
|
-
async inject(Parser) {
|
|
569
|
-
const parser = await this.moduleRef.create(Parser);
|
|
570
|
-
this.instances.push(parser);
|
|
571
|
-
return parser;
|
|
572
|
-
}
|
|
573
|
-
async register(...parsers) {
|
|
574
|
-
await Promise.all(parsers.map(async (parser) => this.inject(parser)));
|
|
575
|
-
this.logger.trace("Registered parsers: %o", parsers.map((p) => p.name));
|
|
576
|
-
}
|
|
577
|
-
async read(file) {
|
|
578
|
-
return this.parse(file, await this.fs.read(file));
|
|
579
|
-
}
|
|
580
|
-
async write(file, data) {
|
|
581
|
-
return this.fs.write(file, this.stringify(file, data));
|
|
582
|
-
}
|
|
583
|
-
parse(file, data) {
|
|
584
|
-
const parser = this.byFt(file);
|
|
585
|
-
this.logger.trace("Parsing file: %s -> %s", file, parser.constructor.name);
|
|
586
|
-
return parser.parse(data);
|
|
587
|
-
}
|
|
588
|
-
parseWith(Parser, data) {
|
|
589
|
-
const parser = this.fetch(Parser);
|
|
590
|
-
this.logger.trace("Parsing data with: %s", parser.constructor.name);
|
|
591
|
-
return parser.parse(data);
|
|
592
|
-
}
|
|
593
|
-
stringify(file, data) {
|
|
594
|
-
const parser = this.byFt(file);
|
|
595
|
-
this.logger.trace("Stringifying file: %s -> %s", file, parser.constructor.name);
|
|
596
|
-
return parser.stringify(data);
|
|
597
|
-
}
|
|
598
|
-
stringifyWith(Parser, data) {
|
|
599
|
-
const parser = this.fetch(Parser);
|
|
600
|
-
this.logger.trace("Stringifying data: %s", parser.constructor.name);
|
|
601
|
-
return parser.stringify(data);
|
|
602
|
-
}
|
|
603
|
-
};
|
|
604
|
-
ParserService = (0, import_decorate$13.default)([Injectable()], ParserService);
|
|
605
|
-
|
|
606
|
-
//#endregion
|
|
607
|
-
//#region src/lib/fs/filesystem.service.ts
|
|
608
|
-
var import_defineProperty$7 = __toESM(require_defineProperty(), 1);
|
|
609
|
-
var import_decorate$12 = __toESM(require_decorate(), 1);
|
|
610
|
-
let FileSystemService = class FileSystemService$1 {
|
|
611
|
-
constructor(logger) {
|
|
612
|
-
this.logger = logger;
|
|
613
|
-
(0, import_defineProperty$7.default)(this, "extra", fs);
|
|
614
|
-
this.logger.setup(this.constructor.name);
|
|
615
|
-
}
|
|
616
|
-
exists(path) {
|
|
617
|
-
return this.extra.existsSync(path);
|
|
618
|
-
}
|
|
619
|
-
stats(path) {
|
|
620
|
-
return this.extra.statSync(path, { throwIfNoEntry: true });
|
|
621
|
-
}
|
|
622
|
-
dirname(path) {
|
|
623
|
-
return dirname(path);
|
|
624
|
-
}
|
|
625
|
-
extname(path) {
|
|
626
|
-
return extname(path);
|
|
627
|
-
}
|
|
628
|
-
async read(file) {
|
|
629
|
-
try {
|
|
630
|
-
const raw = await this.extra.readFile(file, "utf-8");
|
|
631
|
-
return raw;
|
|
632
|
-
} catch (e) {
|
|
633
|
-
throw new Error(`Error while reading file from "${file}": ${e.message}`);
|
|
634
|
-
}
|
|
635
|
-
}
|
|
636
|
-
readSync(file) {
|
|
637
|
-
try {
|
|
638
|
-
const raw = this.extra.readFileSync(file, "utf-8");
|
|
639
|
-
return raw;
|
|
640
|
-
} catch (e) {
|
|
641
|
-
throw new Error(`Error while reading file from "${file}": ${e.message}`);
|
|
642
|
-
}
|
|
643
|
-
}
|
|
644
|
-
async write(file, data, options = {}) {
|
|
645
|
-
try {
|
|
646
|
-
await this.extra.writeFile(file, data, typeof options === "object" ? {
|
|
647
|
-
encoding: "utf-8",
|
|
648
|
-
...options
|
|
649
|
-
} : options);
|
|
650
|
-
} catch (e) {
|
|
651
|
-
throw new Error(`Error while writing file to "${file}": ${e.message}`);
|
|
652
|
-
}
|
|
653
|
-
}
|
|
654
|
-
writeSync(file, data, options = {}) {
|
|
655
|
-
try {
|
|
656
|
-
this.extra.writeFileSync(file, data, typeof options === "object" ? {
|
|
657
|
-
encoding: "utf-8",
|
|
658
|
-
...options
|
|
659
|
-
} : options);
|
|
660
|
-
} catch (e) {
|
|
661
|
-
throw new Error(`Error while writing file to "${file}": ${e.message}`);
|
|
662
|
-
}
|
|
663
|
-
}
|
|
664
|
-
async append(file, data, options) {
|
|
665
|
-
try {
|
|
666
|
-
await this.extra.appendFile(file, data, options);
|
|
667
|
-
} catch (e) {
|
|
668
|
-
throw new Error(`Error while appending to file "${file}": ${e.message}`);
|
|
669
|
-
}
|
|
670
|
-
}
|
|
671
|
-
appendSync(file, data) {
|
|
672
|
-
try {
|
|
673
|
-
this.extra.appendFileSync(file, data);
|
|
674
|
-
} catch (e) {
|
|
675
|
-
throw new Error(`Error while appending to file "${file}": ${e.message}`);
|
|
676
|
-
}
|
|
677
|
-
}
|
|
678
|
-
async remove(file, options) {
|
|
679
|
-
try {
|
|
680
|
-
await this.extra.rm(file, options);
|
|
681
|
-
} catch (e) {
|
|
682
|
-
throw new Error(`Error while deleting the file "${file}": ${e.message}`);
|
|
683
|
-
}
|
|
684
|
-
}
|
|
685
|
-
removeSync(file, options) {
|
|
686
|
-
try {
|
|
687
|
-
this.extra.rmSync(file, options);
|
|
688
|
-
} catch (e) {
|
|
689
|
-
throw new Error(`Error while deleting the file "${file}": ${e.message}`);
|
|
690
|
-
}
|
|
691
|
-
}
|
|
692
|
-
async emptyDir(directory) {
|
|
693
|
-
try {
|
|
694
|
-
await this.extra.emptyDir(directory);
|
|
695
|
-
} catch (e) {
|
|
696
|
-
throw new Error(`Error while emptying the directory "${directory}": ${e.message}`);
|
|
697
|
-
}
|
|
698
|
-
}
|
|
699
|
-
emptyDirSync(directory) {
|
|
700
|
-
try {
|
|
701
|
-
this.extra.emptyDirSync(directory);
|
|
702
|
-
} catch (e) {
|
|
703
|
-
throw new Error(`Error while emptying the directory "${directory}": ${e.message}`);
|
|
704
|
-
}
|
|
705
|
-
}
|
|
706
|
-
async removeDir(directory) {
|
|
707
|
-
try {
|
|
708
|
-
await this.extra.rmdir(directory);
|
|
709
|
-
} catch (e) {
|
|
710
|
-
throw new Error(`Error while removing the directory "${directory}": ${e.message}`);
|
|
711
|
-
}
|
|
712
|
-
}
|
|
713
|
-
removeDirSync(directory) {
|
|
714
|
-
try {
|
|
715
|
-
this.extra.rmdirSync(directory);
|
|
716
|
-
} catch (e) {
|
|
717
|
-
throw new Error(`Error while removing the directory "${directory}": ${e.message}`);
|
|
718
|
-
}
|
|
719
|
-
}
|
|
720
|
-
async mkdir(directory) {
|
|
721
|
-
try {
|
|
722
|
-
await this.extra.mkdirp(directory);
|
|
723
|
-
} catch (e) {
|
|
724
|
-
throw new Error(`Error while creating the directory "${directory}": ${e.message}`);
|
|
725
|
-
}
|
|
726
|
-
}
|
|
727
|
-
mkdirSync(directory) {
|
|
728
|
-
try {
|
|
729
|
-
this.extra.mkdirpSync(directory);
|
|
730
|
-
} catch (e) {
|
|
731
|
-
throw new Error(`Error while creating the directory "${directory}": ${e.message}`);
|
|
732
|
-
}
|
|
733
|
-
}
|
|
734
|
-
};
|
|
735
|
-
FileSystemService = (0, import_decorate$12.default)([Injectable()], FileSystemService);
|
|
736
|
-
|
|
737
|
-
//#endregion
|
|
738
|
-
//#region src/lib/fs/filesystem.module.ts
|
|
739
|
-
var import_decorate$11 = __toESM(require_decorate(), 1);
|
|
740
|
-
let FilesystemModule = class FilesystemModule$1 {};
|
|
741
|
-
FilesystemModule = (0, import_decorate$11.default)([Global(), Module({
|
|
742
|
-
providers: [FileSystemService],
|
|
743
|
-
exports: [FileSystemService]
|
|
744
|
-
})], FilesystemModule);
|
|
745
|
-
|
|
746
|
-
//#endregion
|
|
747
|
-
//#region src/lib/parser/parser.module.ts
|
|
748
|
-
var import_decorate$10 = __toESM(require_decorate(), 1);
|
|
749
|
-
let ParserModule = class ParserModule$1 {};
|
|
750
|
-
ParserModule = (0, import_decorate$10.default)([Global(), Module({
|
|
751
|
-
imports: [FilesystemModule],
|
|
752
|
-
providers: [ParserService],
|
|
753
|
-
exports: [ParserService]
|
|
754
|
-
})], ParserModule);
|
|
755
|
-
|
|
756
|
-
//#endregion
|
|
757
|
-
//#region src/lib/config/config.module.ts
|
|
758
|
-
var import_decorate$9 = __toESM(require_decorate(), 1);
|
|
759
|
-
let ConfigModule = class ConfigModule$1 {};
|
|
760
|
-
ConfigModule = (0, import_decorate$9.default)([Global(), Module({
|
|
761
|
-
imports: [ParserModule],
|
|
762
|
-
providers: [ConfigService],
|
|
763
|
-
exports: [ConfigService]
|
|
764
|
-
})], ConfigModule);
|
|
765
|
-
|
|
766
|
-
//#endregion
|
|
767
|
-
//#region src/lib/locker/locker.service.ts
|
|
768
|
-
var import_defineProperty$6 = __toESM(require_defineProperty(), 1);
|
|
769
|
-
var import_decorate$8 = __toESM(require_decorate(), 1);
|
|
770
|
-
let LockerService = class LockerService$1 {
|
|
771
|
-
constructor(logger, fs$1, parser, options) {
|
|
772
|
-
this.logger = logger;
|
|
773
|
-
this.fs = fs$1;
|
|
774
|
-
this.parser = parser;
|
|
775
|
-
this.options = options;
|
|
776
|
-
(0, import_defineProperty$6.default)(this, "op", op);
|
|
777
|
-
(0, import_defineProperty$6.default)(this, "toLock", []);
|
|
778
|
-
(0, import_defineProperty$6.default)(this, "toUnlock", []);
|
|
779
|
-
this.logger.setup(this.constructor.name);
|
|
780
|
-
}
|
|
781
|
-
hasLock() {
|
|
782
|
-
return this.toLock.length > 0;
|
|
783
|
-
}
|
|
784
|
-
hasUnlock() {
|
|
785
|
-
return this.toUnlock.length > 0;
|
|
786
|
-
}
|
|
787
|
-
addLock(...data) {
|
|
788
|
-
this.toLock.push(...data);
|
|
789
|
-
}
|
|
790
|
-
addUnlock(...data) {
|
|
791
|
-
this.toUnlock.push(...data);
|
|
792
|
-
}
|
|
793
|
-
async applyLockAll(lock) {
|
|
794
|
-
if (this.hasLock()) return this.applyLock(lock, ...this.toLock);
|
|
795
|
-
return lock;
|
|
796
|
-
}
|
|
797
|
-
async lockAll() {
|
|
798
|
-
if (this.hasLock()) {
|
|
799
|
-
await this.lock(...this.toLock);
|
|
800
|
-
this.toLock = [];
|
|
801
|
-
}
|
|
802
|
-
}
|
|
803
|
-
async applyUnlockAll(lock) {
|
|
804
|
-
if (this.hasUnlock()) return this.applyUnlock(lock, ...this.toUnlock);
|
|
805
|
-
return lock;
|
|
806
|
-
}
|
|
807
|
-
async unlockAll() {
|
|
808
|
-
if (this.hasUnlock()) {
|
|
809
|
-
await this.unlock(...this.toUnlock);
|
|
810
|
-
this.toUnlock = [];
|
|
811
|
-
}
|
|
812
|
-
}
|
|
813
|
-
async all() {
|
|
814
|
-
await this.unlockAll();
|
|
815
|
-
await this.lockAll();
|
|
816
|
-
}
|
|
817
|
-
async applyAll(lock) {
|
|
818
|
-
lock = await this.applyUnlockAll(lock);
|
|
819
|
-
lock = await this.applyLockAll(lock);
|
|
820
|
-
return lock;
|
|
821
|
-
}
|
|
822
|
-
async applyLock(lock, ...data) {
|
|
823
|
-
data.forEach((d) => {
|
|
824
|
-
if (d?.enabled === false) return;
|
|
825
|
-
else if (!d?.data || Array.isArray(d?.data) && d.data.length === 0 || typeof d?.data === "object" && Object.keys(d.data).length === 0) return;
|
|
826
|
-
const path = this.buildPath(d);
|
|
827
|
-
if (d?.merge) {
|
|
828
|
-
let parsed;
|
|
829
|
-
if (typeof d.data === "object") parsed = merge(d.merge, this.op.get(lock, path, Array.isArray(d.data) ? [] : {}), d.data);
|
|
830
|
-
else {
|
|
831
|
-
this.logger.warn("\"%s\" path with type \"%s\" is not mergeable.", path, typeof d.data);
|
|
832
|
-
parsed = d.data;
|
|
833
|
-
}
|
|
834
|
-
lock = this.op.set(lock, path, parsed);
|
|
835
|
-
this.logger.verbose("Merge lock: %s -> %o", path, d.data);
|
|
836
|
-
return;
|
|
837
|
-
}
|
|
838
|
-
lock = this.op.set(lock, path, d.data);
|
|
839
|
-
this.logger.verbose("Override lock: %s -> %o", path, d.data);
|
|
840
|
-
});
|
|
841
|
-
return lock;
|
|
842
|
-
}
|
|
843
|
-
async lock(...data) {
|
|
844
|
-
const lock = await this.applyLock(await this.tryRead() ?? {}, ...data);
|
|
845
|
-
await this.write(lock);
|
|
846
|
-
return lock;
|
|
847
|
-
}
|
|
848
|
-
async applyUnlock(lock, ...data) {
|
|
849
|
-
if (data.length > 0) {
|
|
850
|
-
data.forEach((d) => {
|
|
851
|
-
if (d?.enabled === false) return;
|
|
852
|
-
const path = this.buildPath(d);
|
|
853
|
-
lock = op.del(lock, path);
|
|
854
|
-
this.logger.verbose("Unlocked: %s", path);
|
|
855
|
-
for (let i = path.length - 1; i >= 0; i--) {
|
|
856
|
-
const parentPath = path.slice(0, i);
|
|
857
|
-
const parent = this.op.get(lock, parentPath);
|
|
858
|
-
if (!parent || Array.isArray(parent) && parent.length === 0 || typeof parent === "object" && Object.keys(parent).length === 0) {
|
|
859
|
-
this.logger.verbose("Unlocked parent: %s -> %s", path, parentPath);
|
|
860
|
-
lock = op.del(lock, parentPath);
|
|
861
|
-
} else break;
|
|
862
|
-
}
|
|
863
|
-
});
|
|
864
|
-
return lock;
|
|
865
|
-
}
|
|
866
|
-
lock = op.del(lock, this.options.root);
|
|
867
|
-
this.logger.verbose("Unlocked module: %s", this.options.root);
|
|
868
|
-
return lock;
|
|
869
|
-
}
|
|
870
|
-
async unlock(...data) {
|
|
871
|
-
const state = await this.tryRead();
|
|
872
|
-
if (!state) {
|
|
873
|
-
this.logger.verbose("Lock file not found. Nothing to unlock.");
|
|
874
|
-
return;
|
|
875
|
-
}
|
|
876
|
-
const lock = await this.applyUnlock(state, ...data);
|
|
877
|
-
await this.write(lock);
|
|
878
|
-
return lock;
|
|
879
|
-
}
|
|
880
|
-
async read() {
|
|
881
|
-
return this.parser.fetch(this.options.parser).parse(await this.fs.read(this.options.file));
|
|
882
|
-
}
|
|
883
|
-
async tryRead() {
|
|
884
|
-
const lock = await this.fs.read(this.options.file).catch((err) => {
|
|
885
|
-
this.logger.trace("Can not read lockfile: %s -> %s", this.options.file, err.message);
|
|
886
|
-
});
|
|
887
|
-
if (!lock) return;
|
|
888
|
-
return this.parser.fetch(this.options.parser).parse(lock);
|
|
889
|
-
}
|
|
890
|
-
async tryRemove() {
|
|
891
|
-
return this.fs.remove(this.options.file).then(() => {
|
|
892
|
-
this.logger.trace("Removed lockfile: %s", this.options.file);
|
|
893
|
-
}).catch((err) => {
|
|
894
|
-
this.logger.trace("Can not remove lockfile: %s -> %s", this.options.file, err.message);
|
|
895
|
-
});
|
|
896
|
-
}
|
|
897
|
-
async write(data) {
|
|
898
|
-
if (!data || Array.isArray(data) && data.length === 0 || typeof data === "object" && Object.keys(data).length === 0) {
|
|
899
|
-
this.logger.trace("Trying to write empty lock file, deleting it instead: %s", this.options.file);
|
|
900
|
-
return this.fs.remove(this.options.file);
|
|
901
|
-
}
|
|
902
|
-
return this.fs.write(this.options.file, this.parser.fetch(this.options.parser).stringify(data));
|
|
903
|
-
}
|
|
904
|
-
buildPath(d) {
|
|
905
|
-
if (d?.root !== true && this.options.root?.length) return [...this.options.root, ...this.normalizePath(d.path)];
|
|
906
|
-
return this.normalizePath(d.path);
|
|
907
|
-
}
|
|
908
|
-
normalizePath(path) {
|
|
909
|
-
if (Array.isArray(path)) return path.map((p) => p.toString());
|
|
910
|
-
else if (typeof path === "string") return path.split(".");
|
|
911
|
-
return [];
|
|
912
|
-
}
|
|
913
|
-
};
|
|
914
|
-
LockerService = (0, import_decorate$8.default)([Injectable()], LockerService);
|
|
915
|
-
|
|
916
|
-
//#endregion
|
|
917
|
-
//#region src/lib/parser/fts/env-parser.service.ts
|
|
918
|
-
var import_defineProperty$5 = __toESM(require_defineProperty(), 1);
|
|
919
|
-
var import_decorate$7 = __toESM(require_decorate(), 1);
|
|
920
|
-
let EnvironmentVariableParser = class EnvironmentVariableParser$1 {
|
|
921
|
-
constructor(logger) {
|
|
922
|
-
this.logger = logger;
|
|
923
|
-
(0, import_defineProperty$5.default)(this, "extensions", ["env"]);
|
|
924
|
-
(0, import_defineProperty$5.default)(this, "LINE", /(?:^|^)\s*(?:export\s+)?([\w.-]+)(?:\s*=\s*?|:\s+?)(\s*'(?:\\'|[^'])*'|\s*"(?:\\"|[^"])*"|\s*`(?:\\`|[^`])*`|[^#\r\n]+)?\s*(?:#.*)?(?:$|$)/gm);
|
|
925
|
-
this.logger.setup(this.constructor.name);
|
|
926
|
-
}
|
|
927
|
-
parse(data) {
|
|
928
|
-
try {
|
|
929
|
-
return data.toString().split(EOL).reduce((o, line) => {
|
|
930
|
-
const match = this.LINE.exec(line);
|
|
931
|
-
const key = match[1];
|
|
932
|
-
const value = match[2] ?? "";
|
|
933
|
-
return {
|
|
934
|
-
...o,
|
|
935
|
-
[key]: value
|
|
936
|
-
};
|
|
937
|
-
}, {});
|
|
938
|
-
} catch (e) {
|
|
939
|
-
this.logger.trace("Error during parsing environment file: %s", e.message);
|
|
940
|
-
throw e;
|
|
941
|
-
}
|
|
942
|
-
}
|
|
943
|
-
stringify(data) {
|
|
944
|
-
return Object.entries(data).map(([k, v]) => `${k}=${v}`).join(EOL) + EOL;
|
|
945
|
-
}
|
|
946
|
-
};
|
|
947
|
-
EnvironmentVariableParser = (0, import_decorate$7.default)([Injectable()], EnvironmentVariableParser);
|
|
948
|
-
|
|
949
|
-
//#endregion
|
|
950
|
-
//#region src/lib/parser/fts/json-parser.service.ts
|
|
951
|
-
var import_defineProperty$4 = __toESM(require_defineProperty(), 1);
|
|
952
|
-
var import_decorate$6 = __toESM(require_decorate(), 1);
|
|
953
|
-
let JsonParser = class JsonParser$1 {
|
|
954
|
-
constructor(logger) {
|
|
955
|
-
this.logger = logger;
|
|
956
|
-
(0, import_defineProperty$4.default)(this, "extensions", ["json"]);
|
|
957
|
-
this.logger.setup(this.constructor.name);
|
|
958
|
-
}
|
|
959
|
-
parse(data) {
|
|
960
|
-
try {
|
|
961
|
-
return JSON.parse(data.toString());
|
|
962
|
-
} catch (e) {
|
|
963
|
-
this.logger.trace("Error during parsing JSON file: %s", e.message);
|
|
964
|
-
throw e;
|
|
965
|
-
}
|
|
966
|
-
}
|
|
967
|
-
stringify(data) {
|
|
968
|
-
return JSON.stringify(data, null, 2);
|
|
969
|
-
}
|
|
970
|
-
};
|
|
971
|
-
JsonParser = (0, import_decorate$6.default)([Injectable()], JsonParser);
|
|
972
|
-
|
|
973
|
-
//#endregion
|
|
974
|
-
//#region src/lib/parser/fts/yaml-parser.service.ts
|
|
975
|
-
var import_defineProperty$3 = __toESM(require_defineProperty(), 1);
|
|
976
|
-
var import_decorate$5 = __toESM(require_decorate(), 1);
|
|
977
|
-
let YamlParser = class YamlParser$1 {
|
|
978
|
-
constructor(logger) {
|
|
979
|
-
this.logger = logger;
|
|
980
|
-
(0, import_defineProperty$3.default)(this, "extensions", ["yaml", "yml"]);
|
|
981
|
-
this.logger.setup(this.constructor.name);
|
|
982
|
-
}
|
|
983
|
-
parse(data) {
|
|
984
|
-
try {
|
|
985
|
-
return parse(data.toString());
|
|
986
|
-
} catch (e) {
|
|
987
|
-
this.logger.trace("Error during parsing YAML file: %s", e.message);
|
|
988
|
-
throw e;
|
|
989
|
-
}
|
|
990
|
-
}
|
|
991
|
-
stringify(data) {
|
|
992
|
-
return stringify(data, { prettyErrors: true });
|
|
993
|
-
}
|
|
994
|
-
};
|
|
995
|
-
YamlParser = (0, import_decorate$5.default)([Injectable()], YamlParser);
|
|
996
|
-
|
|
997
|
-
//#endregion
|
|
998
|
-
//#region src/lib/locker/locker.module.ts
|
|
999
|
-
var import_decorate$4 = __toESM(require_decorate(), 1);
|
|
1000
|
-
var _LockerModule;
|
|
1001
|
-
let LockerModule = _LockerModule = class LockerModule$1 {
|
|
1002
|
-
static forFeature(options) {
|
|
1003
|
-
const token = options.token ?? LockerService;
|
|
1004
|
-
return {
|
|
1005
|
-
module: _LockerModule,
|
|
1006
|
-
providers: [{
|
|
1007
|
-
provide: token,
|
|
1008
|
-
useFactory: (logger, fs$1, parser) => new LockerService(logger, fs$1, parser, options),
|
|
1009
|
-
inject: [
|
|
1010
|
-
LoggerService,
|
|
1011
|
-
FileSystemService,
|
|
1012
|
-
ParserService
|
|
1013
|
-
]
|
|
1014
|
-
}]
|
|
1015
|
-
};
|
|
1016
|
-
}
|
|
1017
|
-
};
|
|
1018
|
-
LockerModule = _LockerModule = (0, import_decorate$4.default)([Module({})], LockerModule);
|
|
1019
|
-
|
|
1020
|
-
//#endregion
|
|
1021
|
-
//#region src/lib/logo/logo.constants.ts
|
|
1022
|
-
const TOKEN_LOGO_GENERATOR = Symbol("TOKEN_LOGO_GENERATOR");
|
|
1023
|
-
|
|
1024
|
-
//#endregion
|
|
1025
|
-
//#region src/lib/logo/logo.service.ts
|
|
1026
|
-
var import_defineProperty$2 = __toESM(require_defineProperty(), 1);
|
|
1027
|
-
var import_decorate$3 = __toESM(require_decorate(), 1);
|
|
1028
|
-
let LogoService = class LogoService$1 {
|
|
1029
|
-
constructor(cs, moduleRef) {
|
|
1030
|
-
this.cs = cs;
|
|
1031
|
-
(0, import_defineProperty$2.default)(this, "generator", void 0);
|
|
1032
|
-
try {
|
|
1033
|
-
this.generator = moduleRef.get(TOKEN_LOGO_GENERATOR, { strict: false });
|
|
1034
|
-
} catch {
|
|
1035
|
-
this.generator = function() {
|
|
1036
|
-
if (this.shouldBeSilent()) return;
|
|
1037
|
-
const logo = this.cs.oclif.name + " v" + this.cs.oclif.version;
|
|
1038
|
-
this.write(logo);
|
|
1039
|
-
this.write("-".repeat(logo.length));
|
|
1040
|
-
};
|
|
1041
|
-
}
|
|
1042
|
-
}
|
|
1043
|
-
generate() {
|
|
1044
|
-
return this.generator.call(this);
|
|
1045
|
-
}
|
|
1046
|
-
shouldBeSilent() {
|
|
1047
|
-
return this.cs.isJson || this.cs.isSilent;
|
|
1048
|
-
}
|
|
1049
|
-
write(...data) {
|
|
1050
|
-
process.stdout.write(data.join(" ") + EOL);
|
|
1051
|
-
}
|
|
1052
|
-
};
|
|
1053
|
-
LogoService = (0, import_decorate$3.default)([Injectable()], LogoService);
|
|
1054
|
-
|
|
1055
|
-
//#endregion
|
|
1056
|
-
//#region src/lib/logo/logo.module.ts
|
|
1057
|
-
var import_decorate$2 = __toESM(require_decorate(), 1);
|
|
1058
|
-
let LogoModule = class LogoModule$1 {};
|
|
1059
|
-
LogoModule = (0, import_decorate$2.default)([Module({
|
|
1060
|
-
providers: [LogoService],
|
|
1061
|
-
exports: [LogoService]
|
|
1062
|
-
})], LogoModule);
|
|
1063
|
-
|
|
1064
|
-
//#endregion
|
|
1065
|
-
//#region src/lib/validator/validator.constants.ts
|
|
1066
|
-
const TOKEN_VALIDATOR_SERVICE_OPTIONS = Symbol("TOKEN_VALIDATOR_SERVICE_OPTIONS");
|
|
1067
|
-
|
|
1068
|
-
//#endregion
|
|
1069
|
-
//#region src/lib/validator/validator.service.ts
|
|
1070
|
-
var import_defineProperty$1 = __toESM(require_defineProperty(), 1);
|
|
1071
|
-
var import_decorate$1 = __toESM(require_decorate(), 1);
|
|
1072
|
-
let ValidatorService = class ValidatorService$1 {
|
|
1073
|
-
constructor(logger, moduleRef) {
|
|
1074
|
-
this.logger = logger;
|
|
1075
|
-
(0, import_defineProperty$1.default)(this, "options", void 0);
|
|
1076
|
-
this.logger.setup(this.constructor.name);
|
|
1077
|
-
try {
|
|
1078
|
-
this.options = moduleRef.get(TOKEN_VALIDATOR_SERVICE_OPTIONS, { strict: false });
|
|
1079
|
-
} catch {
|
|
1080
|
-
this.options = {
|
|
1081
|
-
validator: {
|
|
1082
|
-
skipMissingProperties: true,
|
|
1083
|
-
whitelist: false,
|
|
1084
|
-
always: true,
|
|
1085
|
-
enableDebugMessages: true
|
|
1086
|
-
},
|
|
1087
|
-
transformer: { enableImplicitConversion: true }
|
|
1088
|
-
};
|
|
1089
|
-
}
|
|
1090
|
-
}
|
|
1091
|
-
async validate(classType, object, options) {
|
|
1092
|
-
const classObject = plainToClass(classType, object, {
|
|
1093
|
-
...this.options.transformer,
|
|
1094
|
-
...options?.transformer ?? {}
|
|
1095
|
-
});
|
|
1096
|
-
const errors = await validate(classObject, {
|
|
1097
|
-
...this.options.validator,
|
|
1098
|
-
...options?.validator ?? {}
|
|
1099
|
-
});
|
|
1100
|
-
if (errors.length) {
|
|
1101
|
-
errors.forEach((error) => {
|
|
1102
|
-
this.logValidationError(error);
|
|
1103
|
-
});
|
|
1104
|
-
throw new Error("Validation failed.");
|
|
1105
|
-
}
|
|
1106
|
-
return classObject;
|
|
1107
|
-
}
|
|
1108
|
-
validateSync(classType, object, options) {
|
|
1109
|
-
const classObject = plainToClass(classType, object, {
|
|
1110
|
-
...this.options.transformer,
|
|
1111
|
-
...options?.transformer ?? {}
|
|
1112
|
-
});
|
|
1113
|
-
const errors = validateSync(classObject, {
|
|
1114
|
-
...this.options.validator,
|
|
1115
|
-
...options?.validator ?? {}
|
|
1116
|
-
});
|
|
1117
|
-
if (errors.length) {
|
|
1118
|
-
errors.forEach((error) => {
|
|
1119
|
-
this.logValidationError(error);
|
|
1120
|
-
});
|
|
1121
|
-
throw new Error("Validation failed.");
|
|
1122
|
-
}
|
|
1123
|
-
return classObject;
|
|
1124
|
-
}
|
|
1125
|
-
logValidationError(err) {
|
|
1126
|
-
this.logger.error("Field \"%s\" failed validation with value \"%s\": %o", err.property, err.value, err.constraints);
|
|
1127
|
-
if (err.children) err.children.forEach((children) => this.logValidationError(children));
|
|
1128
|
-
}
|
|
1129
|
-
};
|
|
1130
|
-
ValidatorService = (0, import_decorate$1.default)([Injectable()], ValidatorService);
|
|
1131
|
-
|
|
1132
|
-
//#endregion
|
|
1133
|
-
//#region src/lib/validator/validator.module.ts
|
|
1134
|
-
var import_decorate = __toESM(require_decorate(), 1);
|
|
1135
|
-
let ValidatorModule = class ValidatorModule$1 {};
|
|
1136
|
-
ValidatorModule = (0, import_decorate.default)([Global(), Module({
|
|
1137
|
-
providers: [ValidatorService],
|
|
1138
|
-
exports: [ValidatorService]
|
|
1139
|
-
})], ValidatorModule);
|
|
1140
|
-
|
|
1141
|
-
//#endregion
|
|
1142
|
-
//#region src/lib/setup.ts
|
|
1143
|
-
async function setup() {
|
|
1144
|
-
const inspect = process.argv.indexOf("--inspect");
|
|
1145
|
-
if (inspect !== -1) {
|
|
1146
|
-
await import("inspector").then((mod) => mod.open());
|
|
1147
|
-
process.argv.splice(inspect, 1);
|
|
1148
|
-
}
|
|
1149
|
-
const sourceMaps = process.argv.indexOf("--source-map");
|
|
1150
|
-
if (sourceMaps !== -1) {
|
|
1151
|
-
await import("./source-map-support-CuBekda-.js").then(__toDynamicImportESM(1)).then((mod) => mod.install());
|
|
1152
|
-
process.argv.splice(sourceMaps, 1);
|
|
1153
|
-
}
|
|
1154
|
-
}
|
|
1155
|
-
|
|
1156
|
-
//#endregion
|
|
1157
|
-
//#region src/lib/cli.module.ts
|
|
1158
|
-
var CliModule = class CliModule {
|
|
1159
|
-
static forRoot(options) {
|
|
1160
|
-
return {
|
|
1161
|
-
module: CliModule,
|
|
1162
|
-
global: true,
|
|
1163
|
-
imports: [
|
|
1164
|
-
ConfigModule,
|
|
1165
|
-
LoggerModule,
|
|
1166
|
-
FilesystemModule,
|
|
1167
|
-
ParserModule,
|
|
1168
|
-
LogoModule
|
|
1169
|
-
],
|
|
1170
|
-
providers: [{
|
|
1171
|
-
provide: TOKEN_CONFIG_MODULE_OPTIONS,
|
|
1172
|
-
useValue: options.config
|
|
1173
|
-
}],
|
|
1174
|
-
exports: [TOKEN_CONFIG_MODULE_OPTIONS]
|
|
1175
|
-
};
|
|
1176
|
-
}
|
|
1177
|
-
static forMinimum() {
|
|
1178
|
-
return {
|
|
1179
|
-
module: CliModule,
|
|
1180
|
-
global: true,
|
|
1181
|
-
imports: [LoggerModule],
|
|
1182
|
-
providers: [{
|
|
1183
|
-
provide: TOKEN_CONFIG_MODULE_OPTIONS,
|
|
1184
|
-
useValue: { config: {
|
|
1185
|
-
logLevel: LogLevels.INFO,
|
|
1186
|
-
isJson: false
|
|
1187
|
-
} }
|
|
1188
|
-
}],
|
|
1189
|
-
exports: [TOKEN_CONFIG_MODULE_OPTIONS]
|
|
1190
|
-
};
|
|
1191
|
-
}
|
|
1192
|
-
static create(cls) {
|
|
1193
|
-
return NestFactory.createApplicationContext(cls, { logger: ["error"] });
|
|
1194
|
-
}
|
|
1195
|
-
};
|
|
1196
|
-
|
|
1197
|
-
//#endregion
|
|
1198
|
-
//#region src/commands/base.command.ts
|
|
1199
|
-
var import_defineProperty = __toESM(require_defineProperty(), 1);
|
|
1200
|
-
var Command = class extends Command$1 {
|
|
1201
|
-
constructor(..._args) {
|
|
1202
|
-
super(..._args);
|
|
1203
|
-
(0, import_defineProperty.default)(this, "logger", void 0);
|
|
1204
|
-
(0, import_defineProperty.default)(this, "tasks", void 0);
|
|
1205
|
-
(0, import_defineProperty.default)(this, "app", void 0);
|
|
1206
|
-
(0, import_defineProperty.default)(this, "flags", void 0);
|
|
1207
|
-
(0, import_defineProperty.default)(this, "args", void 0);
|
|
1208
|
-
}
|
|
1209
|
-
exit(code) {
|
|
1210
|
-
this.logger.trace("Code -> %d", code, { status: LogFieldStatus.EXIT });
|
|
1211
|
-
super.exit(code ?? 0);
|
|
1212
|
-
}
|
|
1213
|
-
/** Run all tasks from task manager. */
|
|
1214
|
-
runTasks() {
|
|
1215
|
-
return this.tasks.runAll();
|
|
1216
|
-
}
|
|
1217
|
-
setCtxDefaults(...defaults) {
|
|
1218
|
-
setCtxDefaults(this.tasks.options.ctx, ...defaults);
|
|
1219
|
-
this.logger.trace("Updated context with defaults: %o", this.tasks.options.ctx, { status: "ctx" });
|
|
1220
|
-
}
|
|
1221
|
-
setCtxAssign(...assigns) {
|
|
1222
|
-
setCtxAssign(this.tasks.options.ctx, ...assigns);
|
|
1223
|
-
this.logger.trace("Updated context with assign: %o", this.tasks.options.ctx, { status: "ctx" });
|
|
1224
|
-
}
|
|
1225
|
-
pipeProcessToLogger(instance, options) {
|
|
1226
|
-
return pipeProcessToLogger(this.logger, instance, options);
|
|
1227
|
-
}
|
|
1228
|
-
pipeProcessThroughListr(instance, task) {
|
|
1229
|
-
return pipeProcessThroughListr(task, instance);
|
|
1230
|
-
}
|
|
1231
|
-
/** Initial functions / constructor */
|
|
1232
|
-
async init() {
|
|
1233
|
-
await super.init();
|
|
1234
|
-
let err;
|
|
1235
|
-
try {
|
|
1236
|
-
const { args, flags } = await this.parse({
|
|
1237
|
-
flags: this.ctor.flags,
|
|
1238
|
-
baseFlags: super.ctor.baseFlags,
|
|
1239
|
-
enableJsonFlag: this.ctor.enableJsonFlag,
|
|
1240
|
-
args: this.ctor.args,
|
|
1241
|
-
strict: this.ctor.strict
|
|
1242
|
-
});
|
|
1243
|
-
this.flags = flags;
|
|
1244
|
-
this.args = args;
|
|
1245
|
-
} catch (e) {
|
|
1246
|
-
err = e;
|
|
1247
|
-
}
|
|
1248
|
-
const options = { config: {
|
|
1249
|
-
oclif: this.config,
|
|
1250
|
-
command: this.ctor,
|
|
1251
|
-
config: {
|
|
1252
|
-
logLevel: this.flags?.["log-level"] ?? LogLevels.INFO,
|
|
1253
|
-
isJson: this.flags?.json ?? false
|
|
1254
|
-
}
|
|
1255
|
-
} };
|
|
1256
|
-
const cli = CliModule.forRoot(options);
|
|
1257
|
-
this.app = await CliModule.create(!err && isHookedWithRegister(this) ? await this.register(cli, options) : cli);
|
|
1258
|
-
const cs = this.app.get(ConfigService);
|
|
1259
|
-
this.logger = await this.app.resolve(LoggerService);
|
|
1260
|
-
this.app.useLogger(this.logger);
|
|
1261
|
-
this.app.get(LogoService).generate();
|
|
1262
|
-
if (err) throw err;
|
|
1263
|
-
this.logger.stage("Created application context.");
|
|
1264
|
-
this.tasks = new Manager({
|
|
1265
|
-
fallbackRendererCondition: cs.isDebug,
|
|
1266
|
-
silentRendererCondition: cs.isSilent || cs.isJson,
|
|
1267
|
-
ctx: {}
|
|
1268
|
-
});
|
|
1269
|
-
if (cs.oclif.windows) createInterface({
|
|
1270
|
-
input: process.stdin,
|
|
1271
|
-
output: process.stdout
|
|
1272
|
-
}).on("SIGINT", () => {
|
|
1273
|
-
process.kill(process.pid, "SIGINT");
|
|
1274
|
-
});
|
|
1275
|
-
const terminate = () => {
|
|
1276
|
-
this.logger.fatal("Caught terminate signal.", { status: LogFieldStatus.TERMINATE });
|
|
1277
|
-
process.exit(1);
|
|
1278
|
-
};
|
|
1279
|
-
process.on("SIGINT", terminate);
|
|
1280
|
-
process.on("SIGTERM", terminate);
|
|
1281
|
-
if (isHookedWithShouldRunBefore(this)) {
|
|
1282
|
-
this.logger.stage("Running hook should-run-before.");
|
|
1283
|
-
await this.shouldRunBefore();
|
|
1284
|
-
this.logger.stage("Finished hook should-run-before.");
|
|
1285
|
-
}
|
|
1286
|
-
}
|
|
1287
|
-
/** Tasks to run before end of the command. */
|
|
1288
|
-
async finally(err) {
|
|
1289
|
-
let ctx;
|
|
1290
|
-
if (err) return { ctx };
|
|
1291
|
-
if (this.tasks?.tasks?.length > 0) {
|
|
1292
|
-
this.logger.stage("Running tasks.");
|
|
1293
|
-
ctx = await this.runTasks();
|
|
1294
|
-
this.logger.stage("Finished tasks.");
|
|
1295
|
-
}
|
|
1296
|
-
if (isHookedWithShouldRunAfter(this)) {
|
|
1297
|
-
this.logger.stage("Running hook should-run-after.");
|
|
1298
|
-
await this.shouldRunAfter(ctx);
|
|
1299
|
-
this.logger.stage("Finished hook should-run-after.");
|
|
1300
|
-
}
|
|
1301
|
-
return { ctx };
|
|
1302
|
-
}
|
|
1303
|
-
/** Catch any error occurred during command. */
|
|
1304
|
-
async catch(err) {
|
|
1305
|
-
process.exitCode = process.exitCode ?? err.exitCode ?? 1;
|
|
1306
|
-
if (!this.logger) {
|
|
1307
|
-
this.app = await CliModule.create(CliModule.forMinimum());
|
|
1308
|
-
this.logger = await this.app.resolve(LoggerService);
|
|
1309
|
-
}
|
|
1310
|
-
this.logger.fatal(err.message);
|
|
1311
|
-
this.logger.debug(err.stack, { context: "crash" });
|
|
1312
|
-
throw err;
|
|
1313
|
-
}
|
|
1314
|
-
};
|
|
1315
|
-
(0, import_defineProperty.default)(Command, "baseFlags", {
|
|
1316
|
-
["log-level"]: Flags$1.string({
|
|
1317
|
-
default: LogLevels.INFO,
|
|
1318
|
-
env: "LOG_LEVEL",
|
|
1319
|
-
description: "Set the log level of the application.",
|
|
1320
|
-
options: Object.values(LogLevels).map((level) => level.toLowerCase()),
|
|
1321
|
-
helpGroup: HelpGroups.CLI,
|
|
1322
|
-
parse: async (input) => input?.toUpperCase()
|
|
1323
|
-
}),
|
|
1324
|
-
ci: Flags$1.boolean({
|
|
1325
|
-
default: false,
|
|
1326
|
-
hidden: true,
|
|
1327
|
-
env: "CI",
|
|
1328
|
-
description: "Instruct whether this is running the CI/CD configuration.",
|
|
1329
|
-
helpGroup: HelpGroups.CLI
|
|
1330
|
-
}),
|
|
1331
|
-
json: Flags$1.boolean({
|
|
1332
|
-
default: false,
|
|
1333
|
-
hidden: true,
|
|
1334
|
-
env: "JSON",
|
|
1335
|
-
description: "Put the CLI to respond in JSON.",
|
|
1336
|
-
helpGroup: HelpGroups.CLI
|
|
1337
|
-
})
|
|
1338
|
-
});
|
|
1339
|
-
|
|
1340
|
-
//#endregion
|
|
1341
|
-
//#region src/hooks/not-found.hook.ts
|
|
1342
|
-
const notFoundHook = async (opts) => {
|
|
1343
|
-
const app = await CliModule.create(CliModule.forMinimum());
|
|
1344
|
-
const logger = await app.resolve(LoggerService);
|
|
1345
|
-
logger.error("Command not found. Take a look at help. You can also use --[h]elp flag for subcommands.");
|
|
1346
|
-
logger.direct("");
|
|
1347
|
-
const help = new Help(opts.config);
|
|
1348
|
-
await help.showHelp(["--all"]);
|
|
1349
|
-
opts.context.exit(127);
|
|
1350
|
-
};
|
|
1351
|
-
|
|
1352
|
-
//#endregion
|
|
1353
|
-
//#region src/hooks/update-notifier.hook.ts
|
|
1354
|
-
const updateNotifierHook = async (opts) => {
|
|
1355
|
-
const { default: notifier } = await import("update-notifier");
|
|
1356
|
-
notifier({ pkg: {
|
|
1357
|
-
name: opts.config.name,
|
|
1358
|
-
version: opts.config.version
|
|
1359
|
-
} }).notify({ isGlobal: true });
|
|
1360
|
-
};
|
|
1361
|
-
|
|
1362
|
-
//#endregion
|
|
1363
44
|
export { Args, CliModule, Command, ConfigModule, ConfigService, EnvironmentVariableParser, FileConstants, FileSystemService, FilesystemModule, Flags, HelpGroups, Inject, JsonParser, LockerModule, LockerService, LogFieldStatus, LogLevels, LoggerModule, LoggerService, LogoModule, LogoService, MergeStrategy, ParserModule, ParserService, TOKEN_LOGO_GENERATOR, TOKEN_VALIDATOR_SERVICE_OPTIONS, ValidatorModule, ValidatorService, WinstonService, YamlParser, isDebug, isHookedWithRegister, isHookedWithShouldRunAfter, isHookedWithShouldRunBefore, isSilent, isVerbose, merge, notFoundHook, pipeProcessThroughListr, pipeProcessToLogger, setCtxAssign, setCtxDefaults, setup, uniqueArrayFilter, updateNotifierHook, ux };
|