@icebreakers/monorepo 1.2.3 → 2.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.
@@ -27,11 +27,11 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
27
27
  mod
28
28
  ));
29
29
 
30
- // ../../node_modules/.pnpm/tsup@8.5.0_@microsoft+api-extractor@7.52.12_@types+node@24.5.2__jiti@2.5.1_postcss@8.5._d1da7b371d2f426607ba6a1b179cf002/node_modules/tsup/assets/esm_shims.js
30
+ // ../../node_modules/.pnpm/tsup@8.5.0_@microsoft+api-extractor@7.52.12_@types+node@24.5.2__jiti@2.6.0_postcss@8.5._6bfe6d2ece7a9e60df9bded316a5214d/node_modules/tsup/assets/esm_shims.js
31
31
  import path from "path";
32
32
  import { fileURLToPath } from "url";
33
33
  var init_esm_shims = __esm({
34
- "../../node_modules/.pnpm/tsup@8.5.0_@microsoft+api-extractor@7.52.12_@types+node@24.5.2__jiti@2.5.1_postcss@8.5._d1da7b371d2f426607ba6a1b179cf002/node_modules/tsup/assets/esm_shims.js"() {
34
+ "../../node_modules/.pnpm/tsup@8.5.0_@microsoft+api-extractor@7.52.12_@types+node@24.5.2__jiti@2.6.0_postcss@8.5._6bfe6d2ece7a9e60df9bded316a5214d/node_modules/tsup/assets/esm_shims.js"() {
35
35
  "use strict";
36
36
  }
37
37
  });
@@ -183,9 +183,9 @@ var require_set_value = __commonJS({
183
183
  }
184
184
  return obj;
185
185
  };
186
- var setValue = (target, path13, value, options) => {
187
- if (!path13 || !isObject2(target)) return target;
188
- const keys = split2(path13, options);
186
+ var setValue = (target, path14, value, options) => {
187
+ if (!path14 || !isObject2(target)) return target;
188
+ const keys = split2(path14, options);
189
189
  let obj = target;
190
190
  for (let i = 0; i < keys.length; i++) {
191
191
  const key = keys[i];
@@ -215,7 +215,164 @@ var require_set_value = __commonJS({
215
215
  }
216
216
  });
217
217
 
218
- // src/monorepo/workspace/index.ts
218
+ // src/core/git.ts
219
+ init_esm_shims();
220
+
221
+ // ../../node_modules/.pnpm/get-value@4.0.1/node_modules/get-value/dist/index.mjs
222
+ init_esm_shims();
223
+ var __defProp2 = Object.defineProperty;
224
+ var __name = (target, value) => __defProp2(target, "name", { value, configurable: true });
225
+ var isObject = /* @__PURE__ */ __name((v) => v !== null && typeof v === "object", "isObject");
226
+ var join = /* @__PURE__ */ __name((segs, joinChar, options) => {
227
+ if (typeof options.join === "function") {
228
+ return options.join(segs);
229
+ }
230
+ return segs[0] + joinChar + segs[1];
231
+ }, "join");
232
+ var split = /* @__PURE__ */ __name((path14, splitChar, options) => {
233
+ if (typeof options.split === "function") {
234
+ return options.split(path14);
235
+ }
236
+ return path14.split(splitChar);
237
+ }, "split");
238
+ var isValid = /* @__PURE__ */ __name((key, target = {}, options) => {
239
+ if (typeof (options == null ? void 0 : options.isValid) === "function") {
240
+ return options.isValid(key, target);
241
+ }
242
+ return true;
243
+ }, "isValid");
244
+ var isValidObject = /* @__PURE__ */ __name((v) => {
245
+ return isObject(v) || typeof v === "function";
246
+ }, "isValidObject");
247
+ var getValue = /* @__PURE__ */ __name((target, path14, options = {}) => {
248
+ if (!isObject(options)) {
249
+ options = { default: options };
250
+ }
251
+ if (!isValidObject(target)) {
252
+ return typeof options.default !== "undefined" ? options.default : target;
253
+ }
254
+ if (typeof path14 === "number") {
255
+ path14 = String(path14);
256
+ }
257
+ const pathIsArray = Array.isArray(path14);
258
+ const pathIsString = typeof path14 === "string";
259
+ const splitChar = options.separator || ".";
260
+ const joinChar = options.joinChar || (typeof splitChar === "string" ? splitChar : ".");
261
+ if (!pathIsString && !pathIsArray) {
262
+ return target;
263
+ }
264
+ if (target[path14] !== void 0) {
265
+ return isValid(path14, target, options) ? target[path14] : options.default;
266
+ }
267
+ const segs = pathIsArray ? path14 : split(path14, splitChar, options);
268
+ const len = segs.length;
269
+ let idx = 0;
270
+ do {
271
+ let prop = segs[idx];
272
+ if (typeof prop !== "string") {
273
+ prop = String(prop);
274
+ }
275
+ while (prop && prop.slice(-1) === "\\") {
276
+ prop = join([prop.slice(0, -1), segs[++idx] || ""], joinChar, options);
277
+ }
278
+ if (target[prop] !== void 0) {
279
+ if (!isValid(prop, target, options)) {
280
+ return options.default;
281
+ }
282
+ target = target[prop];
283
+ } else {
284
+ let hasProp = false;
285
+ let n = idx + 1;
286
+ while (n < len) {
287
+ prop = join([prop, segs[n++]], joinChar, options);
288
+ if (hasProp = target[prop] !== void 0) {
289
+ if (!isValid(prop, target, options)) {
290
+ return options.default;
291
+ }
292
+ target = target[prop];
293
+ idx = n - 1;
294
+ break;
295
+ }
296
+ }
297
+ if (!hasProp) {
298
+ return options.default;
299
+ }
300
+ }
301
+ } while (++idx < len && isValidObject(target));
302
+ if (idx === len) {
303
+ return target;
304
+ }
305
+ return options.default;
306
+ }, "getValue");
307
+ var index_default = getValue;
308
+
309
+ // src/core/git.ts
310
+ import gitUrlParse from "git-url-parse";
311
+ import { simpleGit } from "simple-git";
312
+ var GitClient = class {
313
+ client;
314
+ #config;
315
+ constructor(options = {}) {
316
+ this.client = simpleGit(options);
317
+ }
318
+ /**
319
+ * 读取 Git 的 config 列表,原样返回 simple-git 的结果。
320
+ */
321
+ listConfig() {
322
+ return this.client.listConfig();
323
+ }
324
+ /**
325
+ * 初始化配置缓存,避免多次访问 Git 产生的性能损耗。
326
+ */
327
+ async init() {
328
+ const listConfig = await this.listConfig();
329
+ this.#config = listConfig.all;
330
+ return this.#config;
331
+ }
332
+ /**
333
+ * 获取缓存的配置,若未初始化则自动触发 init。
334
+ */
335
+ async getConfig() {
336
+ if (this.#config) {
337
+ return this.#config;
338
+ } else {
339
+ return await this.init();
340
+ }
341
+ }
342
+ /**
343
+ * 解析 remote.origin.url,返回 git-url-parse 的结构,便于获取仓库元信息。
344
+ */
345
+ async getGitUrl() {
346
+ const config = await this.getConfig();
347
+ const x = index_default(config, "remote.origin.url");
348
+ if (x) {
349
+ return gitUrlParse(x);
350
+ }
351
+ }
352
+ /**
353
+ * 组合 owner/name,生成常用的仓库名表达。
354
+ */
355
+ async getRepoName() {
356
+ const url = await this.getGitUrl();
357
+ if (url) {
358
+ return `${url.owner}/${url.name}`;
359
+ }
360
+ }
361
+ /**
362
+ * 从 Git 配置中提取用户信息,用于填充 package.json author 字段。
363
+ */
364
+ async getUser() {
365
+ const config = await this.getConfig();
366
+ const name2 = index_default(config, "user.name");
367
+ const email = index_default(config, "user.email");
368
+ return {
369
+ name: name2,
370
+ email
371
+ };
372
+ }
373
+ };
374
+
375
+ // src/core/workspace.ts
219
376
  init_esm_shims();
220
377
  import { findWorkspaceDir } from "@pnpm/find-workspace-dir";
221
378
  import { findWorkspacePackages } from "@pnpm/workspace.find-packages";
@@ -290,7 +447,7 @@ var defuArrayFn = createDefu((object, key, currentValue) => {
290
447
  }
291
448
  });
292
449
 
293
- // src/monorepo/workspace/index.ts
450
+ // src/core/workspace.ts
294
451
  import path2 from "pathe";
295
452
  async function getWorkspacePackages(workspaceDir, options) {
296
453
  const { ignoreRootPackage, ignorePrivatePackage, patterns } = defu(options, {
@@ -330,68 +487,122 @@ async function getWorkspaceData(cwd, options) {
330
487
  };
331
488
  }
332
489
 
333
- // src/monorepo/clean.ts
490
+ // src/core/config.ts
491
+ init_esm_shims();
492
+ import { loadConfig } from "c12";
493
+ import path3 from "pathe";
494
+ var cache = /* @__PURE__ */ new Map();
495
+ async function loadConfigInternal(cwd) {
496
+ const { config, configFile } = await loadConfig({
497
+ name: "monorepo",
498
+ cwd,
499
+ // configFile: ['monorepo.config'],
500
+ rcFile: false,
501
+ defaults: {},
502
+ globalRc: false,
503
+ packageJson: false
504
+ });
505
+ return {
506
+ file: configFile ? path3.resolve(configFile) : null,
507
+ config: config ?? {}
508
+ };
509
+ }
510
+ function defineMonorepoConfig(config) {
511
+ return config;
512
+ }
513
+ async function loadMonorepoConfig(cwd) {
514
+ const key = path3.resolve(cwd);
515
+ if (!cache.has(key)) {
516
+ cache.set(key, loadConfigInternal(key));
517
+ }
518
+ const { config } = await cache.get(key);
519
+ return config;
520
+ }
521
+ async function resolveCommandConfig(name2, cwd) {
522
+ const config = await loadMonorepoConfig(cwd);
523
+ const commands = config.commands ?? {};
524
+ const commandConfig = commands[name2];
525
+ return commandConfig ?? {};
526
+ }
527
+
528
+ // src/commands/clean.ts
334
529
  init_esm_shims();
335
530
  var import_set_value = __toESM(require_set_value(), 1);
336
531
  import checkbox from "@inquirer/checkbox";
337
532
  import fs from "fs-extra";
338
- import path3 from "pathe";
533
+ import path4 from "pathe";
339
534
  async function cleanProjects(cwd) {
340
- const { packages, workspaceDir } = await getWorkspaceData(cwd);
341
- const cleanDirs = await checkbox({
342
- message: "\u8BF7\u9009\u62E9\u9700\u8981\u6E05\u7406\u7684\u76EE\u5F55",
343
- choices: packages.map((x) => {
344
- return {
345
- name: path3.relative(workspaceDir, x.rootDir),
346
- value: x.rootDir,
347
- checked: true,
348
- description: x.manifest.name
349
- };
350
- })
535
+ const cleanConfig = await resolveCommandConfig("clean", cwd);
536
+ const workspaceOptions = (cleanConfig == null ? void 0 : cleanConfig.includePrivate) ? { ignorePrivatePackage: false } : void 0;
537
+ const { packages, workspaceDir } = await getWorkspaceData(cwd, workspaceOptions);
538
+ const filteredPackages = packages.filter((pkg) => {
539
+ var _a;
540
+ const name3 = pkg.manifest.name ?? "";
541
+ if (!name3) {
542
+ return true;
543
+ }
544
+ if (!((_a = cleanConfig == null ? void 0 : cleanConfig.ignorePackages) == null ? void 0 : _a.length)) {
545
+ return true;
546
+ }
547
+ return !cleanConfig.ignorePackages.includes(name3);
351
548
  });
352
- for (const dir of cleanDirs) {
353
- await fs.remove(dir);
549
+ let cleanDirs = [];
550
+ if (cleanConfig == null ? void 0 : cleanConfig.autoConfirm) {
551
+ cleanDirs = filteredPackages.map((pkg) => pkg.rootDir);
552
+ } else {
553
+ cleanDirs = await checkbox({
554
+ message: "\u8BF7\u9009\u62E9\u9700\u8981\u6E05\u7406\u7684\u76EE\u5F55",
555
+ choices: filteredPackages.map((x) => {
556
+ return {
557
+ name: path4.relative(workspaceDir, x.rootDir),
558
+ value: x.rootDir,
559
+ checked: true,
560
+ description: x.manifest.name
561
+ };
562
+ })
563
+ });
354
564
  }
355
- const name2 = path3.resolve(workspaceDir, "package.json");
565
+ const candidates = Array.from(new Set(cleanDirs.filter(Boolean)));
566
+ await Promise.all(candidates.map(async (dir) => {
567
+ if (await fs.pathExists(dir)) {
568
+ await fs.remove(dir);
569
+ }
570
+ }));
571
+ const name2 = path4.resolve(workspaceDir, "package.json");
356
572
  const pkgJson = await fs.readJson(name2);
357
- (0, import_set_value.default)(pkgJson, "devDependencies.@icebreakers/monorepo", "latest", { preservePaths: false });
573
+ (0, import_set_value.default)(pkgJson, "devDependencies.@icebreakers/monorepo", (cleanConfig == null ? void 0 : cleanConfig.pinnedVersion) ?? "latest", { preservePaths: false });
358
574
  await fs.outputJson(name2, pkgJson, {
359
575
  spaces: 2
360
576
  });
361
577
  }
362
578
 
363
- // src/monorepo/create.ts
364
- init_esm_shims();
365
- import process from "process";
366
- var import_set_value2 = __toESM(require_set_value(), 1);
367
- import fs2 from "fs-extra";
368
- import path5 from "pathe";
369
- import pc from "picocolors";
370
-
371
- // src/constants.ts
372
- init_esm_shims();
373
- import path4 from "path";
374
- import { fileURLToPath as fileURLToPath2 } from "url";
375
-
376
579
  // package.json
377
580
  var name = "@icebreakers/monorepo";
378
- var version = "1.2.3";
581
+ var version = "2.0.0";
379
582
 
380
583
  // src/constants.ts
381
- var __filename2 = fileURLToPath2(import.meta.url);
382
- var __dirname2 = path4.dirname(__filename2);
383
- var templatesDir = path4.join(__dirname2, "../templates");
384
- var assetsDir = path4.join(__dirname2, "../assets");
385
- var rootDir = path4.join(__dirname2, "../../..");
584
+ init_esm_shims();
585
+ import path5 from "path";
586
+ import { fileURLToPath as fileURLToPath2 } from "url";
587
+ var packageJsonPath = fileURLToPath2(new URL("../package.json", import.meta.url));
588
+ var packageDir = path5.dirname(packageJsonPath);
589
+ var templatesDir = path5.join(packageDir, "templates");
590
+ var assetsDir = path5.join(packageDir, "assets");
591
+ var rootDir = path5.resolve(packageDir, "..", "..");
386
592
 
387
- // src/logger.ts
593
+ // src/core/logger.ts
388
594
  init_esm_shims();
389
595
  import { createConsola } from "consola";
390
596
  var logger = createConsola();
391
597
 
392
- // src/monorepo/create.ts
393
- var defaultTemplate = "unbuild";
394
- var fromMap = {
598
+ // src/commands/create.ts
599
+ init_esm_shims();
600
+ var import_set_value2 = __toESM(require_set_value(), 1);
601
+ import process from "process";
602
+ import fs2 from "fs-extra";
603
+ import path6 from "pathe";
604
+ import pc from "picocolors";
605
+ var templateMap = {
395
606
  "tsup": "packages/tsup-template",
396
607
  "unbuild": "packages/unbuild-template",
397
608
  "vue-lib": "packages/vue-lib-template",
@@ -400,7 +611,8 @@ var fromMap = {
400
611
  "vitepress": "apps/website",
401
612
  "cli": "apps/cli"
402
613
  };
403
- var createChoices = [
614
+ var defaultTemplate = "unbuild";
615
+ var baseChoices = [
404
616
  { name: "unbuild \u6253\u5305", value: "unbuild" },
405
617
  { name: "tsup \u6253\u5305", value: "tsup" },
406
618
  { name: "vue \u7EC4\u4EF6", value: "vue-lib" },
@@ -409,192 +621,85 @@ var createChoices = [
409
621
  { name: "vitepress \u6587\u6863", value: "vitepress" },
410
622
  { name: "cli \u6A21\u677F", value: "cli" }
411
623
  ];
412
- async function createNewProject(options) {
413
- const { name: targetName, renameJson, cwd, type } = defu(options, {
414
- cwd: process.cwd(),
415
- name: fromMap[defaultTemplate],
416
- renameJson: false
417
- });
418
- const bundlerName = type ?? defaultTemplate;
419
- const from = path5.join(templatesDir, fromMap[bundlerName]);
420
- const to = path5.join(cwd, targetName);
421
- const filelist = await fs2.readdir(from);
422
- for (const filename of filelist) {
423
- if (filename === "package.json") {
424
- const sourceJsonPath = path5.resolve(from, filename);
425
- const sourceJson = await fs2.readJson(sourceJsonPath);
426
- (0, import_set_value2.default)(sourceJson, "version", "0.0.0");
427
- (0, import_set_value2.default)(sourceJson, "name", path5.basename(targetName));
428
- await fs2.outputJson(
429
- path5.resolve(
430
- to,
431
- renameJson ? "package.mock.json" : filename
432
- ),
433
- sourceJson,
434
- { spaces: 2 }
435
- );
436
- } else {
437
- await fs2.copy(
438
- path5.resolve(from, filename),
439
- path5.resolve(to, filename === "gitignore" ? ".gitignore" : filename)
440
- );
441
- }
624
+ function getCreateChoices(choices) {
625
+ if (choices == null ? void 0 : choices.length) {
626
+ return choices;
442
627
  }
443
- logger.success(`${pc.bgGreenBright(pc.white(`[${bundlerName}]`))} ${targetName} \u9879\u76EE\u521B\u5EFA\u6210\u529F\uFF01`);
628
+ return [...baseChoices];
444
629
  }
445
-
446
- // src/monorepo/git/index.ts
447
- init_esm_shims();
448
-
449
- // ../../node_modules/.pnpm/get-value@4.0.1/node_modules/get-value/dist/index.mjs
450
- init_esm_shims();
451
- var __defProp2 = Object.defineProperty;
452
- var __name = (target, value) => __defProp2(target, "name", { value, configurable: true });
453
- var isObject = /* @__PURE__ */ __name((v) => v !== null && typeof v === "object", "isObject");
454
- var join = /* @__PURE__ */ __name((segs, joinChar, options) => {
455
- if (typeof options.join === "function") {
456
- return options.join(segs);
457
- }
458
- return segs[0] + joinChar + segs[1];
459
- }, "join");
460
- var split = /* @__PURE__ */ __name((path13, splitChar, options) => {
461
- if (typeof options.split === "function") {
462
- return options.split(path13);
463
- }
464
- return path13.split(splitChar);
465
- }, "split");
466
- var isValid = /* @__PURE__ */ __name((key, target = {}, options) => {
467
- if (typeof (options == null ? void 0 : options.isValid) === "function") {
468
- return options.isValid(key, target);
469
- }
470
- return true;
471
- }, "isValid");
472
- var isValidObject = /* @__PURE__ */ __name((v) => {
473
- return isObject(v) || typeof v === "function";
474
- }, "isValidObject");
475
- var getValue = /* @__PURE__ */ __name((target, path13, options = {}) => {
476
- if (!isObject(options)) {
477
- options = { default: options };
630
+ function getTemplateMap(extra) {
631
+ const base = { ...templateMap };
632
+ if (extra && Object.keys(extra).length) {
633
+ Object.assign(base, extra);
478
634
  }
479
- if (!isValidObject(target)) {
480
- return typeof options.default !== "undefined" ? options.default : target;
481
- }
482
- if (typeof path13 === "number") {
483
- path13 = String(path13);
484
- }
485
- const pathIsArray = Array.isArray(path13);
486
- const pathIsString = typeof path13 === "string";
487
- const splitChar = options.separator || ".";
488
- const joinChar = options.joinChar || (typeof splitChar === "string" ? splitChar : ".");
489
- if (!pathIsString && !pathIsArray) {
490
- return target;
635
+ return base;
636
+ }
637
+ async function createNewProject(options) {
638
+ const cwd = (options == null ? void 0 : options.cwd) ?? process.cwd();
639
+ const createConfig = await resolveCommandConfig("create", cwd);
640
+ const renameJson = (options == null ? void 0 : options.renameJson) ?? (createConfig == null ? void 0 : createConfig.renameJson) ?? false;
641
+ const name2 = (options == null ? void 0 : options.name) ?? (createConfig == null ? void 0 : createConfig.name);
642
+ const requestedTemplate = (options == null ? void 0 : options.type) ?? (createConfig == null ? void 0 : createConfig.type) ?? (createConfig == null ? void 0 : createConfig.defaultTemplate) ?? defaultTemplate;
643
+ const templateDefinitions = getTemplateMap(createConfig == null ? void 0 : createConfig.templateMap);
644
+ const templatesRoot = (createConfig == null ? void 0 : createConfig.templatesDir) ? path6.resolve(cwd, createConfig.templatesDir) : templatesDir;
645
+ const fallbackTemplate = (createConfig == null ? void 0 : createConfig.defaultTemplate) ?? defaultTemplate;
646
+ const bundlerName = typeof requestedTemplate === "string" && templateDefinitions[requestedTemplate] ? requestedTemplate : fallbackTemplate;
647
+ const sourceRelative = templateDefinitions[bundlerName];
648
+ if (!sourceRelative) {
649
+ throw new Error(`\u672A\u627E\u5230\u540D\u4E3A ${bundlerName} \u7684\u6A21\u677F\uFF0C\u8BF7\u68C0\u67E5 monorepo.config.ts`);
491
650
  }
492
- if (target[path13] !== void 0) {
493
- return isValid(path13, target, options) ? target[path13] : options.default;
651
+ const from = path6.join(templatesRoot, sourceRelative);
652
+ const targetName = name2 ?? sourceRelative;
653
+ const to = path6.join(cwd, targetName);
654
+ if (await fs2.pathExists(to)) {
655
+ throw new Error(`${pc.red("\u76EE\u6807\u76EE\u5F55\u5DF2\u5B58\u5728")}: ${path6.relative(cwd, to)}`);
494
656
  }
495
- const segs = pathIsArray ? path13 : split(path13, splitChar, options);
496
- const len = segs.length;
497
- let idx = 0;
498
- do {
499
- let prop = segs[idx];
500
- if (typeof prop !== "string") {
501
- prop = String(prop);
502
- }
503
- while (prop && prop.slice(-1) === "\\") {
504
- prop = join([prop.slice(0, -1), segs[++idx] || ""], joinChar, options);
505
- }
506
- if (target[prop] !== void 0) {
507
- if (!isValid(prop, target, options)) {
508
- return options.default;
509
- }
510
- target = target[prop];
511
- } else {
512
- let hasProp = false;
513
- let n = idx + 1;
514
- while (n < len) {
515
- prop = join([prop, segs[n++]], joinChar, options);
516
- if (hasProp = target[prop] !== void 0) {
517
- if (!isValid(prop, target, options)) {
518
- return options.default;
519
- }
520
- target = target[prop];
521
- idx = n - 1;
522
- break;
657
+ await fs2.ensureDir(to);
658
+ const filelist = await fs2.readdir(from);
659
+ const shouldSkip = (src) => path6.basename(src) === ".DS_Store";
660
+ const copyTasks = filelist.filter((filename) => filename !== "package.json").map(async (filename) => {
661
+ const sourcePath = path6.resolve(from, filename);
662
+ const targetPath = path6.resolve(to, filename === "gitignore" ? ".gitignore" : filename);
663
+ await fs2.copy(sourcePath, targetPath, {
664
+ filter(src) {
665
+ if (shouldSkip(src)) {
666
+ return false;
523
667
  }
668
+ return true;
524
669
  }
525
- if (!hasProp) {
526
- return options.default;
527
- }
528
- }
529
- } while (++idx < len && isValidObject(target));
530
- if (idx === len) {
531
- return target;
532
- }
533
- return options.default;
534
- }, "getValue");
535
- var index_default = getValue;
536
-
537
- // src/monorepo/git/index.ts
538
- import gitUrlParse from "git-url-parse";
539
- import { simpleGit } from "simple-git";
540
- var GitClient = class {
541
- client;
542
- #config;
543
- constructor(options = {}) {
544
- this.client = simpleGit(options);
545
- }
546
- listConfig() {
547
- return this.client.listConfig();
548
- }
549
- async init() {
550
- const listConfig = await this.listConfig();
551
- this.#config = listConfig.all;
552
- return this.#config;
553
- }
554
- async getConfig() {
555
- if (this.#config) {
556
- return this.#config;
557
- } else {
558
- return await this.init();
559
- }
560
- }
561
- async getGitUrl() {
562
- const config = await this.getConfig();
563
- const x = index_default(config, "remote.origin.url");
564
- if (x) {
565
- return gitUrlParse(x);
566
- }
567
- }
568
- async getRepoName() {
569
- const url = await this.getGitUrl();
570
- if (url) {
571
- return `${url.owner}/${url.name}`;
572
- }
573
- }
574
- async getUser() {
575
- const config = await this.getConfig();
576
- const name2 = index_default(config, "user.name");
577
- const email = index_default(config, "user.email");
578
- return {
579
- name: name2,
580
- email
581
- };
670
+ });
671
+ });
672
+ await Promise.all(copyTasks);
673
+ if (filelist.includes("package.json")) {
674
+ const sourceJsonPath = path6.resolve(from, "package.json");
675
+ const sourceJson = await fs2.readJson(sourceJsonPath);
676
+ (0, import_set_value2.default)(sourceJson, "version", "0.0.0");
677
+ (0, import_set_value2.default)(sourceJson, "name", path6.basename(targetName));
678
+ await fs2.outputJson(
679
+ path6.resolve(
680
+ to,
681
+ renameJson ? "package.mock.json" : "package.json"
682
+ ),
683
+ sourceJson,
684
+ { spaces: 2 }
685
+ );
582
686
  }
583
- };
584
-
585
- // src/monorepo/init/index.ts
586
- init_esm_shims();
687
+ logger.success(`${pc.bgGreenBright(pc.white(`[${bundlerName}]`))} ${targetName} \u9879\u76EE\u521B\u5EFA\u6210\u529F\uFF01`);
688
+ }
587
689
 
588
- // src/monorepo/context/index.ts
690
+ // src/core/context.ts
589
691
  init_esm_shims();
590
- import path6 from "pathe";
692
+ import path7 from "pathe";
591
693
  import "@pnpm/types";
592
694
  async function createContext(cwd) {
593
- const git = new GitClient();
594
695
  const { packages, workspaceDir } = await getWorkspaceData(cwd);
595
- const workspaceFilepath = path6.resolve(workspaceDir, "pnpm-workspace.yaml");
696
+ const git = new GitClient({
697
+ baseDir: workspaceDir
698
+ });
699
+ const workspaceFilepath = path7.resolve(workspaceDir, "pnpm-workspace.yaml");
596
700
  const gitUrl = await git.getGitUrl();
597
701
  const gitUser = await git.getUser();
702
+ const config = await loadMonorepoConfig(workspaceDir);
598
703
  return {
599
704
  cwd,
600
705
  git,
@@ -602,19 +707,23 @@ async function createContext(cwd) {
602
707
  gitUser,
603
708
  workspaceDir,
604
709
  workspaceFilepath,
605
- packages
710
+ packages,
711
+ config
606
712
  };
607
713
  }
608
714
 
609
- // src/monorepo/init/setChangeset.ts
715
+ // src/commands/init/index.ts
716
+ init_esm_shims();
717
+
718
+ // src/commands/init/setChangeset.ts
610
719
  init_esm_shims();
611
720
  var import_set_value3 = __toESM(require_set_value(), 1);
612
721
  import fs3 from "fs-extra";
613
- import path7 from "pathe";
722
+ import path8 from "pathe";
614
723
  async function setChangeset_default(ctx) {
615
724
  const { gitUrl, workspaceFilepath } = ctx;
616
725
  if (gitUrl && await fs3.exists(workspaceFilepath)) {
617
- const changesetConfigPath = path7.resolve(path7.dirname(workspaceFilepath), ".changeset/config.json");
726
+ const changesetConfigPath = path8.resolve(path8.dirname(workspaceFilepath), ".changeset/config.json");
618
727
  if (await fs3.exists(changesetConfigPath)) {
619
728
  const changesetConfig = await fs3.readJson(
620
729
  changesetConfigPath
@@ -627,18 +736,22 @@ async function setChangeset_default(ctx) {
627
736
  }
628
737
  }
629
738
 
630
- // src/monorepo/init/setPkgJson.ts
739
+ // src/commands/init/setPkgJson.ts
631
740
  init_esm_shims();
632
741
  var import_set_value4 = __toESM(require_set_value(), 1);
633
742
  import fs4 from "fs-extra";
634
- import path8 from "pathe";
743
+ import path9 from "pathe";
635
744
  async function setPkgJson_default(ctx) {
636
745
  const { gitUrl, gitUser, packages, cwd, workspaceFilepath } = ctx;
637
- if (gitUrl && await fs4.exists(workspaceFilepath)) {
638
- for (const pkg of packages) {
639
- const pkgJson = pkg.manifest;
640
- const directory = path8.relative(cwd, pkg.rootDir);
641
- (0, import_set_value4.default)(pkgJson, "bugs.url", `https://github.com/${gitUrl.full_name}/issues`);
746
+ const workspaceExists = await fs4.pathExists(workspaceFilepath);
747
+ if (gitUrl && workspaceExists) {
748
+ await Promise.all(packages.map(async (pkg) => {
749
+ if (!await fs4.pathExists(pkg.pkgJsonPath)) {
750
+ return;
751
+ }
752
+ const pkgJson = JSON.parse(JSON.stringify(pkg.manifest));
753
+ const directory = path9.relative(cwd, pkg.rootDir);
754
+ (0, import_set_value4.default)(pkgJson, ["bugs", "url"], `https://github.com/${gitUrl.full_name}/issues`);
642
755
  const repository = {
643
756
  type: "git",
644
757
  url: `git+https://github.com/${gitUrl.full_name}.git`
@@ -647,32 +760,38 @@ async function setPkgJson_default(ctx) {
647
760
  repository.directory = directory;
648
761
  }
649
762
  (0, import_set_value4.default)(pkgJson, "repository", repository);
650
- if (gitUser) {
763
+ if ((gitUser == null ? void 0 : gitUser.name) && (gitUser == null ? void 0 : gitUser.email)) {
651
764
  (0, import_set_value4.default)(pkgJson, "author", `${gitUser.name} <${gitUser.email}>`);
652
765
  }
653
- await fs4.writeJSON(pkg.pkgJsonPath, pkgJson, {
654
- spaces: 2
655
- });
656
- }
766
+ const nextContent = `${JSON.stringify(pkgJson, void 0, 2)}
767
+ `;
768
+ const prevContent = await fs4.readFile(pkg.pkgJsonPath, "utf8");
769
+ if (prevContent !== nextContent) {
770
+ await fs4.writeFile(pkg.pkgJsonPath, nextContent, "utf8");
771
+ }
772
+ }));
657
773
  }
658
774
  }
659
775
 
660
- // src/monorepo/init/setReadme.ts
776
+ // src/commands/init/setReadme.ts
661
777
  init_esm_shims();
662
778
  import fs5 from "fs-extra";
663
- import path9 from "pathe";
779
+ import path10 from "pathe";
664
780
  async function getRows(ctx) {
665
- const { packages, git, cwd } = ctx;
666
- const gitUrl = await git.getGitUrl();
667
- const gitUser = await git.getUser();
781
+ const { packages, gitUrl, gitUser, cwd } = ctx;
668
782
  const rows = [];
669
783
  if (gitUrl) {
670
784
  rows.push(`# ${gitUrl.name}
671
785
  `);
672
786
  }
673
787
  rows.push("## Packages\n");
674
- for (const pkg of packages) {
675
- const p = path9.relative(cwd, pkg.rootDirRealPath);
788
+ const sortedPackages = [...packages].sort((a, b) => {
789
+ const left = a.manifest.name ?? "";
790
+ const right = b.manifest.name ?? "";
791
+ return left.localeCompare(right);
792
+ });
793
+ for (const pkg of sortedPackages) {
794
+ const p = path10.relative(cwd, pkg.rootDirRealPath);
676
795
  if (p) {
677
796
  const description = pkg.manifest.description ? `- ${pkg.manifest.description}` : "";
678
797
  rows.push(`- [${pkg.manifest.name}](${p}) ${description}`);
@@ -693,36 +812,42 @@ async function getRows(ctx) {
693
812
  rows.push(`Thanks to [all contributors](https://github.com/${gitUrl.full_name}/graphs/contributors)!`);
694
813
  }
695
814
  rows.push("\n## Authors\n");
696
- rows.push(`${gitUser.name} <${gitUser.email}>`);
815
+ if ((gitUser == null ? void 0 : gitUser.name) && (gitUser == null ? void 0 : gitUser.email)) {
816
+ rows.push(`${gitUser.name} <${gitUser.email}>`);
817
+ }
697
818
  rows.push("\n## License\n");
698
819
  rows.push("Distributed under the MIT License. See [LICENSE](LICENSE) for more information.");
699
820
  return rows;
700
821
  }
701
822
  async function setReadme_default(ctx) {
702
823
  const rows = await getRows(ctx);
703
- await fs5.writeFile(path9.resolve(ctx.cwd, "README.md"), `${rows.join("\n")}
824
+ await fs5.writeFile(path10.resolve(ctx.cwd, "README.md"), `${rows.join("\n")}
704
825
  `);
705
826
  }
706
827
 
707
- // src/monorepo/init/index.ts
828
+ // src/commands/init/index.ts
708
829
  async function init(cwd) {
830
+ var _a;
709
831
  const ctx = await createContext(cwd);
710
- await setChangeset_default(ctx);
711
- await setPkgJson_default(ctx);
712
- await setReadme_default(ctx);
832
+ const initConfig = ((_a = ctx.config.commands) == null ? void 0 : _a.init) ?? {};
833
+ if (!initConfig.skipChangeset) {
834
+ await setChangeset_default(ctx);
835
+ }
836
+ if (!initConfig.skipPkgJson) {
837
+ await setPkgJson_default(ctx);
838
+ }
839
+ if (!initConfig.skipReadme) {
840
+ await setReadme_default(ctx);
841
+ }
713
842
  }
714
843
 
715
- // src/monorepo/mirror/binaryMirror.ts
844
+ // src/commands/mirror/binaryMirror.ts
716
845
  init_esm_shims();
717
846
  import { parse, stringify } from "comment-json";
718
847
  import fs6 from "fs-extra";
719
- import path10 from "pathe";
720
-
721
- // src/monorepo/mirror/utils.ts
722
- init_esm_shims();
723
- var import_set_value5 = __toESM(require_set_value(), 1);
848
+ import path11 from "pathe";
724
849
 
725
- // src/monorepo/mirror/sources.ts
850
+ // src/commands/mirror/sources.ts
726
851
  init_esm_shims();
727
852
  var chinaMirrorsEnvs = {
728
853
  COREPACK_NPM_REGISTRY: "https://registry.npmmirror.com",
@@ -753,57 +878,87 @@ var chinaMirrorsEnvs = {
753
878
  npm_config_robotjs_binary_host: "https://cdn.npmmirror.com/binaries/robotjs"
754
879
  };
755
880
 
756
- // src/monorepo/mirror/utils.ts
757
- function setMirror(obj) {
881
+ // src/commands/mirror/utils.ts
882
+ init_esm_shims();
883
+ var import_set_value5 = __toESM(require_set_value(), 1);
884
+ function setMirror(obj, envs = chinaMirrorsEnvs) {
758
885
  const platforms = ["linux", "windows", "osx"];
759
886
  const prefix = "terminal.integrated.env";
760
887
  if (typeof obj === "object" && obj) {
761
888
  for (const platform of platforms) {
762
- (0, import_set_value5.default)(obj, [prefix, platform].join(".").replaceAll(".", "\\."), chinaMirrorsEnvs);
889
+ (0, import_set_value5.default)(obj, [prefix, platform].join(".").replaceAll(".", "\\."), envs);
763
890
  }
764
891
  }
765
892
  }
766
893
 
767
- // src/monorepo/mirror/binaryMirror.ts
894
+ // src/commands/mirror/binaryMirror.ts
768
895
  async function setVscodeBinaryMirror(cwd) {
769
- const targetJsonPath = path10.resolve(cwd, ".vscode/settings.json");
896
+ const mirrorConfig = await resolveCommandConfig("mirror", cwd);
897
+ const targetJsonPath = path11.resolve(cwd, ".vscode/settings.json");
770
898
  await fs6.ensureFile(targetJsonPath);
771
899
  const json = parse(await fs6.readFile(targetJsonPath, "utf8"), void 0, false);
772
- json && typeof json === "object" && setMirror(json);
900
+ const env = (mirrorConfig == null ? void 0 : mirrorConfig.env) ? { ...chinaMirrorsEnvs, ...mirrorConfig.env } : chinaMirrorsEnvs;
901
+ json && typeof json === "object" && setMirror(json, env);
773
902
  await fs6.writeFile(targetJsonPath, `${stringify(json, void 0, 2)}
774
903
  `, "utf8");
775
904
  }
776
905
 
777
- // src/monorepo/sync.ts
906
+ // src/commands/sync.ts
778
907
  init_esm_shims();
779
908
  import os from "os";
780
- import { execa } from "execa";
909
+ import { execaCommand } from "execa";
781
910
  import PQueue from "p-queue";
782
- import path11 from "pathe";
911
+ import path12 from "pathe";
783
912
  import pc2 from "picocolors";
913
+ function renderCommand(template, pkgName) {
914
+ return template.replaceAll("{name}", pkgName);
915
+ }
784
916
  async function syncNpmMirror(cwd, options) {
785
- const { packages, workspaceDir } = await getWorkspaceData(cwd, options);
917
+ const syncConfig = await resolveCommandConfig("sync", cwd);
918
+ const {
919
+ concurrency: configConcurrency,
920
+ command: configCommand,
921
+ packages: packageFilter,
922
+ ...workspaceOverrides
923
+ } = syncConfig ?? {};
924
+ const workspaceOptions = {
925
+ ...workspaceOverrides,
926
+ ...options ?? {}
927
+ };
928
+ const { packages, workspaceDir } = await getWorkspaceData(cwd, workspaceOptions);
786
929
  logger.info(`[\u5F53\u524D\u5DE5\u4F5C\u533ARepo]:
787
- ${packages.map((x) => `- ${pc2.green(x.manifest.name)} : ${path11.relative(workspaceDir, x.rootDir)}`).join("\n")}
930
+ ${packages.map((x) => `- ${pc2.green(x.manifest.name)} : ${path12.relative(workspaceDir, x.rootDir)}`).join("\n")}
788
931
  `);
789
932
  const set7 = new Set(packages.map((x) => x.manifest.name));
933
+ if (packageFilter == null ? void 0 : packageFilter.length) {
934
+ for (const name2 of Array.from(set7)) {
935
+ if (!name2 || !packageFilter.includes(name2)) {
936
+ set7.delete(name2);
937
+ }
938
+ }
939
+ }
790
940
  logger.info(`[\u5373\u5C06\u540C\u6B65\u7684\u5305]:
791
- ${Array.from(set7).map((x) => `- ${pc2.green(x)}`).join("\n")}
941
+ ${Array.from(set7).map((x) => `- ${pc2.green(x ?? "")}`).join("\n")}
792
942
  `);
793
- const concurrency = Math.max(os.cpus().length, 1);
794
- const queue2 = new PQueue({ concurrency });
943
+ const concurrency = configConcurrency ?? Math.max(os.cpus().length, 1);
944
+ const queue = new PQueue({ concurrency });
945
+ const template = configCommand ?? "cnpm sync {name}";
946
+ const tasks = [];
795
947
  for (const pkgName of set7) {
796
- if (pkgName) {
797
- await queue2.add(async () => {
798
- return execa({
799
- stdout: ["pipe", "inherit"]
800
- })`cnpm sync ${pkgName}`;
801
- });
948
+ if (!pkgName) {
949
+ continue;
802
950
  }
951
+ tasks.push(queue.add(async () => {
952
+ const command = renderCommand(template, pkgName);
953
+ return execaCommand(command, {
954
+ stdio: "inherit"
955
+ });
956
+ }));
803
957
  }
958
+ await Promise.all(tasks);
804
959
  }
805
960
 
806
- // src/utils/md5.ts
961
+ // src/utils/hash.ts
807
962
  init_esm_shims();
808
963
  import crypto from "crypto";
809
964
  function getFileHash(data) {
@@ -836,19 +991,19 @@ function isMatch(str, arr) {
836
991
  return false;
837
992
  }
838
993
 
839
- // src/monorepo/upgrade.ts
994
+ // src/commands/upgrade/index.ts
840
995
  init_esm_shims();
996
+ import { Buffer as Buffer2 } from "buffer";
841
997
  import process2 from "process";
842
998
  import checkbox2 from "@inquirer/checkbox";
843
999
  import confirm from "@inquirer/confirm";
844
1000
  import fs7 from "fs-extra";
845
1001
  var import_set_value6 = __toESM(require_set_value(), 1);
846
1002
  import klaw from "klaw";
847
- import PQueue2 from "p-queue";
848
- import path12 from "pathe";
1003
+ import path13 from "pathe";
849
1004
  import pc3 from "picocolors";
850
1005
 
851
- // src/scripts.ts
1006
+ // src/commands/upgrade/scripts.ts
852
1007
  init_esm_shims();
853
1008
  var scripts = {
854
1009
  "script:init": "monorepo init",
@@ -859,7 +1014,7 @@ var scripts = {
859
1014
  };
860
1015
  var scriptsEntries = Object.entries(scripts);
861
1016
 
862
- // src/targets.ts
1017
+ // src/commands/upgrade/targets.ts
863
1018
  init_esm_shims();
864
1019
  function getAssetTargets(raw) {
865
1020
  const list = [
@@ -874,6 +1029,7 @@ function getAssetTargets(raw) {
874
1029
  "eslint.config.js",
875
1030
  "lint-staged.config.js",
876
1031
  "stylelint.config.js",
1032
+ "monorepo.config.ts",
877
1033
  "package.json",
878
1034
  // pnpm
879
1035
  "pnpm-workspace.yaml",
@@ -895,52 +1051,101 @@ function getAssetTargets(raw) {
895
1051
  return list;
896
1052
  }
897
1053
 
898
- // src/monorepo/upgrade.ts
899
- var queue = new PQueue2({ concurrency: 1 });
1054
+ // src/commands/upgrade/index.ts
900
1055
  function isWorkspace(version2) {
901
1056
  if (typeof version2 === "string") {
902
1057
  return version2.startsWith("workspace:");
903
1058
  }
904
1059
  return false;
905
1060
  }
906
- function setPkgJson(sourcePkgJson, targetPkgJson) {
1061
+ function setPkgJson(sourcePkgJson, targetPkgJson, options) {
907
1062
  const packageManager = index_default(sourcePkgJson, "packageManager", { default: "" });
908
- const deps = index_default(sourcePkgJson, "dependencies", { default: {} });
909
- const devDeps = index_default(sourcePkgJson, "devDependencies", { default: {} });
910
- const targetDeps = index_default(targetPkgJson, "dependencies", { default: {} });
911
- const targetDevDeps = index_default(targetPkgJson, "devDependencies", { default: {} });
912
- (0, import_set_value6.default)(targetPkgJson, "packageManager", packageManager);
913
- Object.entries(deps).forEach((x) => {
914
- if (!isWorkspace(targetDeps[x[0]])) {
915
- (0, import_set_value6.default)(targetPkgJson, `dependencies.${x[0].replaceAll(".", "\\.")}`, x[1], { preservePaths: false });
1063
+ const sourceDeps = index_default(sourcePkgJson, "dependencies", { default: {} });
1064
+ const sourceDevDeps = index_default(sourcePkgJson, "devDependencies", { default: {} });
1065
+ const targetDeps = { ...index_default(targetPkgJson, "dependencies", { default: {} }) };
1066
+ const targetDevDeps = { ...index_default(targetPkgJson, "devDependencies", { default: {} }) };
1067
+ if (packageManager) {
1068
+ targetPkgJson.packageManager = packageManager;
1069
+ }
1070
+ for (const [depName, depVersion] of Object.entries(sourceDeps)) {
1071
+ if (!isWorkspace(targetDeps[depName])) {
1072
+ targetDeps[depName] = depVersion;
916
1073
  }
917
- });
918
- Object.entries(devDeps).forEach((x) => {
919
- if (x[0] === name) {
920
- (0, import_set_value6.default)(targetPkgJson, `devDependencies.${x[0].replaceAll(".", "\\.")}`, `^${version}`, { preservePaths: false });
921
- } else if (!isWorkspace(targetDevDeps[x[0]])) {
922
- (0, import_set_value6.default)(targetPkgJson, `devDependencies.${x[0].replaceAll(".", "\\.")}`, x[1], { preservePaths: false });
1074
+ }
1075
+ if (Object.keys(targetDeps).length) {
1076
+ targetPkgJson.dependencies = targetDeps;
1077
+ }
1078
+ for (const [depName, depVersion] of Object.entries(sourceDevDeps)) {
1079
+ if (depName === name) {
1080
+ targetDevDeps[depName] = `^${version}`;
1081
+ } else if (!isWorkspace(targetDevDeps[depName])) {
1082
+ targetDevDeps[depName] = depVersion;
923
1083
  }
924
- });
925
- for (const [k, v] of scriptsEntries) {
926
- (0, import_set_value6.default)(targetPkgJson, `scripts.${k}`, v);
1084
+ }
1085
+ if (Object.keys(targetDevDeps).length) {
1086
+ targetPkgJson.devDependencies = targetDevDeps;
1087
+ }
1088
+ const scriptPairs = (options == null ? void 0 : options.scripts) ? Object.entries(options.scripts) : scriptsEntries;
1089
+ if (scriptPairs.length) {
1090
+ const scripts2 = { ...targetPkgJson.scripts ?? {} };
1091
+ for (const [scriptName, scriptCmd] of scriptPairs) {
1092
+ scripts2[scriptName] = scriptCmd;
1093
+ }
1094
+ targetPkgJson.scripts = scripts2;
927
1095
  }
928
1096
  }
929
1097
  function confirmOverwrite(filename) {
930
1098
  return confirm({ message: `${pc3.greenBright(filename)} \u6587\u4EF6\u5185\u5BB9\u53D1\u751F\u6539\u53D8,\u662F\u5426\u8986\u76D6?`, default: true });
931
1099
  }
1100
+ function asBuffer(data) {
1101
+ return typeof data === "string" ? Buffer2.from(data) : data;
1102
+ }
1103
+ async function shouldWriteFile(targetPath, options) {
1104
+ const { skipOverwrite, source, promptLabel } = options;
1105
+ const exists = await fs7.pathExists(targetPath);
1106
+ if (!exists) {
1107
+ return true;
1108
+ }
1109
+ if (skipOverwrite) {
1110
+ return false;
1111
+ }
1112
+ const src = asBuffer(source);
1113
+ let destSize = 0;
1114
+ try {
1115
+ const stat = await fs7.stat(targetPath);
1116
+ destSize = stat.size;
1117
+ } catch {
1118
+ return true;
1119
+ }
1120
+ if (destSize !== src.length) {
1121
+ return confirmOverwrite(promptLabel);
1122
+ }
1123
+ const dest = await fs7.readFile(targetPath);
1124
+ if (!isFileChanged(src, dest)) {
1125
+ return false;
1126
+ }
1127
+ return confirmOverwrite(promptLabel);
1128
+ }
932
1129
  async function upgradeMonorepo(opts) {
933
- const { outDir, raw, interactive, cwd, skipOverwrite } = defu(opts, {
934
- cwd: process2.cwd(),
935
- outDir: ""
936
- });
937
- const absOutDir = path12.isAbsolute(outDir) ? outDir : path12.join(cwd, outDir);
1130
+ const cwd = opts.cwd ?? process2.cwd();
1131
+ const upgradeConfig = await resolveCommandConfig("upgrade", cwd);
1132
+ const merged = {
1133
+ cwd,
1134
+ outDir: "",
1135
+ ...upgradeConfig ?? {},
1136
+ ...opts
1137
+ };
1138
+ const outDir = merged.outDir ?? "";
1139
+ const absOutDir = path13.isAbsolute(outDir) ? outDir : path13.join(cwd, outDir);
938
1140
  const gitClient = new GitClient({
939
1141
  baseDir: cwd
940
1142
  });
941
1143
  const repoName = await gitClient.getRepoName();
942
- let targets = getAssetTargets(raw);
943
- if (interactive) {
1144
+ const baseTargets = getAssetTargets(merged.raw);
1145
+ const configTargets = (upgradeConfig == null ? void 0 : upgradeConfig.targets) ?? [];
1146
+ const mergeTargets = upgradeConfig == null ? void 0 : upgradeConfig.mergeTargets;
1147
+ let targets = configTargets.length ? mergeTargets === false ? [...configTargets] : Array.from(/* @__PURE__ */ new Set([...baseTargets, ...configTargets])) : baseTargets;
1148
+ if (merged.interactive) {
944
1149
  targets = await checkbox2({
945
1150
  message: "\u9009\u62E9\u4F60\u9700\u8981\u7684\u6587\u4EF6",
946
1151
  choices: targets.map((x) => {
@@ -954,80 +1159,84 @@ async function upgradeMonorepo(opts) {
954
1159
  const regexpArr = targets.map((x) => {
955
1160
  return new RegExp(`^${escapeStringRegexp(x)}`);
956
1161
  });
1162
+ const skipChangesetMarkdown = (upgradeConfig == null ? void 0 : upgradeConfig.skipChangesetMarkdown) ?? true;
1163
+ const scriptOverrides = upgradeConfig == null ? void 0 : upgradeConfig.scripts;
1164
+ const skipOverwrite = merged.skipOverwrite;
957
1165
  for await (const file of klaw(assetsDir, {
958
1166
  filter(p) {
959
- const str = path12.relative(assetsDir, p);
1167
+ const str = path13.relative(assetsDir, p);
960
1168
  return isMatch(str, regexpArr);
961
1169
  }
962
1170
  })) {
963
- await queue.add(async () => {
964
- if (file.stats.isFile()) {
965
- let relPath = path12.relative(assetsDir, file.path);
966
- if (relPath === "gitignore") {
967
- relPath = ".gitignore";
968
- }
969
- const targetPath = path12.resolve(absOutDir, relPath);
970
- const targetIsExisted = await fs7.exists(targetPath);
971
- async function overwriteOrCopy(target) {
972
- let isOverwrite = true;
973
- if (targetIsExisted) {
974
- const src = await fs7.readFile(file.path);
975
- const dest = target ?? await fs7.readFile(targetPath);
976
- if (await isFileChanged(src, dest)) {
977
- isOverwrite = await confirmOverwrite(relPath);
978
- }
979
- } else if (skipOverwrite) {
980
- isOverwrite = false;
981
- }
982
- return isOverwrite;
983
- }
984
- if (relPath === "package.json") {
985
- const sourcePath = file.path;
986
- if (targetIsExisted) {
987
- const sourcePkgJson = await fs7.readJson(sourcePath);
988
- const targetPkgJson = await fs7.readJson(targetPath);
989
- setPkgJson(sourcePkgJson, targetPkgJson);
990
- const data = JSON.stringify(targetPkgJson, void 0, 2);
991
- await fs7.outputFile(targetPath, `${data}
992
- `, "utf8");
993
- logger.success(targetPath);
994
- }
995
- } else if (relPath === ".changeset/config.json" && repoName) {
996
- const changesetJson = await fs7.readJson(file.path);
997
- (0, import_set_value6.default)(changesetJson, "changelog.1.repo", repoName);
998
- const data = JSON.stringify(changesetJson, void 0, 2);
999
- if (await overwriteOrCopy(data)) {
1000
- await fs7.outputFile(targetPath, `${data}
1001
- `, "utf8");
1002
- logger.success(targetPath);
1003
- }
1004
- } else if (await overwriteOrCopy()) {
1005
- await fs7.copy(
1006
- file.path,
1007
- targetPath
1008
- );
1009
- logger.success(targetPath);
1010
- }
1171
+ if (!file.stats.isFile()) {
1172
+ continue;
1173
+ }
1174
+ let relPath = path13.relative(assetsDir, file.path);
1175
+ if (relPath === "gitignore") {
1176
+ relPath = ".gitignore";
1177
+ }
1178
+ if (skipChangesetMarkdown && relPath.startsWith(".changeset/") && relPath.endsWith(".md")) {
1179
+ continue;
1180
+ }
1181
+ const targetPath = path13.resolve(absOutDir, relPath);
1182
+ if (relPath === "package.json") {
1183
+ if (!await fs7.pathExists(targetPath)) {
1184
+ continue;
1011
1185
  }
1012
- });
1186
+ const sourcePkgJson = await fs7.readJson(file.path);
1187
+ const targetPkgJson = await fs7.readJson(targetPath);
1188
+ setPkgJson(sourcePkgJson, targetPkgJson, { scripts: scriptOverrides });
1189
+ const data = `${JSON.stringify(targetPkgJson, void 0, 2)}
1190
+ `;
1191
+ if (await shouldWriteFile(targetPath, { skipOverwrite, source: data, promptLabel: relPath })) {
1192
+ await fs7.outputFile(targetPath, data, "utf8");
1193
+ logger.success(targetPath);
1194
+ }
1195
+ continue;
1196
+ }
1197
+ if (relPath === ".changeset/config.json" && repoName) {
1198
+ const changesetJson = await fs7.readJson(file.path);
1199
+ (0, import_set_value6.default)(changesetJson, "changelog.1.repo", repoName);
1200
+ const data = `${JSON.stringify(changesetJson, void 0, 2)}
1201
+ `;
1202
+ if (await shouldWriteFile(targetPath, { skipOverwrite, source: data, promptLabel: relPath })) {
1203
+ await fs7.outputFile(targetPath, data, "utf8");
1204
+ logger.success(targetPath);
1205
+ }
1206
+ continue;
1207
+ }
1208
+ if (await shouldWriteFile(targetPath, { skipOverwrite, source: await fs7.readFile(file.path), promptLabel: relPath })) {
1209
+ await fs7.copy(file.path, targetPath);
1210
+ logger.success(targetPath);
1211
+ }
1013
1212
  }
1014
1213
  }
1015
1214
 
1016
- // src/monorepo/index.ts
1215
+ // src/commands/index.ts
1017
1216
  init_esm_shims();
1018
1217
 
1019
1218
  export {
1020
- name,
1021
- version,
1022
1219
  init_esm_shims,
1023
- logger,
1220
+ GitClient,
1024
1221
  getWorkspacePackages,
1025
1222
  getWorkspaceData,
1223
+ defineMonorepoConfig,
1224
+ loadMonorepoConfig,
1225
+ resolveCommandConfig,
1026
1226
  cleanProjects,
1227
+ name,
1228
+ version,
1229
+ packageDir,
1230
+ templatesDir,
1231
+ assetsDir,
1232
+ rootDir,
1233
+ logger,
1234
+ templateMap,
1027
1235
  defaultTemplate,
1028
- createChoices,
1236
+ getCreateChoices,
1237
+ getTemplateMap,
1029
1238
  createNewProject,
1030
- GitClient,
1239
+ createContext,
1031
1240
  init,
1032
1241
  setVscodeBinaryMirror,
1033
1242
  syncNpmMirror,