@done-coding/cli-utils 0.7.8 → 0.8.1
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 +454 -396
- package/package.json +4 -2
- package/types/index.d.ts +108 -17
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@done-coding/cli-utils",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.1",
|
|
4
4
|
"description": "cli utils",
|
|
5
5
|
"private": false,
|
|
6
6
|
"module": "es/index.mjs",
|
|
@@ -47,6 +47,7 @@
|
|
|
47
47
|
"@types/pinyin": "^2.10.0",
|
|
48
48
|
"@types/prompts": "^2.4.6",
|
|
49
49
|
"@types/semver": "^7.5.3",
|
|
50
|
+
"@types/uuid": "^10.0.0",
|
|
50
51
|
"@types/yargs": "^17.0.28",
|
|
51
52
|
"rimraf": "^6.0.1",
|
|
52
53
|
"typescript": "^5.2.2",
|
|
@@ -66,7 +67,8 @@
|
|
|
66
67
|
"pinyin": "^2.11.2",
|
|
67
68
|
"prompts": "^2.4.2",
|
|
68
69
|
"semver": "^7.5.4",
|
|
70
|
+
"uuid": "^11.1.0",
|
|
69
71
|
"yargs": "^17.7.2"
|
|
70
72
|
},
|
|
71
|
-
"gitHead": "
|
|
73
|
+
"gitHead": "0930f800167c04a86b56eae9741872dd51bec0c6"
|
|
72
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';
|
|
@@ -15,6 +14,7 @@ import prompts from 'prompts';
|
|
|
15
14
|
import { PromptType } from 'prompts';
|
|
16
15
|
import { ValueOrFunc as PromptValueOrFunc } from 'prompts';
|
|
17
16
|
import _set from 'lodash.set';
|
|
17
|
+
import { v4 as uuidv4 } from 'uuid';
|
|
18
18
|
import yargs from 'yargs';
|
|
19
19
|
import type { Argv as YargsArgv } from 'yargs';
|
|
20
20
|
import type { Options as YargsOptions } from 'yargs';
|
|
@@ -34,9 +34,30 @@ export declare const addPackageConfig: ({ patchConfig, rootDir, }: {
|
|
|
34
34
|
rootDir: string;
|
|
35
35
|
}) => void;
|
|
36
36
|
|
|
37
|
+
/**
|
|
38
|
+
* 申请使用临时目录
|
|
39
|
+
* ---
|
|
40
|
+
* !!! 临时目录 默认 执行完成及退出信号发出时 清理临时文件
|
|
41
|
+
*/
|
|
42
|
+
export declare const applyUseTempDir: <T>({ dir, fn, endClear, exitClear, }: {
|
|
43
|
+
dir: string;
|
|
44
|
+
fn: (dir: string) => T;
|
|
45
|
+
/** 结束时移除临时目录 */
|
|
46
|
+
endClear?: boolean | undefined;
|
|
47
|
+
/** 退出信号是否移除临时目录 */
|
|
48
|
+
exitClear?: boolean | undefined;
|
|
49
|
+
}) => T;
|
|
50
|
+
|
|
37
51
|
export { ArgumentsCamelCase }
|
|
38
52
|
|
|
39
|
-
|
|
53
|
+
/** 文件或文件夹是否存在(同步) */
|
|
54
|
+
export declare const assetIsExits: (assetPath: string) => boolean;
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* 检查路径是否存在(包括文件、目录、符号链接)
|
|
58
|
+
* 异步版本,行为与 fs.existsSync 一致
|
|
59
|
+
*/
|
|
60
|
+
export declare const assetIsExitsAsync: (path: string) => Promise<boolean>;
|
|
40
61
|
|
|
41
62
|
/** 检测当前正在变基 */
|
|
42
63
|
export declare const checkCurrentIsRebasing: (rootDir: string) => boolean;
|
|
@@ -100,6 +121,22 @@ export declare function decryptAES({ encryptedText, secretKey, }: {
|
|
|
100
121
|
secretKey: string;
|
|
101
122
|
}): string;
|
|
102
123
|
|
|
124
|
+
/** done-coding-cli 全局配置 */
|
|
125
|
+
export declare type DoneCodingCliGlobalConfig = {
|
|
126
|
+
[K in DoneCodingCliGlobalConfigKeyEnum]: string;
|
|
127
|
+
};
|
|
128
|
+
|
|
129
|
+
/** done-coding-cli 全局配置 key 枚举 */
|
|
130
|
+
export declare enum DoneCodingCliGlobalConfigKeyEnum {
|
|
131
|
+
/**
|
|
132
|
+
* 资产配置仓库
|
|
133
|
+
* ---
|
|
134
|
+
* 1. http ssh则认为远程仓库 临时拉取到本地临时目录中
|
|
135
|
+
* 2. 若非上述 则认为本地【绝对】路径
|
|
136
|
+
*/
|
|
137
|
+
ASSETS_CONFIG_REPO_URL = "ASSETS_CONFIG_REPO_URL"
|
|
138
|
+
}
|
|
139
|
+
|
|
103
140
|
/** 编辑器类型枚举 */
|
|
104
141
|
export declare enum EditorTypeEnum {
|
|
105
142
|
/** vscode */
|
|
@@ -121,6 +158,9 @@ export declare const fileAddX: (filePath: string) => void;
|
|
|
121
158
|
|
|
122
159
|
export { _get }
|
|
123
160
|
|
|
161
|
+
/** 获取cli模块【临时】目录[绝对路径] */
|
|
162
|
+
export declare const getCliModuleTempDir: (moduleName: string) => string;
|
|
163
|
+
|
|
124
164
|
/** 根据hookName获取(将)提交的信息 */
|
|
125
165
|
export declare const getCommitByHookName: ({ hookName, rootDir, }: {
|
|
126
166
|
hookName: SupportGetCommitByHookName;
|
|
@@ -171,6 +211,22 @@ export declare const getLastReflogList: ({ count, filterItem, }?: {
|
|
|
171
211
|
filterItem?: ((item: GitReflogItemInfoRaw) => boolean) | undefined;
|
|
172
212
|
}) => GitReflogItemInfo[];
|
|
173
213
|
|
|
214
|
+
/** 获取输出文字 */
|
|
215
|
+
export declare const getLogText: ((type: LogTypeEnum, ...messages: unknown[]) => string) & {
|
|
216
|
+
/** 成功 */
|
|
217
|
+
success: (...messages: unknown[]) => string;
|
|
218
|
+
/** /步骤 */
|
|
219
|
+
stage: (...messages: unknown[]) => string;
|
|
220
|
+
/** 提示信息 */
|
|
221
|
+
info: (...messages: unknown[]) => string;
|
|
222
|
+
/** 警告 */
|
|
223
|
+
warn: (...messages: unknown[]) => string;
|
|
224
|
+
/** 错误 */
|
|
225
|
+
error: (...messages: unknown[]) => string;
|
|
226
|
+
/** 跳过 */
|
|
227
|
+
skip: (...messages: unknown[]) => string;
|
|
228
|
+
};
|
|
229
|
+
|
|
174
230
|
/** 获取package.json文件内容 */
|
|
175
231
|
export declare const getPackageJson: <R extends PackageJson>({ rootDir, }: {
|
|
176
232
|
rootDir: string;
|
|
@@ -391,21 +447,23 @@ export declare const isSshGitUrl: (url: string) => boolean;
|
|
|
391
447
|
export { json5 }
|
|
392
448
|
|
|
393
449
|
/** 日志 */
|
|
394
|
-
export declare const log: ((type: LogTypeEnum, ...messages:
|
|
450
|
+
export declare const log: ((type: LogTypeEnum, ...messages: unknown[]) => void) & {
|
|
395
451
|
/** 成功 */
|
|
396
|
-
success: (...messages:
|
|
452
|
+
success: (...messages: unknown[]) => void;
|
|
397
453
|
/** /步骤 */
|
|
398
|
-
stage: (...messages:
|
|
454
|
+
stage: (...messages: unknown[]) => void;
|
|
399
455
|
/** 提示信息 */
|
|
400
|
-
info: (...messages:
|
|
456
|
+
info: (...messages: unknown[]) => void;
|
|
401
457
|
/** 警告 */
|
|
402
|
-
warn: (...messages:
|
|
458
|
+
warn: (...messages: unknown[]) => void;
|
|
403
459
|
/** 错误 */
|
|
404
|
-
error: (...messages:
|
|
460
|
+
error: (...messages: unknown[]) => void;
|
|
405
461
|
/** 跳过 */
|
|
406
|
-
skip: (...messages:
|
|
462
|
+
skip: (...messages: unknown[]) => void;
|
|
407
463
|
};
|
|
408
464
|
|
|
465
|
+
export declare type LogParams = [type: LogTypeEnum, ...messages: unknown[]];
|
|
466
|
+
|
|
409
467
|
/** 日志类型 */
|
|
410
468
|
declare enum LogTypeEnum {
|
|
411
469
|
/** 成功 */
|
|
@@ -470,19 +528,24 @@ export declare const pushGitPublishInfoToRemote: ({ branchName, version, remoteI
|
|
|
470
528
|
remoteInfo?: GitRemoteInfo | undefined;
|
|
471
529
|
}) => void;
|
|
472
530
|
|
|
473
|
-
/**
|
|
474
|
-
export declare const
|
|
531
|
+
/** 读取(某个模块)配置 */
|
|
532
|
+
export declare const readCliModuleAssetsConfig: <R>({ moduleName, onSuccess, }: {
|
|
475
533
|
moduleName: string;
|
|
476
534
|
onSuccess: (params: {
|
|
535
|
+
/**
|
|
536
|
+
* 资产配置仓库地址
|
|
537
|
+
* ----
|
|
538
|
+
* 可能是 http ssh 也可能是本地【绝对】文件路径
|
|
539
|
+
*/
|
|
477
540
|
repoUrl: string;
|
|
478
|
-
/**
|
|
479
|
-
|
|
480
|
-
/**
|
|
481
|
-
|
|
541
|
+
/** 资产配置文件临时目录[绝对路径] */
|
|
542
|
+
assetsConfigRepoTempDir: string;
|
|
543
|
+
/** 模块对应的资产配置仓库(相对路径) */
|
|
544
|
+
moduleDirFileRelativePath: string;
|
|
545
|
+
/** 模块对应的资产配置入口文件(相对路径) */
|
|
546
|
+
moduleEntryFileRelativePath: string;
|
|
482
547
|
/** 配置文件内容 */
|
|
483
548
|
config: R;
|
|
484
|
-
/** 配置临时目录 */
|
|
485
|
-
configTemporaryDir: string;
|
|
486
549
|
}) => void | Promise<void>;
|
|
487
550
|
}) => Promise<R>;
|
|
488
551
|
|
|
@@ -492,6 +555,32 @@ export declare const readConfigFile: <T>(options: ReadConfigFileOptions, onNotEx
|
|
|
492
555
|
/** 读取配置文件选项 */
|
|
493
556
|
export declare type ReadConfigFileOptions = ConfigFileCommonOptions;
|
|
494
557
|
|
|
558
|
+
/** 读取文件[同步] */
|
|
559
|
+
export declare const readFile: (assetPath: string) => string;
|
|
560
|
+
|
|
561
|
+
/** 读取文件[异步] */
|
|
562
|
+
export declare const readFileAsync: (assetPath: string) => Promise<string>;
|
|
563
|
+
|
|
564
|
+
/** 读取json文件[同步] */
|
|
565
|
+
export declare const readJsonFile: <T>(assetPath: string, defaultValue?: T | undefined) => T;
|
|
566
|
+
|
|
567
|
+
/** 读取json文件[异步] */
|
|
568
|
+
export declare const readJsonFileAsync: <T>(assetPath: string, defaultValue?: T | undefined) => Promise<T>;
|
|
569
|
+
|
|
570
|
+
/**
|
|
571
|
+
* 删除资源 (同步)
|
|
572
|
+
* ---
|
|
573
|
+
* 无论文件还是文件夹
|
|
574
|
+
*/
|
|
575
|
+
export declare const removeAsset: (assetPath: string, force?: boolean) => void;
|
|
576
|
+
|
|
577
|
+
/**
|
|
578
|
+
* 删除资源 (异步)
|
|
579
|
+
* ---
|
|
580
|
+
* 无论文件还是文件夹
|
|
581
|
+
*/
|
|
582
|
+
export declare const removeAssetAsync: (assetPath: string, force?: boolean) => Promise<void>;
|
|
583
|
+
|
|
495
584
|
/** 解析checkoutInfo */
|
|
496
585
|
export declare const resolveCheckoutInfoByRefInfo: (message: string) => {
|
|
497
586
|
fromBranch: string;
|
|
@@ -520,6 +609,8 @@ export declare const SUPPORT_GET_COMMIT_BY_HOOKS_NAMES: readonly [HooksNameEnum.
|
|
|
520
609
|
|
|
521
610
|
export declare type SupportGetCommitByHookName = (typeof SUPPORT_GET_COMMIT_BY_HOOKS_NAMES)[number];
|
|
522
611
|
|
|
612
|
+
export { uuidv4 }
|
|
613
|
+
|
|
523
614
|
/** prompts 拓展 */
|
|
524
615
|
export declare const xPrompts: <T extends string = string>(questions: prompts.PromptObject<T> | prompts.PromptObject<T>[], options?: prompts.Options | undefined) => Promise<prompts.Answers<T>>;
|
|
525
616
|
|