@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
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { PipeProcessToLoggerOptions } from "../lib/logger/pipe/pipe-process-to-logger.interface.js";
|
|
2
|
+
import { LoggerService } from "../lib/logger/logger.service.js";
|
|
3
|
+
import { SetCtxAssignOptions, SetCtxDefaultsOptions } from "../utils/defaults.js";
|
|
4
|
+
import { InferArgs, InferFlags } from "../interfaces/oclif.interface.js";
|
|
5
|
+
import { INestApplicationContext } from "@nestjs/common";
|
|
6
|
+
import { Manager } from "@listr2/manager";
|
|
7
|
+
import { Command } from "@oclif/core";
|
|
8
|
+
import { ListrContext, ListrTaskWrapper } from "listr2";
|
|
9
|
+
import "reflect-metadata";
|
|
10
|
+
import * as _oclif_core_lib_interfaces0 from "@oclif/core/lib/interfaces";
|
|
11
|
+
import { ChildProcess } from "child_process";
|
|
12
|
+
|
|
13
|
+
//#region src/commands/base.command.d.ts
|
|
14
|
+
declare abstract class Command$1<T extends typeof Command = typeof Command, Ctx extends ListrContext = ListrContext> extends Command {
|
|
15
|
+
static baseFlags: {
|
|
16
|
+
"log-level": _oclif_core_lib_interfaces0.OptionFlag<string, _oclif_core_lib_interfaces0.CustomOptions>;
|
|
17
|
+
ci: _oclif_core_lib_interfaces0.BooleanFlag<boolean>;
|
|
18
|
+
json: _oclif_core_lib_interfaces0.BooleanFlag<boolean>;
|
|
19
|
+
};
|
|
20
|
+
logger: LoggerService;
|
|
21
|
+
tasks: Manager<Ctx>;
|
|
22
|
+
app: INestApplicationContext;
|
|
23
|
+
flags: InferFlags<T>;
|
|
24
|
+
args: InferArgs<T>;
|
|
25
|
+
exit(code?: number): never;
|
|
26
|
+
/** Run all tasks from task manager. */
|
|
27
|
+
runTasks<C extends Ctx = Ctx>(): Promise<C>;
|
|
28
|
+
protected setCtxDefaults<T extends Ctx = Ctx>(...defaults: SetCtxDefaultsOptions<T>[]): void;
|
|
29
|
+
protected setCtxAssign<K = Record<PropertyKey, any>>(...assigns: SetCtxAssignOptions<K>[]): void;
|
|
30
|
+
protected pipeProcessToLogger(instance: ChildProcess, options?: PipeProcessToLoggerOptions): ChildProcess;
|
|
31
|
+
protected pipeProcessThroughListr(instance: ChildProcess, task: ListrTaskWrapper<any, any, any>): ChildProcess;
|
|
32
|
+
/** Initial functions / constructor */
|
|
33
|
+
protected init(): Promise<void>;
|
|
34
|
+
/** Tasks to run before end of the command. */
|
|
35
|
+
protected finally<C extends Ctx = Ctx>(err: Error | undefined): Promise<{
|
|
36
|
+
ctx: C;
|
|
37
|
+
}>;
|
|
38
|
+
/** Catch any error occurred during command. */
|
|
39
|
+
protected catch(err: Error): Promise<never>;
|
|
40
|
+
abstract run(): Promise<any>;
|
|
41
|
+
}
|
|
42
|
+
//#endregion
|
|
43
|
+
export { Command$1 as Command };
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
import { HelpGroups } from "../constants/help-groups.constants.js";
|
|
2
|
+
import { pipeProcessThroughListr } from "../lib/logger/pipe/pipe-process-to-listr.js";
|
|
3
|
+
import { LogFieldStatus, LogLevels } from "../lib/logger/logger.constants.js";
|
|
4
|
+
import { pipeProcessToLogger } from "../lib/logger/pipe/pipe-process-to-logger.js";
|
|
5
|
+
import { LoggerService } from "../lib/logger/logger.service.js";
|
|
6
|
+
import { setCtxAssign, setCtxDefaults } from "../utils/defaults.js";
|
|
7
|
+
import { isHookedWithRegister, isHookedWithShouldRunAfter, isHookedWithShouldRunBefore } from "../utils/guards.js";
|
|
8
|
+
import "../utils/index.js";
|
|
9
|
+
import { ConfigService } from "../lib/config/config.service.js";
|
|
10
|
+
import { LogoService } from "../lib/logo/logo.service.js";
|
|
11
|
+
import { CliModule } from "../lib/cli.module.js";
|
|
12
|
+
import "../lib/index.js";
|
|
13
|
+
import { Manager } from "@listr2/manager";
|
|
14
|
+
import { Command, Flags } from "@oclif/core";
|
|
15
|
+
import { createInterface } from "readline";
|
|
16
|
+
import "reflect-metadata";
|
|
17
|
+
|
|
18
|
+
//#region src/commands/base.command.ts
|
|
19
|
+
var Command$1 = class extends Command {
|
|
20
|
+
static {
|
|
21
|
+
this.baseFlags = {
|
|
22
|
+
["log-level"]: Flags.string({
|
|
23
|
+
default: LogLevels.INFO,
|
|
24
|
+
env: "LOG_LEVEL",
|
|
25
|
+
description: "Set the log level of the application.",
|
|
26
|
+
options: Object.values(LogLevels).map((level) => level.toLowerCase()),
|
|
27
|
+
helpGroup: HelpGroups.CLI,
|
|
28
|
+
parse: async (input) => input?.toUpperCase()
|
|
29
|
+
}),
|
|
30
|
+
ci: Flags.boolean({
|
|
31
|
+
default: false,
|
|
32
|
+
hidden: true,
|
|
33
|
+
env: "CI",
|
|
34
|
+
description: "Instruct whether this is running the CI/CD configuration.",
|
|
35
|
+
helpGroup: HelpGroups.CLI
|
|
36
|
+
}),
|
|
37
|
+
json: Flags.boolean({
|
|
38
|
+
default: false,
|
|
39
|
+
hidden: true,
|
|
40
|
+
env: "JSON",
|
|
41
|
+
description: "Put the CLI to respond in JSON.",
|
|
42
|
+
helpGroup: HelpGroups.CLI
|
|
43
|
+
})
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
exit(code) {
|
|
47
|
+
this.logger.trace("Code -> %d", code, { status: LogFieldStatus.EXIT });
|
|
48
|
+
super.exit(code ?? 0);
|
|
49
|
+
}
|
|
50
|
+
/** Run all tasks from task manager. */
|
|
51
|
+
runTasks() {
|
|
52
|
+
return this.tasks.runAll();
|
|
53
|
+
}
|
|
54
|
+
setCtxDefaults(...defaults) {
|
|
55
|
+
setCtxDefaults(this.tasks.options.ctx, ...defaults);
|
|
56
|
+
this.logger.trace("Updated context with defaults: %o", this.tasks.options.ctx, { status: "ctx" });
|
|
57
|
+
}
|
|
58
|
+
setCtxAssign(...assigns) {
|
|
59
|
+
setCtxAssign(this.tasks.options.ctx, ...assigns);
|
|
60
|
+
this.logger.trace("Updated context with assign: %o", this.tasks.options.ctx, { status: "ctx" });
|
|
61
|
+
}
|
|
62
|
+
pipeProcessToLogger(instance, options) {
|
|
63
|
+
return pipeProcessToLogger(this.logger, instance, options);
|
|
64
|
+
}
|
|
65
|
+
pipeProcessThroughListr(instance, task) {
|
|
66
|
+
return pipeProcessThroughListr(task, instance);
|
|
67
|
+
}
|
|
68
|
+
/** Initial functions / constructor */
|
|
69
|
+
async init() {
|
|
70
|
+
await super.init();
|
|
71
|
+
let err;
|
|
72
|
+
try {
|
|
73
|
+
const { args, flags } = await this.parse({
|
|
74
|
+
flags: this.ctor.flags,
|
|
75
|
+
baseFlags: super.ctor.baseFlags,
|
|
76
|
+
enableJsonFlag: this.ctor.enableJsonFlag,
|
|
77
|
+
args: this.ctor.args,
|
|
78
|
+
strict: this.ctor.strict
|
|
79
|
+
});
|
|
80
|
+
this.flags = flags;
|
|
81
|
+
this.args = args;
|
|
82
|
+
} catch (e) {
|
|
83
|
+
err = e;
|
|
84
|
+
}
|
|
85
|
+
const options = { config: {
|
|
86
|
+
oclif: this.config,
|
|
87
|
+
command: this.ctor,
|
|
88
|
+
config: {
|
|
89
|
+
logLevel: this.flags?.["log-level"] ?? LogLevels.INFO,
|
|
90
|
+
isJson: this.flags?.json ?? false
|
|
91
|
+
}
|
|
92
|
+
} };
|
|
93
|
+
const cli = CliModule.forRoot(options);
|
|
94
|
+
this.app = await CliModule.create(!err && isHookedWithRegister(this) ? await this.register(cli, options) : cli);
|
|
95
|
+
await this.app.init();
|
|
96
|
+
const cs = this.app.get(ConfigService);
|
|
97
|
+
this.logger = await this.app.resolve(LoggerService);
|
|
98
|
+
this.app.useLogger(this.logger);
|
|
99
|
+
this.app.get(LogoService).generate();
|
|
100
|
+
if (err) throw err;
|
|
101
|
+
this.logger.stage("Created application context.");
|
|
102
|
+
this.tasks = new Manager({
|
|
103
|
+
fallbackRendererCondition: cs.isDebug,
|
|
104
|
+
silentRendererCondition: cs.isSilent || cs.isJson,
|
|
105
|
+
ctx: {}
|
|
106
|
+
});
|
|
107
|
+
if (cs.oclif.windows) createInterface({
|
|
108
|
+
input: process.stdin,
|
|
109
|
+
output: process.stdout
|
|
110
|
+
}).on("SIGINT", () => {
|
|
111
|
+
process.kill(process.pid, "SIGINT");
|
|
112
|
+
});
|
|
113
|
+
const terminate = () => {
|
|
114
|
+
this.logger.fatal("Caught terminate signal.", { status: LogFieldStatus.TERMINATE });
|
|
115
|
+
process.exit(1);
|
|
116
|
+
};
|
|
117
|
+
process.on("SIGINT", terminate);
|
|
118
|
+
process.on("SIGTERM", terminate);
|
|
119
|
+
if (isHookedWithShouldRunBefore(this)) {
|
|
120
|
+
this.logger.stage("Running hook should-run-before.");
|
|
121
|
+
await this.shouldRunBefore();
|
|
122
|
+
this.logger.stage("Finished hook should-run-before.");
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
/** Tasks to run before end of the command. */
|
|
126
|
+
async finally(err) {
|
|
127
|
+
let ctx;
|
|
128
|
+
if (err) return { ctx };
|
|
129
|
+
if (this.tasks?.tasks?.length > 0) {
|
|
130
|
+
this.logger.stage("Running tasks.");
|
|
131
|
+
ctx = await this.runTasks();
|
|
132
|
+
this.logger.stage("Finished tasks.");
|
|
133
|
+
}
|
|
134
|
+
if (isHookedWithShouldRunAfter(this)) {
|
|
135
|
+
this.logger.stage("Running hook should-run-after.");
|
|
136
|
+
await this.shouldRunAfter(ctx);
|
|
137
|
+
this.logger.stage("Finished hook should-run-after.");
|
|
138
|
+
}
|
|
139
|
+
await this.app.close();
|
|
140
|
+
return { ctx };
|
|
141
|
+
}
|
|
142
|
+
/** Catch any error occurred during command. */
|
|
143
|
+
async catch(err) {
|
|
144
|
+
process.exitCode = process.exitCode ?? err.exitCode ?? 1;
|
|
145
|
+
if (!this.logger) {
|
|
146
|
+
this.app = await CliModule.create(CliModule.forMinimum());
|
|
147
|
+
this.logger = await this.app.resolve(LoggerService);
|
|
148
|
+
}
|
|
149
|
+
this.logger.fatal(err.message);
|
|
150
|
+
this.logger.debug(err.stack, { context: "crash" });
|
|
151
|
+
throw err;
|
|
152
|
+
}
|
|
153
|
+
};
|
|
154
|
+
|
|
155
|
+
//#endregion
|
|
156
|
+
export { Command$1 as Command };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import { Command } from "./base.command.js";
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { LoggerService } from "../lib/logger/logger.service.js";
|
|
2
|
+
import { CliModule } from "../lib/cli.module.js";
|
|
3
|
+
import "../lib/index.js";
|
|
4
|
+
import { Help } from "@oclif/core";
|
|
5
|
+
|
|
6
|
+
//#region src/hooks/not-found.hook.ts
|
|
7
|
+
const notFoundHook = async (opts) => {
|
|
8
|
+
const app = await CliModule.create(CliModule.forMinimum());
|
|
9
|
+
const logger = await app.resolve(LoggerService);
|
|
10
|
+
logger.error("Command not found. Take a look at help. You can also use --[h]elp flag for subcommands.");
|
|
11
|
+
logger.direct("");
|
|
12
|
+
const help = new Help(opts.config);
|
|
13
|
+
await help.showHelp(["--all"]);
|
|
14
|
+
opts.context.exit(127);
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
//#endregion
|
|
18
|
+
export { notFoundHook };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
//#region src/hooks/update-notifier.hook.ts
|
|
2
|
+
const updateNotifierHook = async (opts) => {
|
|
3
|
+
const { default: notifier } = await import("update-notifier");
|
|
4
|
+
notifier({ pkg: {
|
|
5
|
+
name: opts.config.name,
|
|
6
|
+
version: opts.config.version
|
|
7
|
+
} }).notify({ isGlobal: true });
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
//#endregion
|
|
11
|
+
export { updateNotifierHook };
|