@oclif/core 4.1.0 → 4.2.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/lib/interfaces/hooks.d.ts +11 -0
- package/lib/main.js +12 -11
- package/lib/ux/index.d.ts +1 -0
- package/lib/ux/index.js +3 -2
- package/package.json +1 -1
|
@@ -33,6 +33,13 @@ export interface Hooks {
|
|
|
33
33
|
};
|
|
34
34
|
return: unknown;
|
|
35
35
|
};
|
|
36
|
+
finally: {
|
|
37
|
+
options: {
|
|
38
|
+
argv: string[];
|
|
39
|
+
id: string;
|
|
40
|
+
};
|
|
41
|
+
return: void;
|
|
42
|
+
};
|
|
36
43
|
init: {
|
|
37
44
|
options: {
|
|
38
45
|
argv: string[];
|
|
@@ -105,6 +112,10 @@ export type Hook<T extends keyof P, P extends Hooks = Hooks> = (this: Hook.Conte
|
|
|
105
112
|
context: Context;
|
|
106
113
|
}) => Promise<P[T]['return']>;
|
|
107
114
|
export declare namespace Hook {
|
|
115
|
+
/**
|
|
116
|
+
* Runs at the end of the CLI lifecycle - regardless of success or failure.
|
|
117
|
+
*/
|
|
118
|
+
type Finally = Hook<'finally'>;
|
|
108
119
|
/**
|
|
109
120
|
* Runs when the CLI is initialized before a command is executed.
|
|
110
121
|
*/
|
package/lib/main.js
CHANGED
|
@@ -37,13 +37,6 @@ exports.versionAddition = versionAddition;
|
|
|
37
37
|
async function run(argv, options) {
|
|
38
38
|
const marker = performance_1.Performance.mark(performance_1.OCLIF_MARKER_OWNER, 'main.run');
|
|
39
39
|
const initMarker = performance_1.Performance.mark(performance_1.OCLIF_MARKER_OWNER, 'main.run#init');
|
|
40
|
-
const collectPerf = async () => {
|
|
41
|
-
marker?.stop();
|
|
42
|
-
if (!initMarker?.stopped)
|
|
43
|
-
initMarker?.stop();
|
|
44
|
-
await performance_1.Performance.collect();
|
|
45
|
-
performance_1.Performance.debug();
|
|
46
|
-
};
|
|
47
40
|
const showHelp = async (argv) => {
|
|
48
41
|
const Help = await (0, help_1.loadHelpClass)(config);
|
|
49
42
|
const help = new Help(config, config.pjson.oclif.helpOptions ?? config.pjson.helpOptions);
|
|
@@ -66,18 +59,26 @@ async function run(argv, options) {
|
|
|
66
59
|
argv = [symbols_1.SINGLE_COMMAND_CLI_SYMBOL, ...argv];
|
|
67
60
|
}
|
|
68
61
|
const [id, ...argvSlice] = (0, help_1.normalizeArgv)(config, argv);
|
|
62
|
+
const runFinally = async () => {
|
|
63
|
+
marker?.stop();
|
|
64
|
+
if (!initMarker?.stopped)
|
|
65
|
+
initMarker?.stop();
|
|
66
|
+
await performance_1.Performance.collect();
|
|
67
|
+
performance_1.Performance.debug();
|
|
68
|
+
await config.runHook('finally', { argv: argvSlice, id });
|
|
69
|
+
};
|
|
69
70
|
// run init hook
|
|
70
71
|
await config.runHook('init', { argv: argvSlice, id });
|
|
71
72
|
// display version if applicable
|
|
72
73
|
if ((0, exports.versionAddition)(argv, config)) {
|
|
73
74
|
ux_1.ux.stdout(config.userAgent);
|
|
74
|
-
await
|
|
75
|
+
await runFinally();
|
|
75
76
|
return;
|
|
76
77
|
}
|
|
77
78
|
// display help version if applicable
|
|
78
79
|
if ((0, exports.helpAddition)(argv, config)) {
|
|
79
80
|
await showHelp(argv);
|
|
80
|
-
await
|
|
81
|
+
await runFinally();
|
|
81
82
|
return;
|
|
82
83
|
}
|
|
83
84
|
// find & run command
|
|
@@ -86,7 +87,7 @@ async function run(argv, options) {
|
|
|
86
87
|
const topic = config.flexibleTaxonomy ? null : config.findTopic(id);
|
|
87
88
|
if (topic) {
|
|
88
89
|
await showHelp([id]);
|
|
89
|
-
await
|
|
90
|
+
await runFinally();
|
|
90
91
|
return;
|
|
91
92
|
}
|
|
92
93
|
}
|
|
@@ -95,6 +96,6 @@ async function run(argv, options) {
|
|
|
95
96
|
return await config.runCommand(id, argvSlice, cmd);
|
|
96
97
|
}
|
|
97
98
|
finally {
|
|
98
|
-
await
|
|
99
|
+
await runFinally();
|
|
99
100
|
}
|
|
100
101
|
}
|
package/lib/ux/index.d.ts
CHANGED
|
@@ -11,6 +11,7 @@ export { warn } from '../errors/warn';
|
|
|
11
11
|
export { default as colorizeJson } from './colorize-json';
|
|
12
12
|
export { colorize } from './theme';
|
|
13
13
|
export { stderr, stdout } from './write';
|
|
14
|
+
export declare const action: Simple | Spinner;
|
|
14
15
|
export declare const ux: {
|
|
15
16
|
action: Simple | Spinner;
|
|
16
17
|
/**
|
package/lib/ux/index.js
CHANGED
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.ux = exports.stdout = exports.stderr = exports.colorize = exports.colorizeJson = exports.warn = exports.exit = exports.error = void 0;
|
|
6
|
+
exports.ux = exports.action = exports.stdout = exports.stderr = exports.colorize = exports.colorizeJson = exports.warn = exports.exit = exports.error = void 0;
|
|
7
7
|
const error_1 = require("../errors/error");
|
|
8
8
|
const exit_1 = require("../errors/exit");
|
|
9
9
|
const warn_1 = require("../errors/warn");
|
|
@@ -30,8 +30,9 @@ const ACTION_TYPE = (Boolean(process.stderr.isTTY) &&
|
|
|
30
30
|
!['dumb', 'emacs-color'].includes(process.env.TERM) &&
|
|
31
31
|
'spinner') ||
|
|
32
32
|
'simple';
|
|
33
|
+
exports.action = ACTION_TYPE === 'spinner' ? new spinner_1.default() : new simple_1.default();
|
|
33
34
|
exports.ux = {
|
|
34
|
-
action:
|
|
35
|
+
action: exports.action,
|
|
35
36
|
/**
|
|
36
37
|
* Add color to text.
|
|
37
38
|
* @param color color to use. Can be hex code (e.g. `#ff0000`), rgb (e.g. `rgb(255, 255, 255)`) or a standard ansi color (e.g. `red`)
|