mixcli 3.0.10 → 3.2.1
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/index.cjs +4 -0
- package/dist/index.cjs.map +1 -0
- package/dist/{index.d.mts → index.d.cts} +75 -99
- package/dist/index.d.ts +75 -99
- package/dist/index.js +3 -1125
- package/dist/index.js.map +1 -1
- package/package.json +30 -13
- package/readme.md +8 -12
- package/src/cli.ts +21 -21
- package/src/command.ts +452 -451
- package/src/finder.ts +142 -142
- package/src/index.ts +5 -4
- package/src/option.ts +40 -81
- package/src/prompt.ts +183 -110
- package/src/utils.ts +144 -158
- package/dist/index.mjs +0 -1081
- package/dist/index.mjs.map +0 -1
- package/src/oslocate.js +0 -148
package/dist/index.d.ts
CHANGED
@@ -1,12 +1,14 @@
|
|
1
1
|
import { LiteEvent } from 'flex-tools/events/liteEvent';
|
2
|
-
import { Option, Command } from 'commander';
|
2
|
+
import { OptionValues, Option, Command } from 'commander';
|
3
3
|
import { PromptObject } from 'prompts';
|
4
|
-
import * as
|
4
|
+
import * as flex_tools__ from 'flex-tools/*';
|
5
5
|
|
6
6
|
type PromptType = "text" | "password" | "invisible" | "number" | "confirm" | "list" | "toggle" | "select" | "multiselect" | "autocomplete" | "date" | "autocompleteMultiselect";
|
7
7
|
type PromptParam = 'auto' | boolean | PromptType | PromptObject;
|
8
8
|
type InputPromptParam = PromptParam | ((value: any) => PromptParam) | boolean;
|
9
9
|
type PromptParamDefaultValue = string | boolean | string[];
|
10
|
+
declare const promptTypeMap: Record<string, string>;
|
11
|
+
declare const supportedPromptTypes: string[];
|
10
12
|
interface PromptChoice {
|
11
13
|
title: string;
|
12
14
|
value?: any;
|
@@ -14,129 +16,115 @@ interface PromptChoice {
|
|
14
16
|
selected?: boolean | undefined;
|
15
17
|
description?: string | undefined;
|
16
18
|
}
|
17
|
-
|
18
|
-
required?: boolean;
|
19
|
-
optional?: boolean;
|
20
|
-
default?: PromptParamDefaultValue;
|
21
|
-
choices?: (PromptChoice | any)[];
|
22
|
-
prompt?: InputPromptParam;
|
23
|
-
validate?: (value: any) => boolean;
|
24
|
-
}
|
25
|
-
interface IPromptable {
|
26
|
-
name(): string;
|
27
|
-
description?: string;
|
28
|
-
flags: string;
|
29
|
-
promptChoices?: PromptChoice[];
|
30
|
-
argChoices?: string[];
|
31
|
-
variadic?: boolean;
|
32
|
-
defaultValue?: PromptParamDefaultValue;
|
33
|
-
input?: any;
|
34
|
-
required?: boolean;
|
35
|
-
validate?: (value: any) => boolean;
|
36
|
-
getPrompt(inputValue?: any): PromptObject | undefined;
|
37
|
-
}
|
19
|
+
type PromptParams = Omit<PromptObject, 'name'> | PromptType | boolean | 'auto' | undefined;
|
38
20
|
/**
|
39
21
|
* 负责生成prompt对象
|
40
22
|
*
|
41
23
|
*/
|
42
|
-
declare class
|
43
|
-
|
44
|
-
|
45
|
-
constructor(
|
24
|
+
declare class MixOptionPrompt {
|
25
|
+
cliOption: MixOption;
|
26
|
+
params?: PromptParams;
|
27
|
+
constructor(cliOption: MixOption, promptParams?: PromptParams);
|
46
28
|
/**
|
47
29
|
* 返回输入的是否是有效的prompt类型
|
48
30
|
* @param type
|
49
31
|
* @returns
|
50
32
|
*/
|
51
|
-
|
33
|
+
isValidPromptType(type: any): boolean;
|
52
34
|
/**
|
53
35
|
* 推断是否需要提示
|
54
36
|
*
|
37
|
+
* 1. 显式指定prompt=true或者提示类型,或者提示对象,则需要提示
|
38
|
+
*
|
39
|
+
*
|
55
40
|
*/
|
56
|
-
|
41
|
+
isNeedPrompt(input: any, defaultValue?: any): boolean;
|
42
|
+
private _getChoices;
|
57
43
|
/**
|
58
|
-
*
|
44
|
+
* 自动推断prompt类型
|
45
|
+
*
|
46
|
+
*
|
59
47
|
*
|
60
48
|
* @param inputValue 从命令行输入的值
|
61
49
|
*/
|
62
|
-
|
50
|
+
infer(inputValue?: any): PromptType;
|
63
51
|
/**
|
64
|
-
*
|
52
|
+
* 返回生成prompt对象
|
65
53
|
*
|
66
54
|
* @param inputValue 从命令行输入的值
|
67
55
|
*/
|
68
|
-
|
56
|
+
get(inputValue?: any): PromptObject<string> | undefined;
|
69
57
|
}
|
70
58
|
|
71
|
-
interface MixedOptionParams
|
72
|
-
|
59
|
+
interface MixedOptionParams {
|
60
|
+
required?: boolean;
|
61
|
+
optional?: boolean;
|
62
|
+
variadic?: boolean;
|
63
|
+
mandatory?: boolean;
|
64
|
+
negate?: boolean;
|
65
|
+
default?: any;
|
73
66
|
defaultDescription?: string;
|
74
67
|
conflicts?: string | string[];
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
68
|
+
argParser?: unknown;
|
69
|
+
implies?: OptionValues;
|
70
|
+
envVar?: string;
|
71
|
+
parseArg?: <T>(value: string, previous: T) => T;
|
72
|
+
hidden?: boolean;
|
73
|
+
choices?: (string | PromptChoice)[] | ((pre: any, answers: any) => (string | PromptChoice)[]);
|
74
|
+
validate?: (value: any) => boolean;
|
75
|
+
preset?: unknown;
|
76
|
+
prompt?: PromptParams;
|
82
77
|
}
|
83
|
-
declare class MixOption extends Option
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
constructor(flags: string, description
|
88
|
-
|
89
|
-
choices(values: (PromptChoice | string)[]): void;
|
90
|
-
private resetChoices;
|
91
|
-
addChoice(value: PromptChoice | string): void;
|
92
|
-
removeChoice(value: any): void;
|
93
|
-
clearChoice(): void;
|
78
|
+
declare class MixOption extends Option {
|
79
|
+
params?: MixedOptionParams | undefined;
|
80
|
+
__MIX_OPTION__: boolean;
|
81
|
+
prompt?: MixOptionPrompt;
|
82
|
+
constructor(flags: string, description: string, params?: MixedOptionParams | undefined);
|
83
|
+
private _setOption;
|
94
84
|
/**
|
95
85
|
* 返回选项的提示对象
|
96
86
|
*
|
97
87
|
* @remarks
|
98
|
-
*
|
99
|
-
*
|
100
|
-
*
|
101
88
|
* @param inputValue
|
102
89
|
* @returns
|
103
90
|
*/
|
104
91
|
getPrompt(inputValue?: any): PromptObject | undefined;
|
105
92
|
}
|
106
93
|
|
107
|
-
type
|
94
|
+
type IMixCommandHookListener = ({ args, options, command, }: {
|
108
95
|
args: any[];
|
109
96
|
options: Record<string, any>;
|
110
97
|
command: MixCommand;
|
111
98
|
}) => void | Promise<void>;
|
112
|
-
type
|
99
|
+
type BeforeMixCommandHookListener = ({ args, options, command, }: {
|
113
100
|
args: any[];
|
114
101
|
options: Record<string, any>;
|
115
102
|
command: MixCommand;
|
116
103
|
}) => void | Promise<void>;
|
117
|
-
type
|
104
|
+
type AfterMixCommandHookListener = ({ value, args, options, command, }: {
|
118
105
|
value: any;
|
119
106
|
args: any[];
|
120
107
|
options: Record<string, any>;
|
121
108
|
command: MixCommand;
|
122
109
|
}) => void | Promise<void>;
|
123
|
-
interface
|
110
|
+
interface MixActionOptions {
|
124
111
|
id: string;
|
125
112
|
at: "replace" | "before" | "after" | "preappend" | "append" | number;
|
126
113
|
enhance: boolean;
|
127
114
|
}
|
128
|
-
interface
|
115
|
+
interface MixActionRegistry extends Omit<MixActionOptions, "at"> {
|
129
116
|
fn: Function;
|
130
117
|
}
|
131
|
-
type
|
132
|
-
type
|
118
|
+
type MixOriginalAction = (...args: any[]) => any | Promise<void>;
|
119
|
+
type MixEnhanceAction = ({ args, options, value, command, }: {
|
133
120
|
args: any[];
|
134
121
|
options: Record<string, any>;
|
135
122
|
value: any;
|
136
123
|
command: MixCommand;
|
137
|
-
}) =>
|
124
|
+
}) => any | Promise<any>;
|
138
125
|
declare const BREAK: unique symbol;
|
139
126
|
declare class MixCommand extends Command {
|
127
|
+
__MIX_COMMAND__: boolean;
|
140
128
|
private _beforeHooks;
|
141
129
|
private _afterHooks;
|
142
130
|
private _customPrompts;
|
@@ -144,20 +132,18 @@ declare class MixCommand extends Command {
|
|
144
132
|
private _actions;
|
145
133
|
private _enable_prompts;
|
146
134
|
constructor(name?: string);
|
147
|
-
/**
|
148
|
-
* 是否是根命令
|
149
|
-
*/
|
150
135
|
get isRoot(): boolean;
|
151
|
-
get
|
152
|
-
get
|
153
|
-
get
|
136
|
+
get optionValues(): Record<string, any>;
|
137
|
+
get actions(): MixActionRegistry[];
|
138
|
+
get beforeHooks(): [BeforeMixCommandHookListener, boolean][];
|
139
|
+
get afterHooks(): [AfterMixCommandHookListener, boolean][];
|
154
140
|
get fullname(): string;
|
155
141
|
/**
|
156
142
|
* 返回根命令
|
157
143
|
*/
|
158
|
-
root():
|
159
|
-
action(fn:
|
160
|
-
action(fn:
|
144
|
+
root(): any;
|
145
|
+
action(fn: MixEnhanceAction, options: MixActionOptions): this;
|
146
|
+
action(fn: MixOriginalAction): this;
|
161
147
|
/**
|
162
148
|
* 读取命令配置值,包括父命令提供的配置选项
|
163
149
|
* @param command
|
@@ -186,7 +172,7 @@ declare class MixCommand extends Command {
|
|
186
172
|
* @param scope =false时代表只在本命令执行,=true时代表在本命令及其子命令执行
|
187
173
|
* @returns
|
188
174
|
*/
|
189
|
-
before(listener:
|
175
|
+
before(listener: BeforeMixCommandHookListener, scope?: boolean): this;
|
190
176
|
private executeBeforeHooks;
|
191
177
|
/**
|
192
178
|
* 添加一个After钩子
|
@@ -194,7 +180,7 @@ declare class MixCommand extends Command {
|
|
194
180
|
* @param scope =false时代表只在本命令执行,=true时代表在本命令及其子命令执行
|
195
181
|
* @returns
|
196
182
|
*/
|
197
|
-
after(listener:
|
183
|
+
after(listener: AfterMixCommandHookListener, scope?: boolean): this;
|
198
184
|
private executeAfterHooks;
|
199
185
|
private preActionHook;
|
200
186
|
private isEnablePrompts;
|
@@ -202,14 +188,14 @@ declare class MixCommand extends Command {
|
|
202
188
|
* 生成选项自动提示
|
203
189
|
*
|
204
190
|
* @remarks
|
205
|
-
*
|
191
|
+
* 要求所有未提供默认值的Option自动生成提示
|
206
192
|
*
|
207
193
|
* - 未提供默认值,并且是必选的参数Option
|
208
194
|
* - 指定了choices但未提供有效值的Option
|
209
195
|
*
|
210
196
|
*/
|
211
197
|
private generateAutoPrompts;
|
212
|
-
option(flags: string, description
|
198
|
+
option(flags: string, description: string, options?: MixedOptionParams): this;
|
213
199
|
/**
|
214
200
|
* 添加提示
|
215
201
|
*
|
@@ -217,9 +203,7 @@ declare class MixCommand extends Command {
|
|
217
203
|
*
|
218
204
|
* 添加一些自定义提示
|
219
205
|
*
|
220
|
-
*
|
221
206
|
* @param questions
|
222
|
-
* @param show 是否显示提示信息,auto表示只有在用户没有提供option的值时才显示提示信息,always表示总是显示提示信息,never表示不显示提示信息
|
223
207
|
* @returns
|
224
208
|
*/
|
225
209
|
prompt(questions: PromptObject | PromptObject[]): this;
|
@@ -237,6 +221,9 @@ declare class MixCommand extends Command {
|
|
237
221
|
* 禁用/启用所有提示
|
238
222
|
*/
|
239
223
|
disablePrompts(): this;
|
224
|
+
/**
|
225
|
+
* 启用所有提示
|
226
|
+
*/
|
240
227
|
enablePrompts(): this;
|
241
228
|
}
|
242
229
|
|
@@ -253,12 +240,13 @@ interface MixCliOptions {
|
|
253
240
|
cliDir?: string;
|
254
241
|
context?: Record<string, any>;
|
255
242
|
prompt?: 'auto' | boolean;
|
243
|
+
ignoreError?: boolean;
|
256
244
|
}
|
257
245
|
type MixCliCommand = (cli: MixCli) => MixCommand | MixCommand[] | void;
|
258
246
|
type MixCliEvents = "register";
|
259
247
|
declare class MixCli extends LiteEvent<any, MixCliEvents> {
|
260
248
|
options: Required<MixCliOptions>;
|
261
|
-
root:
|
249
|
+
root: MixCommand;
|
262
250
|
private findSignals;
|
263
251
|
constructor(options?: MixCliOptions);
|
264
252
|
get context(): Record<string, any>;
|
@@ -328,12 +316,6 @@ declare class MixCli extends LiteEvent<any, MixCliEvents> {
|
|
328
316
|
* 运行命令行程序
|
329
317
|
*/
|
330
318
|
run(): void;
|
331
|
-
/**
|
332
|
-
* 创建一个命令
|
333
|
-
*
|
334
|
-
*
|
335
|
-
*/
|
336
|
-
create(): void;
|
337
319
|
}
|
338
320
|
|
339
321
|
/**
|
@@ -375,24 +357,17 @@ declare function addBuiltInOptions(command: any): void;
|
|
375
357
|
* 是否命令行中包含了--debug-cli选项
|
376
358
|
*/
|
377
359
|
declare function isDebug(): boolean;
|
378
|
-
declare function
|
360
|
+
declare function isDisablePrompts(): boolean;
|
379
361
|
/**
|
380
362
|
* 打印调试信息
|
381
363
|
* @param message
|
382
364
|
* @param args
|
383
365
|
*/
|
384
366
|
declare function outputDebug(message: string, ...args: any[]): void;
|
385
|
-
declare const fileExists:
|
386
|
-
declare const readFile:
|
387
|
-
declare const writeFile:
|
388
|
-
declare const mkdir:
|
389
|
-
/**
|
390
|
-
* 基于artTemplate模板生成文件
|
391
|
-
*
|
392
|
-
* @param {*} tmplFile
|
393
|
-
* @param {*} vars
|
394
|
-
*/
|
395
|
-
declare function createFileByTemplate(targetFile: string, tmplFile: string, vars?: Record<string, any>): Promise<string>;
|
367
|
+
declare const fileExists: flex_tools__.AsyncFunction;
|
368
|
+
declare const readFile: flex_tools__.AsyncFunction;
|
369
|
+
declare const writeFile: flex_tools__.AsyncFunction;
|
370
|
+
declare const mkdir: flex_tools__.AsyncFunction;
|
396
371
|
/**
|
397
372
|
* 创建目录
|
398
373
|
*
|
@@ -407,7 +382,8 @@ declare function mkDirs(dirs: string[], { callback, base }: {
|
|
407
382
|
base?: string;
|
408
383
|
}): Promise<void>;
|
409
384
|
declare function showError(e: any): void;
|
385
|
+
declare function hyphenToCamelCase(str: string): string;
|
410
386
|
declare function getId(): string;
|
411
387
|
declare function importModule(file: string): Promise<any>;
|
412
388
|
|
413
|
-
export {
|
389
|
+
export { type AfterMixCommandHookListener, BREAK, type BeforeMixCommandHookListener, type IMixCommandHookListener, type InputPromptParam, type MixActionOptions, type MixActionRegistry, MixCli, type MixCliCommand, type MixCliEvents, type MixCliOptions, MixCommand, type MixEnhanceAction, MixOption, MixOptionPrompt, type MixOriginalAction, type MixedOptionParams, type PromptChoice, type PromptParam, type PromptParamDefaultValue, type PromptParams, type PromptType, addBuiltInOptions, fileExists, fixIndent, getId, hyphenToCamelCase, importModule, isDebug, isDisablePrompts, mkDirs, mkdir, outputDebug, outputStr, promptTypeMap, readFile, showError, supportedPromptTypes, writeFile };
|