@done-coding/cli-utils 0.8.0 → 0.8.2-alpha.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/README.md +104 -2
- package/es/index.mjs +341 -334
- package/package.json +3 -3
- package/types/index.d.ts +100 -35
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@done-coding/cli-utils",
|
|
3
|
-
"version": "0.8.0",
|
|
3
|
+
"version": "0.8.2-alpha.0",
|
|
4
4
|
"description": "cli utils",
|
|
5
5
|
"private": false,
|
|
6
6
|
"module": "es/index.mjs",
|
|
@@ -50,7 +50,7 @@
|
|
|
50
50
|
"@types/uuid": "^10.0.0",
|
|
51
51
|
"@types/yargs": "^17.0.28",
|
|
52
52
|
"rimraf": "^6.0.1",
|
|
53
|
-
"typescript": "^5.
|
|
53
|
+
"typescript": "^5.8.3",
|
|
54
54
|
"vite": "^4.4.11",
|
|
55
55
|
"vite-plugin-dts": "^3.6.0"
|
|
56
56
|
},
|
|
@@ -70,5 +70,5 @@
|
|
|
70
70
|
"uuid": "^11.1.0",
|
|
71
71
|
"yargs": "^17.7.2"
|
|
72
72
|
},
|
|
73
|
-
"gitHead": "
|
|
73
|
+
"gitHead": "b09dd794f69ba2dafe22a3519d712d059c2eb376"
|
|
74
74
|
}
|
package/types/index.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import type { ArgumentsCamelCase } from 'yargs';
|
|
2
|
-
import chalk from 'chalk';
|
|
3
2
|
import type { CommandModule } from 'yargs';
|
|
4
3
|
import _curry from 'lodash.curry';
|
|
5
4
|
import _get from 'lodash.get';
|
|
@@ -31,7 +30,7 @@ export declare const addHuskyHooks: <H extends string>({ hookNames, rootDir, get
|
|
|
31
30
|
|
|
32
31
|
/** 添加package.json配置 */
|
|
33
32
|
export declare const addPackageConfig: ({ patchConfig, rootDir, }: {
|
|
34
|
-
patchConfig?: Record<string, any
|
|
33
|
+
patchConfig?: Record<string, any>;
|
|
35
34
|
rootDir: string;
|
|
36
35
|
}) => void;
|
|
37
36
|
|
|
@@ -44,15 +43,17 @@ export declare const applyUseTempDir: <T>({ dir, fn, endClear, exitClear, }: {
|
|
|
44
43
|
dir: string;
|
|
45
44
|
fn: (dir: string) => T;
|
|
46
45
|
/** 结束时移除临时目录 */
|
|
47
|
-
endClear?: boolean
|
|
46
|
+
endClear?: boolean;
|
|
48
47
|
/** 退出信号是否移除临时目录 */
|
|
49
|
-
exitClear?: boolean
|
|
48
|
+
exitClear?: boolean;
|
|
50
49
|
}) => T;
|
|
51
50
|
|
|
52
51
|
export { ArgumentsCamelCase }
|
|
53
52
|
|
|
54
53
|
/** 文件或文件夹是否存在(同步) */
|
|
55
|
-
export declare const assetIsExits: (
|
|
54
|
+
export declare const assetIsExits: (
|
|
55
|
+
/** 资源路径 */
|
|
56
|
+
assetPath: string) => boolean;
|
|
56
57
|
|
|
57
58
|
/**
|
|
58
59
|
* 检查路径是否存在(包括文件、目录、符号链接)
|
|
@@ -60,8 +61,6 @@ export declare const assetIsExits: (assetPath: string) => boolean;
|
|
|
60
61
|
*/
|
|
61
62
|
export declare const assetIsExitsAsync: (path: string) => Promise<boolean>;
|
|
62
63
|
|
|
63
|
-
export { chalk }
|
|
64
|
-
|
|
65
64
|
/** 检测当前正在变基 */
|
|
66
65
|
export declare const checkCurrentIsRebasing: (rootDir: string) => boolean;
|
|
67
66
|
|
|
@@ -161,6 +160,30 @@ export declare const fileAddX: (filePath: string) => void;
|
|
|
161
160
|
|
|
162
161
|
export { _get }
|
|
163
162
|
|
|
163
|
+
/** 快捷获取答案 */
|
|
164
|
+
export declare const getAnswerSwift: <V = unknown, T extends string = string>(key: T,
|
|
165
|
+
/** 表单问询配置 */
|
|
166
|
+
questionConfig: Parameters<typeof prompts<T>>[0]) => Promise<V>;
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* 获取答案 考虑mcp情况
|
|
170
|
+
* ----
|
|
171
|
+
* mcp 只拿预设值,非mcp优先拿默认值
|
|
172
|
+
* 有预设值的场景: MCP
|
|
173
|
+
*/
|
|
174
|
+
export declare const getAnswerWithMCP: <V = unknown, T extends string = string>({ isMCP, key, presetAnswer, defaultValue, questionConfig, }: {
|
|
175
|
+
/** 是否mcp场景 */
|
|
176
|
+
isMCP: boolean;
|
|
177
|
+
/** 表单key */
|
|
178
|
+
key: T;
|
|
179
|
+
/** 预设答案所在的对象 */
|
|
180
|
+
presetAnswer?: object & { [K in T]: any; };
|
|
181
|
+
/** 默认值 */
|
|
182
|
+
defaultValue?: V;
|
|
183
|
+
/** 表单问询配置 */
|
|
184
|
+
questionConfig: Parameters<typeof prompts<T>>[0];
|
|
185
|
+
}) => Promise<V>;
|
|
186
|
+
|
|
164
187
|
/** 获取cli模块【临时】目录[绝对路径] */
|
|
165
188
|
export declare const getCliModuleTempDir: (moduleName: string) => string;
|
|
166
189
|
|
|
@@ -173,14 +196,14 @@ export declare const getCommitByHookName: ({ hookName, rootDir, }: {
|
|
|
173
196
|
/** 获取配置文件通用选项 */
|
|
174
197
|
export declare const getConfigFileCommonOptions: ({ configPathDefault, rootDirDefault, }: {
|
|
175
198
|
configPathDefault: string;
|
|
176
|
-
rootDirDefault?: string
|
|
199
|
+
rootDirDefault?: string;
|
|
177
200
|
}) => Record<keyof ConfigFileCommonOptions, YargsOptions>;
|
|
178
201
|
|
|
179
202
|
/** 获取当前分支最近提交列表 */
|
|
180
203
|
export declare const getCurrentBranchLastCommitList: ({ count, }?: {
|
|
181
|
-
count?: number
|
|
204
|
+
count?: number;
|
|
182
205
|
/** 某个hash之后的提交 */
|
|
183
|
-
afterHash?: string
|
|
206
|
+
afterHash?: string;
|
|
184
207
|
}) => GitLogItemInfo[];
|
|
185
208
|
|
|
186
209
|
/** 获取当前分支名 */
|
|
@@ -202,18 +225,41 @@ export declare interface GetGitLastCommitParams {
|
|
|
202
225
|
remoteAlias?: GitRemoteInfo["alias"];
|
|
203
226
|
}
|
|
204
227
|
|
|
228
|
+
/**
|
|
229
|
+
* 获取git路径
|
|
230
|
+
* ---
|
|
231
|
+
* @param projectPath 项目路径
|
|
232
|
+
*/
|
|
233
|
+
export declare const getGitPath: (projectPath: string) => string;
|
|
234
|
+
|
|
205
235
|
/** 获取git项目目录 */
|
|
206
236
|
export declare const getGitProjectDir: (rootDir: string) => string;
|
|
207
237
|
|
|
208
238
|
/** 获取最后的reflog */
|
|
209
239
|
export declare const getLastReflogList: ({ count, filterItem, }?: {
|
|
210
|
-
count?: number
|
|
240
|
+
count?: number;
|
|
211
241
|
/** 某个hash之后的提交 */
|
|
212
|
-
afterHash?: string
|
|
242
|
+
afterHash?: string;
|
|
213
243
|
/** 过滤函数 */
|
|
214
|
-
filterItem?: (
|
|
244
|
+
filterItem?: (item: GitReflogItemInfoRaw) => boolean;
|
|
215
245
|
}) => GitReflogItemInfo[];
|
|
216
246
|
|
|
247
|
+
/** 获取输出文字 */
|
|
248
|
+
export declare const getLogText: ((type: LogTypeEnum, ...messages: unknown[]) => string) & {
|
|
249
|
+
/** 成功 */
|
|
250
|
+
success: (...messages: unknown[]) => string;
|
|
251
|
+
/** /步骤 */
|
|
252
|
+
stage: (...messages: unknown[]) => string;
|
|
253
|
+
/** 提示信息 */
|
|
254
|
+
info: (...messages: unknown[]) => string;
|
|
255
|
+
/** 警告 */
|
|
256
|
+
warn: (...messages: unknown[]) => string;
|
|
257
|
+
/** 错误 */
|
|
258
|
+
error: (...messages: unknown[]) => string;
|
|
259
|
+
/** 跳过 */
|
|
260
|
+
skip: (...messages: unknown[]) => string;
|
|
261
|
+
};
|
|
262
|
+
|
|
217
263
|
/** 获取package.json文件内容 */
|
|
218
264
|
export declare const getPackageJson: <R extends PackageJson>({ rootDir, }: {
|
|
219
265
|
rootDir: string;
|
|
@@ -222,7 +268,7 @@ export declare const getPackageJson: <R extends PackageJson>({ rootDir, }: {
|
|
|
222
268
|
/** 获取依赖包版本 */
|
|
223
269
|
export declare const getRelyPkgVersion: <R extends PackageJson>({ rootDir, pkgJson, pkgName, isDevPkg, }: {
|
|
224
270
|
rootDir: string;
|
|
225
|
-
pkgJson?: R
|
|
271
|
+
pkgJson?: R;
|
|
226
272
|
pkgName: string;
|
|
227
273
|
/** 是开发依赖包 */
|
|
228
274
|
isDevPkg: boolean;
|
|
@@ -235,8 +281,8 @@ export declare const getRootDirOptions: (rootDirDefault?: string) => {
|
|
|
235
281
|
|
|
236
282
|
/** 获取根命令名称 */
|
|
237
283
|
export declare const getRootScriptName: ({ rootScriptName, packageJson, }: {
|
|
238
|
-
rootScriptName?: string
|
|
239
|
-
packageJson?: Pick<PackageJson, "name" | "bin"
|
|
284
|
+
rootScriptName?: string;
|
|
285
|
+
packageJson?: Pick<PackageJson, "name" | "bin">;
|
|
240
286
|
}) => string | undefined;
|
|
241
287
|
|
|
242
288
|
/** 获取是否使用默认配置 */
|
|
@@ -421,8 +467,8 @@ export declare type InitConfigFileOptions = ConfigFileCommonOptions;
|
|
|
421
467
|
/** 初始化配置文件通用处理器 */
|
|
422
468
|
export declare const initHandlerCommon: <T>(content: T, argv: CliHandlerArgv<InitConfigFileOptions>, { onFileGenerated, edit, }?: {
|
|
423
469
|
/** 文件已生成 */
|
|
424
|
-
onFileGenerated?: (
|
|
425
|
-
edit?: boolean
|
|
470
|
+
onFileGenerated?: (path: string) => void;
|
|
471
|
+
edit?: boolean;
|
|
426
472
|
}) => Promise<void>;
|
|
427
473
|
|
|
428
474
|
/** 是http git地址 */
|
|
@@ -434,21 +480,23 @@ export declare const isSshGitUrl: (url: string) => boolean;
|
|
|
434
480
|
export { json5 }
|
|
435
481
|
|
|
436
482
|
/** 日志 */
|
|
437
|
-
export declare const log: ((type: LogTypeEnum, ...messages:
|
|
483
|
+
export declare const log: ((type: LogTypeEnum, ...messages: unknown[]) => void) & {
|
|
438
484
|
/** 成功 */
|
|
439
|
-
success: (...messages:
|
|
485
|
+
success: (...messages: unknown[]) => void;
|
|
440
486
|
/** /步骤 */
|
|
441
|
-
stage: (...messages:
|
|
487
|
+
stage: (...messages: unknown[]) => void;
|
|
442
488
|
/** 提示信息 */
|
|
443
|
-
info: (...messages:
|
|
489
|
+
info: (...messages: unknown[]) => void;
|
|
444
490
|
/** 警告 */
|
|
445
|
-
warn: (...messages:
|
|
491
|
+
warn: (...messages: unknown[]) => void;
|
|
446
492
|
/** 错误 */
|
|
447
|
-
error: (...messages:
|
|
493
|
+
error: (...messages: unknown[]) => void;
|
|
448
494
|
/** 跳过 */
|
|
449
|
-
skip: (...messages:
|
|
495
|
+
skip: (...messages: unknown[]) => void;
|
|
450
496
|
};
|
|
451
497
|
|
|
498
|
+
export declare type LogParams = [type: LogTypeEnum, ...messages: unknown[]];
|
|
499
|
+
|
|
452
500
|
/** 日志类型 */
|
|
453
501
|
declare enum LogTypeEnum {
|
|
454
502
|
/** 成功 */
|
|
@@ -468,9 +516,11 @@ declare enum LogTypeEnum {
|
|
|
468
516
|
/**
|
|
469
517
|
* 查找目标文件或目录
|
|
470
518
|
*/
|
|
471
|
-
export declare const lookForParentTarget: (
|
|
472
|
-
|
|
473
|
-
|
|
519
|
+
export declare const lookForParentTarget: (
|
|
520
|
+
/** 目标文件或目录 */
|
|
521
|
+
target: string, { currentDir, isFindFarthest, }?: {
|
|
522
|
+
currentDir?: string;
|
|
523
|
+
isFindFarthest?: boolean;
|
|
474
524
|
}) => string | undefined;
|
|
475
525
|
|
|
476
526
|
/** 用编辑器打开文件 */
|
|
@@ -510,7 +560,7 @@ export { PromptValueOrFunc }
|
|
|
510
560
|
export declare const pushGitPublishInfoToRemote: ({ branchName, version, remoteInfo, }: {
|
|
511
561
|
branchName: string;
|
|
512
562
|
version: string;
|
|
513
|
-
remoteInfo?: GitRemoteInfo
|
|
563
|
+
remoteInfo?: GitRemoteInfo;
|
|
514
564
|
}) => void;
|
|
515
565
|
|
|
516
566
|
/** 读取(某个模块)配置 */
|
|
@@ -535,7 +585,7 @@ export declare const readCliModuleAssetsConfig: <R>({ moduleName, onSuccess, }:
|
|
|
535
585
|
}) => Promise<R>;
|
|
536
586
|
|
|
537
587
|
/** 读取配置文件 */
|
|
538
|
-
export declare const readConfigFile: <T>(options: ReadConfigFileOptions, onNotExists?: (
|
|
588
|
+
export declare const readConfigFile: <T>(options: ReadConfigFileOptions, onNotExists?: () => T) => Promise<T>;
|
|
539
589
|
|
|
540
590
|
/** 读取配置文件选项 */
|
|
541
591
|
export declare type ReadConfigFileOptions = ConfigFileCommonOptions;
|
|
@@ -547,24 +597,32 @@ export declare const readFile: (assetPath: string) => string;
|
|
|
547
597
|
export declare const readFileAsync: (assetPath: string) => Promise<string>;
|
|
548
598
|
|
|
549
599
|
/** 读取json文件[同步] */
|
|
550
|
-
export declare const readJsonFile: <T>(assetPath: string, defaultValue?: T
|
|
600
|
+
export declare const readJsonFile: <T>(assetPath: string, defaultValue?: T) => T;
|
|
551
601
|
|
|
552
602
|
/** 读取json文件[异步] */
|
|
553
|
-
export declare const readJsonFileAsync: <T>(assetPath: string, defaultValue?: T
|
|
603
|
+
export declare const readJsonFileAsync: <T>(assetPath: string, defaultValue?: T) => Promise<T>;
|
|
554
604
|
|
|
555
605
|
/**
|
|
556
606
|
* 删除资源 (同步)
|
|
557
607
|
* ---
|
|
558
608
|
* 无论文件还是文件夹
|
|
559
609
|
*/
|
|
560
|
-
export declare const removeAsset: (
|
|
610
|
+
export declare const removeAsset: (
|
|
611
|
+
/** 资源路径 */
|
|
612
|
+
assetPath: string,
|
|
613
|
+
/** 是否要强删除 */
|
|
614
|
+
force?: boolean) => void;
|
|
561
615
|
|
|
562
616
|
/**
|
|
563
617
|
* 删除资源 (异步)
|
|
564
618
|
* ---
|
|
565
619
|
* 无论文件还是文件夹
|
|
566
620
|
*/
|
|
567
|
-
export declare const removeAssetAsync: (
|
|
621
|
+
export declare const removeAssetAsync: (
|
|
622
|
+
/** 资源路径 */
|
|
623
|
+
assetPath: string,
|
|
624
|
+
/** 是否要强删除 */
|
|
625
|
+
force?: boolean) => Promise<void>;
|
|
568
626
|
|
|
569
627
|
/** 解析checkoutInfo */
|
|
570
628
|
export declare const resolveCheckoutInfoByRefInfo: (message: string) => {
|
|
@@ -581,6 +639,13 @@ export declare const resolveMergeInfoByGitReflogAction: () => GitMergeBranchInfo
|
|
|
581
639
|
/** 从reflog type解析合并信息 */
|
|
582
640
|
export declare const resolveMergeInfoByRefType: (type: string) => GitMergeBranchInfo | undefined;
|
|
583
641
|
|
|
642
|
+
/**
|
|
643
|
+
* 移除git控制 - 异步
|
|
644
|
+
* @param projectPath
|
|
645
|
+
* @returns
|
|
646
|
+
*/
|
|
647
|
+
export declare const rmGitCtrlAsync: (projectPath: string) => Promise<void>;
|
|
648
|
+
|
|
584
649
|
export { _set }
|
|
585
650
|
|
|
586
651
|
/** 子cli信息 */
|
|
@@ -597,7 +662,7 @@ export declare type SupportGetCommitByHookName = (typeof SUPPORT_GET_COMMIT_BY_H
|
|
|
597
662
|
export { uuidv4 }
|
|
598
663
|
|
|
599
664
|
/** prompts 拓展 */
|
|
600
|
-
export declare const xPrompts: <T extends string = string>(
|
|
665
|
+
export declare const xPrompts: <T extends string = string>(...args: Parameters<typeof prompts<T>>) => Promise<prompts.Answers<T>>;
|
|
601
666
|
|
|
602
667
|
export { YargsArgv }
|
|
603
668
|
|