@done-coding/cli-utils 0.8.2-alpha.0 → 0.8.2-alpha.2
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/es/index.mjs +616 -347
- package/package.json +2 -4
- package/types/index.d.ts +181 -17
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@done-coding/cli-utils",
|
|
3
|
-
"version": "0.8.2-alpha.
|
|
3
|
+
"version": "0.8.2-alpha.2",
|
|
4
4
|
"description": "cli utils",
|
|
5
5
|
"private": false,
|
|
6
6
|
"module": "es/index.mjs",
|
|
@@ -47,7 +47,6 @@
|
|
|
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",
|
|
51
50
|
"@types/yargs": "^17.0.28",
|
|
52
51
|
"rimraf": "^6.0.1",
|
|
53
52
|
"typescript": "^5.8.3",
|
|
@@ -67,8 +66,7 @@
|
|
|
67
66
|
"pinyin": "^2.11.2",
|
|
68
67
|
"prompts": "^2.4.2",
|
|
69
68
|
"semver": "^7.5.4",
|
|
70
|
-
"uuid": "^11.1.0",
|
|
71
69
|
"yargs": "^17.7.2"
|
|
72
70
|
},
|
|
73
|
-
"gitHead": "
|
|
71
|
+
"gitHead": "7683cce31678dfecc6b35014f9658ad8b59f0c97"
|
|
74
72
|
}
|
package/types/index.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import type { ArgumentsCamelCase } from 'yargs';
|
|
2
2
|
import type { CommandModule } from 'yargs';
|
|
3
3
|
import _curry from 'lodash.curry';
|
|
4
|
+
import { ExecSyncOptions } from 'node:child_process';
|
|
5
|
+
import fs from 'node:fs';
|
|
4
6
|
import _get from 'lodash.get';
|
|
5
7
|
import json5 from 'json5';
|
|
6
8
|
import { Answers as PromptAnswers } from 'prompts';
|
|
@@ -14,7 +16,7 @@ import prompts from 'prompts';
|
|
|
14
16
|
import { PromptType } from 'prompts';
|
|
15
17
|
import { ValueOrFunc as PromptValueOrFunc } from 'prompts';
|
|
16
18
|
import _set from 'lodash.set';
|
|
17
|
-
import {
|
|
19
|
+
import type { WriteStream } from 'node:fs';
|
|
18
20
|
import yargs from 'yargs';
|
|
19
21
|
import type { Argv as YargsArgv } from 'yargs';
|
|
20
22
|
import type { Options as YargsOptions } from 'yargs';
|
|
@@ -34,6 +36,9 @@ export declare const addPackageConfig: ({ patchConfig, rootDir, }: {
|
|
|
34
36
|
rootDir: string;
|
|
35
37
|
}) => void;
|
|
36
38
|
|
|
39
|
+
/** 允许输出日志到控制台 */
|
|
40
|
+
export declare const allowConsoleLog: () => boolean;
|
|
41
|
+
|
|
37
42
|
/**
|
|
38
43
|
* 申请使用临时目录
|
|
39
44
|
* ---
|
|
@@ -123,6 +128,9 @@ export declare function decryptAES({ encryptedText, secretKey, }: {
|
|
|
123
128
|
secretKey: string;
|
|
124
129
|
}): string;
|
|
125
130
|
|
|
131
|
+
/** done-coding 全局环境配置symbol */
|
|
132
|
+
declare const DONE_CONFIG_ENV_CONFIG_GLOBAL_SYMBOL: unique symbol;
|
|
133
|
+
|
|
126
134
|
/** done-coding-cli 全局配置 */
|
|
127
135
|
export declare type DoneCodingCliGlobalConfig = {
|
|
128
136
|
[K in DoneCodingCliGlobalConfigKeyEnum]: string;
|
|
@@ -155,15 +163,76 @@ export declare function encryptAES({ text, secretKey, }: {
|
|
|
155
163
|
secretKey: string;
|
|
156
164
|
}): string;
|
|
157
165
|
|
|
166
|
+
/**
|
|
167
|
+
* 环境配置
|
|
168
|
+
* ----
|
|
169
|
+
* !!! 不应包含token等敏感信息, 只作为通过环境变量标识及相关 如标记mcp调用场景及相关日志行为等
|
|
170
|
+
* ----
|
|
171
|
+
* !!! 不作为主要的通信方式
|
|
172
|
+
*/
|
|
173
|
+
export declare interface EnvConfig {
|
|
174
|
+
/** 调用模式 */
|
|
175
|
+
callMode: EnvConfigCallModeEnum;
|
|
176
|
+
/** 系列
|
|
177
|
+
* ----
|
|
178
|
+
* 规划的系列 会有 cli 、server等
|
|
179
|
+
* 默认会是 `${DONE_CODING_SERIES_DEFAULT}`
|
|
180
|
+
*/
|
|
181
|
+
series: string;
|
|
182
|
+
/** 是否允许日志输出到控制台 */
|
|
183
|
+
consoleLog: boolean;
|
|
184
|
+
/** 日志输出路径 */
|
|
185
|
+
logOutputDir: string;
|
|
186
|
+
/**
|
|
187
|
+
* 进程日志文件名列表
|
|
188
|
+
* ----
|
|
189
|
+
* 新进程的日志从左侧进栈
|
|
190
|
+
*/
|
|
191
|
+
processLogFileNameList: string[];
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
/** 环境配置 - 调用模式枚举 */
|
|
195
|
+
export declare enum EnvConfigCallModeEnum {
|
|
196
|
+
DEFAULT = "DEFAULT",
|
|
197
|
+
MCP = "MCP"
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
/**
|
|
201
|
+
* 环境配置 在进程中 key的初始值枚举
|
|
202
|
+
*/
|
|
203
|
+
export declare enum EnvConfigProcessKeyEnum {
|
|
204
|
+
/**
|
|
205
|
+
* 全局配置镜像
|
|
206
|
+
*/
|
|
207
|
+
GLOBAL_CONFIG_IMAGE = "GLOBAL_CONFIG_IMAGE"
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
/**
|
|
211
|
+
* 工业级同步执行分发日志 (2026 稳定版)
|
|
212
|
+
*/
|
|
213
|
+
export declare const execSyncWithLogDispatch: (command: string, options?: ExecSyncOptions) => string | Buffer;
|
|
214
|
+
|
|
158
215
|
/** 文件添加执行权限 */
|
|
159
216
|
export declare const fileAddX: (filePath: string) => void;
|
|
160
217
|
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
/**
|
|
164
|
-
|
|
218
|
+
/** 格式化日志流写入格式 */
|
|
219
|
+
export declare const formatLogSteamWrite: ({ stream, type, content, }: {
|
|
220
|
+
/** 流类型 */
|
|
221
|
+
stream: WriteStream;
|
|
222
|
+
/** 日志类型 */
|
|
223
|
+
type: LogTypeEnum;
|
|
224
|
+
/** 日志内容 */
|
|
225
|
+
content: string;
|
|
226
|
+
}) => boolean;
|
|
227
|
+
|
|
228
|
+
/** 生成 获取答案的快捷函数 */
|
|
229
|
+
export declare const generateGetAnswerSwiftFn: ({ isMCP, presetAnswer, }: Pick<GetAnswerOptions<unknown, string>, "isMCP" | "presetAnswer">) => <V = unknown, T extends string = string>(key: T,
|
|
165
230
|
/** 表单问询配置 */
|
|
166
|
-
questionConfig
|
|
231
|
+
questionConfig?: Parameters<typeof prompts<T>>[0],
|
|
232
|
+
/** 默认值 */
|
|
233
|
+
defaultValue?: V) => Promise<V | undefined>;
|
|
234
|
+
|
|
235
|
+
export { _get }
|
|
167
236
|
|
|
168
237
|
/**
|
|
169
238
|
* 获取答案 考虑mcp情况
|
|
@@ -171,18 +240,29 @@ questionConfig: Parameters<typeof prompts<T>>[0]) => Promise<V>;
|
|
|
171
240
|
* mcp 只拿预设值,非mcp优先拿默认值
|
|
172
241
|
* 有预设值的场景: MCP
|
|
173
242
|
*/
|
|
174
|
-
export declare const
|
|
243
|
+
export declare const getAnswer: <V = unknown, T extends string = string>({ isMCP, key, presetAnswer, defaultValue, questionConfig, }: GetAnswerOptions<V, T>) => GetAnswerResult<V, T, typeof questionConfig>;
|
|
244
|
+
|
|
245
|
+
/** 获取答案 考虑mcp情况 的选项 */
|
|
246
|
+
export declare interface GetAnswerOptions<V, T extends string> {
|
|
175
247
|
/** 是否mcp场景 */
|
|
176
|
-
isMCP
|
|
248
|
+
isMCP?: boolean;
|
|
177
249
|
/** 表单key */
|
|
178
250
|
key: T;
|
|
179
251
|
/** 预设答案所在的对象 */
|
|
180
|
-
presetAnswer?: object & {
|
|
252
|
+
presetAnswer?: object & {
|
|
253
|
+
[K in T]?: any;
|
|
254
|
+
};
|
|
181
255
|
/** 默认值 */
|
|
182
256
|
defaultValue?: V;
|
|
183
257
|
/** 表单问询配置 */
|
|
184
|
-
questionConfig
|
|
185
|
-
}
|
|
258
|
+
questionConfig?: Parameters<typeof prompts<T>>[0];
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
/** 获取答案结果类型 */
|
|
262
|
+
export declare type GetAnswerResult<V, T extends string, Q extends GetAnswerOptions<V, T>["questionConfig"]> = Promise<Q extends undefined ? V | undefined : V>;
|
|
263
|
+
|
|
264
|
+
/** 获取调用模式 */
|
|
265
|
+
export declare const getCallMode: () => EnvConfigCallModeEnum;
|
|
186
266
|
|
|
187
267
|
/** 获取cli模块【临时】目录[绝对路径] */
|
|
188
268
|
export declare const getCliModuleTempDir: (moduleName: string) => string;
|
|
@@ -209,6 +289,9 @@ export declare const getCurrentBranchLastCommitList: ({ count, }?: {
|
|
|
209
289
|
/** 获取当前分支名 */
|
|
210
290
|
export declare const getCurrentBranchName: () => string | undefined;
|
|
211
291
|
|
|
292
|
+
/** 获取自身进程日志文件名 */
|
|
293
|
+
export declare const getCurrentProcessLogFileName: () => string;
|
|
294
|
+
|
|
212
295
|
/** 获取编辑器类型 */
|
|
213
296
|
export declare const getEditorType: () => Promise<any>;
|
|
214
297
|
|
|
@@ -244,8 +327,18 @@ export declare const getLastReflogList: ({ count, filterItem, }?: {
|
|
|
244
327
|
filterItem?: (item: GitReflogItemInfoRaw) => boolean;
|
|
245
328
|
}) => GitReflogItemInfo[];
|
|
246
329
|
|
|
330
|
+
/**
|
|
331
|
+
* 获取日志文件夹
|
|
332
|
+
* ----
|
|
333
|
+
* 绝对路径
|
|
334
|
+
* @param persistent 是否持久话
|
|
335
|
+
*/
|
|
336
|
+
export declare const getLogOutputDir: (persistent?: boolean) => string;
|
|
337
|
+
|
|
247
338
|
/** 获取输出文字 */
|
|
248
339
|
export declare const getLogText: ((type: LogTypeEnum, ...messages: unknown[]) => string) & {
|
|
340
|
+
/** 系统 */
|
|
341
|
+
system: (...messages: unknown[]) => string;
|
|
249
342
|
/** 成功 */
|
|
250
343
|
success: (...messages: unknown[]) => string;
|
|
251
344
|
/** /步骤 */
|
|
@@ -258,13 +351,30 @@ export declare const getLogText: ((type: LogTypeEnum, ...messages: unknown[]) =>
|
|
|
258
351
|
error: (...messages: unknown[]) => string;
|
|
259
352
|
/** 跳过 */
|
|
260
353
|
skip: (...messages: unknown[]) => string;
|
|
354
|
+
/** 表格 */
|
|
355
|
+
table: (...messages: unknown[]) => string;
|
|
261
356
|
};
|
|
262
357
|
|
|
358
|
+
/** 格式: 2026-01-18 11:38:05 */
|
|
359
|
+
export declare const getLogTime: () => string;
|
|
360
|
+
|
|
361
|
+
/** 通过 LogTypeEnum 枚举值或者key */
|
|
362
|
+
export declare const getLogTypeByValue: (value: LogTypeEnum) => string;
|
|
363
|
+
|
|
263
364
|
/** 获取package.json文件内容 */
|
|
264
365
|
export declare const getPackageJson: <R extends PackageJson>({ rootDir, }: {
|
|
265
366
|
rootDir: string;
|
|
266
367
|
}) => R;
|
|
267
368
|
|
|
369
|
+
/** 获取父级进程日志文件名 */
|
|
370
|
+
export declare const getParentProcessLogFileName: () => string | undefined;
|
|
371
|
+
|
|
372
|
+
/** 获取环境变量 */
|
|
373
|
+
export declare const getProcessEnv: <T>(keyInit: EnvConfigProcessKeyEnum, defaultValue?: T) => T | undefined;
|
|
374
|
+
|
|
375
|
+
/** 获取当前进程对应的日志流 */
|
|
376
|
+
export declare const getProcessLogStream: () => XFsWriteStream;
|
|
377
|
+
|
|
268
378
|
/** 获取依赖包版本 */
|
|
269
379
|
export declare const getRelyPkgVersion: <R extends PackageJson>({ rootDir, pkgJson, pkgName, isDevPkg, }: {
|
|
270
380
|
rootDir: string;
|
|
@@ -285,6 +395,9 @@ export declare const getRootScriptName: ({ rootScriptName, packageJson, }: {
|
|
|
285
395
|
packageJson?: Pick<PackageJson, "name" | "bin">;
|
|
286
396
|
}) => string | undefined;
|
|
287
397
|
|
|
398
|
+
/** 获取安全路径 */
|
|
399
|
+
export declare const getSafePath: (path?: string) => string;
|
|
400
|
+
|
|
288
401
|
/** 获取是否使用默认配置 */
|
|
289
402
|
export declare const getUseDefaultConfig: () => Promise<any>;
|
|
290
403
|
|
|
@@ -464,6 +577,19 @@ export declare const initConfigFile: <T>(content: T, argv: CliHandlerArgv<InitCo
|
|
|
464
577
|
/** 初始化文件选项 */
|
|
465
578
|
export declare type InitConfigFileOptions = ConfigFileCommonOptions;
|
|
466
579
|
|
|
580
|
+
/**
|
|
581
|
+
* 初始化环境配置
|
|
582
|
+
* ---
|
|
583
|
+
* !!! 顶级进程才调用且只能调用一次
|
|
584
|
+
* 非顶级进程调用会忽略入参 即优先使用父级设置的进程配置
|
|
585
|
+
* ---
|
|
586
|
+
* 即顶级进程调用
|
|
587
|
+
* 非顶级进程通过进程环境继承
|
|
588
|
+
*/
|
|
589
|
+
export declare const initEnvConfig: ({ series, ...otherConfig }: Partial<Pick<EnvConfig, "callMode" | "consoleLog"> & {
|
|
590
|
+
series: string;
|
|
591
|
+
}>) => EnvConfig;
|
|
592
|
+
|
|
467
593
|
/** 初始化配置文件通用处理器 */
|
|
468
594
|
export declare const initHandlerCommon: <T>(content: T, argv: CliHandlerArgv<InitConfigFileOptions>, { onFileGenerated, edit, }?: {
|
|
469
595
|
/** 文件已生成 */
|
|
@@ -474,6 +600,9 @@ export declare const initHandlerCommon: <T>(content: T, argv: CliHandlerArgv<Ini
|
|
|
474
600
|
/** 是http git地址 */
|
|
475
601
|
export declare const isHttpGitUrl: (url: string) => boolean;
|
|
476
602
|
|
|
603
|
+
/** 是mcp模式 */
|
|
604
|
+
export declare const isMcpMode: () => boolean;
|
|
605
|
+
|
|
477
606
|
/** 是 ssh git地址 */
|
|
478
607
|
export declare const isSshGitUrl: (url: string) => boolean;
|
|
479
608
|
|
|
@@ -481,6 +610,8 @@ export { json5 }
|
|
|
481
610
|
|
|
482
611
|
/** 日志 */
|
|
483
612
|
export declare const log: ((type: LogTypeEnum, ...messages: unknown[]) => void) & {
|
|
613
|
+
/** 系统 */
|
|
614
|
+
system: (...messages: unknown[]) => void;
|
|
484
615
|
/** 成功 */
|
|
485
616
|
success: (...messages: unknown[]) => void;
|
|
486
617
|
/** /步骤 */
|
|
@@ -493,24 +624,30 @@ export declare const log: ((type: LogTypeEnum, ...messages: unknown[]) => void)
|
|
|
493
624
|
error: (...messages: unknown[]) => void;
|
|
494
625
|
/** 跳过 */
|
|
495
626
|
skip: (...messages: unknown[]) => void;
|
|
627
|
+
/** 表格 */
|
|
628
|
+
table: (...messages: unknown[]) => void;
|
|
496
629
|
};
|
|
497
630
|
|
|
498
631
|
export declare type LogParams = [type: LogTypeEnum, ...messages: unknown[]];
|
|
499
632
|
|
|
500
633
|
/** 日志类型 */
|
|
501
|
-
declare enum LogTypeEnum {
|
|
634
|
+
export declare enum LogTypeEnum {
|
|
635
|
+
/** 系统 */
|
|
636
|
+
SYSTEM = "magenta",
|
|
502
637
|
/** 成功 */
|
|
503
|
-
SUCCESS = "
|
|
638
|
+
SUCCESS = "greenBright",
|
|
504
639
|
/** 步骤 */
|
|
505
640
|
STAGE = "blue",
|
|
506
641
|
/** 提示信息 */
|
|
507
|
-
INFO = "
|
|
642
|
+
INFO = "white",
|
|
508
643
|
/** 警告 */
|
|
509
644
|
WARN = "yellow",
|
|
510
645
|
/** 错误 */
|
|
511
|
-
ERROR = "
|
|
646
|
+
ERROR = "redBright",
|
|
512
647
|
/** 跳过 */
|
|
513
|
-
SKIP = "
|
|
648
|
+
SKIP = "dim",
|
|
649
|
+
/** ---- 表格 ---- */
|
|
650
|
+
TABLE = "table"
|
|
514
651
|
}
|
|
515
652
|
|
|
516
653
|
/**
|
|
@@ -538,6 +675,22 @@ export declare interface PackageJson {
|
|
|
538
675
|
peerDependencies?: Record<string, string>;
|
|
539
676
|
}
|
|
540
677
|
|
|
678
|
+
/**
|
|
679
|
+
* 参数转cli参数
|
|
680
|
+
* -----
|
|
681
|
+
* yargs 参数格式:
|
|
682
|
+
* --key=value
|
|
683
|
+
*/
|
|
684
|
+
export declare const params2cliParams: (params: Record<string, any>) => string;
|
|
685
|
+
|
|
686
|
+
/** 路径是否安全 */
|
|
687
|
+
export declare const pathIsSafe: (path?: string) => boolean;
|
|
688
|
+
|
|
689
|
+
/** 进程值变量初始值 */
|
|
690
|
+
export declare interface ProcessValueInit<T> {
|
|
691
|
+
value: T;
|
|
692
|
+
}
|
|
693
|
+
|
|
541
694
|
export { PromptAnswers }
|
|
542
695
|
|
|
543
696
|
export { PromptChoice }
|
|
@@ -659,7 +812,18 @@ export declare const SUPPORT_GET_COMMIT_BY_HOOKS_NAMES: readonly [HooksNameEnum.
|
|
|
659
812
|
|
|
660
813
|
export declare type SupportGetCommitByHookName = (typeof SUPPORT_GET_COMMIT_BY_HOOKS_NAMES)[number];
|
|
661
814
|
|
|
662
|
-
export
|
|
815
|
+
export declare const uuidv4: () => `${string}-${string}-${string}-${string}-${string}`;
|
|
816
|
+
|
|
817
|
+
/**
|
|
818
|
+
* fs.WriteStream 确实没有直接声明 fd 属性(虽然运行时它确实存在)。这是因为 fd 是由底层的物理文件句柄分配的,其类型定义在内部较为隐蔽。
|
|
819
|
+
*/
|
|
820
|
+
declare interface XFsWriteStream extends fs.WriteStream {
|
|
821
|
+
fd?: number;
|
|
822
|
+
}
|
|
823
|
+
|
|
824
|
+
export declare interface XGlobalThis {
|
|
825
|
+
[DONE_CONFIG_ENV_CONFIG_GLOBAL_SYMBOL]: EnvConfig;
|
|
826
|
+
}
|
|
663
827
|
|
|
664
828
|
/** prompts 拓展 */
|
|
665
829
|
export declare const xPrompts: <T extends string = string>(...args: Parameters<typeof prompts<T>>) => Promise<prompts.Answers<T>>;
|