@cenk1cenk2/oclif-common 6.3.30 → 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 -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 +26 -22
- package/dist/chunk-DzC9Nte8.js +0 -31
- package/dist/source-map-support-CuBekda-.js +0 -2435
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { CliModuleOptions } from "../lib/cli.interface.js";
|
|
2
|
+
import { DynamicModule } from "@nestjs/common";
|
|
3
|
+
import { ListrContext } from "listr2";
|
|
4
|
+
|
|
5
|
+
//#region src/interfaces/hooks.interface.d.ts
|
|
6
|
+
declare class ShouldRunBeforeHook {
|
|
7
|
+
shouldRunBefore(): void | Promise<void>;
|
|
8
|
+
}
|
|
9
|
+
declare class ShouldRunAfterHook<Ctx extends ListrContext = ListrContext> {
|
|
10
|
+
shouldRunAfter(ctx: Ctx): void | Promise<void>;
|
|
11
|
+
}
|
|
12
|
+
declare class RegisterHook {
|
|
13
|
+
register(cli: DynamicModule, options: CliModuleOptions): DynamicModule | Promise<DynamicModule>;
|
|
14
|
+
}
|
|
15
|
+
//#endregion
|
|
16
|
+
export { RegisterHook, ShouldRunAfterHook, ShouldRunBeforeHook };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import { Args, Flags } from "./oclif.interface.js";
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Args, Command, Flags as Flags$1, Interfaces } from "@oclif/core";
|
|
2
|
+
import { Flag, InferredFlags } from "@oclif/core/lib/interfaces";
|
|
3
|
+
import { Arg, ArgInput, FlagInput } from "@oclif/core/lib/interfaces/parser";
|
|
4
|
+
|
|
5
|
+
//#region src/interfaces/oclif.interface.d.ts
|
|
6
|
+
type InferFlags<T extends typeof Command> = Interfaces.InferredFlags<(typeof Command)['baseFlags'] & T['flags']>;
|
|
7
|
+
type InferArgs<T extends typeof Command> = Interfaces.InferredArgs<T['args']>;
|
|
8
|
+
//#endregion
|
|
9
|
+
export { type Arg, type ArgInput, Args, type Flag, type FlagInput, Flags$1 as Flags, InferArgs, InferFlags, type InferredFlags };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { CliModuleOptions } from "./cli.interface.js";
|
|
2
|
+
import { DynamicModule, INestApplicationContext } from "@nestjs/common";
|
|
3
|
+
|
|
4
|
+
//#region src/lib/cli.module.d.ts
|
|
5
|
+
declare class CliModule {
|
|
6
|
+
static forRoot(options: CliModuleOptions): DynamicModule;
|
|
7
|
+
static forMinimum(): DynamicModule;
|
|
8
|
+
static create(cls: DynamicModule): Promise<INestApplicationContext>;
|
|
9
|
+
}
|
|
10
|
+
//#endregion
|
|
11
|
+
export { CliModule };
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { TOKEN_CONFIG_MODULE_OPTIONS } from "./config/config.constants.js";
|
|
2
|
+
import { LogLevels } from "./logger/logger.constants.js";
|
|
3
|
+
import { LoggerModule } from "./logger/logger.module.js";
|
|
4
|
+
import "./logger/index.js";
|
|
5
|
+
import { FilesystemModule } from "./fs/filesystem.module.js";
|
|
6
|
+
import "./fs/index.js";
|
|
7
|
+
import { ParserModule } from "./parser/parser.module.js";
|
|
8
|
+
import { ConfigModule } from "./config/config.module.js";
|
|
9
|
+
import "./config/index.js";
|
|
10
|
+
import "./parser/index.js";
|
|
11
|
+
import { LogoModule } from "./logo/logo.module.js";
|
|
12
|
+
import "./logo/index.js";
|
|
13
|
+
import { NestFactory } from "@nestjs/core";
|
|
14
|
+
|
|
15
|
+
//#region src/lib/cli.module.ts
|
|
16
|
+
var CliModule = class CliModule {
|
|
17
|
+
static forRoot(options) {
|
|
18
|
+
return {
|
|
19
|
+
module: CliModule,
|
|
20
|
+
global: true,
|
|
21
|
+
imports: [
|
|
22
|
+
ConfigModule,
|
|
23
|
+
LoggerModule,
|
|
24
|
+
FilesystemModule,
|
|
25
|
+
ParserModule,
|
|
26
|
+
LogoModule
|
|
27
|
+
],
|
|
28
|
+
providers: [{
|
|
29
|
+
provide: TOKEN_CONFIG_MODULE_OPTIONS,
|
|
30
|
+
useValue: options.config
|
|
31
|
+
}],
|
|
32
|
+
exports: [TOKEN_CONFIG_MODULE_OPTIONS]
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
static forMinimum() {
|
|
36
|
+
return {
|
|
37
|
+
module: CliModule,
|
|
38
|
+
global: true,
|
|
39
|
+
imports: [LoggerModule],
|
|
40
|
+
providers: [{
|
|
41
|
+
provide: TOKEN_CONFIG_MODULE_OPTIONS,
|
|
42
|
+
useValue: { config: {
|
|
43
|
+
logLevel: LogLevels.INFO,
|
|
44
|
+
isJson: false
|
|
45
|
+
} }
|
|
46
|
+
}],
|
|
47
|
+
exports: [TOKEN_CONFIG_MODULE_OPTIONS]
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
static create(cls) {
|
|
51
|
+
if (process.env.LOG_LEVEL === "trace") process.env.NEST_DEBUG = "true";
|
|
52
|
+
return NestFactory.createApplicationContext(cls, { logger: [process.env.LOG_LEVEL === "trace" ? "debug" : "error"] });
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
//#endregion
|
|
57
|
+
export { CliModule };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
//#region src/lib/config/config.constants.ts
|
|
2
|
+
let ConfigEnvKeys = /* @__PURE__ */ function(ConfigEnvKeys$1) {
|
|
3
|
+
ConfigEnvKeys$1["NAME"] = "__name";
|
|
4
|
+
ConfigEnvKeys$1["PARSER"] = "__format";
|
|
5
|
+
ConfigEnvKeys$1["ELEMENT"] = "__element";
|
|
6
|
+
ConfigEnvKeys$1["ELEMENT_REPLACER"] = "${i}";
|
|
7
|
+
return ConfigEnvKeys$1;
|
|
8
|
+
}({});
|
|
9
|
+
const TOKEN_CONFIG_MODULE_OPTIONS = Symbol("TOKEN_CONFIG_MODULE_OPTIONS");
|
|
10
|
+
|
|
11
|
+
//#endregion
|
|
12
|
+
export { ConfigEnvKeys, TOKEN_CONFIG_MODULE_OPTIONS };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { LogLevels } from "../logger/logger.constants.js";
|
|
2
|
+
import { Command, Config } from "@oclif/core";
|
|
3
|
+
|
|
4
|
+
//#region src/lib/config/config.interface.d.ts
|
|
5
|
+
interface GlobalConfig {
|
|
6
|
+
logLevel: LogLevels;
|
|
7
|
+
isJson: boolean;
|
|
8
|
+
}
|
|
9
|
+
interface ConfigIterator {
|
|
10
|
+
key: (string | number)[];
|
|
11
|
+
env: string;
|
|
12
|
+
parser?: string;
|
|
13
|
+
extensions?: ConfigIterator[];
|
|
14
|
+
}
|
|
15
|
+
interface ConfigModuleOptions {
|
|
16
|
+
oclif?: Config;
|
|
17
|
+
command?: typeof Command;
|
|
18
|
+
config: GlobalConfig;
|
|
19
|
+
}
|
|
20
|
+
//#endregion
|
|
21
|
+
export { ConfigIterator, ConfigModuleOptions, GlobalConfig };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { ConfigService } from "./config.service.js";
|
|
2
|
+
import { ParserModule } from "../parser/parser.module.js";
|
|
3
|
+
import { Global, Module } from "@nestjs/common";
|
|
4
|
+
import _decorate from "@oxc-project/runtime/helpers/decorate";
|
|
5
|
+
|
|
6
|
+
//#region src/lib/config/config.module.ts
|
|
7
|
+
let ConfigModule = class ConfigModule$1 {};
|
|
8
|
+
ConfigModule = _decorate([Global(), Module({
|
|
9
|
+
imports: [ParserModule],
|
|
10
|
+
providers: [ConfigService],
|
|
11
|
+
exports: [ConfigService]
|
|
12
|
+
})], ConfigModule);
|
|
13
|
+
|
|
14
|
+
//#endregion
|
|
15
|
+
export { ConfigModule };
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { ConfigModuleOptions, GlobalConfig } from "./config.interface.js";
|
|
2
|
+
import { LoggerService } from "../logger/logger.service.js";
|
|
3
|
+
import { ParserService } from "../parser/parser.service.js";
|
|
4
|
+
import { MergeStrategy } from "../../utils/merge.constants.js";
|
|
5
|
+
import { LockableData } from "../locker/locker.interface.js";
|
|
6
|
+
import { OnModuleInit } from "@nestjs/common";
|
|
7
|
+
import { Command, Config } from "@oclif/core";
|
|
8
|
+
|
|
9
|
+
//#region src/lib/config/config.service.d.ts
|
|
10
|
+
declare class ConfigService implements OnModuleInit {
|
|
11
|
+
private readonly parser;
|
|
12
|
+
private readonly logger;
|
|
13
|
+
private options;
|
|
14
|
+
defaults: string;
|
|
15
|
+
root: string;
|
|
16
|
+
config: GlobalConfig;
|
|
17
|
+
oclif: Config;
|
|
18
|
+
command: typeof Command;
|
|
19
|
+
constructor(parser: ParserService, logger: LoggerService, options: ConfigModuleOptions);
|
|
20
|
+
onModuleInit(): Promise<void>;
|
|
21
|
+
get isVerbose(): boolean;
|
|
22
|
+
get isDebug(): boolean;
|
|
23
|
+
get isSilent(): boolean;
|
|
24
|
+
get isJson(): boolean;
|
|
25
|
+
read<T extends LockableData = LockableData>(path: string): Promise<T>;
|
|
26
|
+
extend<T extends LockableData = LockableData>(paths: (string | Partial<T>)[], strategy?: MergeStrategy): Promise<T>;
|
|
27
|
+
merge<T extends LockableData = LockableData>(configs: Partial<T>[], strategy?: MergeStrategy): T;
|
|
28
|
+
env<T extends LockableData = LockableData>(definition: string | Record<PropertyKey, any>, config: T): Promise<T>;
|
|
29
|
+
write<T extends LockableData = LockableData>(path: string, data: T): Promise<void>;
|
|
30
|
+
}
|
|
31
|
+
//#endregion
|
|
32
|
+
export { ConfigService };
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
import { FileConstants } from "../../constants/file.constants.js";
|
|
2
|
+
import { ConfigEnvKeys, TOKEN_CONFIG_MODULE_OPTIONS } from "./config.constants.js";
|
|
3
|
+
import { LoggerService } from "../logger/logger.service.js";
|
|
4
|
+
import "../logger/index.js";
|
|
5
|
+
import { ParserService } from "../parser/parser.service.js";
|
|
6
|
+
import { isDebug, isSilent, isVerbose } from "../../utils/environment.js";
|
|
7
|
+
import { MergeStrategy } from "../../utils/merge.constants.js";
|
|
8
|
+
import { merge } from "../../utils/merge.js";
|
|
9
|
+
import "../../utils/index.js";
|
|
10
|
+
import { Inject, Injectable } from "@nestjs/common";
|
|
11
|
+
import op from "object-path-immutable";
|
|
12
|
+
import { join } from "path";
|
|
13
|
+
import _decorateMetadata from "@oxc-project/runtime/helpers/decorateMetadata";
|
|
14
|
+
import _decorateParam from "@oxc-project/runtime/helpers/decorateParam";
|
|
15
|
+
import _decorate from "@oxc-project/runtime/helpers/decorate";
|
|
16
|
+
|
|
17
|
+
//#region src/lib/config/config.service.ts
|
|
18
|
+
var _ref, _ref2;
|
|
19
|
+
let ConfigService = class ConfigService$1 {
|
|
20
|
+
constructor(parser, logger, options) {
|
|
21
|
+
this.parser = parser;
|
|
22
|
+
this.logger = logger;
|
|
23
|
+
this.options = options;
|
|
24
|
+
}
|
|
25
|
+
async onModuleInit() {
|
|
26
|
+
this.root = this.options.oclif?.root;
|
|
27
|
+
this.defaults = join(this.options.oclif?.root, FileConstants.CONFIG_SERVICE_DEFAULTS_DIR);
|
|
28
|
+
this.oclif = this.options.oclif;
|
|
29
|
+
this.config = this.options.config;
|
|
30
|
+
this.command = this.options.command;
|
|
31
|
+
this.logger.setup(this.constructor.name);
|
|
32
|
+
}
|
|
33
|
+
get isVerbose() {
|
|
34
|
+
return isVerbose(this.config.logLevel);
|
|
35
|
+
}
|
|
36
|
+
get isDebug() {
|
|
37
|
+
return isDebug(this.config.logLevel);
|
|
38
|
+
}
|
|
39
|
+
get isSilent() {
|
|
40
|
+
return isSilent(this.config.logLevel);
|
|
41
|
+
}
|
|
42
|
+
get isJson() {
|
|
43
|
+
return this.config.isJson;
|
|
44
|
+
}
|
|
45
|
+
async read(path) {
|
|
46
|
+
const config = await this.parser.read(path);
|
|
47
|
+
this.logger.trace("Read config from: %s", path);
|
|
48
|
+
return config;
|
|
49
|
+
}
|
|
50
|
+
async extend(paths, strategy = MergeStrategy.OVERWRITE) {
|
|
51
|
+
this.logger.trace("Will generate config from: %o with %s", paths, strategy);
|
|
52
|
+
const configs = (await Promise.all(paths.map(async (path) => {
|
|
53
|
+
try {
|
|
54
|
+
const config = typeof path === "string" ? await this.parser.read(path) : path;
|
|
55
|
+
this.logger.trace("Extending config from: %s", path);
|
|
56
|
+
return config;
|
|
57
|
+
} catch (e) {
|
|
58
|
+
this.logger.trace("Failed to extend config from: %s", e.message);
|
|
59
|
+
}
|
|
60
|
+
}))).filter(Boolean);
|
|
61
|
+
return this.merge(configs, strategy);
|
|
62
|
+
}
|
|
63
|
+
merge(configs, strategy = MergeStrategy.OVERWRITE) {
|
|
64
|
+
if (configs.length === 0) throw new Error("Nothing to merge, configuration files are empty.");
|
|
65
|
+
return merge(strategy, ...configs);
|
|
66
|
+
}
|
|
67
|
+
async env(definition, config) {
|
|
68
|
+
const env = typeof definition === "string" ? await this.parser.read(definition) : definition;
|
|
69
|
+
this.logger.trace("Environment variable extensions read: %o", definition);
|
|
70
|
+
const iter = async (obj, parent) => {
|
|
71
|
+
const data = await Promise.all(Object.entries(obj).map(async ([key, value]) => {
|
|
72
|
+
const location = [...parent ?? [], key];
|
|
73
|
+
if (typeof value === "string") return [{
|
|
74
|
+
key: location,
|
|
75
|
+
env: value
|
|
76
|
+
}];
|
|
77
|
+
else if (typeof value === "object") {
|
|
78
|
+
let extensions;
|
|
79
|
+
if (ConfigEnvKeys.ELEMENT in value) {
|
|
80
|
+
extensions = await iter(value[ConfigEnvKeys.ELEMENT], [...location, ConfigEnvKeys.ELEMENT]);
|
|
81
|
+
this.logger.trace("Expanding location to elements: %s -> %s", location, extensions.map((extension) => extension.key.join(".")).join(", "));
|
|
82
|
+
}
|
|
83
|
+
if (ConfigEnvKeys.NAME in value && ConfigEnvKeys.PARSER in value) {
|
|
84
|
+
const variable = [{
|
|
85
|
+
key: location,
|
|
86
|
+
env: value[ConfigEnvKeys.NAME],
|
|
87
|
+
parser: value[ConfigEnvKeys.PARSER],
|
|
88
|
+
extensions
|
|
89
|
+
}];
|
|
90
|
+
return variable;
|
|
91
|
+
} else return iter(value, location);
|
|
92
|
+
}
|
|
93
|
+
}));
|
|
94
|
+
return data.flatMap((d) => d).filter(Boolean);
|
|
95
|
+
};
|
|
96
|
+
const parsed = await iter(env);
|
|
97
|
+
const cb = (config$1, variable, data) => {
|
|
98
|
+
if (variable.parser) try {
|
|
99
|
+
data = this.parser.parse(variable.parser, data);
|
|
100
|
+
} catch (e) {
|
|
101
|
+
this.logger.trace("Can not parse environment environment variable for config: %s -> %s with %s", variable.key.join("."), variable.env, variable.parser);
|
|
102
|
+
throw e;
|
|
103
|
+
}
|
|
104
|
+
this.logger.trace("Overwriting config with environment variable: %s -> %s", variable.key.join("."), variable.env);
|
|
105
|
+
return op.set(config$1, variable.key, data);
|
|
106
|
+
};
|
|
107
|
+
parsed.forEach((variable) => {
|
|
108
|
+
let data;
|
|
109
|
+
data = process.env[variable.env];
|
|
110
|
+
if (data) config = cb(config, variable, data);
|
|
111
|
+
if (variable.extensions && variable.extensions.length > 0) {
|
|
112
|
+
const timeout = 6e4;
|
|
113
|
+
const startedAt = Date.now();
|
|
114
|
+
for (let i = 0; i < Infinity; i++) {
|
|
115
|
+
if (Date.now() - startedAt > timeout) throw new Error(`Timed-out in ${timeout}ms while looking for element environment variables.`);
|
|
116
|
+
const extensions = variable.extensions.map((extension) => {
|
|
117
|
+
const clone = JSON.parse(JSON.stringify(extension));
|
|
118
|
+
clone.env = clone.env.replace(ConfigEnvKeys.ELEMENT_REPLACER, i.toString());
|
|
119
|
+
clone.key[clone.key.findIndex((value) => value === ConfigEnvKeys.ELEMENT)] = i.toString();
|
|
120
|
+
data = process.env[clone.env];
|
|
121
|
+
if (!data) {
|
|
122
|
+
this.logger.trace("No extension for environment variable: %s -> %s", clone.key.join("."), clone.env);
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
config = cb(config, clone, data);
|
|
126
|
+
return true;
|
|
127
|
+
}).filter(Boolean);
|
|
128
|
+
if (extensions.length === 0) {
|
|
129
|
+
this.logger.trace("No more extensions for environment variables: %s -> %d", variable.key.join("."), i);
|
|
130
|
+
break;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
});
|
|
135
|
+
return config;
|
|
136
|
+
}
|
|
137
|
+
async write(path, data) {
|
|
138
|
+
return this.parser.write(path, data);
|
|
139
|
+
}
|
|
140
|
+
};
|
|
141
|
+
ConfigService = _decorate([
|
|
142
|
+
Injectable(),
|
|
143
|
+
_decorateMetadata("design:paramtypes", [
|
|
144
|
+
typeof (_ref = typeof ParserService !== "undefined" && ParserService) === "function" ? _ref : Object,
|
|
145
|
+
typeof (_ref2 = typeof LoggerService !== "undefined" && LoggerService) === "function" ? _ref2 : Object,
|
|
146
|
+
Object
|
|
147
|
+
]),
|
|
148
|
+
_decorateParam(2, Inject(TOKEN_CONFIG_MODULE_OPTIONS))
|
|
149
|
+
], ConfigService);
|
|
150
|
+
|
|
151
|
+
//#endregion
|
|
152
|
+
export { ConfigService };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { FileSystemService } from "./filesystem.service.js";
|
|
2
|
+
import { Global, Module } from "@nestjs/common";
|
|
3
|
+
import _decorate from "@oxc-project/runtime/helpers/decorate";
|
|
4
|
+
|
|
5
|
+
//#region src/lib/fs/filesystem.module.ts
|
|
6
|
+
let FilesystemModule = class FilesystemModule$1 {};
|
|
7
|
+
FilesystemModule = _decorate([Global(), Module({
|
|
8
|
+
providers: [FileSystemService],
|
|
9
|
+
exports: [FileSystemService]
|
|
10
|
+
})], FilesystemModule);
|
|
11
|
+
|
|
12
|
+
//#endregion
|
|
13
|
+
export { FilesystemModule };
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { LoggerService } from "../logger/logger.service.js";
|
|
2
|
+
import { OnModuleInit } from "@nestjs/common";
|
|
3
|
+
import fs from "fs-extra";
|
|
4
|
+
|
|
5
|
+
//#region src/lib/fs/filesystem.service.d.ts
|
|
6
|
+
declare class FileSystemService implements OnModuleInit {
|
|
7
|
+
private readonly logger;
|
|
8
|
+
readonly extra: typeof fs;
|
|
9
|
+
constructor(logger: LoggerService);
|
|
10
|
+
onModuleInit(): Promise<void>;
|
|
11
|
+
exists(path: string): boolean;
|
|
12
|
+
stats(path: string): fs.Stats;
|
|
13
|
+
dirname(path: string): string;
|
|
14
|
+
extname(path: string): string;
|
|
15
|
+
read(file: string): Promise<string>;
|
|
16
|
+
readSync(file: string): string;
|
|
17
|
+
write(file: string, data: string | Buffer, options?: fs.WriteFileOptions): Promise<void>;
|
|
18
|
+
writeSync(file: string, data: string | Buffer, options?: fs.WriteFileOptions): void;
|
|
19
|
+
append(file: string, data: string | Buffer, options?: fs.WriteFileOptions): Promise<void>;
|
|
20
|
+
appendSync(file: string, data: string | Buffer): void;
|
|
21
|
+
remove(file: string, options?: fs.RmOptions): Promise<void>;
|
|
22
|
+
removeSync(file: string, options?: fs.RmOptions): void;
|
|
23
|
+
emptyDir(directory: string): Promise<void>;
|
|
24
|
+
emptyDirSync(directory: string): void;
|
|
25
|
+
removeDir(directory: string): Promise<void>;
|
|
26
|
+
removeDirSync(directory: string): void;
|
|
27
|
+
mkdir(directory: string): Promise<void>;
|
|
28
|
+
mkdirSync(directory: string): void;
|
|
29
|
+
}
|
|
30
|
+
//#endregion
|
|
31
|
+
export { FileSystemService };
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
import { LoggerService } from "../logger/logger.service.js";
|
|
2
|
+
import "../logger/index.js";
|
|
3
|
+
import { Injectable } from "@nestjs/common";
|
|
4
|
+
import { dirname, extname } from "path";
|
|
5
|
+
import _decorateMetadata from "@oxc-project/runtime/helpers/decorateMetadata";
|
|
6
|
+
import _decorate from "@oxc-project/runtime/helpers/decorate";
|
|
7
|
+
import fs from "fs-extra";
|
|
8
|
+
|
|
9
|
+
//#region src/lib/fs/filesystem.service.ts
|
|
10
|
+
var _ref;
|
|
11
|
+
let FileSystemService = class FileSystemService$1 {
|
|
12
|
+
constructor(logger) {
|
|
13
|
+
this.logger = logger;
|
|
14
|
+
this.extra = fs;
|
|
15
|
+
}
|
|
16
|
+
async onModuleInit() {
|
|
17
|
+
this.logger.setup(this.constructor.name);
|
|
18
|
+
}
|
|
19
|
+
exists(path) {
|
|
20
|
+
return this.extra.existsSync(path);
|
|
21
|
+
}
|
|
22
|
+
stats(path) {
|
|
23
|
+
return this.extra.statSync(path, { throwIfNoEntry: true });
|
|
24
|
+
}
|
|
25
|
+
dirname(path) {
|
|
26
|
+
return dirname(path);
|
|
27
|
+
}
|
|
28
|
+
extname(path) {
|
|
29
|
+
return extname(path);
|
|
30
|
+
}
|
|
31
|
+
async read(file) {
|
|
32
|
+
try {
|
|
33
|
+
const raw = await this.extra.readFile(file, "utf-8");
|
|
34
|
+
return raw;
|
|
35
|
+
} catch (e) {
|
|
36
|
+
throw new Error(`Error while reading file from "${file}": ${e.message}`);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
readSync(file) {
|
|
40
|
+
try {
|
|
41
|
+
const raw = this.extra.readFileSync(file, "utf-8");
|
|
42
|
+
return raw;
|
|
43
|
+
} catch (e) {
|
|
44
|
+
throw new Error(`Error while reading file from "${file}": ${e.message}`);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
async write(file, data, options = {}) {
|
|
48
|
+
try {
|
|
49
|
+
await this.extra.writeFile(file, data, typeof options === "object" ? {
|
|
50
|
+
encoding: "utf-8",
|
|
51
|
+
...options
|
|
52
|
+
} : options);
|
|
53
|
+
} catch (e) {
|
|
54
|
+
throw new Error(`Error while writing file to "${file}": ${e.message}`);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
writeSync(file, data, options = {}) {
|
|
58
|
+
try {
|
|
59
|
+
this.extra.writeFileSync(file, data, typeof options === "object" ? {
|
|
60
|
+
encoding: "utf-8",
|
|
61
|
+
...options
|
|
62
|
+
} : options);
|
|
63
|
+
} catch (e) {
|
|
64
|
+
throw new Error(`Error while writing file to "${file}": ${e.message}`);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
async append(file, data, options) {
|
|
68
|
+
try {
|
|
69
|
+
await this.extra.appendFile(file, data, options);
|
|
70
|
+
} catch (e) {
|
|
71
|
+
throw new Error(`Error while appending to file "${file}": ${e.message}`);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
appendSync(file, data) {
|
|
75
|
+
try {
|
|
76
|
+
this.extra.appendFileSync(file, data);
|
|
77
|
+
} catch (e) {
|
|
78
|
+
throw new Error(`Error while appending to file "${file}": ${e.message}`);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
async remove(file, options) {
|
|
82
|
+
try {
|
|
83
|
+
await this.extra.rm(file, options);
|
|
84
|
+
} catch (e) {
|
|
85
|
+
throw new Error(`Error while deleting the file "${file}": ${e.message}`);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
removeSync(file, options) {
|
|
89
|
+
try {
|
|
90
|
+
this.extra.rmSync(file, options);
|
|
91
|
+
} catch (e) {
|
|
92
|
+
throw new Error(`Error while deleting the file "${file}": ${e.message}`);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
async emptyDir(directory) {
|
|
96
|
+
try {
|
|
97
|
+
await this.extra.emptyDir(directory);
|
|
98
|
+
} catch (e) {
|
|
99
|
+
throw new Error(`Error while emptying the directory "${directory}": ${e.message}`);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
emptyDirSync(directory) {
|
|
103
|
+
try {
|
|
104
|
+
this.extra.emptyDirSync(directory);
|
|
105
|
+
} catch (e) {
|
|
106
|
+
throw new Error(`Error while emptying the directory "${directory}": ${e.message}`);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
async removeDir(directory) {
|
|
110
|
+
try {
|
|
111
|
+
await this.extra.rmdir(directory);
|
|
112
|
+
} catch (e) {
|
|
113
|
+
throw new Error(`Error while removing the directory "${directory}": ${e.message}`);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
removeDirSync(directory) {
|
|
117
|
+
try {
|
|
118
|
+
this.extra.rmdirSync(directory);
|
|
119
|
+
} catch (e) {
|
|
120
|
+
throw new Error(`Error while removing the directory "${directory}": ${e.message}`);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
async mkdir(directory) {
|
|
124
|
+
try {
|
|
125
|
+
await this.extra.mkdirp(directory);
|
|
126
|
+
} catch (e) {
|
|
127
|
+
throw new Error(`Error while creating the directory "${directory}": ${e.message}`);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
mkdirSync(directory) {
|
|
131
|
+
try {
|
|
132
|
+
this.extra.mkdirpSync(directory);
|
|
133
|
+
} catch (e) {
|
|
134
|
+
throw new Error(`Error while creating the directory "${directory}": ${e.message}`);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
};
|
|
138
|
+
FileSystemService = _decorate([Injectable(), _decorateMetadata("design:paramtypes", [typeof (_ref = typeof LoggerService !== "undefined" && LoggerService) === "function" ? _ref : Object])], FileSystemService);
|
|
139
|
+
|
|
140
|
+
//#endregion
|
|
141
|
+
export { FileSystemService };
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { pipeProcessThroughListr } from "./logger/pipe/pipe-process-to-listr.js";
|
|
2
|
+
import { LogFieldStatus, LogLevels } from "./logger/logger.constants.js";
|
|
3
|
+
import { pipeProcessToLogger } from "./logger/pipe/pipe-process-to-logger.js";
|
|
4
|
+
import { WinstonService } from "./logger/winston.service.js";
|
|
5
|
+
import { LoggerService } from "./logger/logger.service.js";
|
|
6
|
+
import { LoggerModule } from "./logger/logger.module.js";
|
|
7
|
+
import "./logger/index.js";
|
|
8
|
+
import { FileSystemService } from "./fs/filesystem.service.js";
|
|
9
|
+
import { FilesystemModule } from "./fs/filesystem.module.js";
|
|
10
|
+
import "./fs/index.js";
|
|
11
|
+
import { ParserService } from "./parser/parser.service.js";
|
|
12
|
+
import { ConfigService } from "./config/config.service.js";
|
|
13
|
+
import { ParserModule } from "./parser/parser.module.js";
|
|
14
|
+
import { ConfigModule } from "./config/config.module.js";
|
|
15
|
+
import "./config/index.js";
|
|
16
|
+
import { EnvironmentVariableParser } from "./parser/fts/env-parser.service.js";
|
|
17
|
+
import { JsonParser } from "./parser/fts/json-parser.service.js";
|
|
18
|
+
import { YamlParser } from "./parser/fts/yaml-parser.service.js";
|
|
19
|
+
import "./parser/index.js";
|
|
20
|
+
import { LockerService } from "./locker/locker.service.js";
|
|
21
|
+
import { LockerModule } from "./locker/locker.module.js";
|
|
22
|
+
import "./locker/index.js";
|
|
23
|
+
import { TOKEN_LOGO_GENERATOR } from "./logo/logo.constants.js";
|
|
24
|
+
import { LogoService } from "./logo/logo.service.js";
|
|
25
|
+
import { LogoModule } from "./logo/logo.module.js";
|
|
26
|
+
import "./logo/index.js";
|
|
27
|
+
import { TOKEN_VALIDATOR_SERVICE_OPTIONS } from "./validator/validator.constants.js";
|
|
28
|
+
import { ValidatorService } from "./validator/validator.service.js";
|
|
29
|
+
import { ValidatorModule } from "./validator/validator.module.js";
|
|
30
|
+
import "./validator/index.js";
|
|
31
|
+
import { setup } from "./setup.js";
|
|
32
|
+
import { CliModule } from "./cli.module.js";
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { ClassType } from "../../interfaces/class.interface.js";
|
|
2
|
+
import { GenericParser } from "../parser/parser.interface.js";
|
|
3
|
+
import { MergeStrategy } from "../../utils/merge.constants.js";
|
|
4
|
+
import { InjectionToken } from "@nestjs/common";
|
|
5
|
+
|
|
6
|
+
//#region src/lib/locker/locker.interface.d.ts
|
|
7
|
+
interface CommonLockerData {
|
|
8
|
+
path?: string | string[];
|
|
9
|
+
enabled?: boolean;
|
|
10
|
+
root?: boolean;
|
|
11
|
+
}
|
|
12
|
+
type LockableData = any;
|
|
13
|
+
interface LockData<T extends LockableData = LockableData> extends Partial<CommonLockerData> {
|
|
14
|
+
data: T;
|
|
15
|
+
merge?: MergeStrategy;
|
|
16
|
+
}
|
|
17
|
+
interface UnlockData extends CommonLockerData {
|
|
18
|
+
path: string | string[];
|
|
19
|
+
}
|
|
20
|
+
interface LockerServiceOptions {
|
|
21
|
+
file: string;
|
|
22
|
+
parser: ClassType<GenericParser>;
|
|
23
|
+
root?: string[];
|
|
24
|
+
context?: string;
|
|
25
|
+
token?: InjectionToken;
|
|
26
|
+
}
|
|
27
|
+
//#endregion
|
|
28
|
+
export { CommonLockerData, LockData, LockableData, LockerServiceOptions, UnlockData };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { LockerServiceOptions } from "./locker.interface.js";
|
|
2
|
+
import { DynamicModule } from "@nestjs/common";
|
|
3
|
+
|
|
4
|
+
//#region src/lib/locker/locker.module.d.ts
|
|
5
|
+
declare class LockerModule {
|
|
6
|
+
static forFeature(options: LockerServiceOptions): DynamicModule;
|
|
7
|
+
}
|
|
8
|
+
//#endregion
|
|
9
|
+
export { LockerModule };
|