@icebreakers/monorepo 1.2.4 → 2.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +28 -0
- package/assets/.husky/commit-msg +4 -1
- package/assets/.husky/pre-commit +4 -1
- package/assets/monorepo.config.ts +22 -0
- package/assets/package.json +7 -7
- package/assets/turbo.json +10 -2
- package/dist/{chunk-MGL2NBGH.js → chunk-KHTXCQMQ.js} +575 -364
- package/dist/cli.cjs +605 -397
- package/dist/cli.js +12 -7
- package/dist/index.cjs +624 -382
- package/dist/index.d.cts +275 -14
- package/dist/index.d.ts +275 -14
- package/dist/index.js +31 -3
- package/package.json +5 -4
- package/templates/apps/cli/src/cli.ts +2 -1
- package/templates/apps/cli/src/index.ts +14 -0
- package/templates/apps/client/package.json +11 -9
- package/templates/apps/server/package.json +3 -3
- package/templates/apps/website/index.md +83 -121
- package/templates/apps/website/monorepo/index.md +34 -56
- package/templates/apps/website/monorepo/manage.md +102 -37
- package/templates/apps/website/monorepo/publish.md +57 -109
- package/templates/apps/website/package.json +3 -1
- package/templates/packages/vue-lib-template/package.json +2 -2
|
@@ -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.
|
|
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.
|
|
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,
|
|
187
|
-
if (!
|
|
188
|
-
const keys = split2(
|
|
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/
|
|
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/
|
|
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/
|
|
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
|
|
533
|
+
import path4 from "pathe";
|
|
339
534
|
async function cleanProjects(cwd) {
|
|
340
|
-
const
|
|
341
|
-
const
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
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
|
-
|
|
353
|
-
|
|
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
|
|
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 = "
|
|
581
|
+
var version = "2.0.1";
|
|
379
582
|
|
|
380
583
|
// src/constants.ts
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
var
|
|
385
|
-
var
|
|
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/
|
|
393
|
-
|
|
394
|
-
var
|
|
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
|
|
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,87 @@ var createChoices = [
|
|
|
409
621
|
{ name: "vitepress \u6587\u6863", value: "vitepress" },
|
|
410
622
|
{ name: "cli \u6A21\u677F", value: "cli" }
|
|
411
623
|
];
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
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
|
-
|
|
628
|
+
return [...baseChoices];
|
|
444
629
|
}
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
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
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
const
|
|
486
|
-
const
|
|
487
|
-
const
|
|
488
|
-
const
|
|
489
|
-
|
|
490
|
-
|
|
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 rawName = (options == null ? void 0 : options.name) ?? (createConfig == null ? void 0 : createConfig.name);
|
|
642
|
+
const name2 = typeof rawName === "string" ? rawName.trim() : void 0;
|
|
643
|
+
const requestedTemplate = (options == null ? void 0 : options.type) ?? (createConfig == null ? void 0 : createConfig.type) ?? (createConfig == null ? void 0 : createConfig.defaultTemplate) ?? defaultTemplate;
|
|
644
|
+
const templateDefinitions = getTemplateMap(createConfig == null ? void 0 : createConfig.templateMap);
|
|
645
|
+
const templatesRoot = (createConfig == null ? void 0 : createConfig.templatesDir) ? path6.resolve(cwd, createConfig.templatesDir) : templatesDir;
|
|
646
|
+
const fallbackTemplate = (createConfig == null ? void 0 : createConfig.defaultTemplate) ?? defaultTemplate;
|
|
647
|
+
const bundlerName = typeof requestedTemplate === "string" && templateDefinitions[requestedTemplate] ? requestedTemplate : fallbackTemplate;
|
|
648
|
+
const sourceRelative = templateDefinitions[bundlerName];
|
|
649
|
+
if (!sourceRelative) {
|
|
650
|
+
throw new Error(`\u672A\u627E\u5230\u540D\u4E3A ${bundlerName} \u7684\u6A21\u677F\uFF0C\u8BF7\u68C0\u67E5 monorepo.config.ts`);
|
|
491
651
|
}
|
|
492
|
-
|
|
493
|
-
|
|
652
|
+
const from = path6.join(templatesRoot, sourceRelative);
|
|
653
|
+
const targetName = name2 && name2.length > 0 ? name2 : sourceRelative;
|
|
654
|
+
const to = path6.join(cwd, targetName);
|
|
655
|
+
if (await fs2.pathExists(to)) {
|
|
656
|
+
throw new Error(`${pc.red("\u76EE\u6807\u76EE\u5F55\u5DF2\u5B58\u5728")}: ${path6.relative(cwd, to)}`);
|
|
494
657
|
}
|
|
495
|
-
|
|
496
|
-
const
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
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;
|
|
658
|
+
await fs2.ensureDir(to);
|
|
659
|
+
const filelist = await fs2.readdir(from);
|
|
660
|
+
const shouldSkip = (src) => path6.basename(src) === ".DS_Store";
|
|
661
|
+
const copyTasks = filelist.filter((filename) => filename !== "package.json").map(async (filename) => {
|
|
662
|
+
const sourcePath = path6.resolve(from, filename);
|
|
663
|
+
const targetPath = path6.resolve(to, filename === "gitignore" ? ".gitignore" : filename);
|
|
664
|
+
await fs2.copy(sourcePath, targetPath, {
|
|
665
|
+
filter(src) {
|
|
666
|
+
if (shouldSkip(src)) {
|
|
667
|
+
return false;
|
|
523
668
|
}
|
|
669
|
+
return true;
|
|
524
670
|
}
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
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
|
-
};
|
|
671
|
+
});
|
|
672
|
+
});
|
|
673
|
+
await Promise.all(copyTasks);
|
|
674
|
+
if (filelist.includes("package.json")) {
|
|
675
|
+
const sourceJsonPath = path6.resolve(from, "package.json");
|
|
676
|
+
const sourceJson = await fs2.readJson(sourceJsonPath);
|
|
677
|
+
(0, import_set_value2.default)(sourceJson, "version", "0.0.0");
|
|
678
|
+
const packageName = (name2 == null ? void 0 : name2.startsWith("@")) ? name2 : path6.basename(targetName);
|
|
679
|
+
(0, import_set_value2.default)(sourceJson, "name", packageName);
|
|
680
|
+
await fs2.outputJson(
|
|
681
|
+
path6.resolve(
|
|
682
|
+
to,
|
|
683
|
+
renameJson ? "package.mock.json" : "package.json"
|
|
684
|
+
),
|
|
685
|
+
sourceJson,
|
|
686
|
+
{ spaces: 2 }
|
|
687
|
+
);
|
|
582
688
|
}
|
|
583
|
-
};
|
|
584
|
-
|
|
585
|
-
// src/monorepo/init/index.ts
|
|
586
|
-
init_esm_shims();
|
|
689
|
+
logger.success(`${pc.bgGreenBright(pc.white(`[${bundlerName}]`))} ${targetName} \u9879\u76EE\u521B\u5EFA\u6210\u529F\uFF01`);
|
|
690
|
+
}
|
|
587
691
|
|
|
588
|
-
// src/
|
|
692
|
+
// src/core/context.ts
|
|
589
693
|
init_esm_shims();
|
|
590
|
-
import
|
|
694
|
+
import path7 from "pathe";
|
|
591
695
|
import "@pnpm/types";
|
|
592
696
|
async function createContext(cwd) {
|
|
593
|
-
const git = new GitClient();
|
|
594
697
|
const { packages, workspaceDir } = await getWorkspaceData(cwd);
|
|
595
|
-
const
|
|
698
|
+
const git = new GitClient({
|
|
699
|
+
baseDir: workspaceDir
|
|
700
|
+
});
|
|
701
|
+
const workspaceFilepath = path7.resolve(workspaceDir, "pnpm-workspace.yaml");
|
|
596
702
|
const gitUrl = await git.getGitUrl();
|
|
597
703
|
const gitUser = await git.getUser();
|
|
704
|
+
const config = await loadMonorepoConfig(workspaceDir);
|
|
598
705
|
return {
|
|
599
706
|
cwd,
|
|
600
707
|
git,
|
|
@@ -602,19 +709,23 @@ async function createContext(cwd) {
|
|
|
602
709
|
gitUser,
|
|
603
710
|
workspaceDir,
|
|
604
711
|
workspaceFilepath,
|
|
605
|
-
packages
|
|
712
|
+
packages,
|
|
713
|
+
config
|
|
606
714
|
};
|
|
607
715
|
}
|
|
608
716
|
|
|
609
|
-
// src/
|
|
717
|
+
// src/commands/init/index.ts
|
|
718
|
+
init_esm_shims();
|
|
719
|
+
|
|
720
|
+
// src/commands/init/setChangeset.ts
|
|
610
721
|
init_esm_shims();
|
|
611
722
|
var import_set_value3 = __toESM(require_set_value(), 1);
|
|
612
723
|
import fs3 from "fs-extra";
|
|
613
|
-
import
|
|
724
|
+
import path8 from "pathe";
|
|
614
725
|
async function setChangeset_default(ctx) {
|
|
615
726
|
const { gitUrl, workspaceFilepath } = ctx;
|
|
616
727
|
if (gitUrl && await fs3.exists(workspaceFilepath)) {
|
|
617
|
-
const changesetConfigPath =
|
|
728
|
+
const changesetConfigPath = path8.resolve(path8.dirname(workspaceFilepath), ".changeset/config.json");
|
|
618
729
|
if (await fs3.exists(changesetConfigPath)) {
|
|
619
730
|
const changesetConfig = await fs3.readJson(
|
|
620
731
|
changesetConfigPath
|
|
@@ -627,18 +738,22 @@ async function setChangeset_default(ctx) {
|
|
|
627
738
|
}
|
|
628
739
|
}
|
|
629
740
|
|
|
630
|
-
// src/
|
|
741
|
+
// src/commands/init/setPkgJson.ts
|
|
631
742
|
init_esm_shims();
|
|
632
743
|
var import_set_value4 = __toESM(require_set_value(), 1);
|
|
633
744
|
import fs4 from "fs-extra";
|
|
634
|
-
import
|
|
745
|
+
import path9 from "pathe";
|
|
635
746
|
async function setPkgJson_default(ctx) {
|
|
636
747
|
const { gitUrl, gitUser, packages, cwd, workspaceFilepath } = ctx;
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
748
|
+
const workspaceExists = await fs4.pathExists(workspaceFilepath);
|
|
749
|
+
if (gitUrl && workspaceExists) {
|
|
750
|
+
await Promise.all(packages.map(async (pkg) => {
|
|
751
|
+
if (!await fs4.pathExists(pkg.pkgJsonPath)) {
|
|
752
|
+
return;
|
|
753
|
+
}
|
|
754
|
+
const pkgJson = JSON.parse(JSON.stringify(pkg.manifest));
|
|
755
|
+
const directory = path9.relative(cwd, pkg.rootDir);
|
|
756
|
+
(0, import_set_value4.default)(pkgJson, ["bugs", "url"], `https://github.com/${gitUrl.full_name}/issues`);
|
|
642
757
|
const repository = {
|
|
643
758
|
type: "git",
|
|
644
759
|
url: `git+https://github.com/${gitUrl.full_name}.git`
|
|
@@ -647,32 +762,38 @@ async function setPkgJson_default(ctx) {
|
|
|
647
762
|
repository.directory = directory;
|
|
648
763
|
}
|
|
649
764
|
(0, import_set_value4.default)(pkgJson, "repository", repository);
|
|
650
|
-
if (gitUser) {
|
|
765
|
+
if ((gitUser == null ? void 0 : gitUser.name) && (gitUser == null ? void 0 : gitUser.email)) {
|
|
651
766
|
(0, import_set_value4.default)(pkgJson, "author", `${gitUser.name} <${gitUser.email}>`);
|
|
652
767
|
}
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
768
|
+
const nextContent = `${JSON.stringify(pkgJson, void 0, 2)}
|
|
769
|
+
`;
|
|
770
|
+
const prevContent = await fs4.readFile(pkg.pkgJsonPath, "utf8");
|
|
771
|
+
if (prevContent !== nextContent) {
|
|
772
|
+
await fs4.writeFile(pkg.pkgJsonPath, nextContent, "utf8");
|
|
773
|
+
}
|
|
774
|
+
}));
|
|
657
775
|
}
|
|
658
776
|
}
|
|
659
777
|
|
|
660
|
-
// src/
|
|
778
|
+
// src/commands/init/setReadme.ts
|
|
661
779
|
init_esm_shims();
|
|
662
780
|
import fs5 from "fs-extra";
|
|
663
|
-
import
|
|
781
|
+
import path10 from "pathe";
|
|
664
782
|
async function getRows(ctx) {
|
|
665
|
-
const { packages,
|
|
666
|
-
const gitUrl = await git.getGitUrl();
|
|
667
|
-
const gitUser = await git.getUser();
|
|
783
|
+
const { packages, gitUrl, gitUser, cwd } = ctx;
|
|
668
784
|
const rows = [];
|
|
669
785
|
if (gitUrl) {
|
|
670
786
|
rows.push(`# ${gitUrl.name}
|
|
671
787
|
`);
|
|
672
788
|
}
|
|
673
789
|
rows.push("## Packages\n");
|
|
674
|
-
|
|
675
|
-
const
|
|
790
|
+
const sortedPackages = [...packages].sort((a, b) => {
|
|
791
|
+
const left = a.manifest.name ?? "";
|
|
792
|
+
const right = b.manifest.name ?? "";
|
|
793
|
+
return left.localeCompare(right);
|
|
794
|
+
});
|
|
795
|
+
for (const pkg of sortedPackages) {
|
|
796
|
+
const p = path10.relative(cwd, pkg.rootDirRealPath);
|
|
676
797
|
if (p) {
|
|
677
798
|
const description = pkg.manifest.description ? `- ${pkg.manifest.description}` : "";
|
|
678
799
|
rows.push(`- [${pkg.manifest.name}](${p}) ${description}`);
|
|
@@ -693,36 +814,42 @@ async function getRows(ctx) {
|
|
|
693
814
|
rows.push(`Thanks to [all contributors](https://github.com/${gitUrl.full_name}/graphs/contributors)!`);
|
|
694
815
|
}
|
|
695
816
|
rows.push("\n## Authors\n");
|
|
696
|
-
|
|
817
|
+
if ((gitUser == null ? void 0 : gitUser.name) && (gitUser == null ? void 0 : gitUser.email)) {
|
|
818
|
+
rows.push(`${gitUser.name} <${gitUser.email}>`);
|
|
819
|
+
}
|
|
697
820
|
rows.push("\n## License\n");
|
|
698
821
|
rows.push("Distributed under the MIT License. See [LICENSE](LICENSE) for more information.");
|
|
699
822
|
return rows;
|
|
700
823
|
}
|
|
701
824
|
async function setReadme_default(ctx) {
|
|
702
825
|
const rows = await getRows(ctx);
|
|
703
|
-
await fs5.writeFile(
|
|
826
|
+
await fs5.writeFile(path10.resolve(ctx.cwd, "README.md"), `${rows.join("\n")}
|
|
704
827
|
`);
|
|
705
828
|
}
|
|
706
829
|
|
|
707
|
-
// src/
|
|
830
|
+
// src/commands/init/index.ts
|
|
708
831
|
async function init(cwd) {
|
|
832
|
+
var _a;
|
|
709
833
|
const ctx = await createContext(cwd);
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
834
|
+
const initConfig = ((_a = ctx.config.commands) == null ? void 0 : _a.init) ?? {};
|
|
835
|
+
if (!initConfig.skipChangeset) {
|
|
836
|
+
await setChangeset_default(ctx);
|
|
837
|
+
}
|
|
838
|
+
if (!initConfig.skipPkgJson) {
|
|
839
|
+
await setPkgJson_default(ctx);
|
|
840
|
+
}
|
|
841
|
+
if (!initConfig.skipReadme) {
|
|
842
|
+
await setReadme_default(ctx);
|
|
843
|
+
}
|
|
713
844
|
}
|
|
714
845
|
|
|
715
|
-
// src/
|
|
846
|
+
// src/commands/mirror/binaryMirror.ts
|
|
716
847
|
init_esm_shims();
|
|
717
848
|
import { parse, stringify } from "comment-json";
|
|
718
849
|
import fs6 from "fs-extra";
|
|
719
|
-
import
|
|
720
|
-
|
|
721
|
-
// src/monorepo/mirror/utils.ts
|
|
722
|
-
init_esm_shims();
|
|
723
|
-
var import_set_value5 = __toESM(require_set_value(), 1);
|
|
850
|
+
import path11 from "pathe";
|
|
724
851
|
|
|
725
|
-
// src/
|
|
852
|
+
// src/commands/mirror/sources.ts
|
|
726
853
|
init_esm_shims();
|
|
727
854
|
var chinaMirrorsEnvs = {
|
|
728
855
|
COREPACK_NPM_REGISTRY: "https://registry.npmmirror.com",
|
|
@@ -753,57 +880,87 @@ var chinaMirrorsEnvs = {
|
|
|
753
880
|
npm_config_robotjs_binary_host: "https://cdn.npmmirror.com/binaries/robotjs"
|
|
754
881
|
};
|
|
755
882
|
|
|
756
|
-
// src/
|
|
757
|
-
|
|
883
|
+
// src/commands/mirror/utils.ts
|
|
884
|
+
init_esm_shims();
|
|
885
|
+
var import_set_value5 = __toESM(require_set_value(), 1);
|
|
886
|
+
function setMirror(obj, envs = chinaMirrorsEnvs) {
|
|
758
887
|
const platforms = ["linux", "windows", "osx"];
|
|
759
888
|
const prefix = "terminal.integrated.env";
|
|
760
889
|
if (typeof obj === "object" && obj) {
|
|
761
890
|
for (const platform of platforms) {
|
|
762
|
-
(0, import_set_value5.default)(obj, [prefix, platform].join(".").replaceAll(".", "\\."),
|
|
891
|
+
(0, import_set_value5.default)(obj, [prefix, platform].join(".").replaceAll(".", "\\."), envs);
|
|
763
892
|
}
|
|
764
893
|
}
|
|
765
894
|
}
|
|
766
895
|
|
|
767
|
-
// src/
|
|
896
|
+
// src/commands/mirror/binaryMirror.ts
|
|
768
897
|
async function setVscodeBinaryMirror(cwd) {
|
|
769
|
-
const
|
|
898
|
+
const mirrorConfig = await resolveCommandConfig("mirror", cwd);
|
|
899
|
+
const targetJsonPath = path11.resolve(cwd, ".vscode/settings.json");
|
|
770
900
|
await fs6.ensureFile(targetJsonPath);
|
|
771
901
|
const json = parse(await fs6.readFile(targetJsonPath, "utf8"), void 0, false);
|
|
772
|
-
|
|
902
|
+
const env = (mirrorConfig == null ? void 0 : mirrorConfig.env) ? { ...chinaMirrorsEnvs, ...mirrorConfig.env } : chinaMirrorsEnvs;
|
|
903
|
+
json && typeof json === "object" && setMirror(json, env);
|
|
773
904
|
await fs6.writeFile(targetJsonPath, `${stringify(json, void 0, 2)}
|
|
774
905
|
`, "utf8");
|
|
775
906
|
}
|
|
776
907
|
|
|
777
|
-
// src/
|
|
908
|
+
// src/commands/sync.ts
|
|
778
909
|
init_esm_shims();
|
|
779
910
|
import os from "os";
|
|
780
|
-
import {
|
|
911
|
+
import { execaCommand } from "execa";
|
|
781
912
|
import PQueue from "p-queue";
|
|
782
|
-
import
|
|
913
|
+
import path12 from "pathe";
|
|
783
914
|
import pc2 from "picocolors";
|
|
915
|
+
function renderCommand(template, pkgName) {
|
|
916
|
+
return template.replaceAll("{name}", pkgName);
|
|
917
|
+
}
|
|
784
918
|
async function syncNpmMirror(cwd, options) {
|
|
785
|
-
const
|
|
919
|
+
const syncConfig = await resolveCommandConfig("sync", cwd);
|
|
920
|
+
const {
|
|
921
|
+
concurrency: configConcurrency,
|
|
922
|
+
command: configCommand,
|
|
923
|
+
packages: packageFilter,
|
|
924
|
+
...workspaceOverrides
|
|
925
|
+
} = syncConfig ?? {};
|
|
926
|
+
const workspaceOptions = {
|
|
927
|
+
...workspaceOverrides,
|
|
928
|
+
...options ?? {}
|
|
929
|
+
};
|
|
930
|
+
const { packages, workspaceDir } = await getWorkspaceData(cwd, workspaceOptions);
|
|
786
931
|
logger.info(`[\u5F53\u524D\u5DE5\u4F5C\u533ARepo]:
|
|
787
|
-
${packages.map((x) => `- ${pc2.green(x.manifest.name)} : ${
|
|
932
|
+
${packages.map((x) => `- ${pc2.green(x.manifest.name)} : ${path12.relative(workspaceDir, x.rootDir)}`).join("\n")}
|
|
788
933
|
`);
|
|
789
934
|
const set7 = new Set(packages.map((x) => x.manifest.name));
|
|
935
|
+
if (packageFilter == null ? void 0 : packageFilter.length) {
|
|
936
|
+
for (const name2 of Array.from(set7)) {
|
|
937
|
+
if (!name2 || !packageFilter.includes(name2)) {
|
|
938
|
+
set7.delete(name2);
|
|
939
|
+
}
|
|
940
|
+
}
|
|
941
|
+
}
|
|
790
942
|
logger.info(`[\u5373\u5C06\u540C\u6B65\u7684\u5305]:
|
|
791
|
-
${Array.from(set7).map((x) => `- ${pc2.green(x)}`).join("\n")}
|
|
943
|
+
${Array.from(set7).map((x) => `- ${pc2.green(x ?? "")}`).join("\n")}
|
|
792
944
|
`);
|
|
793
|
-
const concurrency = Math.max(os.cpus().length, 1);
|
|
794
|
-
const
|
|
945
|
+
const concurrency = configConcurrency ?? Math.max(os.cpus().length, 1);
|
|
946
|
+
const queue = new PQueue({ concurrency });
|
|
947
|
+
const template = configCommand ?? "cnpm sync {name}";
|
|
948
|
+
const tasks = [];
|
|
795
949
|
for (const pkgName of set7) {
|
|
796
|
-
if (pkgName) {
|
|
797
|
-
|
|
798
|
-
return execa({
|
|
799
|
-
stdout: ["pipe", "inherit"]
|
|
800
|
-
})`cnpm sync ${pkgName}`;
|
|
801
|
-
});
|
|
950
|
+
if (!pkgName) {
|
|
951
|
+
continue;
|
|
802
952
|
}
|
|
953
|
+
tasks.push(queue.add(async () => {
|
|
954
|
+
const command = renderCommand(template, pkgName);
|
|
955
|
+
return execaCommand(command, {
|
|
956
|
+
stdio: "inherit"
|
|
957
|
+
});
|
|
958
|
+
}));
|
|
803
959
|
}
|
|
960
|
+
await Promise.all(tasks);
|
|
804
961
|
}
|
|
805
962
|
|
|
806
|
-
// src/utils/
|
|
963
|
+
// src/utils/hash.ts
|
|
807
964
|
init_esm_shims();
|
|
808
965
|
import crypto from "crypto";
|
|
809
966
|
function getFileHash(data) {
|
|
@@ -836,19 +993,19 @@ function isMatch(str, arr) {
|
|
|
836
993
|
return false;
|
|
837
994
|
}
|
|
838
995
|
|
|
839
|
-
// src/
|
|
996
|
+
// src/commands/upgrade/index.ts
|
|
840
997
|
init_esm_shims();
|
|
998
|
+
import { Buffer as Buffer2 } from "buffer";
|
|
841
999
|
import process2 from "process";
|
|
842
1000
|
import checkbox2 from "@inquirer/checkbox";
|
|
843
1001
|
import confirm from "@inquirer/confirm";
|
|
844
1002
|
import fs7 from "fs-extra";
|
|
845
1003
|
var import_set_value6 = __toESM(require_set_value(), 1);
|
|
846
1004
|
import klaw from "klaw";
|
|
847
|
-
import
|
|
848
|
-
import path12 from "pathe";
|
|
1005
|
+
import path13 from "pathe";
|
|
849
1006
|
import pc3 from "picocolors";
|
|
850
1007
|
|
|
851
|
-
// src/scripts.ts
|
|
1008
|
+
// src/commands/upgrade/scripts.ts
|
|
852
1009
|
init_esm_shims();
|
|
853
1010
|
var scripts = {
|
|
854
1011
|
"script:init": "monorepo init",
|
|
@@ -859,7 +1016,7 @@ var scripts = {
|
|
|
859
1016
|
};
|
|
860
1017
|
var scriptsEntries = Object.entries(scripts);
|
|
861
1018
|
|
|
862
|
-
// src/targets.ts
|
|
1019
|
+
// src/commands/upgrade/targets.ts
|
|
863
1020
|
init_esm_shims();
|
|
864
1021
|
function getAssetTargets(raw) {
|
|
865
1022
|
const list = [
|
|
@@ -874,6 +1031,7 @@ function getAssetTargets(raw) {
|
|
|
874
1031
|
"eslint.config.js",
|
|
875
1032
|
"lint-staged.config.js",
|
|
876
1033
|
"stylelint.config.js",
|
|
1034
|
+
"monorepo.config.ts",
|
|
877
1035
|
"package.json",
|
|
878
1036
|
// pnpm
|
|
879
1037
|
"pnpm-workspace.yaml",
|
|
@@ -895,52 +1053,101 @@ function getAssetTargets(raw) {
|
|
|
895
1053
|
return list;
|
|
896
1054
|
}
|
|
897
1055
|
|
|
898
|
-
// src/
|
|
899
|
-
var queue = new PQueue2({ concurrency: 1 });
|
|
1056
|
+
// src/commands/upgrade/index.ts
|
|
900
1057
|
function isWorkspace(version2) {
|
|
901
1058
|
if (typeof version2 === "string") {
|
|
902
1059
|
return version2.startsWith("workspace:");
|
|
903
1060
|
}
|
|
904
1061
|
return false;
|
|
905
1062
|
}
|
|
906
|
-
function setPkgJson(sourcePkgJson, targetPkgJson) {
|
|
1063
|
+
function setPkgJson(sourcePkgJson, targetPkgJson, options) {
|
|
907
1064
|
const packageManager = index_default(sourcePkgJson, "packageManager", { default: "" });
|
|
908
|
-
const
|
|
909
|
-
const
|
|
910
|
-
const targetDeps = index_default(targetPkgJson, "dependencies", { default: {} });
|
|
911
|
-
const targetDevDeps = index_default(targetPkgJson, "devDependencies", { default: {} });
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
1065
|
+
const sourceDeps = index_default(sourcePkgJson, "dependencies", { default: {} });
|
|
1066
|
+
const sourceDevDeps = index_default(sourcePkgJson, "devDependencies", { default: {} });
|
|
1067
|
+
const targetDeps = { ...index_default(targetPkgJson, "dependencies", { default: {} }) };
|
|
1068
|
+
const targetDevDeps = { ...index_default(targetPkgJson, "devDependencies", { default: {} }) };
|
|
1069
|
+
if (packageManager) {
|
|
1070
|
+
targetPkgJson.packageManager = packageManager;
|
|
1071
|
+
}
|
|
1072
|
+
for (const [depName, depVersion] of Object.entries(sourceDeps)) {
|
|
1073
|
+
if (!isWorkspace(targetDeps[depName])) {
|
|
1074
|
+
targetDeps[depName] = depVersion;
|
|
916
1075
|
}
|
|
917
|
-
}
|
|
918
|
-
Object.
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
1076
|
+
}
|
|
1077
|
+
if (Object.keys(targetDeps).length) {
|
|
1078
|
+
targetPkgJson.dependencies = targetDeps;
|
|
1079
|
+
}
|
|
1080
|
+
for (const [depName, depVersion] of Object.entries(sourceDevDeps)) {
|
|
1081
|
+
if (depName === name) {
|
|
1082
|
+
targetDevDeps[depName] = `^${version}`;
|
|
1083
|
+
} else if (!isWorkspace(targetDevDeps[depName])) {
|
|
1084
|
+
targetDevDeps[depName] = depVersion;
|
|
923
1085
|
}
|
|
924
|
-
}
|
|
925
|
-
|
|
926
|
-
|
|
1086
|
+
}
|
|
1087
|
+
if (Object.keys(targetDevDeps).length) {
|
|
1088
|
+
targetPkgJson.devDependencies = targetDevDeps;
|
|
1089
|
+
}
|
|
1090
|
+
const scriptPairs = (options == null ? void 0 : options.scripts) ? Object.entries(options.scripts) : scriptsEntries;
|
|
1091
|
+
if (scriptPairs.length) {
|
|
1092
|
+
const scripts2 = { ...targetPkgJson.scripts ?? {} };
|
|
1093
|
+
for (const [scriptName, scriptCmd] of scriptPairs) {
|
|
1094
|
+
scripts2[scriptName] = scriptCmd;
|
|
1095
|
+
}
|
|
1096
|
+
targetPkgJson.scripts = scripts2;
|
|
927
1097
|
}
|
|
928
1098
|
}
|
|
929
1099
|
function confirmOverwrite(filename) {
|
|
930
1100
|
return confirm({ message: `${pc3.greenBright(filename)} \u6587\u4EF6\u5185\u5BB9\u53D1\u751F\u6539\u53D8,\u662F\u5426\u8986\u76D6?`, default: true });
|
|
931
1101
|
}
|
|
1102
|
+
function asBuffer(data) {
|
|
1103
|
+
return typeof data === "string" ? Buffer2.from(data) : data;
|
|
1104
|
+
}
|
|
1105
|
+
async function shouldWriteFile(targetPath, options) {
|
|
1106
|
+
const { skipOverwrite, source, promptLabel } = options;
|
|
1107
|
+
const exists = await fs7.pathExists(targetPath);
|
|
1108
|
+
if (!exists) {
|
|
1109
|
+
return true;
|
|
1110
|
+
}
|
|
1111
|
+
if (skipOverwrite) {
|
|
1112
|
+
return false;
|
|
1113
|
+
}
|
|
1114
|
+
const src = asBuffer(source);
|
|
1115
|
+
let destSize = 0;
|
|
1116
|
+
try {
|
|
1117
|
+
const stat = await fs7.stat(targetPath);
|
|
1118
|
+
destSize = stat.size;
|
|
1119
|
+
} catch {
|
|
1120
|
+
return true;
|
|
1121
|
+
}
|
|
1122
|
+
if (destSize !== src.length) {
|
|
1123
|
+
return confirmOverwrite(promptLabel);
|
|
1124
|
+
}
|
|
1125
|
+
const dest = await fs7.readFile(targetPath);
|
|
1126
|
+
if (!isFileChanged(src, dest)) {
|
|
1127
|
+
return false;
|
|
1128
|
+
}
|
|
1129
|
+
return confirmOverwrite(promptLabel);
|
|
1130
|
+
}
|
|
932
1131
|
async function upgradeMonorepo(opts) {
|
|
933
|
-
const
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
1132
|
+
const cwd = opts.cwd ?? process2.cwd();
|
|
1133
|
+
const upgradeConfig = await resolveCommandConfig("upgrade", cwd);
|
|
1134
|
+
const merged = {
|
|
1135
|
+
cwd,
|
|
1136
|
+
outDir: "",
|
|
1137
|
+
...upgradeConfig ?? {},
|
|
1138
|
+
...opts
|
|
1139
|
+
};
|
|
1140
|
+
const outDir = merged.outDir ?? "";
|
|
1141
|
+
const absOutDir = path13.isAbsolute(outDir) ? outDir : path13.join(cwd, outDir);
|
|
938
1142
|
const gitClient = new GitClient({
|
|
939
1143
|
baseDir: cwd
|
|
940
1144
|
});
|
|
941
1145
|
const repoName = await gitClient.getRepoName();
|
|
942
|
-
|
|
943
|
-
|
|
1146
|
+
const baseTargets = getAssetTargets(merged.raw);
|
|
1147
|
+
const configTargets = (upgradeConfig == null ? void 0 : upgradeConfig.targets) ?? [];
|
|
1148
|
+
const mergeTargets = upgradeConfig == null ? void 0 : upgradeConfig.mergeTargets;
|
|
1149
|
+
let targets = configTargets.length ? mergeTargets === false ? [...configTargets] : Array.from(/* @__PURE__ */ new Set([...baseTargets, ...configTargets])) : baseTargets;
|
|
1150
|
+
if (merged.interactive) {
|
|
944
1151
|
targets = await checkbox2({
|
|
945
1152
|
message: "\u9009\u62E9\u4F60\u9700\u8981\u7684\u6587\u4EF6",
|
|
946
1153
|
choices: targets.map((x) => {
|
|
@@ -954,80 +1161,84 @@ async function upgradeMonorepo(opts) {
|
|
|
954
1161
|
const regexpArr = targets.map((x) => {
|
|
955
1162
|
return new RegExp(`^${escapeStringRegexp(x)}`);
|
|
956
1163
|
});
|
|
1164
|
+
const skipChangesetMarkdown = (upgradeConfig == null ? void 0 : upgradeConfig.skipChangesetMarkdown) ?? true;
|
|
1165
|
+
const scriptOverrides = upgradeConfig == null ? void 0 : upgradeConfig.scripts;
|
|
1166
|
+
const skipOverwrite = merged.skipOverwrite;
|
|
957
1167
|
for await (const file of klaw(assetsDir, {
|
|
958
1168
|
filter(p) {
|
|
959
|
-
const str =
|
|
1169
|
+
const str = path13.relative(assetsDir, p);
|
|
960
1170
|
return isMatch(str, regexpArr);
|
|
961
1171
|
}
|
|
962
1172
|
})) {
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
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
|
-
}
|
|
1173
|
+
if (!file.stats.isFile()) {
|
|
1174
|
+
continue;
|
|
1175
|
+
}
|
|
1176
|
+
let relPath = path13.relative(assetsDir, file.path);
|
|
1177
|
+
if (relPath === "gitignore") {
|
|
1178
|
+
relPath = ".gitignore";
|
|
1179
|
+
}
|
|
1180
|
+
if (skipChangesetMarkdown && relPath.startsWith(".changeset/") && relPath.endsWith(".md")) {
|
|
1181
|
+
continue;
|
|
1182
|
+
}
|
|
1183
|
+
const targetPath = path13.resolve(absOutDir, relPath);
|
|
1184
|
+
if (relPath === "package.json") {
|
|
1185
|
+
if (!await fs7.pathExists(targetPath)) {
|
|
1186
|
+
continue;
|
|
1011
1187
|
}
|
|
1012
|
-
|
|
1188
|
+
const sourcePkgJson = await fs7.readJson(file.path);
|
|
1189
|
+
const targetPkgJson = await fs7.readJson(targetPath);
|
|
1190
|
+
setPkgJson(sourcePkgJson, targetPkgJson, { scripts: scriptOverrides });
|
|
1191
|
+
const data = `${JSON.stringify(targetPkgJson, void 0, 2)}
|
|
1192
|
+
`;
|
|
1193
|
+
if (await shouldWriteFile(targetPath, { skipOverwrite, source: data, promptLabel: relPath })) {
|
|
1194
|
+
await fs7.outputFile(targetPath, data, "utf8");
|
|
1195
|
+
logger.success(targetPath);
|
|
1196
|
+
}
|
|
1197
|
+
continue;
|
|
1198
|
+
}
|
|
1199
|
+
if (relPath === ".changeset/config.json" && repoName) {
|
|
1200
|
+
const changesetJson = await fs7.readJson(file.path);
|
|
1201
|
+
(0, import_set_value6.default)(changesetJson, "changelog.1.repo", repoName);
|
|
1202
|
+
const data = `${JSON.stringify(changesetJson, void 0, 2)}
|
|
1203
|
+
`;
|
|
1204
|
+
if (await shouldWriteFile(targetPath, { skipOverwrite, source: data, promptLabel: relPath })) {
|
|
1205
|
+
await fs7.outputFile(targetPath, data, "utf8");
|
|
1206
|
+
logger.success(targetPath);
|
|
1207
|
+
}
|
|
1208
|
+
continue;
|
|
1209
|
+
}
|
|
1210
|
+
if (await shouldWriteFile(targetPath, { skipOverwrite, source: await fs7.readFile(file.path), promptLabel: relPath })) {
|
|
1211
|
+
await fs7.copy(file.path, targetPath);
|
|
1212
|
+
logger.success(targetPath);
|
|
1213
|
+
}
|
|
1013
1214
|
}
|
|
1014
1215
|
}
|
|
1015
1216
|
|
|
1016
|
-
// src/
|
|
1217
|
+
// src/commands/index.ts
|
|
1017
1218
|
init_esm_shims();
|
|
1018
1219
|
|
|
1019
1220
|
export {
|
|
1020
|
-
name,
|
|
1021
|
-
version,
|
|
1022
1221
|
init_esm_shims,
|
|
1023
|
-
|
|
1222
|
+
GitClient,
|
|
1024
1223
|
getWorkspacePackages,
|
|
1025
1224
|
getWorkspaceData,
|
|
1225
|
+
defineMonorepoConfig,
|
|
1226
|
+
loadMonorepoConfig,
|
|
1227
|
+
resolveCommandConfig,
|
|
1026
1228
|
cleanProjects,
|
|
1229
|
+
name,
|
|
1230
|
+
version,
|
|
1231
|
+
packageDir,
|
|
1232
|
+
templatesDir,
|
|
1233
|
+
assetsDir,
|
|
1234
|
+
rootDir,
|
|
1235
|
+
logger,
|
|
1236
|
+
templateMap,
|
|
1027
1237
|
defaultTemplate,
|
|
1028
|
-
|
|
1238
|
+
getCreateChoices,
|
|
1239
|
+
getTemplateMap,
|
|
1029
1240
|
createNewProject,
|
|
1030
|
-
|
|
1241
|
+
createContext,
|
|
1031
1242
|
init,
|
|
1032
1243
|
setVscodeBinaryMirror,
|
|
1033
1244
|
syncNpmMirror,
|