@cenk1cenk2/oclif-common 3.9.11 → 4.0.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/index.d.ts +10 -40
- package/dist/index.js +34 -11
- package/package.json +6 -6
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Command as Command$1,
|
|
2
|
-
export {
|
|
1
|
+
import { Command as Command$1, ux, Hook } from '@oclif/core';
|
|
2
|
+
export { Flags, ux } from '@oclif/core';
|
|
3
3
|
import { ExecaChildProcess } from 'execa';
|
|
4
4
|
import { Logger as Logger$2, ListrTaskWrapper, ListrContext, Manager, PromptOptions } from 'listr2';
|
|
5
5
|
import { Logger as Logger$1, LeveledLogMethod } from 'winston';
|
|
@@ -7,15 +7,10 @@ import fs from 'fs-extra';
|
|
|
7
7
|
export { default as fs } from 'fs-extra';
|
|
8
8
|
import { ClassTransformOptions } from 'class-transformer';
|
|
9
9
|
import { ValidatorOptions } from 'class-validator';
|
|
10
|
-
import { InferredFlags
|
|
11
|
-
export {
|
|
12
|
-
import
|
|
13
|
-
|
|
14
|
-
import * as _oclif_core_lib_cli_ux_styled_tree from '@oclif/core/lib/cli-ux/styled/tree';
|
|
15
|
-
import * as _oclif_core_lib_cli_ux_styled_json from '@oclif/core/lib/cli-ux/styled/json';
|
|
16
|
-
import * as _oclif_core_lib_cli_ux_styled_header from '@oclif/core/lib/cli-ux/styled/header';
|
|
17
|
-
import * as _oclif_core_lib_cli_ux_prompt from '@oclif/core/lib/cli-ux/prompt';
|
|
18
|
-
import * as _oclif_core_lib_errors from '@oclif/core/lib/errors';
|
|
10
|
+
import { InferredFlags } from '@oclif/core/lib/interfaces';
|
|
11
|
+
export { Flag, InferredFlags } from '@oclif/core/lib/interfaces';
|
|
12
|
+
import { FlagInput } from '@oclif/core/lib/interfaces/parser';
|
|
13
|
+
export { Arg, ArgInput, FlagInput } from '@oclif/core/lib/interfaces/parser';
|
|
19
14
|
import * as colorette from 'colorette';
|
|
20
15
|
|
|
21
16
|
type ClassType<T> = new (...args: any[]) => T;
|
|
@@ -319,7 +314,7 @@ interface ConfigCommandSetup<T extends string = string, LockFile = any> {
|
|
|
319
314
|
locker?: LockerService<LockFile>;
|
|
320
315
|
}
|
|
321
316
|
|
|
322
|
-
type InferFlags<T extends typeof Command$1> = InferredFlags<T['
|
|
317
|
+
type InferFlags<T extends typeof Command$1> = InferredFlags<T['baseFlags'] & T['flags']>;
|
|
323
318
|
type InferArgs<T extends typeof Command$1> = Record<T['args'][number]['name'], string>;
|
|
324
319
|
|
|
325
320
|
/**
|
|
@@ -330,6 +325,8 @@ type DeepPartial<T> = {
|
|
|
330
325
|
};
|
|
331
326
|
|
|
332
327
|
declare class Command<Ctx extends ListrContext = ListrContext, Flags extends Record<PropertyKey, any> = InferFlags<typeof Command>, Args extends Record<PropertyKey, any> = InferArgs<typeof Command>, Store extends Record<PropertyKey, any> = Record<PropertyKey, any>> extends Command$1 {
|
|
328
|
+
static get baseFlags(): FlagInput;
|
|
329
|
+
static set baseFlags(flags: FlagInput);
|
|
333
330
|
context: string;
|
|
334
331
|
logger: Logger;
|
|
335
332
|
tasks: Manager<Ctx, 'default' | 'verbose' | 'silent' | 'simple'>;
|
|
@@ -373,36 +370,9 @@ declare class Command<Ctx extends ListrContext = ListrContext, Flags extends Rec
|
|
|
373
370
|
declare class ConfigCommand<CommandChoices extends string = string, LockFile = any, Ctx extends ListrContext = ListrContext, Flags extends Record<PropertyKey, any> = InferFlags<typeof ConfigCommand>, Args extends Record<PropertyKey, any> = InferArgs<typeof ConfigCommand>, Store extends Record<PropertyKey, any> = Record<PropertyKey, any>> extends Command<Ctx, Flags, Args, Store> {
|
|
374
371
|
choices: ConfigCommandChoices<CommandChoices>;
|
|
375
372
|
locker: LockerService<LockFile>;
|
|
376
|
-
protected ux: {
|
|
377
|
-
config: CliUx.Config;
|
|
378
|
-
warn: typeof _oclif_core_lib_errors.warn;
|
|
379
|
-
error: typeof _oclif_core_lib_errors.error;
|
|
380
|
-
exit: typeof _oclif_core_lib_errors.exit;
|
|
381
|
-
readonly prompt: typeof _oclif_core_lib_cli_ux_prompt.prompt;
|
|
382
|
-
readonly anykey: typeof _oclif_core_lib_cli_ux_prompt.anykey;
|
|
383
|
-
readonly confirm: typeof _oclif_core_lib_cli_ux_prompt.confirm;
|
|
384
|
-
readonly action: CliUx.ActionBase;
|
|
385
|
-
readonly prideAction: CliUx.ActionBase;
|
|
386
|
-
styledObject(obj: any, keys?: string[]): void;
|
|
387
|
-
readonly styledHeader: typeof _oclif_core_lib_cli_ux_styled_header.default;
|
|
388
|
-
readonly styledJSON: typeof _oclif_core_lib_cli_ux_styled_json.default;
|
|
389
|
-
readonly table: typeof CliUx.Table.table;
|
|
390
|
-
readonly tree: typeof _oclif_core_lib_cli_ux_styled_tree.default;
|
|
391
|
-
readonly open: typeof _oclif_core_lib_cli_ux_open.default;
|
|
392
|
-
readonly wait: (ms?: number) => Promise<unknown>;
|
|
393
|
-
readonly progress: typeof _oclif_core_lib_cli_ux_styled_progress.default;
|
|
394
|
-
done(): Promise<void>;
|
|
395
|
-
trace(format: string, ...args: string[]): void;
|
|
396
|
-
debug(format: string, ...args: string[]): void;
|
|
397
|
-
info(format: string, ...args: string[]): void;
|
|
398
|
-
log(format?: string, ...args: string[]): void;
|
|
399
|
-
url(text: string, uri: string, params?: {}): void;
|
|
400
|
-
annotation(text: string, annotation: string): void;
|
|
401
|
-
flush(ms?: number): Promise<void>;
|
|
402
|
-
};
|
|
403
373
|
run(): Promise<any>;
|
|
404
374
|
setup(): ConfigCommandSetup<CommandChoices, LockFile> | Promise<ConfigCommandSetup<CommandChoices, LockFile>>;
|
|
405
|
-
protected table(...options: Parameters<typeof
|
|
375
|
+
protected table(...options: Parameters<typeof ux.table>): void;
|
|
406
376
|
protected select(): Promise<string>;
|
|
407
377
|
}
|
|
408
378
|
|
package/dist/index.js
CHANGED
|
@@ -195,14 +195,14 @@ var FileSystemService = class {
|
|
|
195
195
|
}
|
|
196
196
|
async write(file, data, options = {}) {
|
|
197
197
|
try {
|
|
198
|
-
await _fsextra2.default.writeFile(file, data, { encoding: "utf-8", ...options });
|
|
198
|
+
await _fsextra2.default.writeFile(file, data, typeof options === "object" ? { encoding: "utf-8", ...options } : options);
|
|
199
199
|
} catch (e) {
|
|
200
200
|
throw new Error(`Error while writing file to "${file}": ${e.message}`);
|
|
201
201
|
}
|
|
202
202
|
}
|
|
203
203
|
writeSync(file, data, options = {}) {
|
|
204
204
|
try {
|
|
205
|
-
_fsextra2.default.writeFileSync(file, data, { encoding: "utf-8", ...options });
|
|
205
|
+
_fsextra2.default.writeFileSync(file, data, typeof options === "object" ? { encoding: "utf-8", ...options } : options);
|
|
206
206
|
} catch (e) {
|
|
207
207
|
throw new Error(`Error while writing file to "${file}": ${e.message}`);
|
|
208
208
|
}
|
|
@@ -460,7 +460,9 @@ var ConfigService = class {
|
|
|
460
460
|
const variable = [
|
|
461
461
|
{
|
|
462
462
|
key: location,
|
|
463
|
+
// eslint-disable-next-line no-underscore-dangle
|
|
463
464
|
env: value["__name" /* NAME */],
|
|
465
|
+
// eslint-disable-next-line no-underscore-dangle
|
|
464
466
|
parser: value["__format" /* PARSER */],
|
|
465
467
|
extensions
|
|
466
468
|
}
|
|
@@ -824,6 +826,7 @@ var Logger = class {
|
|
|
824
826
|
trace(data, ...args) {
|
|
825
827
|
return this.parseMessage("TRACE" /* TRACE */, data, args);
|
|
826
828
|
}
|
|
829
|
+
// status levels
|
|
827
830
|
run(data, ...args) {
|
|
828
831
|
return this.parseMessage("INFO" /* INFO */, data, args, { status: "run" /* RUN */ });
|
|
829
832
|
}
|
|
@@ -1034,11 +1037,11 @@ __name(pipeProcessToLogger, "pipeProcessToLogger");
|
|
|
1034
1037
|
|
|
1035
1038
|
// src/constants/global-flags.constants.ts
|
|
1036
1039
|
var CLI_FLAGS = {
|
|
1037
|
-
["log-level"]: _core.Flags.
|
|
1040
|
+
["log-level"]: _core.Flags.string({
|
|
1038
1041
|
default: "INFO" /* INFO */,
|
|
1039
1042
|
env: "LOG_LEVEL",
|
|
1040
1043
|
description: "Set the log level of the application.",
|
|
1041
|
-
options:
|
|
1044
|
+
options: Object.values(LogLevels).map((level) => level.toLowerCase()),
|
|
1042
1045
|
helpGroup: "CLI" /* CLI */,
|
|
1043
1046
|
parse: async (input) => _optionalChain([input, 'optionalAccess', _41 => _41.toUpperCase, 'call', _42 => _42()])
|
|
1044
1047
|
}),
|
|
@@ -1065,13 +1068,30 @@ var Command = class extends _core.Command {
|
|
|
1065
1068
|
this.flags = {};
|
|
1066
1069
|
this.args = {};
|
|
1067
1070
|
}
|
|
1071
|
+
static get baseFlags() {
|
|
1072
|
+
return this._baseFlags;
|
|
1073
|
+
}
|
|
1074
|
+
static set baseFlags(flags) {
|
|
1075
|
+
this._baseFlags = Object.assign(CLI_FLAGS, this.baseFlags, flags);
|
|
1076
|
+
this.flags = {};
|
|
1077
|
+
}
|
|
1078
|
+
/**
|
|
1079
|
+
* Construct the class if you dont want to extend init or constructor.
|
|
1080
|
+
*/
|
|
1081
|
+
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
1068
1082
|
shouldRunBefore() {
|
|
1069
1083
|
}
|
|
1084
|
+
/**
|
|
1085
|
+
* Deconstruct the class if you dont want to extend finally or catch.
|
|
1086
|
+
*/
|
|
1087
|
+
// eslint-disable-next-line @typescript-eslint/no-empty-function, @typescript-eslint/no-unused-vars
|
|
1070
1088
|
shouldRunAfter(_ctx) {
|
|
1071
1089
|
}
|
|
1090
|
+
// make run non-abstract for other classes
|
|
1072
1091
|
run() {
|
|
1073
1092
|
throw new Error("The command should have a run function to do something!");
|
|
1074
1093
|
}
|
|
1094
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
1075
1095
|
async _run() {
|
|
1076
1096
|
let result;
|
|
1077
1097
|
try {
|
|
@@ -1083,7 +1103,7 @@ var Command = class extends _core.Command {
|
|
|
1083
1103
|
await this.catch(error, 127);
|
|
1084
1104
|
}
|
|
1085
1105
|
if (result && this.jsonEnabled()) {
|
|
1086
|
-
_core.
|
|
1106
|
+
_core.ux.styledJSON(this.toSuccessJson(result));
|
|
1087
1107
|
}
|
|
1088
1108
|
return result;
|
|
1089
1109
|
}
|
|
@@ -1091,9 +1111,11 @@ var Command = class extends _core.Command {
|
|
|
1091
1111
|
this.logger.trace("Code -> %d", code, { status: "exit" /* EXIT */ });
|
|
1092
1112
|
process.exit(_nullishCoalesce(code, () => ( 0)));
|
|
1093
1113
|
}
|
|
1114
|
+
/** Run all tasks from task manager. */
|
|
1094
1115
|
runTasks() {
|
|
1095
1116
|
return this.tasks.runAll();
|
|
1096
1117
|
}
|
|
1118
|
+
/** Gets prompt from user. */
|
|
1097
1119
|
prompt(options) {
|
|
1098
1120
|
return _listr2.createPrompt.call(void 0, options, {
|
|
1099
1121
|
error: true,
|
|
@@ -1114,6 +1136,8 @@ var Command = class extends _core.Command {
|
|
|
1114
1136
|
pipeProcessThroughListr(task, instance) {
|
|
1115
1137
|
return pipeProcessThroughListr(task, instance);
|
|
1116
1138
|
}
|
|
1139
|
+
/** Initial functions / constructor */
|
|
1140
|
+
// can not override constructor, init function is defined by oclif
|
|
1117
1141
|
async init() {
|
|
1118
1142
|
this.constructor.flags = Object.assign({}, CLI_FLAGS, this.constructor.flags);
|
|
1119
1143
|
await super.init();
|
|
@@ -1169,6 +1193,7 @@ var Command = class extends _core.Command {
|
|
|
1169
1193
|
await this.shouldRunBefore();
|
|
1170
1194
|
this.logger.stage("Finished shouldRunBefore.");
|
|
1171
1195
|
}
|
|
1196
|
+
/** Tasks to run before end of the command. */
|
|
1172
1197
|
async finally() {
|
|
1173
1198
|
this.logger.stage("Running tasks.");
|
|
1174
1199
|
const ctx = await this.runTasks();
|
|
@@ -1178,6 +1203,8 @@ var Command = class extends _core.Command {
|
|
|
1178
1203
|
this.logger.stage("Finished shouldRunAfter.");
|
|
1179
1204
|
return { ctx };
|
|
1180
1205
|
}
|
|
1206
|
+
/** Catch any error occurred during command. */
|
|
1207
|
+
// catch all those errors, not verbose
|
|
1181
1208
|
catch(e, exit) {
|
|
1182
1209
|
if (!this.logger) {
|
|
1183
1210
|
console.error("Logger has not been initiated yet!");
|
|
@@ -1206,10 +1233,6 @@ __name(Command, "Command");
|
|
|
1206
1233
|
|
|
1207
1234
|
// src/commands/config.command.ts
|
|
1208
1235
|
var ConfigCommand = class extends Command {
|
|
1209
|
-
constructor() {
|
|
1210
|
-
super(...arguments);
|
|
1211
|
-
this.ux = _core.CliUx.ux;
|
|
1212
|
-
}
|
|
1213
1236
|
async run() {
|
|
1214
1237
|
this.logger.stage("Setting up config command.");
|
|
1215
1238
|
const setup2 = await this.setup();
|
|
@@ -1224,7 +1247,7 @@ var ConfigCommand = class extends Command {
|
|
|
1224
1247
|
throw new Error("The command should be setup first!");
|
|
1225
1248
|
}
|
|
1226
1249
|
table(...options) {
|
|
1227
|
-
|
|
1250
|
+
_core.ux.table(...options);
|
|
1228
1251
|
}
|
|
1229
1252
|
async select() {
|
|
1230
1253
|
const response = await this.prompt({
|
|
@@ -1295,4 +1318,4 @@ var storeHook = /* @__PURE__ */ __name((cb) => async (opts) => {
|
|
|
1295
1318
|
|
|
1296
1319
|
|
|
1297
1320
|
|
|
1298
|
-
exports.CLI_FLAGS = CLI_FLAGS; exports.
|
|
1321
|
+
exports.CLI_FLAGS = CLI_FLAGS; exports.Command = Command; exports.ConfigCommand = ConfigCommand; exports.ConfigService = ConfigService; exports.EnvironmentVariableParser = EnvironmentVariableParser; exports.FileConstants = FileConstants; exports.FileSystemService = FileSystemService; exports.Flags = _core.Flags; exports.HelpGroups = HelpGroups; exports.JsonParser = JsonParser; exports.ListrLogger = ListrLogger; exports.LockerService = LockerService; exports.LogFieldStatus = LogFieldStatus; exports.LogLevels = LogLevels; exports.Logger = Logger; exports.MergeStrategy = MergeStrategy; exports.ParserService = ParserService; exports.StoreService = StoreService; exports.ValidatorService = ValidatorService; exports.YamlParser = YamlParser; exports.color = color; exports.fs = _fsextra2.default; exports.isDebug = isDebug; exports.isSilent = isSilent; exports.isVerbose = isVerbose; exports.merge = merge; exports.notFoundHook = notFoundHook; exports.pipeProcessThroughListr = pipeProcessThroughListr; exports.pipeProcessToLogger = pipeProcessToLogger; exports.setCtxAssign = setCtxAssign; exports.setCtxDefaults = setCtxDefaults; exports.setup = setup; exports.storeHook = storeHook; exports.uniqueFilter = uniqueFilter; exports.updateNotifierHook = updateNotifierHook; exports.ux = _core.ux;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cenk1cenk2/oclif-common",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.0.0",
|
|
4
4
|
"description": "Oclif common package for oclif2 projects.",
|
|
5
5
|
"repository": "https://gitlab.kilic.dev/libraries/oclif-tools",
|
|
6
6
|
"author": {
|
|
@@ -57,7 +57,7 @@
|
|
|
57
57
|
},
|
|
58
58
|
"dependencies": {
|
|
59
59
|
"colorette": "^2.0.19",
|
|
60
|
-
"deepmerge": "^4.
|
|
60
|
+
"deepmerge": "^4.3.0",
|
|
61
61
|
"object-path-immutable": "^4.1.2",
|
|
62
62
|
"reflect-metadata": "^0.1.13",
|
|
63
63
|
"through": "^2.3.8",
|
|
@@ -66,15 +66,15 @@
|
|
|
66
66
|
"yaml": "^2.2.1"
|
|
67
67
|
},
|
|
68
68
|
"devDependencies": {
|
|
69
|
-
"@oclif/core": "^
|
|
70
|
-
"@types/fs-extra": "^
|
|
69
|
+
"@oclif/core": "^2.5.0",
|
|
70
|
+
"@types/fs-extra": "^11.0.1",
|
|
71
71
|
"@types/through": "^0.0.30",
|
|
72
72
|
"@types/update-notifier": "^6",
|
|
73
73
|
"class-transformer": "^0.5.1",
|
|
74
74
|
"class-validator": "^0.14.0",
|
|
75
75
|
"enquirer": "^2.3.6",
|
|
76
76
|
"execa": "^5",
|
|
77
|
-
"fs-extra": "^
|
|
78
|
-
"listr2": "^5.0.
|
|
77
|
+
"fs-extra": "^11.1.0",
|
|
78
|
+
"listr2": "^5.0.7"
|
|
79
79
|
}
|
|
80
80
|
}
|