@done-coding/cli-utils 0.8.2-alpha.0 → 0.8.2-alpha.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.
Files changed (3) hide show
  1. package/es/index.mjs +607 -345
  2. package/package.json +2 -4
  3. package/types/index.d.ts +153 -7
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@done-coding/cli-utils",
3
- "version": "0.8.2-alpha.0",
3
+ "version": "0.8.2-alpha.1",
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": "b09dd794f69ba2dafe22a3519d712d059c2eb376"
71
+ "gitHead": "660e39fc523e4eba1ea621e3c59122f98015a2de"
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 { v4 as uuidv4 } from 'uuid';
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,9 +163,68 @@ 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
 
218
+ /** 格式化日志流写入格式 */
219
+ export declare const formatLogSteamWrite: ({ stream, type, content, }: {
220
+ /** 流类型 */
221
+ stream: WriteStream;
222
+ /** 日志类型 */
223
+ type: LogTypeEnum;
224
+ /** 日志内容 */
225
+ content: string;
226
+ }) => boolean;
227
+
161
228
  export { _get }
162
229
 
163
230
  /** 快捷获取答案 */
@@ -184,6 +251,9 @@ export declare const getAnswerWithMCP: <V = unknown, T extends string = string>(
184
251
  questionConfig: Parameters<typeof prompts<T>>[0];
185
252
  }) => Promise<V>;
186
253
 
254
+ /** 获取调用模式 */
255
+ export declare const getCallMode: () => EnvConfigCallModeEnum;
256
+
187
257
  /** 获取cli模块【临时】目录[绝对路径] */
188
258
  export declare const getCliModuleTempDir: (moduleName: string) => string;
189
259
 
@@ -209,6 +279,9 @@ export declare const getCurrentBranchLastCommitList: ({ count, }?: {
209
279
  /** 获取当前分支名 */
210
280
  export declare const getCurrentBranchName: () => string | undefined;
211
281
 
282
+ /** 获取自身进程日志文件名 */
283
+ export declare const getCurrentProcessLogFileName: () => string;
284
+
212
285
  /** 获取编辑器类型 */
213
286
  export declare const getEditorType: () => Promise<any>;
214
287
 
@@ -244,8 +317,18 @@ export declare const getLastReflogList: ({ count, filterItem, }?: {
244
317
  filterItem?: (item: GitReflogItemInfoRaw) => boolean;
245
318
  }) => GitReflogItemInfo[];
246
319
 
320
+ /**
321
+ * 获取日志文件夹
322
+ * ----
323
+ * 绝对路径
324
+ * @param persistent 是否持久话
325
+ */
326
+ export declare const getLogOutputDir: (persistent?: boolean) => string;
327
+
247
328
  /** 获取输出文字 */
248
329
  export declare const getLogText: ((type: LogTypeEnum, ...messages: unknown[]) => string) & {
330
+ /** 系统 */
331
+ system: (...messages: unknown[]) => string;
249
332
  /** 成功 */
250
333
  success: (...messages: unknown[]) => string;
251
334
  /** /步骤 */
@@ -258,13 +341,30 @@ export declare const getLogText: ((type: LogTypeEnum, ...messages: unknown[]) =>
258
341
  error: (...messages: unknown[]) => string;
259
342
  /** 跳过 */
260
343
  skip: (...messages: unknown[]) => string;
344
+ /** 表格 */
345
+ table: (...messages: unknown[]) => string;
261
346
  };
262
347
 
348
+ /** 格式: 2026-01-18 11:38:05 */
349
+ export declare const getLogTime: () => string;
350
+
351
+ /** 通过 LogTypeEnum 枚举值或者key */
352
+ export declare const getLogTypeByValue: (value: LogTypeEnum) => string;
353
+
263
354
  /** 获取package.json文件内容 */
264
355
  export declare const getPackageJson: <R extends PackageJson>({ rootDir, }: {
265
356
  rootDir: string;
266
357
  }) => R;
267
358
 
359
+ /** 获取父级进程日志文件名 */
360
+ export declare const getParentProcessLogFileName: () => string | undefined;
361
+
362
+ /** 获取环境变量 */
363
+ export declare const getProcessEnv: <T>(keyInit: EnvConfigProcessKeyEnum, defaultValue?: T) => T | undefined;
364
+
365
+ /** 获取当前进程对应的日志流 */
366
+ export declare const getProcessLogStream: () => XFsWriteStream;
367
+
268
368
  /** 获取依赖包版本 */
269
369
  export declare const getRelyPkgVersion: <R extends PackageJson>({ rootDir, pkgJson, pkgName, isDevPkg, }: {
270
370
  rootDir: string;
@@ -285,6 +385,9 @@ export declare const getRootScriptName: ({ rootScriptName, packageJson, }: {
285
385
  packageJson?: Pick<PackageJson, "name" | "bin">;
286
386
  }) => string | undefined;
287
387
 
388
+ /** 获取安全路径 */
389
+ export declare const getSafePath: (path?: string) => string;
390
+
288
391
  /** 获取是否使用默认配置 */
289
392
  export declare const getUseDefaultConfig: () => Promise<any>;
290
393
 
@@ -464,6 +567,19 @@ export declare const initConfigFile: <T>(content: T, argv: CliHandlerArgv<InitCo
464
567
  /** 初始化文件选项 */
465
568
  export declare type InitConfigFileOptions = ConfigFileCommonOptions;
466
569
 
570
+ /**
571
+ * 初始化环境配置
572
+ * ---
573
+ * !!! 顶级进程才调用且只能调用一次
574
+ * 非顶级进程调用会忽略入参 即优先使用父级设置的进程配置
575
+ * ---
576
+ * 即顶级进程调用
577
+ * 非顶级进程通过进程环境继承
578
+ */
579
+ export declare const initEnvConfig: ({ series, ...otherConfig }: Partial<Pick<EnvConfig, "callMode" | "consoleLog"> & {
580
+ series: string;
581
+ }>) => EnvConfig;
582
+
467
583
  /** 初始化配置文件通用处理器 */
468
584
  export declare const initHandlerCommon: <T>(content: T, argv: CliHandlerArgv<InitConfigFileOptions>, { onFileGenerated, edit, }?: {
469
585
  /** 文件已生成 */
@@ -474,6 +590,9 @@ export declare const initHandlerCommon: <T>(content: T, argv: CliHandlerArgv<Ini
474
590
  /** 是http git地址 */
475
591
  export declare const isHttpGitUrl: (url: string) => boolean;
476
592
 
593
+ /** 是mcp模式 */
594
+ export declare const isMcpMode: () => boolean;
595
+
477
596
  /** 是 ssh git地址 */
478
597
  export declare const isSshGitUrl: (url: string) => boolean;
479
598
 
@@ -481,6 +600,8 @@ export { json5 }
481
600
 
482
601
  /** 日志 */
483
602
  export declare const log: ((type: LogTypeEnum, ...messages: unknown[]) => void) & {
603
+ /** 系统 */
604
+ system: (...messages: unknown[]) => void;
484
605
  /** 成功 */
485
606
  success: (...messages: unknown[]) => void;
486
607
  /** /步骤 */
@@ -493,24 +614,30 @@ export declare const log: ((type: LogTypeEnum, ...messages: unknown[]) => void)
493
614
  error: (...messages: unknown[]) => void;
494
615
  /** 跳过 */
495
616
  skip: (...messages: unknown[]) => void;
617
+ /** 表格 */
618
+ table: (...messages: unknown[]) => void;
496
619
  };
497
620
 
498
621
  export declare type LogParams = [type: LogTypeEnum, ...messages: unknown[]];
499
622
 
500
623
  /** 日志类型 */
501
- declare enum LogTypeEnum {
624
+ export declare enum LogTypeEnum {
625
+ /** 系统 */
626
+ SYSTEM = "magenta",
502
627
  /** 成功 */
503
- SUCCESS = "green",
628
+ SUCCESS = "greenBright",
504
629
  /** 步骤 */
505
630
  STAGE = "blue",
506
631
  /** 提示信息 */
507
- INFO = "cyan",
632
+ INFO = "white",
508
633
  /** 警告 */
509
634
  WARN = "yellow",
510
635
  /** 错误 */
511
- ERROR = "red",
636
+ ERROR = "redBright",
512
637
  /** 跳过 */
513
- SKIP = "gray"
638
+ SKIP = "dim",
639
+ /** ---- 表格 ---- */
640
+ TABLE = "table"
514
641
  }
515
642
 
516
643
  /**
@@ -538,6 +665,14 @@ export declare interface PackageJson {
538
665
  peerDependencies?: Record<string, string>;
539
666
  }
540
667
 
668
+ /** 路径是否安全 */
669
+ export declare const pathIsSafe: (path?: string) => boolean;
670
+
671
+ /** 进程值变量初始值 */
672
+ export declare interface ProcessValueInit<T> {
673
+ value: T;
674
+ }
675
+
541
676
  export { PromptAnswers }
542
677
 
543
678
  export { PromptChoice }
@@ -659,7 +794,18 @@ export declare const SUPPORT_GET_COMMIT_BY_HOOKS_NAMES: readonly [HooksNameEnum.
659
794
 
660
795
  export declare type SupportGetCommitByHookName = (typeof SUPPORT_GET_COMMIT_BY_HOOKS_NAMES)[number];
661
796
 
662
- export { uuidv4 }
797
+ export declare const uuidv4: () => `${string}-${string}-${string}-${string}-${string}`;
798
+
799
+ /**
800
+ * fs.WriteStream 确实没有直接声明 fd 属性(虽然运行时它确实存在)。这是因为 fd 是由底层的物理文件句柄分配的,其类型定义在内部较为隐蔽。
801
+ */
802
+ declare interface XFsWriteStream extends fs.WriteStream {
803
+ fd?: number;
804
+ }
805
+
806
+ export declare interface XGlobalThis {
807
+ [DONE_CONFIG_ENV_CONFIG_GLOBAL_SYMBOL]: EnvConfig;
808
+ }
663
809
 
664
810
  /** prompts 拓展 */
665
811
  export declare const xPrompts: <T extends string = string>(...args: Parameters<typeof prompts<T>>) => Promise<prompts.Answers<T>>;