@cenk1cenk2/oclif-common 6.3.29 → 6.4.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/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 -413
- package/dist/index.js +44 -1881
- 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 +31 -27
package/dist/index.js
CHANGED
|
@@ -1,1881 +1,44 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
import {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
import {
|
|
28
|
-
import
|
|
29
|
-
import {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
return instance;
|
|
46
|
-
}
|
|
47
|
-
__name(pipeProcessThroughListr, "pipeProcessThroughListr");
|
|
48
|
-
|
|
49
|
-
// src/lib/logger/pipe/pipe-process-to-logger.ts
|
|
50
|
-
import { Writable } from "stream";
|
|
51
|
-
|
|
52
|
-
// src/lib/logger/logger.constants.ts
|
|
53
|
-
var LogLevels = /* @__PURE__ */ function(LogLevels2) {
|
|
54
|
-
LogLevels2["SILENT"] = "SILENT";
|
|
55
|
-
LogLevels2["DIRECT"] = "DIRECT";
|
|
56
|
-
LogLevels2["FATAL"] = "FATAL";
|
|
57
|
-
LogLevels2["ERROR"] = "ERROR";
|
|
58
|
-
LogLevels2["WARN"] = "WARN";
|
|
59
|
-
LogLevels2["INFO"] = "INFO";
|
|
60
|
-
LogLevels2["VERBOSE"] = "VERBOSE";
|
|
61
|
-
LogLevels2["DEBUG"] = "DEBUG";
|
|
62
|
-
LogLevels2["TRACE"] = "TRACE";
|
|
63
|
-
return LogLevels2;
|
|
64
|
-
}({});
|
|
65
|
-
var LogFieldStatus = /* @__PURE__ */ function(LogFieldStatus2) {
|
|
66
|
-
LogFieldStatus2["RUN"] = "run";
|
|
67
|
-
LogFieldStatus2["END"] = "end";
|
|
68
|
-
LogFieldStatus2["STAGE"] = "stage";
|
|
69
|
-
LogFieldStatus2["EXIT"] = "exit";
|
|
70
|
-
LogFieldStatus2["TERMINATE"] = "terminate";
|
|
71
|
-
return LogFieldStatus2;
|
|
72
|
-
}({});
|
|
73
|
-
|
|
74
|
-
// src/lib/logger/pipe/pipe-process-to-logger.ts
|
|
75
|
-
function pipeProcessToLogger(logger, instance, options) {
|
|
76
|
-
options = {
|
|
77
|
-
start: LogLevels.INFO,
|
|
78
|
-
end: LogLevels.INFO,
|
|
79
|
-
stdout: LogLevels.INFO,
|
|
80
|
-
stderr: LogLevels.WARN,
|
|
81
|
-
...options
|
|
82
|
-
};
|
|
83
|
-
if (options.start) {
|
|
84
|
-
logger.run(instance.spawnargs.join(" "), {
|
|
85
|
-
level: options.start,
|
|
86
|
-
context: options.context
|
|
87
|
-
});
|
|
88
|
-
}
|
|
89
|
-
if (instance.stdout) {
|
|
90
|
-
const writable = new Writable();
|
|
91
|
-
writable.write = (chunk) => {
|
|
92
|
-
logger.log(options.stdout, chunk, {
|
|
93
|
-
context: options.context
|
|
94
|
-
});
|
|
95
|
-
return true;
|
|
96
|
-
};
|
|
97
|
-
instance.stdout.pipe(writable);
|
|
98
|
-
}
|
|
99
|
-
if (instance.stderr) {
|
|
100
|
-
const writable = new Writable();
|
|
101
|
-
writable.write = (chunk) => {
|
|
102
|
-
logger.log(options.stderr, chunk, {
|
|
103
|
-
context: options.context
|
|
104
|
-
});
|
|
105
|
-
return true;
|
|
106
|
-
};
|
|
107
|
-
instance.stderr.pipe(writable);
|
|
108
|
-
}
|
|
109
|
-
void instance.on("exit", (code, signal) => {
|
|
110
|
-
const message = `Process ended with code ${code}${signal ? ` and signal ${signal}` : ""}.`;
|
|
111
|
-
logger.debug(message, {
|
|
112
|
-
context: options.context
|
|
113
|
-
});
|
|
114
|
-
if (options.end) {
|
|
115
|
-
logger.end(instance.spawnargs.join(" "), {
|
|
116
|
-
level: options.end,
|
|
117
|
-
context: options.context
|
|
118
|
-
});
|
|
119
|
-
}
|
|
120
|
-
if (options?.callback) {
|
|
121
|
-
options.callback();
|
|
122
|
-
}
|
|
123
|
-
});
|
|
124
|
-
void instance.on("error", (error) => {
|
|
125
|
-
logger.fatal(error.message, {
|
|
126
|
-
context: options.context
|
|
127
|
-
});
|
|
128
|
-
logger.debug(error.stack, {
|
|
129
|
-
context: options.context
|
|
130
|
-
});
|
|
131
|
-
if (options?.callback) {
|
|
132
|
-
options.callback(error);
|
|
133
|
-
}
|
|
134
|
-
});
|
|
135
|
-
return instance;
|
|
136
|
-
}
|
|
137
|
-
__name(pipeProcessToLogger, "pipeProcessToLogger");
|
|
138
|
-
|
|
139
|
-
// src/lib/logger/logger.module.ts
|
|
140
|
-
import { Global, Module } from "@nestjs/common";
|
|
141
|
-
|
|
142
|
-
// src/lib/logger/logger.service.ts
|
|
143
|
-
import { Injectable as Injectable2, Scope } from "@nestjs/common";
|
|
144
|
-
import { splat } from "listr2";
|
|
145
|
-
|
|
146
|
-
// src/lib/logger/winston.service.ts
|
|
147
|
-
import { Inject, Injectable } from "@nestjs/common";
|
|
148
|
-
import { color, figures } from "listr2";
|
|
149
|
-
import { EOL } from "os";
|
|
150
|
-
import winston, { format, transports } from "winston";
|
|
151
|
-
function _ts_decorate(decorators, target, key, desc) {
|
|
152
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
153
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
154
|
-
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;
|
|
155
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
156
|
-
}
|
|
157
|
-
__name(_ts_decorate, "_ts_decorate");
|
|
158
|
-
function _ts_metadata(k, v) {
|
|
159
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
160
|
-
}
|
|
161
|
-
__name(_ts_metadata, "_ts_metadata");
|
|
162
|
-
function _ts_param(paramIndex, decorator) {
|
|
163
|
-
return function(target, key) {
|
|
164
|
-
decorator(target, key, paramIndex);
|
|
165
|
-
};
|
|
166
|
-
}
|
|
167
|
-
__name(_ts_param, "_ts_param");
|
|
168
|
-
var _WinstonService = class _WinstonService {
|
|
169
|
-
constructor(options) {
|
|
170
|
-
__publicField(this, "options");
|
|
171
|
-
__publicField(this, "instance");
|
|
172
|
-
this.options = options;
|
|
173
|
-
this.instance = this.initiateLogger();
|
|
174
|
-
}
|
|
175
|
-
initiateLogger() {
|
|
176
|
-
const logFormat = format.printf(({ level, message, context, status }) => {
|
|
177
|
-
return message.split(EOL).filter((msg) => !msg || msg.trim() !== "").map((msg) => {
|
|
178
|
-
return this.logColoring({
|
|
179
|
-
level,
|
|
180
|
-
message: msg,
|
|
181
|
-
context,
|
|
182
|
-
status
|
|
183
|
-
});
|
|
184
|
-
}).join(EOL);
|
|
185
|
-
});
|
|
186
|
-
const logger = winston.createLogger({
|
|
187
|
-
level: this.options.config.logLevel,
|
|
188
|
-
format: format.combine(format.splat(), format.json({
|
|
189
|
-
space: 2
|
|
190
|
-
}), format.prettyPrint(), logFormat),
|
|
191
|
-
levels: Object.fromEntries(Object.values(LogLevels).map((level, i) => {
|
|
192
|
-
return [
|
|
193
|
-
level,
|
|
194
|
-
i
|
|
195
|
-
];
|
|
196
|
-
})),
|
|
197
|
-
silent: this.options.config.logLevel === LogLevels.SILENT || this.options.config.isJson,
|
|
198
|
-
transports: [
|
|
199
|
-
new transports.Console({
|
|
200
|
-
stderrLevels: [
|
|
201
|
-
LogLevels.FATAL,
|
|
202
|
-
LogLevels.ERROR
|
|
203
|
-
]
|
|
204
|
-
})
|
|
205
|
-
]
|
|
206
|
-
});
|
|
207
|
-
logger.log(LogLevels.TRACE, "Initiated new winston with level: %s", this.options.config.logLevel, {
|
|
208
|
-
context: this.constructor.name
|
|
209
|
-
});
|
|
210
|
-
return logger;
|
|
211
|
-
}
|
|
212
|
-
logColoring({ level, message, context, status }) {
|
|
213
|
-
let icon;
|
|
214
|
-
let coloring = /* @__PURE__ */ __name((input) => {
|
|
215
|
-
return input;
|
|
216
|
-
}, "coloring");
|
|
217
|
-
let msgColoring = /* @__PURE__ */ __name((input) => {
|
|
218
|
-
return input;
|
|
219
|
-
}, "msgColoring");
|
|
220
|
-
switch (level) {
|
|
221
|
-
case LogLevels.DIRECT:
|
|
222
|
-
return message;
|
|
223
|
-
case LogLevels.FATAL:
|
|
224
|
-
coloring = color.red;
|
|
225
|
-
msgColoring = color.red;
|
|
226
|
-
break;
|
|
227
|
-
case LogLevels.ERROR:
|
|
228
|
-
coloring = color.red;
|
|
229
|
-
icon = figures.cross;
|
|
230
|
-
break;
|
|
231
|
-
case LogLevels.WARN:
|
|
232
|
-
coloring = color.yellow;
|
|
233
|
-
icon = figures.warning;
|
|
234
|
-
break;
|
|
235
|
-
case LogLevels.INFO:
|
|
236
|
-
coloring = color.green;
|
|
237
|
-
icon = figures.pointerSmall;
|
|
238
|
-
break;
|
|
239
|
-
case LogLevels.VERBOSE:
|
|
240
|
-
coloring = color.dim;
|
|
241
|
-
break;
|
|
242
|
-
case LogLevels.DEBUG:
|
|
243
|
-
coloring = color.cyan;
|
|
244
|
-
msgColoring = color.dim;
|
|
245
|
-
break;
|
|
246
|
-
case LogLevels.TRACE:
|
|
247
|
-
coloring = color.magenta;
|
|
248
|
-
msgColoring = color.dim;
|
|
249
|
-
break;
|
|
250
|
-
}
|
|
251
|
-
if (!icon) {
|
|
252
|
-
icon = `[${level.at(0).toUpperCase()}]`;
|
|
253
|
-
}
|
|
254
|
-
return `${coloring(icon)}${context ? " " + coloring(`[${context}]`) : ""}${status ? " " + coloring(`[${status}]`) : ""} ${msgColoring(message)}`;
|
|
255
|
-
}
|
|
256
|
-
};
|
|
257
|
-
__name(_WinstonService, "WinstonService");
|
|
258
|
-
var WinstonService = _WinstonService;
|
|
259
|
-
WinstonService = _ts_decorate([
|
|
260
|
-
Injectable(),
|
|
261
|
-
_ts_param(0, Inject(TOKEN_CONFIG_MODULE_OPTIONS)),
|
|
262
|
-
_ts_metadata("design:type", Function),
|
|
263
|
-
_ts_metadata("design:paramtypes", [
|
|
264
|
-
typeof ConfigModuleOptions === "undefined" ? Object : ConfigModuleOptions
|
|
265
|
-
])
|
|
266
|
-
], WinstonService);
|
|
267
|
-
|
|
268
|
-
// src/lib/logger/logger.service.ts
|
|
269
|
-
function _ts_decorate2(decorators, target, key, desc) {
|
|
270
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
271
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
272
|
-
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;
|
|
273
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
274
|
-
}
|
|
275
|
-
__name(_ts_decorate2, "_ts_decorate");
|
|
276
|
-
function _ts_metadata2(k, v) {
|
|
277
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
278
|
-
}
|
|
279
|
-
__name(_ts_metadata2, "_ts_metadata");
|
|
280
|
-
var _LoggerService = class _LoggerService {
|
|
281
|
-
constructor(winston2) {
|
|
282
|
-
__publicField(this, "winston");
|
|
283
|
-
__publicField(this, "context");
|
|
284
|
-
this.winston = winston2;
|
|
285
|
-
}
|
|
286
|
-
setup(context) {
|
|
287
|
-
this.context = context;
|
|
288
|
-
return this;
|
|
289
|
-
}
|
|
290
|
-
log(level, data, ...args) {
|
|
291
|
-
return this.parseMessage(level, data, args);
|
|
292
|
-
}
|
|
293
|
-
direct(data, ...args) {
|
|
294
|
-
return this.parseMessage(LogLevels.DIRECT, data, args);
|
|
295
|
-
}
|
|
296
|
-
fatal(data, ...args) {
|
|
297
|
-
return this.parseMessage(LogLevels.FATAL, data, args);
|
|
298
|
-
}
|
|
299
|
-
error(data, ...args) {
|
|
300
|
-
return this.parseMessage(LogLevels.ERROR, data, args);
|
|
301
|
-
}
|
|
302
|
-
warn(data, ...args) {
|
|
303
|
-
return this.parseMessage(LogLevels.WARN, data, args);
|
|
304
|
-
}
|
|
305
|
-
info(data, ...args) {
|
|
306
|
-
return this.parseMessage(LogLevels.INFO, data, args);
|
|
307
|
-
}
|
|
308
|
-
verbose(data, ...args) {
|
|
309
|
-
return this.parseMessage(LogLevels.VERBOSE, data, args);
|
|
310
|
-
}
|
|
311
|
-
debug(data, ...args) {
|
|
312
|
-
return this.parseMessage(LogLevels.DEBUG, data, args);
|
|
313
|
-
}
|
|
314
|
-
trace(data, ...args) {
|
|
315
|
-
return this.parseMessage(LogLevels.TRACE, data, args);
|
|
316
|
-
}
|
|
317
|
-
// status levels
|
|
318
|
-
run(data, ...args) {
|
|
319
|
-
return this.parseMessage(LogLevels.INFO, data, args, {
|
|
320
|
-
status: LogFieldStatus.RUN
|
|
321
|
-
});
|
|
322
|
-
}
|
|
323
|
-
end(data, ...args) {
|
|
324
|
-
return this.parseMessage(LogLevels.INFO, data, args, {
|
|
325
|
-
status: LogFieldStatus.END
|
|
326
|
-
});
|
|
327
|
-
}
|
|
328
|
-
stage(data, ...args) {
|
|
329
|
-
return this.parseMessage(LogLevels.TRACE, data, args, {
|
|
330
|
-
status: LogFieldStatus.STAGE
|
|
331
|
-
});
|
|
332
|
-
}
|
|
333
|
-
splat(...args) {
|
|
334
|
-
const message = args.shift();
|
|
335
|
-
if (typeof message === "undefined") {
|
|
336
|
-
return "";
|
|
337
|
-
}
|
|
338
|
-
if (args.length === 0) {
|
|
339
|
-
return message;
|
|
340
|
-
}
|
|
341
|
-
return splat(message, args);
|
|
342
|
-
}
|
|
343
|
-
parseMessage(level, data, args, format2) {
|
|
344
|
-
this.winston.instance.log(level, data.toString(), ...args ?? [], {
|
|
345
|
-
context: this.context,
|
|
346
|
-
...format2 ?? {}
|
|
347
|
-
});
|
|
348
|
-
}
|
|
349
|
-
};
|
|
350
|
-
__name(_LoggerService, "LoggerService");
|
|
351
|
-
var LoggerService = _LoggerService;
|
|
352
|
-
LoggerService = _ts_decorate2([
|
|
353
|
-
Injectable2({
|
|
354
|
-
scope: Scope.TRANSIENT
|
|
355
|
-
}),
|
|
356
|
-
_ts_metadata2("design:type", Function),
|
|
357
|
-
_ts_metadata2("design:paramtypes", [
|
|
358
|
-
typeof WinstonService === "undefined" ? Object : WinstonService
|
|
359
|
-
])
|
|
360
|
-
], LoggerService);
|
|
361
|
-
|
|
362
|
-
// src/lib/logger/logger.module.ts
|
|
363
|
-
function _ts_decorate3(decorators, target, key, desc) {
|
|
364
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
365
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
366
|
-
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;
|
|
367
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
368
|
-
}
|
|
369
|
-
__name(_ts_decorate3, "_ts_decorate");
|
|
370
|
-
var _LoggerModule = class _LoggerModule {
|
|
371
|
-
};
|
|
372
|
-
__name(_LoggerModule, "LoggerModule");
|
|
373
|
-
var LoggerModule = _LoggerModule;
|
|
374
|
-
LoggerModule = _ts_decorate3([
|
|
375
|
-
Global(),
|
|
376
|
-
Module({
|
|
377
|
-
providers: [
|
|
378
|
-
WinstonService,
|
|
379
|
-
LoggerService
|
|
380
|
-
],
|
|
381
|
-
exports: [
|
|
382
|
-
LoggerService
|
|
383
|
-
]
|
|
384
|
-
})
|
|
385
|
-
], LoggerModule);
|
|
386
|
-
|
|
387
|
-
// src/lib/parser/parser.service.ts
|
|
388
|
-
import { Injectable as Injectable4 } from "@nestjs/common";
|
|
389
|
-
import { ModuleRef } from "@nestjs/core";
|
|
390
|
-
|
|
391
|
-
// src/lib/fs/filesystem.service.ts
|
|
392
|
-
import { Injectable as Injectable3 } from "@nestjs/common";
|
|
393
|
-
import fs from "fs-extra";
|
|
394
|
-
import { extname, dirname } from "path";
|
|
395
|
-
function _ts_decorate4(decorators, target, key, desc) {
|
|
396
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
397
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
398
|
-
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;
|
|
399
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
400
|
-
}
|
|
401
|
-
__name(_ts_decorate4, "_ts_decorate");
|
|
402
|
-
function _ts_metadata3(k, v) {
|
|
403
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
404
|
-
}
|
|
405
|
-
__name(_ts_metadata3, "_ts_metadata");
|
|
406
|
-
var _FileSystemService = class _FileSystemService {
|
|
407
|
-
constructor(logger) {
|
|
408
|
-
__publicField(this, "logger");
|
|
409
|
-
__publicField(this, "extra");
|
|
410
|
-
this.logger = logger;
|
|
411
|
-
this.extra = fs;
|
|
412
|
-
this.logger.setup(this.constructor.name);
|
|
413
|
-
}
|
|
414
|
-
exists(path) {
|
|
415
|
-
return this.extra.existsSync(path);
|
|
416
|
-
}
|
|
417
|
-
stats(path) {
|
|
418
|
-
return this.extra.statSync(path, {
|
|
419
|
-
throwIfNoEntry: true
|
|
420
|
-
});
|
|
421
|
-
}
|
|
422
|
-
dirname(path) {
|
|
423
|
-
return dirname(path);
|
|
424
|
-
}
|
|
425
|
-
extname(path) {
|
|
426
|
-
return extname(path);
|
|
427
|
-
}
|
|
428
|
-
async read(file) {
|
|
429
|
-
try {
|
|
430
|
-
const raw = await this.extra.readFile(file, "utf-8");
|
|
431
|
-
return raw;
|
|
432
|
-
} catch (e) {
|
|
433
|
-
throw new Error(`Error while reading file from "${file}": ${e.message}`);
|
|
434
|
-
}
|
|
435
|
-
}
|
|
436
|
-
readSync(file) {
|
|
437
|
-
try {
|
|
438
|
-
const raw = this.extra.readFileSync(file, "utf-8");
|
|
439
|
-
return raw;
|
|
440
|
-
} catch (e) {
|
|
441
|
-
throw new Error(`Error while reading file from "${file}": ${e.message}`);
|
|
442
|
-
}
|
|
443
|
-
}
|
|
444
|
-
async write(file, data, options = {}) {
|
|
445
|
-
try {
|
|
446
|
-
await this.extra.writeFile(file, data, typeof options === "object" ? {
|
|
447
|
-
encoding: "utf-8",
|
|
448
|
-
...options
|
|
449
|
-
} : options);
|
|
450
|
-
} catch (e) {
|
|
451
|
-
throw new Error(`Error while writing file to "${file}": ${e.message}`);
|
|
452
|
-
}
|
|
453
|
-
}
|
|
454
|
-
writeSync(file, data, options = {}) {
|
|
455
|
-
try {
|
|
456
|
-
this.extra.writeFileSync(file, data, typeof options === "object" ? {
|
|
457
|
-
encoding: "utf-8",
|
|
458
|
-
...options
|
|
459
|
-
} : options);
|
|
460
|
-
} catch (e) {
|
|
461
|
-
throw new Error(`Error while writing file to "${file}": ${e.message}`);
|
|
462
|
-
}
|
|
463
|
-
}
|
|
464
|
-
async append(file, data, options) {
|
|
465
|
-
try {
|
|
466
|
-
await this.extra.appendFile(file, data, options);
|
|
467
|
-
} catch (e) {
|
|
468
|
-
throw new Error(`Error while appending to file "${file}": ${e.message}`);
|
|
469
|
-
}
|
|
470
|
-
}
|
|
471
|
-
appendSync(file, data) {
|
|
472
|
-
try {
|
|
473
|
-
this.extra.appendFileSync(file, data);
|
|
474
|
-
} catch (e) {
|
|
475
|
-
throw new Error(`Error while appending to file "${file}": ${e.message}`);
|
|
476
|
-
}
|
|
477
|
-
}
|
|
478
|
-
async remove(file, options) {
|
|
479
|
-
try {
|
|
480
|
-
await this.extra.rm(file, options);
|
|
481
|
-
} catch (e) {
|
|
482
|
-
throw new Error(`Error while deleting the file "${file}": ${e.message}`);
|
|
483
|
-
}
|
|
484
|
-
}
|
|
485
|
-
removeSync(file, options) {
|
|
486
|
-
try {
|
|
487
|
-
this.extra.rmSync(file, options);
|
|
488
|
-
} catch (e) {
|
|
489
|
-
throw new Error(`Error while deleting the file "${file}": ${e.message}`);
|
|
490
|
-
}
|
|
491
|
-
}
|
|
492
|
-
async emptyDir(directory) {
|
|
493
|
-
try {
|
|
494
|
-
await this.extra.emptyDir(directory);
|
|
495
|
-
} catch (e) {
|
|
496
|
-
throw new Error(`Error while emptying the directory "${directory}": ${e.message}`);
|
|
497
|
-
}
|
|
498
|
-
}
|
|
499
|
-
emptyDirSync(directory) {
|
|
500
|
-
try {
|
|
501
|
-
this.extra.emptyDirSync(directory);
|
|
502
|
-
} catch (e) {
|
|
503
|
-
throw new Error(`Error while emptying the directory "${directory}": ${e.message}`);
|
|
504
|
-
}
|
|
505
|
-
}
|
|
506
|
-
async removeDir(directory) {
|
|
507
|
-
try {
|
|
508
|
-
await this.extra.rmdir(directory);
|
|
509
|
-
} catch (e) {
|
|
510
|
-
throw new Error(`Error while removing the directory "${directory}": ${e.message}`);
|
|
511
|
-
}
|
|
512
|
-
}
|
|
513
|
-
removeDirSync(directory) {
|
|
514
|
-
try {
|
|
515
|
-
this.extra.rmdirSync(directory);
|
|
516
|
-
} catch (e) {
|
|
517
|
-
throw new Error(`Error while removing the directory "${directory}": ${e.message}`);
|
|
518
|
-
}
|
|
519
|
-
}
|
|
520
|
-
async mkdir(directory) {
|
|
521
|
-
try {
|
|
522
|
-
await this.extra.mkdirp(directory);
|
|
523
|
-
} catch (e) {
|
|
524
|
-
throw new Error(`Error while creating the directory "${directory}": ${e.message}`);
|
|
525
|
-
}
|
|
526
|
-
}
|
|
527
|
-
mkdirSync(directory) {
|
|
528
|
-
try {
|
|
529
|
-
this.extra.mkdirpSync(directory);
|
|
530
|
-
} catch (e) {
|
|
531
|
-
throw new Error(`Error while creating the directory "${directory}": ${e.message}`);
|
|
532
|
-
}
|
|
533
|
-
}
|
|
534
|
-
};
|
|
535
|
-
__name(_FileSystemService, "FileSystemService");
|
|
536
|
-
var FileSystemService = _FileSystemService;
|
|
537
|
-
FileSystemService = _ts_decorate4([
|
|
538
|
-
Injectable3(),
|
|
539
|
-
_ts_metadata3("design:type", Function),
|
|
540
|
-
_ts_metadata3("design:paramtypes", [
|
|
541
|
-
typeof LoggerService === "undefined" ? Object : LoggerService
|
|
542
|
-
])
|
|
543
|
-
], FileSystemService);
|
|
544
|
-
|
|
545
|
-
// src/lib/fs/filesystem.module.ts
|
|
546
|
-
import { Global as Global2, Module as Module2 } from "@nestjs/common";
|
|
547
|
-
function _ts_decorate5(decorators, target, key, desc) {
|
|
548
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
549
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
550
|
-
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;
|
|
551
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
552
|
-
}
|
|
553
|
-
__name(_ts_decorate5, "_ts_decorate");
|
|
554
|
-
var _FilesystemModule = class _FilesystemModule {
|
|
555
|
-
};
|
|
556
|
-
__name(_FilesystemModule, "FilesystemModule");
|
|
557
|
-
var FilesystemModule = _FilesystemModule;
|
|
558
|
-
FilesystemModule = _ts_decorate5([
|
|
559
|
-
Global2(),
|
|
560
|
-
Module2({
|
|
561
|
-
providers: [
|
|
562
|
-
FileSystemService
|
|
563
|
-
],
|
|
564
|
-
exports: [
|
|
565
|
-
FileSystemService
|
|
566
|
-
]
|
|
567
|
-
})
|
|
568
|
-
], FilesystemModule);
|
|
569
|
-
|
|
570
|
-
// src/lib/parser/parser.service.ts
|
|
571
|
-
function _ts_decorate6(decorators, target, key, desc) {
|
|
572
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
573
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
574
|
-
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;
|
|
575
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
576
|
-
}
|
|
577
|
-
__name(_ts_decorate6, "_ts_decorate");
|
|
578
|
-
function _ts_metadata4(k, v) {
|
|
579
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
580
|
-
}
|
|
581
|
-
__name(_ts_metadata4, "_ts_metadata");
|
|
582
|
-
var _ParserService = class _ParserService {
|
|
583
|
-
constructor(moduleRef, fs2, logger) {
|
|
584
|
-
__publicField(this, "moduleRef");
|
|
585
|
-
__publicField(this, "fs");
|
|
586
|
-
__publicField(this, "logger");
|
|
587
|
-
__publicField(this, "instances");
|
|
588
|
-
this.moduleRef = moduleRef;
|
|
589
|
-
this.fs = fs2;
|
|
590
|
-
this.logger = logger;
|
|
591
|
-
this.instances = [];
|
|
592
|
-
this.logger.setup(this.constructor.name);
|
|
593
|
-
}
|
|
594
|
-
byFt(file) {
|
|
595
|
-
const ext = (file.includes(".") ? this.fs.extname(file) : file).replace(/^\./, "");
|
|
596
|
-
const Parser = this.instances.find((parser) => parser.extensions.includes(ext));
|
|
597
|
-
if (!Parser) {
|
|
598
|
-
throw new Error(`Parser for the extension is not configured: ${ext}`);
|
|
599
|
-
}
|
|
600
|
-
return Parser;
|
|
601
|
-
}
|
|
602
|
-
fetch(Parser) {
|
|
603
|
-
const parser = this.instances.find((instance) => instance instanceof Parser);
|
|
604
|
-
if (!parser) {
|
|
605
|
-
throw new Error(`Specified parser has not been initiated: ${Parser.name}`);
|
|
606
|
-
}
|
|
607
|
-
return parser;
|
|
608
|
-
}
|
|
609
|
-
async inject(Parser) {
|
|
610
|
-
const parser = await this.moduleRef.create(Parser);
|
|
611
|
-
this.instances.push(parser);
|
|
612
|
-
return parser;
|
|
613
|
-
}
|
|
614
|
-
async register(...parsers) {
|
|
615
|
-
await Promise.all(parsers.map(async (parser) => this.inject(parser)));
|
|
616
|
-
this.logger.trace("Registered parsers: %o", parsers.map((p) => p.name));
|
|
617
|
-
}
|
|
618
|
-
async read(file) {
|
|
619
|
-
return this.parse(file, await this.fs.read(file));
|
|
620
|
-
}
|
|
621
|
-
async write(file, data) {
|
|
622
|
-
return this.fs.write(file, this.stringify(file, data));
|
|
623
|
-
}
|
|
624
|
-
parse(file, data) {
|
|
625
|
-
const parser = this.byFt(file);
|
|
626
|
-
this.logger.trace("Parsing file: %s -> %s", file, parser.constructor.name);
|
|
627
|
-
return parser.parse(data);
|
|
628
|
-
}
|
|
629
|
-
parseWith(Parser, data) {
|
|
630
|
-
const parser = this.fetch(Parser);
|
|
631
|
-
this.logger.trace("Parsing data with: %s", parser.constructor.name);
|
|
632
|
-
return parser.parse(data);
|
|
633
|
-
}
|
|
634
|
-
stringify(file, data) {
|
|
635
|
-
const parser = this.byFt(file);
|
|
636
|
-
this.logger.trace("Stringifying file: %s -> %s", file, parser.constructor.name);
|
|
637
|
-
return parser.stringify(data);
|
|
638
|
-
}
|
|
639
|
-
stringifyWith(Parser, data) {
|
|
640
|
-
const parser = this.fetch(Parser);
|
|
641
|
-
this.logger.trace("Stringifying data: %s", parser.constructor.name);
|
|
642
|
-
return parser.stringify(data);
|
|
643
|
-
}
|
|
644
|
-
};
|
|
645
|
-
__name(_ParserService, "ParserService");
|
|
646
|
-
var ParserService = _ParserService;
|
|
647
|
-
ParserService = _ts_decorate6([
|
|
648
|
-
Injectable4(),
|
|
649
|
-
_ts_metadata4("design:type", Function),
|
|
650
|
-
_ts_metadata4("design:paramtypes", [
|
|
651
|
-
typeof ModuleRef === "undefined" ? Object : ModuleRef,
|
|
652
|
-
typeof FileSystemService === "undefined" ? Object : FileSystemService,
|
|
653
|
-
typeof LoggerService === "undefined" ? Object : LoggerService
|
|
654
|
-
])
|
|
655
|
-
], ParserService);
|
|
656
|
-
|
|
657
|
-
// src/utils/defaults.ts
|
|
658
|
-
function setCtxDefaults(ctx, ...defaults) {
|
|
659
|
-
defaults?.forEach((i) => {
|
|
660
|
-
if (typeof i === "object" && !Array.isArray(i)) {
|
|
661
|
-
Object.assign(ctx, i);
|
|
662
|
-
}
|
|
663
|
-
});
|
|
664
|
-
}
|
|
665
|
-
__name(setCtxDefaults, "setCtxDefaults");
|
|
666
|
-
function setCtxAssign(ctx, ...assigns) {
|
|
667
|
-
assigns.forEach((assign) => {
|
|
668
|
-
assign?.keys.forEach((i) => {
|
|
669
|
-
if (assign.from[i]) {
|
|
670
|
-
ctx[i] = assign.from[i];
|
|
671
|
-
}
|
|
672
|
-
});
|
|
673
|
-
});
|
|
674
|
-
}
|
|
675
|
-
__name(setCtxAssign, "setCtxAssign");
|
|
676
|
-
|
|
677
|
-
// src/utils/environment.ts
|
|
678
|
-
function isVerbose(logLevel) {
|
|
679
|
-
return logLevel === LogLevels.VERBOSE;
|
|
680
|
-
}
|
|
681
|
-
__name(isVerbose, "isVerbose");
|
|
682
|
-
function isDebug(logLevel) {
|
|
683
|
-
return [
|
|
684
|
-
LogLevels.DEBUG,
|
|
685
|
-
LogLevels.TRACE
|
|
686
|
-
].includes(logLevel);
|
|
687
|
-
}
|
|
688
|
-
__name(isDebug, "isDebug");
|
|
689
|
-
function isSilent(logLevel) {
|
|
690
|
-
return logLevel === LogLevels.SILENT;
|
|
691
|
-
}
|
|
692
|
-
__name(isSilent, "isSilent");
|
|
693
|
-
|
|
694
|
-
// src/utils/guards.ts
|
|
695
|
-
function isHookedWithShouldRunBefore(command) {
|
|
696
|
-
return typeof command.shouldRunBefore === "function";
|
|
697
|
-
}
|
|
698
|
-
__name(isHookedWithShouldRunBefore, "isHookedWithShouldRunBefore");
|
|
699
|
-
function isHookedWithShouldRunAfter(command) {
|
|
700
|
-
return typeof command.shouldRunAfter === "function";
|
|
701
|
-
}
|
|
702
|
-
__name(isHookedWithShouldRunAfter, "isHookedWithShouldRunAfter");
|
|
703
|
-
function isHookedWithRegister(command) {
|
|
704
|
-
return typeof command.register === "function";
|
|
705
|
-
}
|
|
706
|
-
__name(isHookedWithRegister, "isHookedWithRegister");
|
|
707
|
-
|
|
708
|
-
// src/utils/merge.constants.ts
|
|
709
|
-
var MergeStrategy = /* @__PURE__ */ function(MergeStrategy2) {
|
|
710
|
-
MergeStrategy2["OVERWRITE"] = "OVERWRITE";
|
|
711
|
-
MergeStrategy2["EXTEND"] = "EXTEND";
|
|
712
|
-
return MergeStrategy2;
|
|
713
|
-
}({});
|
|
714
|
-
|
|
715
|
-
// src/utils/merge.ts
|
|
716
|
-
import deepmerge from "deepmerge";
|
|
717
|
-
function merge(strategy, ...source) {
|
|
718
|
-
return deepmerge.all(source, {
|
|
719
|
-
arrayMerge: strategy === MergeStrategy.EXTEND ? (dest, src) => [
|
|
720
|
-
...dest,
|
|
721
|
-
...src
|
|
722
|
-
].filter(uniqueArrayFilter) : (_, src) => src
|
|
723
|
-
});
|
|
724
|
-
}
|
|
725
|
-
__name(merge, "merge");
|
|
726
|
-
function uniqueArrayFilter(value, index, self) {
|
|
727
|
-
return self.indexOf(value) === index;
|
|
728
|
-
}
|
|
729
|
-
__name(uniqueArrayFilter, "uniqueArrayFilter");
|
|
730
|
-
|
|
731
|
-
// src/utils/index.ts
|
|
732
|
-
import { ux } from "@oclif/core";
|
|
733
|
-
|
|
734
|
-
// src/lib/config/config.service.ts
|
|
735
|
-
function _ts_decorate7(decorators, target, key, desc) {
|
|
736
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
737
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
738
|
-
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;
|
|
739
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
740
|
-
}
|
|
741
|
-
__name(_ts_decorate7, "_ts_decorate");
|
|
742
|
-
function _ts_metadata5(k, v) {
|
|
743
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
744
|
-
}
|
|
745
|
-
__name(_ts_metadata5, "_ts_metadata");
|
|
746
|
-
function _ts_param2(paramIndex, decorator) {
|
|
747
|
-
return function(target, key) {
|
|
748
|
-
decorator(target, key, paramIndex);
|
|
749
|
-
};
|
|
750
|
-
}
|
|
751
|
-
__name(_ts_param2, "_ts_param");
|
|
752
|
-
var _ConfigService = class _ConfigService {
|
|
753
|
-
constructor(parser, logger, options) {
|
|
754
|
-
__publicField(this, "parser");
|
|
755
|
-
__publicField(this, "logger");
|
|
756
|
-
__publicField(this, "defaults");
|
|
757
|
-
__publicField(this, "root");
|
|
758
|
-
__publicField(this, "config");
|
|
759
|
-
__publicField(this, "oclif");
|
|
760
|
-
__publicField(this, "command");
|
|
761
|
-
this.parser = parser;
|
|
762
|
-
this.logger = logger;
|
|
763
|
-
this.root = options.oclif.root;
|
|
764
|
-
this.defaults = join(options.oclif.root, FileConstants.CONFIG_SERVICE_DEFAULTS_DIR);
|
|
765
|
-
this.oclif = options.oclif;
|
|
766
|
-
this.config = options.config;
|
|
767
|
-
this.command = options.command;
|
|
768
|
-
this.logger.setup(this.constructor.name);
|
|
769
|
-
}
|
|
770
|
-
get isVerbose() {
|
|
771
|
-
return isVerbose(this.config.logLevel);
|
|
772
|
-
}
|
|
773
|
-
get isDebug() {
|
|
774
|
-
return isDebug(this.config.logLevel);
|
|
775
|
-
}
|
|
776
|
-
get isSilent() {
|
|
777
|
-
return isSilent(this.config.logLevel);
|
|
778
|
-
}
|
|
779
|
-
get isJson() {
|
|
780
|
-
return this.config.isJson;
|
|
781
|
-
}
|
|
782
|
-
async read(path) {
|
|
783
|
-
const config = await this.parser.read(path);
|
|
784
|
-
this.logger.trace("Read config from: %s", path);
|
|
785
|
-
return config;
|
|
786
|
-
}
|
|
787
|
-
async extend(paths, strategy = MergeStrategy.OVERWRITE) {
|
|
788
|
-
this.logger.trace("Will generate config from: %o with %s", paths, strategy);
|
|
789
|
-
const configs = (await Promise.all(paths.map(async (path) => {
|
|
790
|
-
try {
|
|
791
|
-
const config = typeof path === "string" ? await this.parser.read(path) : path;
|
|
792
|
-
this.logger.trace("Extending config from: %s", path);
|
|
793
|
-
return config;
|
|
794
|
-
} catch (e) {
|
|
795
|
-
this.logger.trace("Failed to extend config from: %s", e.message);
|
|
796
|
-
}
|
|
797
|
-
}))).filter(Boolean);
|
|
798
|
-
return this.merge(configs, strategy);
|
|
799
|
-
}
|
|
800
|
-
merge(configs, strategy = MergeStrategy.OVERWRITE) {
|
|
801
|
-
if (configs.length === 0) {
|
|
802
|
-
throw new Error("Nothing to merge, configuration files are empty.");
|
|
803
|
-
}
|
|
804
|
-
return merge(strategy, ...configs);
|
|
805
|
-
}
|
|
806
|
-
async env(definition, config) {
|
|
807
|
-
const env = typeof definition === "string" ? await this.parser.read(definition) : definition;
|
|
808
|
-
this.logger.trace("Environment variable extensions read: %o", definition);
|
|
809
|
-
const iter = /* @__PURE__ */ __name(async (obj, parent) => {
|
|
810
|
-
const data = await Promise.all(Object.entries(obj).map(async ([key, value]) => {
|
|
811
|
-
const location = [
|
|
812
|
-
...parent ?? [],
|
|
813
|
-
key
|
|
814
|
-
];
|
|
815
|
-
if (typeof value === "string") {
|
|
816
|
-
return [
|
|
817
|
-
{
|
|
818
|
-
key: location,
|
|
819
|
-
env: value
|
|
820
|
-
}
|
|
821
|
-
];
|
|
822
|
-
} else if (typeof value === "object") {
|
|
823
|
-
let extensions;
|
|
824
|
-
if (ConfigEnvKeys.ELEMENT in value) {
|
|
825
|
-
extensions = await iter(value[ConfigEnvKeys.ELEMENT], [
|
|
826
|
-
...location,
|
|
827
|
-
ConfigEnvKeys.ELEMENT
|
|
828
|
-
]);
|
|
829
|
-
this.logger.trace("Expanding location to elements: %s -> %s", location, extensions.map((extension) => extension.key.join(".")).join(", "));
|
|
830
|
-
}
|
|
831
|
-
if (ConfigEnvKeys.NAME in value && ConfigEnvKeys.PARSER in value) {
|
|
832
|
-
const variable = [
|
|
833
|
-
{
|
|
834
|
-
key: location,
|
|
835
|
-
env: value[ConfigEnvKeys.NAME],
|
|
836
|
-
parser: value[ConfigEnvKeys.PARSER],
|
|
837
|
-
extensions
|
|
838
|
-
}
|
|
839
|
-
];
|
|
840
|
-
return variable;
|
|
841
|
-
} else {
|
|
842
|
-
return iter(value, location);
|
|
843
|
-
}
|
|
844
|
-
}
|
|
845
|
-
}));
|
|
846
|
-
return data.flatMap((d) => d).filter(Boolean);
|
|
847
|
-
}, "iter");
|
|
848
|
-
const parsed = await iter(env);
|
|
849
|
-
const cb = /* @__PURE__ */ __name((config2, variable, data) => {
|
|
850
|
-
if (variable.parser) {
|
|
851
|
-
try {
|
|
852
|
-
data = this.parser.parse(variable.parser, data);
|
|
853
|
-
} catch (e) {
|
|
854
|
-
this.logger.trace("Can not parse environment environment variable for config: %s -> %s with %s", variable.key.join("."), variable.env, variable.parser);
|
|
855
|
-
throw e;
|
|
856
|
-
}
|
|
857
|
-
}
|
|
858
|
-
this.logger.trace("Overwriting config with environment variable: %s -> %s", variable.key.join("."), variable.env);
|
|
859
|
-
return op.set(config2, variable.key, data);
|
|
860
|
-
}, "cb");
|
|
861
|
-
parsed.forEach((variable) => {
|
|
862
|
-
let data;
|
|
863
|
-
data = process.env[variable.env];
|
|
864
|
-
if (data) {
|
|
865
|
-
config = cb(config, variable, data);
|
|
866
|
-
}
|
|
867
|
-
if (variable.extensions && variable.extensions.length > 0) {
|
|
868
|
-
const timeout = 6e4;
|
|
869
|
-
const startedAt = Date.now();
|
|
870
|
-
for (let i = 0; i < Infinity; i++) {
|
|
871
|
-
if (Date.now() - startedAt > timeout) {
|
|
872
|
-
throw new Error(`Timed-out in ${timeout}ms while looking for element environment variables.`);
|
|
873
|
-
}
|
|
874
|
-
const extensions = variable.extensions.map((extension) => {
|
|
875
|
-
const clone = JSON.parse(JSON.stringify(extension));
|
|
876
|
-
clone.env = clone.env.replace(ConfigEnvKeys.ELEMENT_REPLACER, i.toString());
|
|
877
|
-
clone.key[clone.key.findIndex((value) => value === ConfigEnvKeys.ELEMENT)] = i.toString();
|
|
878
|
-
data = process.env[clone.env];
|
|
879
|
-
if (!data) {
|
|
880
|
-
this.logger.trace("No extension for environment variable: %s -> %s", clone.key.join("."), clone.env);
|
|
881
|
-
return;
|
|
882
|
-
}
|
|
883
|
-
config = cb(config, clone, data);
|
|
884
|
-
return true;
|
|
885
|
-
}).filter(Boolean);
|
|
886
|
-
if (extensions.length === 0) {
|
|
887
|
-
this.logger.trace("No more extensions for environment variables: %s -> %d", variable.key.join("."), i);
|
|
888
|
-
break;
|
|
889
|
-
}
|
|
890
|
-
}
|
|
891
|
-
}
|
|
892
|
-
});
|
|
893
|
-
return config;
|
|
894
|
-
}
|
|
895
|
-
async write(path, data) {
|
|
896
|
-
return this.parser.write(path, data);
|
|
897
|
-
}
|
|
898
|
-
};
|
|
899
|
-
__name(_ConfigService, "ConfigService");
|
|
900
|
-
var ConfigService = _ConfigService;
|
|
901
|
-
ConfigService = _ts_decorate7([
|
|
902
|
-
Injectable5(),
|
|
903
|
-
_ts_param2(2, Inject2(TOKEN_CONFIG_MODULE_OPTIONS)),
|
|
904
|
-
_ts_metadata5("design:type", Function),
|
|
905
|
-
_ts_metadata5("design:paramtypes", [
|
|
906
|
-
typeof ParserService === "undefined" ? Object : ParserService,
|
|
907
|
-
typeof LoggerService === "undefined" ? Object : LoggerService,
|
|
908
|
-
typeof ConfigModuleOptions === "undefined" ? Object : ConfigModuleOptions
|
|
909
|
-
])
|
|
910
|
-
], ConfigService);
|
|
911
|
-
|
|
912
|
-
// src/lib/config/config.module.ts
|
|
913
|
-
import { Global as Global4, Module as Module4 } from "@nestjs/common";
|
|
914
|
-
|
|
915
|
-
// src/lib/parser/parser.module.ts
|
|
916
|
-
import { Global as Global3, Module as Module3 } from "@nestjs/common";
|
|
917
|
-
function _ts_decorate8(decorators, target, key, desc) {
|
|
918
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
919
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
920
|
-
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;
|
|
921
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
922
|
-
}
|
|
923
|
-
__name(_ts_decorate8, "_ts_decorate");
|
|
924
|
-
var _ParserModule = class _ParserModule {
|
|
925
|
-
};
|
|
926
|
-
__name(_ParserModule, "ParserModule");
|
|
927
|
-
var ParserModule = _ParserModule;
|
|
928
|
-
ParserModule = _ts_decorate8([
|
|
929
|
-
Global3(),
|
|
930
|
-
Module3({
|
|
931
|
-
imports: [
|
|
932
|
-
FilesystemModule
|
|
933
|
-
],
|
|
934
|
-
providers: [
|
|
935
|
-
ParserService
|
|
936
|
-
],
|
|
937
|
-
exports: [
|
|
938
|
-
ParserService
|
|
939
|
-
]
|
|
940
|
-
})
|
|
941
|
-
], ParserModule);
|
|
942
|
-
|
|
943
|
-
// src/lib/config/config.module.ts
|
|
944
|
-
function _ts_decorate9(decorators, target, key, desc) {
|
|
945
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
946
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
947
|
-
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;
|
|
948
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
949
|
-
}
|
|
950
|
-
__name(_ts_decorate9, "_ts_decorate");
|
|
951
|
-
var _ConfigModule = class _ConfigModule {
|
|
952
|
-
};
|
|
953
|
-
__name(_ConfigModule, "ConfigModule");
|
|
954
|
-
var ConfigModule = _ConfigModule;
|
|
955
|
-
ConfigModule = _ts_decorate9([
|
|
956
|
-
Global4(),
|
|
957
|
-
Module4({
|
|
958
|
-
imports: [
|
|
959
|
-
ParserModule
|
|
960
|
-
],
|
|
961
|
-
providers: [
|
|
962
|
-
ConfigService
|
|
963
|
-
],
|
|
964
|
-
exports: [
|
|
965
|
-
ConfigService
|
|
966
|
-
]
|
|
967
|
-
})
|
|
968
|
-
], ConfigModule);
|
|
969
|
-
|
|
970
|
-
// src/lib/locker/locker.service.ts
|
|
971
|
-
import { Injectable as Injectable9 } from "@nestjs/common";
|
|
972
|
-
import op2 from "object-path-immutable";
|
|
973
|
-
|
|
974
|
-
// src/lib/parser/fts/env-parser.service.ts
|
|
975
|
-
import { Injectable as Injectable6 } from "@nestjs/common";
|
|
976
|
-
import { EOL as EOL2 } from "os";
|
|
977
|
-
function _ts_decorate10(decorators, target, key, desc) {
|
|
978
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
979
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
980
|
-
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;
|
|
981
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
982
|
-
}
|
|
983
|
-
__name(_ts_decorate10, "_ts_decorate");
|
|
984
|
-
function _ts_metadata6(k, v) {
|
|
985
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
986
|
-
}
|
|
987
|
-
__name(_ts_metadata6, "_ts_metadata");
|
|
988
|
-
var _EnvironmentVariableParser = class _EnvironmentVariableParser {
|
|
989
|
-
constructor(logger) {
|
|
990
|
-
__publicField(this, "logger");
|
|
991
|
-
__publicField(this, "extensions");
|
|
992
|
-
__publicField(this, "LINE");
|
|
993
|
-
this.logger = logger;
|
|
994
|
-
this.extensions = [
|
|
995
|
-
"env"
|
|
996
|
-
];
|
|
997
|
-
this.LINE = /(?:^|^)\s*(?:export\s+)?([\w.-]+)(?:\s*=\s*?|:\s+?)(\s*'(?:\\'|[^'])*'|\s*"(?:\\"|[^"])*"|\s*`(?:\\`|[^`])*`|[^#\r\n]+)?\s*(?:#.*)?(?:$|$)/gm;
|
|
998
|
-
this.logger.setup(this.constructor.name);
|
|
999
|
-
}
|
|
1000
|
-
parse(data) {
|
|
1001
|
-
try {
|
|
1002
|
-
return data.toString().split(EOL2).reduce((o, line) => {
|
|
1003
|
-
const match = this.LINE.exec(line);
|
|
1004
|
-
const key = match[1];
|
|
1005
|
-
const value = match[2] ?? "";
|
|
1006
|
-
return {
|
|
1007
|
-
...o,
|
|
1008
|
-
[key]: value
|
|
1009
|
-
};
|
|
1010
|
-
}, {});
|
|
1011
|
-
} catch (e) {
|
|
1012
|
-
this.logger.trace("Error during parsing environment file: %s", e.message);
|
|
1013
|
-
throw e;
|
|
1014
|
-
}
|
|
1015
|
-
}
|
|
1016
|
-
stringify(data) {
|
|
1017
|
-
return Object.entries(data).map(([k, v]) => `${k}=${v}`).join(EOL2) + EOL2;
|
|
1018
|
-
}
|
|
1019
|
-
};
|
|
1020
|
-
__name(_EnvironmentVariableParser, "EnvironmentVariableParser");
|
|
1021
|
-
var EnvironmentVariableParser = _EnvironmentVariableParser;
|
|
1022
|
-
EnvironmentVariableParser = _ts_decorate10([
|
|
1023
|
-
Injectable6(),
|
|
1024
|
-
_ts_metadata6("design:type", Function),
|
|
1025
|
-
_ts_metadata6("design:paramtypes", [
|
|
1026
|
-
typeof LoggerService === "undefined" ? Object : LoggerService
|
|
1027
|
-
])
|
|
1028
|
-
], EnvironmentVariableParser);
|
|
1029
|
-
|
|
1030
|
-
// src/lib/parser/fts/json-parser.service.ts
|
|
1031
|
-
import { Injectable as Injectable7 } from "@nestjs/common";
|
|
1032
|
-
function _ts_decorate11(decorators, target, key, desc) {
|
|
1033
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
1034
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
1035
|
-
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;
|
|
1036
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
1037
|
-
}
|
|
1038
|
-
__name(_ts_decorate11, "_ts_decorate");
|
|
1039
|
-
function _ts_metadata7(k, v) {
|
|
1040
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
1041
|
-
}
|
|
1042
|
-
__name(_ts_metadata7, "_ts_metadata");
|
|
1043
|
-
var _JsonParser = class _JsonParser {
|
|
1044
|
-
constructor(logger) {
|
|
1045
|
-
__publicField(this, "logger");
|
|
1046
|
-
__publicField(this, "extensions");
|
|
1047
|
-
this.logger = logger;
|
|
1048
|
-
this.extensions = [
|
|
1049
|
-
"json"
|
|
1050
|
-
];
|
|
1051
|
-
this.logger.setup(this.constructor.name);
|
|
1052
|
-
}
|
|
1053
|
-
parse(data) {
|
|
1054
|
-
try {
|
|
1055
|
-
return JSON.parse(data.toString());
|
|
1056
|
-
} catch (e) {
|
|
1057
|
-
this.logger.trace("Error during parsing JSON file: %s", e.message);
|
|
1058
|
-
throw e;
|
|
1059
|
-
}
|
|
1060
|
-
}
|
|
1061
|
-
stringify(data) {
|
|
1062
|
-
return JSON.stringify(data, null, 2);
|
|
1063
|
-
}
|
|
1064
|
-
};
|
|
1065
|
-
__name(_JsonParser, "JsonParser");
|
|
1066
|
-
var JsonParser = _JsonParser;
|
|
1067
|
-
JsonParser = _ts_decorate11([
|
|
1068
|
-
Injectable7(),
|
|
1069
|
-
_ts_metadata7("design:type", Function),
|
|
1070
|
-
_ts_metadata7("design:paramtypes", [
|
|
1071
|
-
typeof LoggerService === "undefined" ? Object : LoggerService
|
|
1072
|
-
])
|
|
1073
|
-
], JsonParser);
|
|
1074
|
-
|
|
1075
|
-
// src/lib/parser/fts/yaml-parser.service.ts
|
|
1076
|
-
import { Injectable as Injectable8 } from "@nestjs/common";
|
|
1077
|
-
import { parse, stringify } from "yaml";
|
|
1078
|
-
function _ts_decorate12(decorators, target, key, desc) {
|
|
1079
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
1080
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
1081
|
-
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;
|
|
1082
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
1083
|
-
}
|
|
1084
|
-
__name(_ts_decorate12, "_ts_decorate");
|
|
1085
|
-
function _ts_metadata8(k, v) {
|
|
1086
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
1087
|
-
}
|
|
1088
|
-
__name(_ts_metadata8, "_ts_metadata");
|
|
1089
|
-
var _YamlParser = class _YamlParser {
|
|
1090
|
-
constructor(logger) {
|
|
1091
|
-
__publicField(this, "logger");
|
|
1092
|
-
__publicField(this, "extensions");
|
|
1093
|
-
this.logger = logger;
|
|
1094
|
-
this.extensions = [
|
|
1095
|
-
"yaml",
|
|
1096
|
-
"yml"
|
|
1097
|
-
];
|
|
1098
|
-
this.logger.setup(this.constructor.name);
|
|
1099
|
-
}
|
|
1100
|
-
parse(data) {
|
|
1101
|
-
try {
|
|
1102
|
-
return parse(data.toString());
|
|
1103
|
-
} catch (e) {
|
|
1104
|
-
this.logger.trace("Error during parsing YAML file: %s", e.message);
|
|
1105
|
-
throw e;
|
|
1106
|
-
}
|
|
1107
|
-
}
|
|
1108
|
-
stringify(data) {
|
|
1109
|
-
return stringify(data, {
|
|
1110
|
-
prettyErrors: true
|
|
1111
|
-
});
|
|
1112
|
-
}
|
|
1113
|
-
};
|
|
1114
|
-
__name(_YamlParser, "YamlParser");
|
|
1115
|
-
var YamlParser = _YamlParser;
|
|
1116
|
-
YamlParser = _ts_decorate12([
|
|
1117
|
-
Injectable8(),
|
|
1118
|
-
_ts_metadata8("design:type", Function),
|
|
1119
|
-
_ts_metadata8("design:paramtypes", [
|
|
1120
|
-
typeof LoggerService === "undefined" ? Object : LoggerService
|
|
1121
|
-
])
|
|
1122
|
-
], YamlParser);
|
|
1123
|
-
|
|
1124
|
-
// src/lib/locker/locker.service.ts
|
|
1125
|
-
function _ts_decorate13(decorators, target, key, desc) {
|
|
1126
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
1127
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
1128
|
-
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;
|
|
1129
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
1130
|
-
}
|
|
1131
|
-
__name(_ts_decorate13, "_ts_decorate");
|
|
1132
|
-
function _ts_metadata9(k, v) {
|
|
1133
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
1134
|
-
}
|
|
1135
|
-
__name(_ts_metadata9, "_ts_metadata");
|
|
1136
|
-
var _LockerService = class _LockerService {
|
|
1137
|
-
constructor(logger, fs2, parser, options) {
|
|
1138
|
-
__publicField(this, "logger");
|
|
1139
|
-
__publicField(this, "fs");
|
|
1140
|
-
__publicField(this, "parser");
|
|
1141
|
-
__publicField(this, "options");
|
|
1142
|
-
__publicField(this, "op");
|
|
1143
|
-
__publicField(this, "toLock");
|
|
1144
|
-
__publicField(this, "toUnlock");
|
|
1145
|
-
this.logger = logger;
|
|
1146
|
-
this.fs = fs2;
|
|
1147
|
-
this.parser = parser;
|
|
1148
|
-
this.options = options;
|
|
1149
|
-
this.op = op2;
|
|
1150
|
-
this.toLock = [];
|
|
1151
|
-
this.toUnlock = [];
|
|
1152
|
-
this.logger.setup(this.constructor.name);
|
|
1153
|
-
}
|
|
1154
|
-
hasLock() {
|
|
1155
|
-
return this.toLock.length > 0;
|
|
1156
|
-
}
|
|
1157
|
-
hasUnlock() {
|
|
1158
|
-
return this.toUnlock.length > 0;
|
|
1159
|
-
}
|
|
1160
|
-
addLock(...data) {
|
|
1161
|
-
this.toLock.push(...data);
|
|
1162
|
-
}
|
|
1163
|
-
addUnlock(...data) {
|
|
1164
|
-
this.toUnlock.push(...data);
|
|
1165
|
-
}
|
|
1166
|
-
async applyLockAll(lock) {
|
|
1167
|
-
if (this.hasLock()) {
|
|
1168
|
-
return this.applyLock(lock, ...this.toLock);
|
|
1169
|
-
}
|
|
1170
|
-
return lock;
|
|
1171
|
-
}
|
|
1172
|
-
async lockAll() {
|
|
1173
|
-
if (this.hasLock()) {
|
|
1174
|
-
await this.lock(...this.toLock);
|
|
1175
|
-
this.toLock = [];
|
|
1176
|
-
}
|
|
1177
|
-
}
|
|
1178
|
-
async applyUnlockAll(lock) {
|
|
1179
|
-
if (this.hasUnlock()) {
|
|
1180
|
-
return this.applyUnlock(lock, ...this.toUnlock);
|
|
1181
|
-
}
|
|
1182
|
-
return lock;
|
|
1183
|
-
}
|
|
1184
|
-
async unlockAll() {
|
|
1185
|
-
if (this.hasUnlock()) {
|
|
1186
|
-
await this.unlock(...this.toUnlock);
|
|
1187
|
-
this.toUnlock = [];
|
|
1188
|
-
}
|
|
1189
|
-
}
|
|
1190
|
-
async all() {
|
|
1191
|
-
await this.unlockAll();
|
|
1192
|
-
await this.lockAll();
|
|
1193
|
-
}
|
|
1194
|
-
async applyAll(lock) {
|
|
1195
|
-
lock = await this.applyUnlockAll(lock);
|
|
1196
|
-
lock = await this.applyLockAll(lock);
|
|
1197
|
-
return lock;
|
|
1198
|
-
}
|
|
1199
|
-
async applyLock(lock, ...data) {
|
|
1200
|
-
data.forEach((d) => {
|
|
1201
|
-
if (d?.enabled === false) {
|
|
1202
|
-
return;
|
|
1203
|
-
} else if (!d?.data || Array.isArray(d?.data) && d.data.length === 0 || typeof d?.data === "object" && Object.keys(d.data).length === 0) {
|
|
1204
|
-
return;
|
|
1205
|
-
}
|
|
1206
|
-
const path = this.buildPath(d);
|
|
1207
|
-
if (d?.merge) {
|
|
1208
|
-
let parsed;
|
|
1209
|
-
if (typeof d.data === "object") {
|
|
1210
|
-
parsed = merge(d.merge, this.op.get(lock, path, Array.isArray(d.data) ? [] : {}), d.data);
|
|
1211
|
-
} else {
|
|
1212
|
-
this.logger.warn('"%s" path with type "%s" is not mergeable.', path, typeof d.data);
|
|
1213
|
-
parsed = d.data;
|
|
1214
|
-
}
|
|
1215
|
-
lock = this.op.set(lock, path, parsed);
|
|
1216
|
-
this.logger.verbose("Merge lock: %s -> %o", path, d.data);
|
|
1217
|
-
return;
|
|
1218
|
-
}
|
|
1219
|
-
lock = this.op.set(lock, path, d.data);
|
|
1220
|
-
this.logger.verbose("Override lock: %s -> %o", path, d.data);
|
|
1221
|
-
});
|
|
1222
|
-
return lock;
|
|
1223
|
-
}
|
|
1224
|
-
async lock(...data) {
|
|
1225
|
-
const lock = await this.applyLock(await this.tryRead() ?? {}, ...data);
|
|
1226
|
-
await this.write(lock);
|
|
1227
|
-
return lock;
|
|
1228
|
-
}
|
|
1229
|
-
async applyUnlock(lock, ...data) {
|
|
1230
|
-
if (data.length > 0) {
|
|
1231
|
-
data.forEach((d) => {
|
|
1232
|
-
if (d?.enabled === false) {
|
|
1233
|
-
return;
|
|
1234
|
-
}
|
|
1235
|
-
const path = this.buildPath(d);
|
|
1236
|
-
lock = op2.del(lock, path);
|
|
1237
|
-
this.logger.verbose("Unlocked: %s", path);
|
|
1238
|
-
for (let i = path.length - 1; i >= 0; i--) {
|
|
1239
|
-
const parentPath = path.slice(0, i);
|
|
1240
|
-
const parent = this.op.get(lock, parentPath);
|
|
1241
|
-
if (!parent || Array.isArray(parent) && parent.length === 0 || typeof parent === "object" && Object.keys(parent).length === 0) {
|
|
1242
|
-
this.logger.verbose("Unlocked parent: %s -> %s", path, parentPath);
|
|
1243
|
-
lock = op2.del(lock, parentPath);
|
|
1244
|
-
} else {
|
|
1245
|
-
break;
|
|
1246
|
-
}
|
|
1247
|
-
}
|
|
1248
|
-
});
|
|
1249
|
-
return lock;
|
|
1250
|
-
}
|
|
1251
|
-
lock = op2.del(lock, this.options.root);
|
|
1252
|
-
this.logger.verbose("Unlocked module: %s", this.options.root);
|
|
1253
|
-
return lock;
|
|
1254
|
-
}
|
|
1255
|
-
async unlock(...data) {
|
|
1256
|
-
const state = await this.tryRead();
|
|
1257
|
-
if (!state) {
|
|
1258
|
-
this.logger.verbose("Lock file not found. Nothing to unlock.");
|
|
1259
|
-
return;
|
|
1260
|
-
}
|
|
1261
|
-
const lock = await this.applyUnlock(state, ...data);
|
|
1262
|
-
await this.write(lock);
|
|
1263
|
-
return lock;
|
|
1264
|
-
}
|
|
1265
|
-
async read() {
|
|
1266
|
-
return this.parser.fetch(this.options.parser).parse(await this.fs.read(this.options.file));
|
|
1267
|
-
}
|
|
1268
|
-
async tryRead() {
|
|
1269
|
-
const lock = await this.fs.read(this.options.file).catch((err) => {
|
|
1270
|
-
this.logger.trace("Can not read lockfile: %s -> %s", this.options.file, err.message);
|
|
1271
|
-
});
|
|
1272
|
-
if (!lock) {
|
|
1273
|
-
return;
|
|
1274
|
-
}
|
|
1275
|
-
return this.parser.fetch(this.options.parser).parse(lock);
|
|
1276
|
-
}
|
|
1277
|
-
async tryRemove() {
|
|
1278
|
-
return this.fs.remove(this.options.file).then(() => {
|
|
1279
|
-
this.logger.trace("Removed lockfile: %s", this.options.file);
|
|
1280
|
-
}).catch((err) => {
|
|
1281
|
-
this.logger.trace("Can not remove lockfile: %s -> %s", this.options.file, err.message);
|
|
1282
|
-
});
|
|
1283
|
-
}
|
|
1284
|
-
async write(data) {
|
|
1285
|
-
if (!data || Array.isArray(data) && data.length === 0 || typeof data === "object" && Object.keys(data).length === 0) {
|
|
1286
|
-
this.logger.trace("Trying to write empty lock file, deleting it instead: %s", this.options.file);
|
|
1287
|
-
return this.fs.remove(this.options.file);
|
|
1288
|
-
}
|
|
1289
|
-
return this.fs.write(this.options.file, this.parser.fetch(this.options.parser).stringify(data));
|
|
1290
|
-
}
|
|
1291
|
-
buildPath(d) {
|
|
1292
|
-
if (d?.root !== true && this.options.root?.length) {
|
|
1293
|
-
return [
|
|
1294
|
-
...this.options.root,
|
|
1295
|
-
...this.normalizePath(d.path)
|
|
1296
|
-
];
|
|
1297
|
-
}
|
|
1298
|
-
return this.normalizePath(d.path);
|
|
1299
|
-
}
|
|
1300
|
-
normalizePath(path) {
|
|
1301
|
-
if (Array.isArray(path)) {
|
|
1302
|
-
return path.map((p) => p.toString());
|
|
1303
|
-
} else if (typeof path === "string") {
|
|
1304
|
-
return path.split(".");
|
|
1305
|
-
}
|
|
1306
|
-
return [];
|
|
1307
|
-
}
|
|
1308
|
-
};
|
|
1309
|
-
__name(_LockerService, "LockerService");
|
|
1310
|
-
var LockerService = _LockerService;
|
|
1311
|
-
LockerService = _ts_decorate13([
|
|
1312
|
-
Injectable9(),
|
|
1313
|
-
_ts_metadata9("design:type", Function),
|
|
1314
|
-
_ts_metadata9("design:paramtypes", [
|
|
1315
|
-
typeof LoggerService === "undefined" ? Object : LoggerService,
|
|
1316
|
-
typeof FileSystemService === "undefined" ? Object : FileSystemService,
|
|
1317
|
-
typeof ParserService === "undefined" ? Object : ParserService,
|
|
1318
|
-
typeof LockerServiceOptions === "undefined" ? Object : LockerServiceOptions
|
|
1319
|
-
])
|
|
1320
|
-
], LockerService);
|
|
1321
|
-
|
|
1322
|
-
// src/lib/locker/locker.module.ts
|
|
1323
|
-
import { Module as Module5 } from "@nestjs/common";
|
|
1324
|
-
function _ts_decorate14(decorators, target, key, desc) {
|
|
1325
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
1326
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
1327
|
-
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;
|
|
1328
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
1329
|
-
}
|
|
1330
|
-
__name(_ts_decorate14, "_ts_decorate");
|
|
1331
|
-
var _LockerModule = class _LockerModule {
|
|
1332
|
-
static forFeature(options) {
|
|
1333
|
-
const token = options.token ?? LockerService;
|
|
1334
|
-
return {
|
|
1335
|
-
module: _LockerModule,
|
|
1336
|
-
providers: [
|
|
1337
|
-
{
|
|
1338
|
-
provide: token,
|
|
1339
|
-
useFactory: /* @__PURE__ */ __name((logger, fs2, parser) => new LockerService(logger, fs2, parser, options), "useFactory"),
|
|
1340
|
-
inject: [
|
|
1341
|
-
LoggerService,
|
|
1342
|
-
FileSystemService,
|
|
1343
|
-
ParserService
|
|
1344
|
-
]
|
|
1345
|
-
}
|
|
1346
|
-
]
|
|
1347
|
-
};
|
|
1348
|
-
}
|
|
1349
|
-
};
|
|
1350
|
-
__name(_LockerModule, "LockerModule");
|
|
1351
|
-
var LockerModule = _LockerModule;
|
|
1352
|
-
LockerModule = _ts_decorate14([
|
|
1353
|
-
Module5({})
|
|
1354
|
-
], LockerModule);
|
|
1355
|
-
|
|
1356
|
-
// src/lib/logo/logo.constants.ts
|
|
1357
|
-
var TOKEN_LOGO_GENERATOR = Symbol("TOKEN_LOGO_GENERATOR");
|
|
1358
|
-
|
|
1359
|
-
// src/lib/logo/logo.module.ts
|
|
1360
|
-
import { Module as Module6 } from "@nestjs/common";
|
|
1361
|
-
|
|
1362
|
-
// src/lib/logo/logo.service.ts
|
|
1363
|
-
import { Injectable as Injectable10 } from "@nestjs/common";
|
|
1364
|
-
import { ModuleRef as ModuleRef2 } from "@nestjs/core";
|
|
1365
|
-
import { EOL as EOL3 } from "os";
|
|
1366
|
-
function _ts_decorate15(decorators, target, key, desc) {
|
|
1367
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
1368
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
1369
|
-
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;
|
|
1370
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
1371
|
-
}
|
|
1372
|
-
__name(_ts_decorate15, "_ts_decorate");
|
|
1373
|
-
function _ts_metadata10(k, v) {
|
|
1374
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
1375
|
-
}
|
|
1376
|
-
__name(_ts_metadata10, "_ts_metadata");
|
|
1377
|
-
var _LogoService = class _LogoService {
|
|
1378
|
-
constructor(cs, moduleRef) {
|
|
1379
|
-
__publicField(this, "cs");
|
|
1380
|
-
__publicField(this, "generator");
|
|
1381
|
-
this.cs = cs;
|
|
1382
|
-
try {
|
|
1383
|
-
this.generator = moduleRef.get(TOKEN_LOGO_GENERATOR, {
|
|
1384
|
-
strict: false
|
|
1385
|
-
});
|
|
1386
|
-
} catch {
|
|
1387
|
-
this.generator = function() {
|
|
1388
|
-
if (this.shouldBeSilent()) {
|
|
1389
|
-
return;
|
|
1390
|
-
}
|
|
1391
|
-
const logo = this.cs.oclif.name + " v" + this.cs.oclif.version;
|
|
1392
|
-
this.write(logo);
|
|
1393
|
-
this.write("-".repeat(logo.length));
|
|
1394
|
-
};
|
|
1395
|
-
}
|
|
1396
|
-
}
|
|
1397
|
-
generate() {
|
|
1398
|
-
return this.generator.call(this);
|
|
1399
|
-
}
|
|
1400
|
-
shouldBeSilent() {
|
|
1401
|
-
return this.cs.isJson || this.cs.isSilent;
|
|
1402
|
-
}
|
|
1403
|
-
write(...data) {
|
|
1404
|
-
process.stdout.write(data.join(" ") + EOL3);
|
|
1405
|
-
}
|
|
1406
|
-
};
|
|
1407
|
-
__name(_LogoService, "LogoService");
|
|
1408
|
-
var LogoService = _LogoService;
|
|
1409
|
-
LogoService = _ts_decorate15([
|
|
1410
|
-
Injectable10(),
|
|
1411
|
-
_ts_metadata10("design:type", Function),
|
|
1412
|
-
_ts_metadata10("design:paramtypes", [
|
|
1413
|
-
typeof ConfigService === "undefined" ? Object : ConfigService,
|
|
1414
|
-
typeof ModuleRef2 === "undefined" ? Object : ModuleRef2
|
|
1415
|
-
])
|
|
1416
|
-
], LogoService);
|
|
1417
|
-
|
|
1418
|
-
// src/lib/logo/logo.module.ts
|
|
1419
|
-
function _ts_decorate16(decorators, target, key, desc) {
|
|
1420
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
1421
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
1422
|
-
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;
|
|
1423
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
1424
|
-
}
|
|
1425
|
-
__name(_ts_decorate16, "_ts_decorate");
|
|
1426
|
-
var _LogoModule = class _LogoModule {
|
|
1427
|
-
};
|
|
1428
|
-
__name(_LogoModule, "LogoModule");
|
|
1429
|
-
var LogoModule = _LogoModule;
|
|
1430
|
-
LogoModule = _ts_decorate16([
|
|
1431
|
-
Module6({
|
|
1432
|
-
providers: [
|
|
1433
|
-
LogoService
|
|
1434
|
-
],
|
|
1435
|
-
exports: [
|
|
1436
|
-
LogoService
|
|
1437
|
-
]
|
|
1438
|
-
})
|
|
1439
|
-
], LogoModule);
|
|
1440
|
-
|
|
1441
|
-
// src/lib/validator/validator.constants.ts
|
|
1442
|
-
var TOKEN_VALIDATOR_SERVICE_OPTIONS = Symbol("TOKEN_VALIDATOR_SERVICE_OPTIONS");
|
|
1443
|
-
|
|
1444
|
-
// src/lib/validator/validator.module.ts
|
|
1445
|
-
import { Global as Global5, Module as Module7 } from "@nestjs/common";
|
|
1446
|
-
|
|
1447
|
-
// src/lib/validator/validator.service.ts
|
|
1448
|
-
import { Injectable as Injectable11 } from "@nestjs/common";
|
|
1449
|
-
import { ModuleRef as ModuleRef3 } from "@nestjs/core";
|
|
1450
|
-
import { plainToClass } from "class-transformer";
|
|
1451
|
-
import { validate, validateSync } from "class-validator";
|
|
1452
|
-
function _ts_decorate17(decorators, target, key, desc) {
|
|
1453
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
1454
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
1455
|
-
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;
|
|
1456
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
1457
|
-
}
|
|
1458
|
-
__name(_ts_decorate17, "_ts_decorate");
|
|
1459
|
-
function _ts_metadata11(k, v) {
|
|
1460
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
1461
|
-
}
|
|
1462
|
-
__name(_ts_metadata11, "_ts_metadata");
|
|
1463
|
-
var _ValidatorService = class _ValidatorService {
|
|
1464
|
-
constructor(logger, moduleRef) {
|
|
1465
|
-
__publicField(this, "logger");
|
|
1466
|
-
__publicField(this, "options");
|
|
1467
|
-
this.logger = logger;
|
|
1468
|
-
this.logger.setup(this.constructor.name);
|
|
1469
|
-
try {
|
|
1470
|
-
this.options = moduleRef.get(TOKEN_VALIDATOR_SERVICE_OPTIONS, {
|
|
1471
|
-
strict: false
|
|
1472
|
-
});
|
|
1473
|
-
} catch {
|
|
1474
|
-
this.options = {
|
|
1475
|
-
validator: {
|
|
1476
|
-
skipMissingProperties: true,
|
|
1477
|
-
whitelist: false,
|
|
1478
|
-
always: true,
|
|
1479
|
-
enableDebugMessages: true
|
|
1480
|
-
},
|
|
1481
|
-
transformer: {
|
|
1482
|
-
enableImplicitConversion: true
|
|
1483
|
-
}
|
|
1484
|
-
};
|
|
1485
|
-
}
|
|
1486
|
-
}
|
|
1487
|
-
async validate(classType, object, options) {
|
|
1488
|
-
const classObject = plainToClass(classType, object, {
|
|
1489
|
-
...this.options.transformer,
|
|
1490
|
-
...options?.transformer ?? {}
|
|
1491
|
-
});
|
|
1492
|
-
const errors = await validate(classObject, {
|
|
1493
|
-
...this.options.validator,
|
|
1494
|
-
...options?.validator ?? {}
|
|
1495
|
-
});
|
|
1496
|
-
if (errors.length) {
|
|
1497
|
-
errors.forEach((error) => {
|
|
1498
|
-
this.logValidationError(error);
|
|
1499
|
-
});
|
|
1500
|
-
throw new Error("Validation failed.");
|
|
1501
|
-
}
|
|
1502
|
-
return classObject;
|
|
1503
|
-
}
|
|
1504
|
-
validateSync(classType, object, options) {
|
|
1505
|
-
const classObject = plainToClass(classType, object, {
|
|
1506
|
-
...this.options.transformer,
|
|
1507
|
-
...options?.transformer ?? {}
|
|
1508
|
-
});
|
|
1509
|
-
const errors = validateSync(classObject, {
|
|
1510
|
-
...this.options.validator,
|
|
1511
|
-
...options?.validator ?? {}
|
|
1512
|
-
});
|
|
1513
|
-
if (errors.length) {
|
|
1514
|
-
errors.forEach((error) => {
|
|
1515
|
-
this.logValidationError(error);
|
|
1516
|
-
});
|
|
1517
|
-
throw new Error("Validation failed.");
|
|
1518
|
-
}
|
|
1519
|
-
return classObject;
|
|
1520
|
-
}
|
|
1521
|
-
logValidationError(err) {
|
|
1522
|
-
this.logger.error('Field "%s" failed validation with value "%s": %o', err.property, err.value, err.constraints);
|
|
1523
|
-
if (err.children) {
|
|
1524
|
-
err.children.forEach((children) => this.logValidationError(children));
|
|
1525
|
-
}
|
|
1526
|
-
}
|
|
1527
|
-
};
|
|
1528
|
-
__name(_ValidatorService, "ValidatorService");
|
|
1529
|
-
var ValidatorService = _ValidatorService;
|
|
1530
|
-
ValidatorService = _ts_decorate17([
|
|
1531
|
-
Injectable11(),
|
|
1532
|
-
_ts_metadata11("design:type", Function),
|
|
1533
|
-
_ts_metadata11("design:paramtypes", [
|
|
1534
|
-
typeof LoggerService === "undefined" ? Object : LoggerService,
|
|
1535
|
-
typeof ModuleRef3 === "undefined" ? Object : ModuleRef3
|
|
1536
|
-
])
|
|
1537
|
-
], ValidatorService);
|
|
1538
|
-
|
|
1539
|
-
// src/lib/validator/validator.module.ts
|
|
1540
|
-
function _ts_decorate18(decorators, target, key, desc) {
|
|
1541
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
1542
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
1543
|
-
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;
|
|
1544
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
1545
|
-
}
|
|
1546
|
-
__name(_ts_decorate18, "_ts_decorate");
|
|
1547
|
-
var _ValidatorModule = class _ValidatorModule {
|
|
1548
|
-
};
|
|
1549
|
-
__name(_ValidatorModule, "ValidatorModule");
|
|
1550
|
-
var ValidatorModule = _ValidatorModule;
|
|
1551
|
-
ValidatorModule = _ts_decorate18([
|
|
1552
|
-
Global5(),
|
|
1553
|
-
Module7({
|
|
1554
|
-
providers: [
|
|
1555
|
-
ValidatorService
|
|
1556
|
-
],
|
|
1557
|
-
exports: [
|
|
1558
|
-
ValidatorService
|
|
1559
|
-
]
|
|
1560
|
-
})
|
|
1561
|
-
], ValidatorModule);
|
|
1562
|
-
|
|
1563
|
-
// src/lib/setup.ts
|
|
1564
|
-
async function setup() {
|
|
1565
|
-
const inspect = process.argv.indexOf("--inspect");
|
|
1566
|
-
if (inspect !== -1) {
|
|
1567
|
-
await import("inspector").then((mod) => mod.open());
|
|
1568
|
-
process.argv.splice(inspect, 1);
|
|
1569
|
-
}
|
|
1570
|
-
const sourceMaps = process.argv.indexOf("--source-map");
|
|
1571
|
-
if (sourceMaps !== -1) {
|
|
1572
|
-
await import("source-map-support").then((mod) => mod.install());
|
|
1573
|
-
process.argv.splice(sourceMaps, 1);
|
|
1574
|
-
}
|
|
1575
|
-
}
|
|
1576
|
-
__name(setup, "setup");
|
|
1577
|
-
|
|
1578
|
-
// src/lib/cli.module.ts
|
|
1579
|
-
import { NestFactory } from "@nestjs/core";
|
|
1580
|
-
var _CliModule = class _CliModule {
|
|
1581
|
-
static forRoot(options) {
|
|
1582
|
-
return {
|
|
1583
|
-
module: _CliModule,
|
|
1584
|
-
global: true,
|
|
1585
|
-
imports: [
|
|
1586
|
-
ConfigModule,
|
|
1587
|
-
LoggerModule,
|
|
1588
|
-
FilesystemModule,
|
|
1589
|
-
ParserModule,
|
|
1590
|
-
LogoModule
|
|
1591
|
-
],
|
|
1592
|
-
providers: [
|
|
1593
|
-
{
|
|
1594
|
-
provide: TOKEN_CONFIG_MODULE_OPTIONS,
|
|
1595
|
-
useValue: options.config
|
|
1596
|
-
}
|
|
1597
|
-
],
|
|
1598
|
-
exports: [
|
|
1599
|
-
TOKEN_CONFIG_MODULE_OPTIONS
|
|
1600
|
-
]
|
|
1601
|
-
};
|
|
1602
|
-
}
|
|
1603
|
-
static forMinimum() {
|
|
1604
|
-
return {
|
|
1605
|
-
module: _CliModule,
|
|
1606
|
-
global: true,
|
|
1607
|
-
imports: [
|
|
1608
|
-
LoggerModule
|
|
1609
|
-
],
|
|
1610
|
-
providers: [
|
|
1611
|
-
{
|
|
1612
|
-
provide: TOKEN_CONFIG_MODULE_OPTIONS,
|
|
1613
|
-
useValue: {
|
|
1614
|
-
config: {
|
|
1615
|
-
logLevel: LogLevels.INFO,
|
|
1616
|
-
isJson: false
|
|
1617
|
-
}
|
|
1618
|
-
}
|
|
1619
|
-
}
|
|
1620
|
-
],
|
|
1621
|
-
exports: [
|
|
1622
|
-
TOKEN_CONFIG_MODULE_OPTIONS
|
|
1623
|
-
]
|
|
1624
|
-
};
|
|
1625
|
-
}
|
|
1626
|
-
static create(cls) {
|
|
1627
|
-
return NestFactory.createApplicationContext(cls, {
|
|
1628
|
-
logger: [
|
|
1629
|
-
"error"
|
|
1630
|
-
]
|
|
1631
|
-
});
|
|
1632
|
-
}
|
|
1633
|
-
};
|
|
1634
|
-
__name(_CliModule, "CliModule");
|
|
1635
|
-
var CliModule = _CliModule;
|
|
1636
|
-
|
|
1637
|
-
// src/commands/base.command.ts
|
|
1638
|
-
import "reflect-metadata";
|
|
1639
|
-
var _Command = class _Command extends BaseCommand {
|
|
1640
|
-
constructor() {
|
|
1641
|
-
super(...arguments);
|
|
1642
|
-
__publicField(this, "logger");
|
|
1643
|
-
__publicField(this, "tasks");
|
|
1644
|
-
__publicField(this, "app");
|
|
1645
|
-
__publicField(this, "flags");
|
|
1646
|
-
__publicField(this, "args");
|
|
1647
|
-
}
|
|
1648
|
-
exit(code) {
|
|
1649
|
-
this.logger.trace("Code -> %d", code, {
|
|
1650
|
-
status: LogFieldStatus.EXIT
|
|
1651
|
-
});
|
|
1652
|
-
super.exit(code ?? 0);
|
|
1653
|
-
}
|
|
1654
|
-
/** Run all tasks from task manager. */
|
|
1655
|
-
runTasks() {
|
|
1656
|
-
return this.tasks.runAll();
|
|
1657
|
-
}
|
|
1658
|
-
setCtxDefaults(...defaults) {
|
|
1659
|
-
setCtxDefaults(this.tasks.options.ctx, ...defaults);
|
|
1660
|
-
this.logger.trace("Updated context with defaults: %o", this.tasks.options.ctx, {
|
|
1661
|
-
status: "ctx"
|
|
1662
|
-
});
|
|
1663
|
-
}
|
|
1664
|
-
setCtxAssign(...assigns) {
|
|
1665
|
-
setCtxAssign(this.tasks.options.ctx, ...assigns);
|
|
1666
|
-
this.logger.trace("Updated context with assign: %o", this.tasks.options.ctx, {
|
|
1667
|
-
status: "ctx"
|
|
1668
|
-
});
|
|
1669
|
-
}
|
|
1670
|
-
pipeProcessToLogger(instance, options) {
|
|
1671
|
-
return pipeProcessToLogger(this.logger, instance, options);
|
|
1672
|
-
}
|
|
1673
|
-
pipeProcessThroughListr(instance, task) {
|
|
1674
|
-
return pipeProcessThroughListr(task, instance);
|
|
1675
|
-
}
|
|
1676
|
-
/** Initial functions / constructor */
|
|
1677
|
-
// can not override constructor, init function is defined by oclif
|
|
1678
|
-
async init() {
|
|
1679
|
-
await super.init();
|
|
1680
|
-
let err;
|
|
1681
|
-
try {
|
|
1682
|
-
const { args, flags } = await this.parse({
|
|
1683
|
-
flags: this.ctor.flags,
|
|
1684
|
-
baseFlags: super.ctor.baseFlags,
|
|
1685
|
-
enableJsonFlag: this.ctor.enableJsonFlag,
|
|
1686
|
-
args: this.ctor.args,
|
|
1687
|
-
strict: this.ctor.strict
|
|
1688
|
-
});
|
|
1689
|
-
this.flags = flags;
|
|
1690
|
-
this.args = args;
|
|
1691
|
-
} catch (e) {
|
|
1692
|
-
err = e;
|
|
1693
|
-
}
|
|
1694
|
-
const options = {
|
|
1695
|
-
config: {
|
|
1696
|
-
oclif: this.config,
|
|
1697
|
-
command: this.ctor,
|
|
1698
|
-
config: {
|
|
1699
|
-
logLevel: this.flags?.["log-level"] ?? LogLevels.INFO,
|
|
1700
|
-
isJson: this.flags?.json ?? false
|
|
1701
|
-
}
|
|
1702
|
-
}
|
|
1703
|
-
};
|
|
1704
|
-
const cli = CliModule.forRoot(options);
|
|
1705
|
-
this.app = await CliModule.create(!err && isHookedWithRegister(this) ? await this.register(cli, options) : cli);
|
|
1706
|
-
const cs = this.app.get(ConfigService);
|
|
1707
|
-
this.logger = await this.app.resolve(LoggerService);
|
|
1708
|
-
this.app.useLogger(this.logger);
|
|
1709
|
-
this.app.get(LogoService).generate();
|
|
1710
|
-
if (err) {
|
|
1711
|
-
throw err;
|
|
1712
|
-
}
|
|
1713
|
-
this.logger.stage("Created application context.");
|
|
1714
|
-
this.tasks = new Manager({
|
|
1715
|
-
fallbackRendererCondition: cs.isDebug,
|
|
1716
|
-
silentRendererCondition: cs.isSilent || cs.isJson,
|
|
1717
|
-
ctx: {}
|
|
1718
|
-
});
|
|
1719
|
-
if (cs.oclif.windows) {
|
|
1720
|
-
createInterface({
|
|
1721
|
-
input: process.stdin,
|
|
1722
|
-
output: process.stdout
|
|
1723
|
-
}).on("SIGINT", () => {
|
|
1724
|
-
process.kill(process.pid, "SIGINT");
|
|
1725
|
-
});
|
|
1726
|
-
}
|
|
1727
|
-
const terminate = /* @__PURE__ */ __name(() => {
|
|
1728
|
-
this.logger.fatal("Caught terminate signal.", {
|
|
1729
|
-
status: LogFieldStatus.TERMINATE
|
|
1730
|
-
});
|
|
1731
|
-
process.exit(1);
|
|
1732
|
-
}, "terminate");
|
|
1733
|
-
process.on("SIGINT", terminate);
|
|
1734
|
-
process.on("SIGTERM", terminate);
|
|
1735
|
-
if (isHookedWithShouldRunBefore(this)) {
|
|
1736
|
-
this.logger.stage("Running hook should-run-before.");
|
|
1737
|
-
await this.shouldRunBefore();
|
|
1738
|
-
this.logger.stage("Finished hook should-run-before.");
|
|
1739
|
-
}
|
|
1740
|
-
}
|
|
1741
|
-
/** Tasks to run before end of the command. */
|
|
1742
|
-
async finally(err) {
|
|
1743
|
-
let ctx;
|
|
1744
|
-
if (err) {
|
|
1745
|
-
return {
|
|
1746
|
-
ctx
|
|
1747
|
-
};
|
|
1748
|
-
}
|
|
1749
|
-
if (this.tasks?.tasks?.length > 0) {
|
|
1750
|
-
this.logger.stage("Running tasks.");
|
|
1751
|
-
ctx = await this.runTasks();
|
|
1752
|
-
this.logger.stage("Finished tasks.");
|
|
1753
|
-
}
|
|
1754
|
-
if (isHookedWithShouldRunAfter(this)) {
|
|
1755
|
-
this.logger.stage("Running hook should-run-after.");
|
|
1756
|
-
await this.shouldRunAfter(ctx);
|
|
1757
|
-
this.logger.stage("Finished hook should-run-after.");
|
|
1758
|
-
}
|
|
1759
|
-
return {
|
|
1760
|
-
ctx
|
|
1761
|
-
};
|
|
1762
|
-
}
|
|
1763
|
-
/** Catch any error occurred during command. */
|
|
1764
|
-
// catch all those errors, not verbose
|
|
1765
|
-
async catch(err) {
|
|
1766
|
-
process.exitCode = process.exitCode ?? err.exitCode ?? 1;
|
|
1767
|
-
if (!this.logger) {
|
|
1768
|
-
this.app = await CliModule.create(CliModule.forMinimum());
|
|
1769
|
-
this.logger = await this.app.resolve(LoggerService);
|
|
1770
|
-
}
|
|
1771
|
-
this.logger.fatal(err.message);
|
|
1772
|
-
this.logger.debug(err.stack, {
|
|
1773
|
-
context: "crash"
|
|
1774
|
-
});
|
|
1775
|
-
throw err;
|
|
1776
|
-
}
|
|
1777
|
-
};
|
|
1778
|
-
__name(_Command, "Command");
|
|
1779
|
-
__publicField(_Command, "baseFlags", {
|
|
1780
|
-
["log-level"]: Flags.string({
|
|
1781
|
-
default: LogLevels.INFO,
|
|
1782
|
-
env: "LOG_LEVEL",
|
|
1783
|
-
description: "Set the log level of the application.",
|
|
1784
|
-
options: Object.values(LogLevels).map((level) => level.toLowerCase()),
|
|
1785
|
-
helpGroup: HelpGroups.CLI,
|
|
1786
|
-
parse: /* @__PURE__ */ __name(async (input) => input?.toUpperCase(), "parse")
|
|
1787
|
-
}),
|
|
1788
|
-
ci: Flags.boolean({
|
|
1789
|
-
default: false,
|
|
1790
|
-
hidden: true,
|
|
1791
|
-
env: "CI",
|
|
1792
|
-
description: "Instruct whether this is running the CI/CD configuration.",
|
|
1793
|
-
helpGroup: HelpGroups.CLI
|
|
1794
|
-
}),
|
|
1795
|
-
json: Flags.boolean({
|
|
1796
|
-
default: false,
|
|
1797
|
-
hidden: true,
|
|
1798
|
-
env: "JSON",
|
|
1799
|
-
description: "Put the CLI to respond in JSON.",
|
|
1800
|
-
helpGroup: HelpGroups.CLI
|
|
1801
|
-
})
|
|
1802
|
-
});
|
|
1803
|
-
var Command = _Command;
|
|
1804
|
-
|
|
1805
|
-
// src/hooks/not-found.hook.ts
|
|
1806
|
-
import { Help } from "@oclif/core";
|
|
1807
|
-
var notFoundHook = /* @__PURE__ */ __name(async (opts) => {
|
|
1808
|
-
const app = await CliModule.create(CliModule.forMinimum());
|
|
1809
|
-
const logger = await app.resolve(LoggerService);
|
|
1810
|
-
logger.error("Command not found. Take a look at help. You can also use --[h]elp flag for subcommands.");
|
|
1811
|
-
logger.direct("");
|
|
1812
|
-
const help = new Help(opts.config);
|
|
1813
|
-
await help.showHelp([
|
|
1814
|
-
"--all"
|
|
1815
|
-
]);
|
|
1816
|
-
opts.context.exit(127);
|
|
1817
|
-
}, "notFoundHook");
|
|
1818
|
-
|
|
1819
|
-
// src/hooks/update-notifier.hook.ts
|
|
1820
|
-
var updateNotifierHook = /* @__PURE__ */ __name(async (opts) => {
|
|
1821
|
-
const { default: notifier } = await import("update-notifier");
|
|
1822
|
-
notifier({
|
|
1823
|
-
pkg: {
|
|
1824
|
-
name: opts.config.name,
|
|
1825
|
-
version: opts.config.version
|
|
1826
|
-
}
|
|
1827
|
-
}).notify({
|
|
1828
|
-
isGlobal: true
|
|
1829
|
-
});
|
|
1830
|
-
}, "updateNotifierHook");
|
|
1831
|
-
|
|
1832
|
-
// src/interfaces/oclif.interface.ts
|
|
1833
|
-
import { Flags as Flags2, Args } from "@oclif/core";
|
|
1834
|
-
export {
|
|
1835
|
-
Args,
|
|
1836
|
-
CliModule,
|
|
1837
|
-
Command,
|
|
1838
|
-
ConfigModule,
|
|
1839
|
-
ConfigService,
|
|
1840
|
-
EnvironmentVariableParser,
|
|
1841
|
-
FileConstants,
|
|
1842
|
-
FileSystemService,
|
|
1843
|
-
FilesystemModule,
|
|
1844
|
-
Flags2 as Flags,
|
|
1845
|
-
HelpGroups,
|
|
1846
|
-
Inject3 as Inject,
|
|
1847
|
-
JsonParser,
|
|
1848
|
-
LockerModule,
|
|
1849
|
-
LockerService,
|
|
1850
|
-
LogFieldStatus,
|
|
1851
|
-
LogLevels,
|
|
1852
|
-
LoggerModule,
|
|
1853
|
-
LoggerService,
|
|
1854
|
-
LogoModule,
|
|
1855
|
-
LogoService,
|
|
1856
|
-
MergeStrategy,
|
|
1857
|
-
ParserModule,
|
|
1858
|
-
ParserService,
|
|
1859
|
-
TOKEN_LOGO_GENERATOR,
|
|
1860
|
-
TOKEN_VALIDATOR_SERVICE_OPTIONS,
|
|
1861
|
-
ValidatorModule,
|
|
1862
|
-
ValidatorService,
|
|
1863
|
-
WinstonService,
|
|
1864
|
-
YamlParser,
|
|
1865
|
-
isDebug,
|
|
1866
|
-
isHookedWithRegister,
|
|
1867
|
-
isHookedWithShouldRunAfter,
|
|
1868
|
-
isHookedWithShouldRunBefore,
|
|
1869
|
-
isSilent,
|
|
1870
|
-
isVerbose,
|
|
1871
|
-
merge,
|
|
1872
|
-
notFoundHook,
|
|
1873
|
-
pipeProcessThroughListr,
|
|
1874
|
-
pipeProcessToLogger,
|
|
1875
|
-
setCtxAssign,
|
|
1876
|
-
setCtxDefaults,
|
|
1877
|
-
setup,
|
|
1878
|
-
uniqueArrayFilter,
|
|
1879
|
-
updateNotifierHook,
|
|
1880
|
-
ux
|
|
1881
|
-
};
|
|
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";
|
|
43
|
+
|
|
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 };
|