@icebreakers/monorepo 2.2.0 → 3.0.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/dist/cli.d.ts DELETED
@@ -1,2 +0,0 @@
1
-
2
- export { }
package/dist/cli.js DELETED
@@ -1,76 +0,0 @@
1
- import {
2
- cleanProjects,
3
- createNewProject,
4
- defaultTemplate,
5
- getCreateChoices,
6
- init,
7
- init_esm_shims,
8
- logger,
9
- name,
10
- resolveCommandConfig,
11
- setVscodeBinaryMirror,
12
- syncNpmMirror,
13
- upgradeMonorepo,
14
- version
15
- } from "./chunk-Y4HUH2J5.js";
16
-
17
- // src/cli.ts
18
- init_esm_shims();
19
-
20
- // src/cli/program.ts
21
- init_esm_shims();
22
- import process from "process";
23
- import input from "@inquirer/input";
24
- import select from "@inquirer/select";
25
- import { program } from "commander";
26
- var cwd = process.cwd();
27
- program.name(name).version(version);
28
- program.command("upgrade").description("\u5347\u7EA7/\u540C\u6B65 monorepo \u76F8\u5173\u5305").alias("up").option("-i,--interactive").option("-c,--core", "\u4EC5\u540C\u6B65\u6838\u5FC3\u914D\u7F6E\uFF0C\u8DF3\u8FC7 GitHub \u76F8\u5173\u8D44\u4EA7").option("--outDir <dir>", "Output directory").option("-s,--skip-overwrite", "skip overwrite").action(async (opts) => {
29
- const normalized = {
30
- ...opts,
31
- core: opts.core ?? false,
32
- cwd
33
- };
34
- await upgradeMonorepo(normalized);
35
- logger.success("upgrade @icebreakers/monorepo ok!");
36
- });
37
- program.command("init").description("\u521D\u59CB\u5316 package.json \u548C README.md").action(async () => {
38
- await init(cwd);
39
- logger.success("init finished!");
40
- });
41
- program.command("sync").description("\u5411 npmmirror \u540C\u6B65\u6240\u6709\u5B50\u5305").action(async () => {
42
- await syncNpmMirror(cwd);
43
- logger.success("sync npm mirror finished!");
44
- });
45
- program.command("clean").description("\u6E05\u9664\u9009\u4E2D\u7684\u5305").action(async () => {
46
- await cleanProjects(cwd);
47
- logger.success("clean projects finished!");
48
- });
49
- program.command("mirror").description("\u8BBE\u7F6E VscodeBinaryMirror").action(async () => {
50
- await setVscodeBinaryMirror(cwd);
51
- logger.success("set vscode binary mirror finished!");
52
- });
53
- program.command("new").description("\u521B\u5EFA\u4E00\u4E2A\u65B0\u7684\u5B50\u5305").alias("create").argument("[name]").action(async (name2) => {
54
- const createConfig = await resolveCommandConfig("create", cwd);
55
- if (!name2) {
56
- name2 = await input({
57
- message: "\u8BF7\u8F93\u5165\u5305\u540D",
58
- default: (createConfig == null ? void 0 : createConfig.name) ?? "my-package"
59
- });
60
- }
61
- const type = await select({
62
- message: "\u8BF7\u9009\u62E9\u6A21\u677F\u7C7B\u578B",
63
- choices: getCreateChoices(createConfig == null ? void 0 : createConfig.choices),
64
- default: (createConfig == null ? void 0 : createConfig.type) ?? (createConfig == null ? void 0 : createConfig.defaultTemplate) ?? defaultTemplate
65
- });
66
- await createNewProject({
67
- name: name2,
68
- cwd,
69
- type
70
- });
71
- logger.success("create a package");
72
- });
73
- var program_default = program;
74
-
75
- // src/cli.ts
76
- program_default.parse();
package/dist/index.d.ts DELETED
@@ -1,490 +0,0 @@
1
- export { PackageJson } from 'pkg-types';
2
- import * as simple_git from 'simple-git';
3
- import { SimpleGitOptions, ConfigValues } from 'simple-git';
4
- export { ConfigValues, SimpleGit, SimpleGitOptions } from 'simple-git';
5
- import * as gitUrlParse from 'git-url-parse';
6
- import gitUrlParse__default from 'git-url-parse';
7
- import * as _pnpm_types from '@pnpm/types';
8
- import * as consola from 'consola';
9
- import crypto from 'node:crypto';
10
-
11
- /**
12
- * CLI 公用参数,保证各命令对外暴露一致的行为。
13
- */
14
- interface CliOpts {
15
- /**
16
- * 是否开启交互模式,开启后每一步都会提示用户确认。
17
- * @default false
18
- */
19
- interactive?: boolean;
20
- /**
21
- * 是否使用 core 版资产,只同步最精简的文件集合。
22
- * @default false
23
- */
24
- core?: boolean;
25
- /**
26
- * 输出目录(相对 `cwd`),用于放置生成或拷贝出来的文件。
27
- * @default ''
28
- */
29
- outDir?: string;
30
- /**
31
- * 命令执行的工作目录。
32
- * @default process.cwd()
33
- */
34
- cwd?: string;
35
- /**
36
- * 是否跳过已有文件的覆写;开启后保留旧文件不做对比。
37
- * @default false
38
- */
39
- skipOverwrite?: boolean;
40
- }
41
-
42
- /**
43
- * 内置模板映射表,value 指向仓库中对应模板所在路径。
44
- */
45
- declare const templateMap: {
46
- readonly tsup: "packages/tsup-template";
47
- readonly tsdown: "packages/tsdown-template";
48
- readonly unbuild: "packages/unbuild-template";
49
- readonly 'vue-lib': "packages/vue-lib-template";
50
- readonly 'hono-server': "apps/server";
51
- readonly 'vue-hono': "apps/client";
52
- readonly vitepress: "apps/website";
53
- readonly cli: "apps/cli";
54
- };
55
- type CreateNewProjectType = keyof typeof templateMap;
56
- interface CreateNewProjectOptions {
57
- name?: string;
58
- cwd?: string;
59
- renameJson?: boolean;
60
- type?: CreateNewProjectType | string;
61
- }
62
- /**
63
- * 若配置中提供 choices 则优先使用,否则退回默认预设。
64
- */
65
- declare function getCreateChoices(choices?: CreateChoiceOption[]): CreateChoiceOption[] | ({
66
- readonly name: "unbuild 打包";
67
- readonly value: "unbuild";
68
- } | {
69
- readonly name: "tsup 打包";
70
- readonly value: "tsup";
71
- } | {
72
- readonly name: "tsdown 打包";
73
- readonly value: "tsdown";
74
- } | {
75
- readonly name: "vue 组件";
76
- readonly value: "vue-lib";
77
- } | {
78
- readonly name: "vue hono 全栈";
79
- readonly value: "vue-hono";
80
- } | {
81
- readonly name: "hono 模板";
82
- readonly value: "hono-server";
83
- } | {
84
- readonly name: "vitepress 文档";
85
- readonly value: "vitepress";
86
- } | {
87
- readonly name: "cli 模板";
88
- readonly value: "cli";
89
- })[];
90
- /**
91
- * 合并内置与自定义模板映射,允许扩展新的模板类型。
92
- */
93
- declare function getTemplateMap(extra?: Record<string, string>): Record<string, string>;
94
- /**
95
- * 根据提供的参数或配置生成新工程目录,并可自动改写 package.json。
96
- */
97
- declare function createNewProject(options?: CreateNewProjectOptions): Promise<void>;
98
-
99
- /**
100
- * 工作区工具可接收的筛选选项。
101
- */
102
- interface GetWorkspacePackagesOptions {
103
- /**
104
- * 是否在结果中排除 workspace 根包。
105
- * @default true
106
- */
107
- ignoreRootPackage?: boolean;
108
- /**
109
- * 是否过滤掉标记为 `private` 的包。
110
- * @default true
111
- */
112
- ignorePrivatePackage?: boolean;
113
- /**
114
- * 自定义 glob,覆盖 `pnpm-workspace.yaml` 的 `packages` 配置。
115
- * @default workspace manifest `packages`
116
- */
117
- patterns?: string[];
118
- }
119
-
120
- /**
121
- * `monorepo new` 命令的配置项,允许外部覆写模板目录、模板清单等。
122
- */
123
- interface CreateCommandConfig extends Partial<Omit<CreateNewProjectOptions, 'cwd'>> {
124
- /**
125
- * 自定义模板根目录。
126
- * @default 内置模板所在的 `packages/monorepo/templates`
127
- */
128
- templatesDir?: string;
129
- /**
130
- * 扩展模板映射表,key 为类型,value 为模板相对路径。
131
- * @default 内置 `templateMap`
132
- */
133
- templateMap?: Record<string, string>;
134
- /**
135
- * 自定义交互提示的选项列表。
136
- * @default 内置 `baseChoices`
137
- */
138
- choices?: CreateChoiceOption[];
139
- /**
140
- * 当未选择模板时使用的默认模板。
141
- * @default 'unbuild'
142
- */
143
- defaultTemplate?: CreateNewProjectOptions['type'];
144
- }
145
- /**
146
- * CLI 交互式选择框的选项结构。
147
- */
148
- interface CreateChoiceOption {
149
- /**
150
- * 唯一值,将回传给命令逻辑使用。
151
- * @default undefined
152
- */
153
- value: string;
154
- /**
155
- * 选项展示名称。
156
- * @default value
157
- */
158
- name?: string;
159
- /**
160
- * 选项描述信息。
161
- * @default undefined
162
- */
163
- description?: string;
164
- /**
165
- * 短名称,用于命令行紧凑展示。
166
- * @default undefined
167
- */
168
- short?: string;
169
- /**
170
- * 设置为 true 或字符串即可禁用该选项并显示原因。
171
- * @default false
172
- */
173
- disabled?: boolean | string;
174
- }
175
- /**
176
- * `monorepo clean` 命令配置,可控制自动选择、排除包等行为。
177
- */
178
- interface CleanCommandConfig {
179
- /**
180
- * 是否跳过交互直接清理全部。
181
- * @default false
182
- */
183
- autoConfirm?: boolean;
184
- /**
185
- * 不允许被清理的包名列表。
186
- * @default []
187
- */
188
- ignorePackages?: string[];
189
- /**
190
- * 是否包含 private 包。
191
- * @default false
192
- */
193
- includePrivate?: boolean;
194
- /**
195
- * 强制写回的 @icebreakers/monorepo 版本。
196
- * @default 当前依赖版本
197
- */
198
- pinnedVersion?: string;
199
- }
200
- /**
201
- * `monorepo sync` 命令配置,可覆盖 workspace 过滤规则或同步命令模板。
202
- */
203
- interface SyncCommandConfig extends Partial<GetWorkspacePackagesOptions> {
204
- /**
205
- * 并发执行同步命令的最大数量。
206
- * @default os.cpus().length
207
- */
208
- concurrency?: number;
209
- /**
210
- * 自定义执行的同步命令模板,使用 {name} 占位。
211
- * @default 'cnpm sync {name}'
212
- */
213
- command?: string;
214
- /**
215
- * 仅同步指定的包(按名称过滤)。
216
- * @default 同步全部可见包
217
- */
218
- packages?: string[];
219
- }
220
- /**
221
- * `monorepo upgrade` 命令配置,覆盖脚本、目标文件等能力。
222
- */
223
- interface UpgradeCommandConfig extends Partial<CliOpts> {
224
- /**
225
- * 额外需要写入的目标文件列表。
226
- * @default []
227
- */
228
- targets?: string[];
229
- /**
230
- * 是否与默认目标合并,false 表示完全覆盖。
231
- * @default true
232
- */
233
- mergeTargets?: boolean;
234
- /**
235
- * 需要写入 package.json 的脚本集合。
236
- * @default {}
237
- */
238
- scripts?: Record<string, string>;
239
- /**
240
- * 是否跳过生成 changeset markdown。
241
- * @default true
242
- */
243
- skipChangesetMarkdown?: boolean;
244
- }
245
- /**
246
- * `monorepo init` 命令配置,用于跳过部分初始化步骤。
247
- */
248
- interface InitCommandConfig {
249
- /**
250
- * 是否跳过 README 生成。
251
- * @default false
252
- */
253
- skipReadme?: boolean;
254
- /**
255
- * 是否跳过 package.json 写入。
256
- * @default false
257
- */
258
- skipPkgJson?: boolean;
259
- /**
260
- * 是否跳过 changeset 的更新。
261
- * @default false
262
- */
263
- skipChangeset?: boolean;
264
- }
265
- /**
266
- * `monorepo mirror` 命令配置,可增加额外的环境变量镜像。
267
- */
268
- interface MirrorCommandConfig {
269
- /**
270
- * 需要注入的环境变量键值对。
271
- * @default {}
272
- */
273
- env?: Record<string, string>;
274
- }
275
- /**
276
- * 项目级配置入口,按命令划分可插拔的配置块。
277
- */
278
- interface MonorepoConfig {
279
- /**
280
- * 按命令分类的可选配置。
281
- * @default {}
282
- */
283
- commands?: {
284
- create?: CreateCommandConfig;
285
- clean?: CleanCommandConfig;
286
- sync?: SyncCommandConfig;
287
- upgrade?: UpgradeCommandConfig;
288
- init?: InitCommandConfig;
289
- mirror?: MirrorCommandConfig;
290
- };
291
- }
292
-
293
- /**
294
- * 对 simple-git 的轻量封装,集中处理配置缓存与常用查询。
295
- */
296
- declare class GitClient {
297
- #private;
298
- private readonly client;
299
- constructor(options?: Partial<SimpleGitOptions>);
300
- /**
301
- * 读取 Git 的 config 列表,原样返回 simple-git 的结果。
302
- */
303
- listConfig(): simple_git.Response<simple_git.ConfigListSummary>;
304
- /**
305
- * 初始化配置缓存,避免多次访问 Git 产生的性能损耗。
306
- */
307
- init(): Promise<ConfigValues>;
308
- /**
309
- * 获取缓存的配置,若未初始化则自动触发 init。
310
- */
311
- getConfig(): Promise<ConfigValues>;
312
- /**
313
- * 解析 remote.origin.url,返回 git-url-parse 的结构,便于获取仓库元信息。
314
- */
315
- getGitUrl(): Promise<gitUrlParse__default.GitUrl | undefined>;
316
- /**
317
- * 组合 owner/name,生成常用的仓库名表达。
318
- */
319
- getRepoName(): Promise<string | undefined>;
320
- /**
321
- * 从 Git 配置中提取用户信息,用于填充 package.json author 字段。
322
- */
323
- getUser(): Promise<{
324
- name: string;
325
- email: string;
326
- }>;
327
- /**
328
- * 获取当前仓库的顶层目录路径。
329
- */
330
- getRepoRoot(): Promise<string | undefined>;
331
- }
332
-
333
- /**
334
- * 读取 pnpm workspace 下的所有包,并根据配置过滤与补充字段。
335
- */
336
- declare function getWorkspacePackages(workspaceDir: string, options?: GetWorkspacePackagesOptions): Promise<{
337
- pkgJsonPath: string;
338
- rootDir: _pnpm_types.ProjectRootDir;
339
- rootDirRealPath: _pnpm_types.ProjectRootDirRealPath;
340
- modulesDir?: string;
341
- manifest: _pnpm_types.ProjectManifest;
342
- writeProjectManifest: (manifest: _pnpm_types.ProjectManifest, force?: boolean | undefined) => Promise<void>;
343
- }[]>;
344
- /**
345
- * 将工作区绝对路径、包列表与当前 cwd 打包返回,方便调用方一次获取所有信息。
346
- */
347
- declare function getWorkspaceData(cwd: string, options?: GetWorkspacePackagesOptions): Promise<{
348
- cwd: string;
349
- workspaceDir: string;
350
- packages: {
351
- pkgJsonPath: string;
352
- rootDir: _pnpm_types.ProjectRootDir;
353
- rootDirRealPath: _pnpm_types.ProjectRootDirRealPath;
354
- modulesDir?: string;
355
- manifest: _pnpm_types.ProjectManifest;
356
- writeProjectManifest: (manifest: _pnpm_types.ProjectManifest, force?: boolean | undefined) => Promise<void>;
357
- }[];
358
- }>;
359
-
360
- /**
361
- * 交互式清理被选中的包目录,同时重写根 package.json 中的 @icebreakers/monorepo 版本。
362
- */
363
- declare function cleanProjects(cwd: string): Promise<void>;
364
-
365
- /**
366
- * 初始化命令入口,根据配置逐步生成基础文件。
367
- */
368
- declare function init(cwd: string): Promise<void>;
369
-
370
- /**
371
- * 根据中国大陆镜像源,自动向 VSCode settings.json 注入终端环境变量。
372
- */
373
- declare function setVscodeBinaryMirror(cwd: string): Promise<void>;
374
-
375
- /**
376
- * 批量执行 `cnpm sync`(或自定义命令),将所有包同步到 npmmirror。
377
- */
378
- declare function syncNpmMirror(cwd: string, options?: GetWorkspacePackagesOptions): Promise<void>;
379
-
380
- /**
381
- * 将 assets 目录的模版文件同步到工程中,实现一键升级脚手架能力。
382
- */
383
- declare function upgradeMonorepo(opts: CliOpts): Promise<void>;
384
-
385
- var name = "@icebreakers/monorepo";
386
- var version = "2.2.0";
387
-
388
- /**
389
- * @icebreakers/monorepo 包的根目录,所有模板与资产目录都以此为基准。
390
- */
391
- declare const packageDir: string;
392
- /**
393
- * CLI 提供的模板目录,`monorepo new` 会从这里复制目标工程骨架。
394
- */
395
- declare const templatesDir: string;
396
- /**
397
- * 升级命令需要写入的静态文件集合,位于 assets 目录中。
398
- */
399
- declare const assetsDir: string;
400
- /**
401
- * monorepo 根目录,方便需要跳出当前包的逻辑(例如定位工作区文件)。
402
- */
403
- declare const rootDir: string;
404
-
405
- /**
406
- * 提供类型提示的辅助函数,供外部定义配置时使用。
407
- */
408
- declare function defineMonorepoConfig(config: MonorepoConfig): MonorepoConfig;
409
- /**
410
- * 加载指定目录的 monorepo 配置,并利用缓存提升性能。
411
- */
412
- declare function loadMonorepoConfig(cwd: string): Promise<MonorepoConfig>;
413
- /**
414
- * 获取命令对应的合并配置,若未配置则返回空对象,保证调用端逻辑简单。
415
- */
416
- declare function resolveCommandConfig<Name extends keyof NonNullable<MonorepoConfig['commands']>>(name: Name, cwd: string): Promise<NonNullable<MonorepoConfig['commands']>[Name]>;
417
-
418
- /**
419
- * 构建命令执行上下文,封装常用的工作区、Git、配置等信息。
420
- */
421
- declare function createContext(cwd: string): Promise<{
422
- cwd: string;
423
- git: GitClient;
424
- gitUrl: gitUrlParse.GitUrl | undefined;
425
- gitUser: {
426
- name: string;
427
- email: string;
428
- };
429
- workspaceDir: string;
430
- workspaceFilepath: string;
431
- packages: {
432
- pkgJsonPath: string;
433
- rootDir: _pnpm_types.ProjectRootDir;
434
- rootDirRealPath: _pnpm_types.ProjectRootDirRealPath;
435
- modulesDir?: string;
436
- manifest: _pnpm_types.ProjectManifest;
437
- writeProjectManifest: (manifest: _pnpm_types.ProjectManifest, force?: boolean | undefined) => Promise<void>;
438
- }[];
439
- config: MonorepoConfig;
440
- }>;
441
- /**
442
- * 统一导出的上下文类型,方便下游函数准确获知可用字段。
443
- */
444
- type Context = Awaited<ReturnType<typeof createContext>>;
445
-
446
- /**
447
- * 统一的日志实例,便于在命令行中输出带有前缀和颜色的消息。
448
- */
449
- declare const logger: consola.ConsolaInstance;
450
-
451
- /**
452
- * 判断是否为可忽略的文件系统错误。
453
- * - ENOENT: 文件已被删除
454
- * - EBUSY: Windows 中资源被系统占用
455
- */
456
- declare function isIgnorableFsError(error: unknown): error is NodeJS.ErrnoException;
457
-
458
- /**
459
- * Map a workspace path (containing `.gitignore`) to its packaged variant.
460
- */
461
- declare function toPublishGitignorePath(input: string): string;
462
- /**
463
- * Map a packaged path (containing `gitignore`) back to the workspace form.
464
- */
465
- declare function toWorkspaceGitignorePath(input: string): string;
466
- /**
467
- * Convenient helper to check whether a filename (with or without dot prefix)
468
- * should be treated as a gitignore file.
469
- */
470
- declare function isGitignoreFile(name: string): boolean;
471
-
472
- /**
473
- * 生成给定二进制内容的 md5 摘要,用于快速比较文件内容。
474
- */
475
- declare function getFileHash(data: crypto.BinaryLike): string;
476
- /**
477
- * 对比两个文件的 md5,如果不一致则认为内容有变化。
478
- */
479
- declare function isFileChanged(src: crypto.BinaryLike, dest: crypto.BinaryLike): boolean;
480
-
481
- /**
482
- * 逃逸正则表达式中所有特殊字符,避免被当做模式解析。
483
- */
484
- declare function escapeStringRegexp(str: string): string;
485
- /**
486
- * 判断字符串是否命中任意一个正则,用于过滤要同步的资产文件。
487
- */
488
- declare function isMatch(str: string, arr: RegExp[]): boolean;
489
-
490
- export { type CleanCommandConfig, type CliOpts, type Context, type CreateChoiceOption, type CreateCommandConfig, type CreateNewProjectOptions, type GetWorkspacePackagesOptions, GitClient, type InitCommandConfig, type MirrorCommandConfig, type MonorepoConfig, type SyncCommandConfig, type UpgradeCommandConfig, assetsDir, cleanProjects, createContext, createNewProject, defineMonorepoConfig, escapeStringRegexp, getCreateChoices, getFileHash, getTemplateMap, getWorkspaceData, getWorkspacePackages, init, isFileChanged, isGitignoreFile, isIgnorableFsError, isMatch, loadMonorepoConfig, logger, name, packageDir, resolveCommandConfig, rootDir, setVscodeBinaryMirror, syncNpmMirror, templateMap, templatesDir, toPublishGitignorePath, toWorkspaceGitignorePath, upgradeMonorepo, version };
package/dist/index.js DELETED
@@ -1,70 +0,0 @@
1
- import {
2
- GitClient,
3
- assetsDir,
4
- cleanProjects,
5
- createContext,
6
- createNewProject,
7
- defineMonorepoConfig,
8
- escapeStringRegexp,
9
- getCreateChoices,
10
- getFileHash,
11
- getTemplateMap,
12
- getWorkspaceData,
13
- getWorkspacePackages,
14
- init,
15
- init_esm_shims,
16
- isFileChanged,
17
- isGitignoreFile,
18
- isIgnorableFsError,
19
- isMatch,
20
- loadMonorepoConfig,
21
- logger,
22
- name,
23
- packageDir,
24
- resolveCommandConfig,
25
- rootDir,
26
- setVscodeBinaryMirror,
27
- syncNpmMirror,
28
- templateMap,
29
- templatesDir,
30
- toPublishGitignorePath,
31
- toWorkspaceGitignorePath,
32
- upgradeMonorepo,
33
- version
34
- } from "./chunk-Y4HUH2J5.js";
35
-
36
- // src/index.ts
37
- init_esm_shims();
38
- export {
39
- GitClient,
40
- assetsDir,
41
- cleanProjects,
42
- createContext,
43
- createNewProject,
44
- defineMonorepoConfig,
45
- escapeStringRegexp,
46
- getCreateChoices,
47
- getFileHash,
48
- getTemplateMap,
49
- getWorkspaceData,
50
- getWorkspacePackages,
51
- init,
52
- isFileChanged,
53
- isGitignoreFile,
54
- isIgnorableFsError,
55
- isMatch,
56
- loadMonorepoConfig,
57
- logger,
58
- name,
59
- packageDir,
60
- resolveCommandConfig,
61
- rootDir,
62
- setVscodeBinaryMirror,
63
- syncNpmMirror,
64
- templateMap,
65
- templatesDir,
66
- toPublishGitignorePath,
67
- toWorkspaceGitignorePath,
68
- upgradeMonorepo,
69
- version
70
- };