@icebreakers/monorepo 0.6.10 → 0.6.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{chunk-7PE67Z6G.js → chunk-JI7KKKU2.js} +446 -447
- package/dist/cli.cjs +503 -468
- package/dist/cli.js +48 -6
- package/dist/index.cjs +450 -455
- package/dist/index.d.cts +12 -12
- package/dist/index.d.ts +12 -12
- package/dist/index.js +1 -3
- package/package.json +2 -2
|
@@ -34,107 +34,6 @@ var init_esm_shims = __esm({
|
|
|
34
34
|
}
|
|
35
35
|
});
|
|
36
36
|
|
|
37
|
-
// ../../node_modules/.pnpm/isobject@3.0.1/node_modules/isobject/index.js
|
|
38
|
-
var require_isobject = __commonJS({
|
|
39
|
-
"../../node_modules/.pnpm/isobject@3.0.1/node_modules/isobject/index.js"(exports, module) {
|
|
40
|
-
"use strict";
|
|
41
|
-
init_esm_shims();
|
|
42
|
-
module.exports = function isObject(val) {
|
|
43
|
-
return val != null && typeof val === "object" && Array.isArray(val) === false;
|
|
44
|
-
};
|
|
45
|
-
}
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
// ../../node_modules/.pnpm/get-value@3.0.1/node_modules/get-value/index.js
|
|
49
|
-
var require_get_value = __commonJS({
|
|
50
|
-
"../../node_modules/.pnpm/get-value@3.0.1/node_modules/get-value/index.js"(exports, module) {
|
|
51
|
-
"use strict";
|
|
52
|
-
init_esm_shims();
|
|
53
|
-
var isObject = require_isobject();
|
|
54
|
-
module.exports = function(target, path9, options) {
|
|
55
|
-
if (!isObject(options)) {
|
|
56
|
-
options = { default: options };
|
|
57
|
-
}
|
|
58
|
-
if (!isValidObject(target)) {
|
|
59
|
-
return typeof options.default !== "undefined" ? options.default : target;
|
|
60
|
-
}
|
|
61
|
-
if (typeof path9 === "number") {
|
|
62
|
-
path9 = String(path9);
|
|
63
|
-
}
|
|
64
|
-
const isArray = Array.isArray(path9);
|
|
65
|
-
const isString = typeof path9 === "string";
|
|
66
|
-
const splitChar = options.separator || ".";
|
|
67
|
-
const joinChar = options.joinChar || (typeof splitChar === "string" ? splitChar : ".");
|
|
68
|
-
if (!isString && !isArray) {
|
|
69
|
-
return target;
|
|
70
|
-
}
|
|
71
|
-
if (isString && path9 in target) {
|
|
72
|
-
return isValid(path9, target, options) ? target[path9] : options.default;
|
|
73
|
-
}
|
|
74
|
-
let segs = isArray ? path9 : split(path9, splitChar, options);
|
|
75
|
-
let len = segs.length;
|
|
76
|
-
let idx = 0;
|
|
77
|
-
do {
|
|
78
|
-
let prop = segs[idx];
|
|
79
|
-
if (typeof prop === "number") {
|
|
80
|
-
prop = String(prop);
|
|
81
|
-
}
|
|
82
|
-
while (prop && prop.slice(-1) === "\\") {
|
|
83
|
-
prop = join([prop.slice(0, -1), segs[++idx] || ""], joinChar, options);
|
|
84
|
-
}
|
|
85
|
-
if (prop in target) {
|
|
86
|
-
if (!isValid(prop, target, options)) {
|
|
87
|
-
return options.default;
|
|
88
|
-
}
|
|
89
|
-
target = target[prop];
|
|
90
|
-
} else {
|
|
91
|
-
let hasProp = false;
|
|
92
|
-
let n = idx + 1;
|
|
93
|
-
while (n < len) {
|
|
94
|
-
prop = join([prop, segs[n++]], joinChar, options);
|
|
95
|
-
if (hasProp = prop in target) {
|
|
96
|
-
if (!isValid(prop, target, options)) {
|
|
97
|
-
return options.default;
|
|
98
|
-
}
|
|
99
|
-
target = target[prop];
|
|
100
|
-
idx = n - 1;
|
|
101
|
-
break;
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
if (!hasProp) {
|
|
105
|
-
return options.default;
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
} while (++idx < len && isValidObject(target));
|
|
109
|
-
if (idx === len) {
|
|
110
|
-
return target;
|
|
111
|
-
}
|
|
112
|
-
return options.default;
|
|
113
|
-
};
|
|
114
|
-
function join(segs, joinChar, options) {
|
|
115
|
-
if (typeof options.join === "function") {
|
|
116
|
-
return options.join(segs);
|
|
117
|
-
}
|
|
118
|
-
return segs[0] + joinChar + segs[1];
|
|
119
|
-
}
|
|
120
|
-
function split(path9, splitChar, options) {
|
|
121
|
-
if (typeof options.split === "function") {
|
|
122
|
-
return options.split(path9);
|
|
123
|
-
}
|
|
124
|
-
return path9.split(splitChar);
|
|
125
|
-
}
|
|
126
|
-
function isValid(key, target, options) {
|
|
127
|
-
if (typeof options.isValid === "function") {
|
|
128
|
-
return options.isValid(key, target);
|
|
129
|
-
}
|
|
130
|
-
return true;
|
|
131
|
-
}
|
|
132
|
-
function isValidObject(val) {
|
|
133
|
-
return isObject(val) || Array.isArray(val) || typeof val === "function";
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
});
|
|
137
|
-
|
|
138
37
|
// ../../node_modules/.pnpm/is-primitive@3.0.1/node_modules/is-primitive/index.js
|
|
139
38
|
var require_is_primitive = __commonJS({
|
|
140
39
|
"../../node_modules/.pnpm/is-primitive@3.0.1/node_modules/is-primitive/index.js"(exports, module) {
|
|
@@ -149,6 +48,17 @@ var require_is_primitive = __commonJS({
|
|
|
149
48
|
}
|
|
150
49
|
});
|
|
151
50
|
|
|
51
|
+
// ../../node_modules/.pnpm/isobject@3.0.1/node_modules/isobject/index.js
|
|
52
|
+
var require_isobject = __commonJS({
|
|
53
|
+
"../../node_modules/.pnpm/isobject@3.0.1/node_modules/isobject/index.js"(exports, module) {
|
|
54
|
+
"use strict";
|
|
55
|
+
init_esm_shims();
|
|
56
|
+
module.exports = function isObject(val) {
|
|
57
|
+
return val != null && typeof val === "object" && Array.isArray(val) === false;
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
|
|
152
62
|
// ../../node_modules/.pnpm/is-plain-object@2.0.4/node_modules/is-plain-object/index.js
|
|
153
63
|
var require_is_plain_object = __commonJS({
|
|
154
64
|
"../../node_modules/.pnpm/is-plain-object@2.0.4/node_modules/is-plain-object/index.js"(exports, module) {
|
|
@@ -303,291 +213,101 @@ var require_set_value = __commonJS({
|
|
|
303
213
|
}
|
|
304
214
|
});
|
|
305
215
|
|
|
306
|
-
//
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
var
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
this.client = simpleGit(options);
|
|
316
|
-
}
|
|
317
|
-
listConfig() {
|
|
318
|
-
return this.client.listConfig();
|
|
319
|
-
}
|
|
320
|
-
async init() {
|
|
321
|
-
const listConfig = await this.listConfig();
|
|
322
|
-
this.#config = listConfig.all;
|
|
323
|
-
return this.#config;
|
|
324
|
-
}
|
|
325
|
-
async getConfig() {
|
|
326
|
-
if (this.#config) {
|
|
327
|
-
return this.#config;
|
|
328
|
-
} else {
|
|
329
|
-
return await this.init();
|
|
330
|
-
}
|
|
331
|
-
}
|
|
332
|
-
async getGitUrl() {
|
|
333
|
-
const config = await this.getConfig();
|
|
334
|
-
const x = (0, import_get_value.default)(config, "remote.origin.url");
|
|
335
|
-
if (x) {
|
|
336
|
-
return gitUrlParse(x);
|
|
337
|
-
}
|
|
338
|
-
}
|
|
339
|
-
async getRepoName() {
|
|
340
|
-
const url = await this.getGitUrl();
|
|
341
|
-
if (url) {
|
|
342
|
-
return `${url.owner}/${url.name}`;
|
|
343
|
-
}
|
|
344
|
-
}
|
|
345
|
-
async getUser() {
|
|
346
|
-
const config = await this.getConfig();
|
|
347
|
-
const name2 = (0, import_get_value.default)(config, "user.name");
|
|
348
|
-
const email = (0, import_get_value.default)(config, "user.email");
|
|
349
|
-
return {
|
|
350
|
-
name: name2,
|
|
351
|
-
email
|
|
352
|
-
};
|
|
353
|
-
}
|
|
354
|
-
};
|
|
355
|
-
|
|
356
|
-
// src/utils/md5.ts
|
|
357
|
-
init_esm_shims();
|
|
358
|
-
import crypto from "node:crypto";
|
|
359
|
-
function getFileHash(data) {
|
|
360
|
-
const hashSum = crypto.createHash("md5");
|
|
361
|
-
hashSum.update(data);
|
|
362
|
-
return hashSum.digest("hex");
|
|
363
|
-
}
|
|
364
|
-
function isFileChanged(src, dest) {
|
|
365
|
-
try {
|
|
366
|
-
const currentHash = getFileHash(src);
|
|
367
|
-
const previousHash = getFileHash(dest);
|
|
368
|
-
return currentHash !== previousHash;
|
|
369
|
-
} catch (err) {
|
|
370
|
-
console.error("Error calculating file hash:", err);
|
|
371
|
-
return false;
|
|
372
|
-
}
|
|
373
|
-
}
|
|
374
|
-
|
|
375
|
-
// src/utils/regexp.ts
|
|
376
|
-
init_esm_shims();
|
|
377
|
-
function escapeStringRegexp(str) {
|
|
378
|
-
return str.replace(/[|\\{}()[\]^$+*?.]/g, "\\$&").replace(/-/g, "\\x2d");
|
|
379
|
-
}
|
|
380
|
-
function isMatch(str, arr) {
|
|
381
|
-
for (const reg of arr) {
|
|
382
|
-
if (reg.test(str)) {
|
|
383
|
-
return true;
|
|
384
|
-
}
|
|
385
|
-
}
|
|
386
|
-
return false;
|
|
387
|
-
}
|
|
388
|
-
|
|
389
|
-
// src/lib.ts
|
|
390
|
-
init_esm_shims();
|
|
391
|
-
var import_get_value2 = __toESM(require_get_value(), 1);
|
|
392
|
-
var import_set_value = __toESM(require_set_value(), 1);
|
|
393
|
-
import process from "node:process";
|
|
394
|
-
import { fileURLToPath } from "node:url";
|
|
395
|
-
import checkbox from "@inquirer/checkbox";
|
|
396
|
-
import confirm from "@inquirer/confirm";
|
|
397
|
-
import fs from "fs-extra";
|
|
398
|
-
import klaw from "klaw";
|
|
399
|
-
import PQueue from "p-queue";
|
|
400
|
-
import path from "pathe";
|
|
401
|
-
import pc from "picocolors";
|
|
402
|
-
|
|
403
|
-
// src/constants.ts
|
|
404
|
-
init_esm_shims();
|
|
405
|
-
|
|
406
|
-
// package.json
|
|
407
|
-
var name = "@icebreakers/monorepo";
|
|
408
|
-
var version = "0.6.10";
|
|
409
|
-
|
|
410
|
-
// src/logger.ts
|
|
411
|
-
init_esm_shims();
|
|
412
|
-
import { createConsola } from "consola";
|
|
413
|
-
var logger = createConsola();
|
|
414
|
-
|
|
415
|
-
// src/scripts.ts
|
|
416
|
-
init_esm_shims();
|
|
417
|
-
var scripts = {
|
|
418
|
-
"script:init": "monorepo init",
|
|
419
|
-
"script:sync": "monorepo sync",
|
|
420
|
-
"script:clean": "monorepo clean",
|
|
421
|
-
"script:mirror": "monorepo mirror"
|
|
422
|
-
};
|
|
423
|
-
var scriptsEntries = Object.entries(scripts);
|
|
424
|
-
|
|
425
|
-
// src/targets.ts
|
|
426
|
-
init_esm_shims();
|
|
427
|
-
function getAssetTargets(raw) {
|
|
428
|
-
const list = [
|
|
429
|
-
".changeset",
|
|
430
|
-
".husky",
|
|
431
|
-
".vscode",
|
|
432
|
-
".editorconfig",
|
|
433
|
-
".gitattributes",
|
|
434
|
-
".gitignore",
|
|
435
|
-
".npmrc",
|
|
436
|
-
"commitlint.config.ts",
|
|
437
|
-
"eslint.config.js",
|
|
438
|
-
"lint-staged.config.js",
|
|
439
|
-
"stylelint.config.js",
|
|
440
|
-
"package.json",
|
|
441
|
-
// pnpm
|
|
442
|
-
"pnpm-workspace.yaml",
|
|
443
|
-
// base tsconfig
|
|
444
|
-
"tsconfig.json",
|
|
445
|
-
// turbo
|
|
446
|
-
"turbo.json",
|
|
447
|
-
// vitest
|
|
448
|
-
"vitest.workspace.ts",
|
|
449
|
-
// #region docker
|
|
450
|
-
"Dockerfile",
|
|
451
|
-
".dockerignore"
|
|
452
|
-
// #endregion
|
|
453
|
-
];
|
|
454
|
-
if (!raw) {
|
|
455
|
-
list.push(".github", "LICENSE", "renovate.json", "SECURITY.md", "CODE_OF_CONDUCT.md", "CONTRIBUTING.md", "netlify.toml");
|
|
456
|
-
}
|
|
457
|
-
return list;
|
|
458
|
-
}
|
|
459
|
-
|
|
460
|
-
// src/lib.ts
|
|
461
|
-
var queue = new PQueue({ concurrency: 1 });
|
|
462
|
-
var __filename2 = fileURLToPath(import.meta.url);
|
|
463
|
-
var __dirname2 = path.dirname(__filename2);
|
|
464
|
-
var assetsDir = path.join(__dirname2, "../assets");
|
|
465
|
-
var templatesDir = path.join(__dirname2, "../templates");
|
|
466
|
-
var cwd = process.cwd();
|
|
467
|
-
function isWorkspace(version2) {
|
|
468
|
-
if (typeof version2 === "string") {
|
|
469
|
-
return version2.startsWith("workspace:");
|
|
470
|
-
}
|
|
471
|
-
return false;
|
|
472
|
-
}
|
|
473
|
-
function setPkgJson(sourcePkgJson, targetPkgJson) {
|
|
474
|
-
const packageManager = (0, import_get_value2.default)(sourcePkgJson, "packageManager", { default: "" });
|
|
475
|
-
const deps = (0, import_get_value2.default)(sourcePkgJson, "dependencies", { default: {} });
|
|
476
|
-
const devDeps = (0, import_get_value2.default)(sourcePkgJson, "devDependencies", { default: {} });
|
|
477
|
-
const targetDeps = (0, import_get_value2.default)(targetPkgJson, "dependencies", { default: {} });
|
|
478
|
-
const targetDevDeps = (0, import_get_value2.default)(targetPkgJson, "devDependencies", { default: {} });
|
|
479
|
-
(0, import_set_value.default)(targetPkgJson, "packageManager", packageManager);
|
|
480
|
-
Object.entries(deps).forEach((x) => {
|
|
481
|
-
if (!isWorkspace(targetDeps[x[0]])) {
|
|
482
|
-
(0, import_set_value.default)(targetPkgJson, `dependencies.${x[0].replaceAll(".", "\\.")}`, x[1], { preservePaths: false });
|
|
483
|
-
}
|
|
484
|
-
});
|
|
485
|
-
Object.entries(devDeps).forEach((x) => {
|
|
486
|
-
if (x[0] === name) {
|
|
487
|
-
(0, import_set_value.default)(targetPkgJson, `devDependencies.${x[0].replaceAll(".", "\\.")}`, `^${version}`, { preservePaths: false });
|
|
488
|
-
} else {
|
|
489
|
-
if (!isWorkspace(targetDevDeps[x[0]])) {
|
|
490
|
-
(0, import_set_value.default)(targetPkgJson, `devDependencies.${x[0].replaceAll(".", "\\.")}`, x[1], { preservePaths: false });
|
|
216
|
+
// ../../node_modules/.pnpm/get-value@3.0.1/node_modules/get-value/index.js
|
|
217
|
+
var require_get_value = __commonJS({
|
|
218
|
+
"../../node_modules/.pnpm/get-value@3.0.1/node_modules/get-value/index.js"(exports, module) {
|
|
219
|
+
"use strict";
|
|
220
|
+
init_esm_shims();
|
|
221
|
+
var isObject = require_isobject();
|
|
222
|
+
module.exports = function(target, path9, options) {
|
|
223
|
+
if (!isObject(options)) {
|
|
224
|
+
options = { default: options };
|
|
491
225
|
}
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
}
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
checked: true
|
|
516
|
-
};
|
|
517
|
-
})
|
|
518
|
-
});
|
|
519
|
-
}
|
|
520
|
-
const regexpArr = targets.map((x) => {
|
|
521
|
-
return new RegExp(`^${escapeStringRegexp(x)}`);
|
|
522
|
-
});
|
|
523
|
-
for await (const file of klaw(assetsDir, {
|
|
524
|
-
filter(p) {
|
|
525
|
-
const str = path.relative(assetsDir, p);
|
|
526
|
-
return isMatch(str, regexpArr);
|
|
527
|
-
}
|
|
528
|
-
})) {
|
|
529
|
-
await queue.add(async () => {
|
|
530
|
-
if (file.stats.isFile()) {
|
|
531
|
-
const relPath = path.relative(assetsDir, file.path);
|
|
532
|
-
const targetPath = path.resolve(absOutDir, relPath);
|
|
533
|
-
const targetIsExisted = await fs.exists(targetPath);
|
|
534
|
-
async function overwriteOrCopy(target) {
|
|
535
|
-
let isOverwrite = true;
|
|
536
|
-
if (targetIsExisted) {
|
|
537
|
-
const src = await fs.readFile(file.path);
|
|
538
|
-
const dest = target ?? await fs.readFile(targetPath);
|
|
539
|
-
if (await isFileChanged(src, dest)) {
|
|
540
|
-
isOverwrite = await confirmOverwrite(relPath);
|
|
541
|
-
}
|
|
542
|
-
}
|
|
543
|
-
return isOverwrite;
|
|
226
|
+
if (!isValidObject(target)) {
|
|
227
|
+
return typeof options.default !== "undefined" ? options.default : target;
|
|
228
|
+
}
|
|
229
|
+
if (typeof path9 === "number") {
|
|
230
|
+
path9 = String(path9);
|
|
231
|
+
}
|
|
232
|
+
const isArray = Array.isArray(path9);
|
|
233
|
+
const isString = typeof path9 === "string";
|
|
234
|
+
const splitChar = options.separator || ".";
|
|
235
|
+
const joinChar = options.joinChar || (typeof splitChar === "string" ? splitChar : ".");
|
|
236
|
+
if (!isString && !isArray) {
|
|
237
|
+
return target;
|
|
238
|
+
}
|
|
239
|
+
if (isString && path9 in target) {
|
|
240
|
+
return isValid(path9, target, options) ? target[path9] : options.default;
|
|
241
|
+
}
|
|
242
|
+
let segs = isArray ? path9 : split(path9, splitChar, options);
|
|
243
|
+
let len = segs.length;
|
|
244
|
+
let idx = 0;
|
|
245
|
+
do {
|
|
246
|
+
let prop = segs[idx];
|
|
247
|
+
if (typeof prop === "number") {
|
|
248
|
+
prop = String(prop);
|
|
544
249
|
}
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
const data = JSON.stringify(targetPkgJson, void 0, 2);
|
|
552
|
-
await fs.writeFile(targetPath, `${data}
|
|
553
|
-
`, "utf8");
|
|
554
|
-
logger.success(targetPath);
|
|
555
|
-
}
|
|
556
|
-
} else if (relPath === ".changeset/config.json" && repoName) {
|
|
557
|
-
const changesetJson = await fs.readJson(file.path);
|
|
558
|
-
(0, import_set_value.default)(changesetJson, "changelog.1.repo", repoName);
|
|
559
|
-
const data = JSON.stringify(changesetJson, void 0, 2);
|
|
560
|
-
if (await overwriteOrCopy(data)) {
|
|
561
|
-
await fs.ensureDir(path.dirname(targetPath));
|
|
562
|
-
await fs.writeFile(targetPath, `${data}
|
|
563
|
-
`, "utf8");
|
|
564
|
-
logger.success(targetPath);
|
|
250
|
+
while (prop && prop.slice(-1) === "\\") {
|
|
251
|
+
prop = join([prop.slice(0, -1), segs[++idx] || ""], joinChar, options);
|
|
252
|
+
}
|
|
253
|
+
if (prop in target) {
|
|
254
|
+
if (!isValid(prop, target, options)) {
|
|
255
|
+
return options.default;
|
|
565
256
|
}
|
|
257
|
+
target = target[prop];
|
|
566
258
|
} else {
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
)
|
|
572
|
-
|
|
259
|
+
let hasProp = false;
|
|
260
|
+
let n = idx + 1;
|
|
261
|
+
while (n < len) {
|
|
262
|
+
prop = join([prop, segs[n++]], joinChar, options);
|
|
263
|
+
if (hasProp = prop in target) {
|
|
264
|
+
if (!isValid(prop, target, options)) {
|
|
265
|
+
return options.default;
|
|
266
|
+
}
|
|
267
|
+
target = target[prop];
|
|
268
|
+
idx = n - 1;
|
|
269
|
+
break;
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
if (!hasProp) {
|
|
273
|
+
return options.default;
|
|
573
274
|
}
|
|
574
275
|
}
|
|
276
|
+
} while (++idx < len && isValidObject(target));
|
|
277
|
+
if (idx === len) {
|
|
278
|
+
return target;
|
|
575
279
|
}
|
|
576
|
-
|
|
280
|
+
return options.default;
|
|
281
|
+
};
|
|
282
|
+
function join(segs, joinChar, options) {
|
|
283
|
+
if (typeof options.join === "function") {
|
|
284
|
+
return options.join(segs);
|
|
285
|
+
}
|
|
286
|
+
return segs[0] + joinChar + segs[1];
|
|
287
|
+
}
|
|
288
|
+
function split(path9, splitChar, options) {
|
|
289
|
+
if (typeof options.split === "function") {
|
|
290
|
+
return options.split(path9);
|
|
291
|
+
}
|
|
292
|
+
return path9.split(splitChar);
|
|
293
|
+
}
|
|
294
|
+
function isValid(key, target, options) {
|
|
295
|
+
if (typeof options.isValid === "function") {
|
|
296
|
+
return options.isValid(key, target);
|
|
297
|
+
}
|
|
298
|
+
return true;
|
|
299
|
+
}
|
|
300
|
+
function isValidObject(val) {
|
|
301
|
+
return isObject(val) || Array.isArray(val) || typeof val === "function";
|
|
302
|
+
}
|
|
577
303
|
}
|
|
578
|
-
}
|
|
579
|
-
async function createNewProject(name2) {
|
|
580
|
-
const defaultTemplate = "bar";
|
|
581
|
-
const targetTemplate = name2 ?? defaultTemplate;
|
|
582
|
-
await fs.copy(path.join(templatesDir, defaultTemplate), path.join(cwd, targetTemplate));
|
|
583
|
-
logger.success(`${targetTemplate} \u9879\u76EE\u521B\u5EFA\u6210\u529F\uFF01`);
|
|
584
|
-
}
|
|
304
|
+
});
|
|
585
305
|
|
|
586
306
|
// src/monorepo/binaryMirror.ts
|
|
587
307
|
init_esm_shims();
|
|
588
308
|
import { parse, stringify } from "comment-json";
|
|
589
|
-
import
|
|
590
|
-
import
|
|
309
|
+
import fs from "fs-extra";
|
|
310
|
+
import path from "pathe";
|
|
591
311
|
|
|
592
312
|
// src/monorepo/mirror/sources.ts
|
|
593
313
|
init_esm_shims();
|
|
@@ -622,32 +342,32 @@ var chinaMirrorsEnvs = {
|
|
|
622
342
|
|
|
623
343
|
// src/monorepo/mirror/utils.ts
|
|
624
344
|
init_esm_shims();
|
|
625
|
-
var
|
|
345
|
+
var import_set_value = __toESM(require_set_value(), 1);
|
|
626
346
|
function setMirror(obj) {
|
|
627
347
|
const platforms = ["linux", "windows", "osx"];
|
|
628
348
|
const prefix = "terminal.integrated.env";
|
|
629
349
|
if (typeof obj === "object" && obj) {
|
|
630
350
|
for (const platform of platforms) {
|
|
631
|
-
(0,
|
|
351
|
+
(0, import_set_value.default)(obj, [prefix, platform].join(".").replaceAll(".", "\\."), chinaMirrorsEnvs);
|
|
632
352
|
}
|
|
633
353
|
}
|
|
634
354
|
}
|
|
635
355
|
|
|
636
356
|
// src/monorepo/binaryMirror.ts
|
|
637
|
-
async function setVscodeBinaryMirror(
|
|
638
|
-
const targetJsonPath =
|
|
639
|
-
await
|
|
640
|
-
const json = parse(await
|
|
357
|
+
async function setVscodeBinaryMirror(cwd) {
|
|
358
|
+
const targetJsonPath = path.resolve(cwd, ".vscode/settings.json");
|
|
359
|
+
await fs.ensureFile(targetJsonPath);
|
|
360
|
+
const json = parse(await fs.readFile(targetJsonPath, "utf8"), void 0, false);
|
|
641
361
|
json && typeof json === "object" && setMirror(json);
|
|
642
|
-
await
|
|
362
|
+
await fs.writeFile(targetJsonPath, `${stringify(json, void 0, 2)}
|
|
643
363
|
`, "utf8");
|
|
644
364
|
}
|
|
645
365
|
|
|
646
366
|
// src/monorepo/clean.ts
|
|
647
367
|
init_esm_shims();
|
|
648
|
-
var
|
|
649
|
-
import
|
|
650
|
-
import
|
|
368
|
+
var import_set_value2 = __toESM(require_set_value(), 1);
|
|
369
|
+
import fs2 from "fs-extra";
|
|
370
|
+
import path2 from "pathe";
|
|
651
371
|
var dirs = [
|
|
652
372
|
"packages/monorepo",
|
|
653
373
|
"packages/foo",
|
|
@@ -655,20 +375,70 @@ var dirs = [
|
|
|
655
375
|
// 'apps/website',
|
|
656
376
|
"apps"
|
|
657
377
|
];
|
|
658
|
-
async function cleanProjects(
|
|
378
|
+
async function cleanProjects(cwd) {
|
|
659
379
|
for (const dir of dirs.map((x) => {
|
|
660
|
-
return
|
|
380
|
+
return path2.resolve(cwd, x);
|
|
661
381
|
})) {
|
|
662
|
-
await
|
|
382
|
+
await fs2.remove(dir);
|
|
663
383
|
}
|
|
664
384
|
const name2 = "package.json";
|
|
665
|
-
const pkgJson = await
|
|
666
|
-
(0,
|
|
667
|
-
await
|
|
385
|
+
const pkgJson = await fs2.readJson(name2);
|
|
386
|
+
(0, import_set_value2.default)(pkgJson, "devDependencies.@icebreakers/monorepo", "latest", { preservePaths: false });
|
|
387
|
+
await fs2.outputJson(name2, pkgJson, {
|
|
668
388
|
spaces: 2
|
|
669
389
|
});
|
|
670
390
|
}
|
|
671
391
|
|
|
392
|
+
// src/monorepo/git.ts
|
|
393
|
+
init_esm_shims();
|
|
394
|
+
var import_get_value = __toESM(require_get_value(), 1);
|
|
395
|
+
import gitUrlParse from "git-url-parse";
|
|
396
|
+
import { simpleGit } from "simple-git";
|
|
397
|
+
var GitClient = class {
|
|
398
|
+
client;
|
|
399
|
+
#config;
|
|
400
|
+
constructor(options = {}) {
|
|
401
|
+
this.client = simpleGit(options);
|
|
402
|
+
}
|
|
403
|
+
listConfig() {
|
|
404
|
+
return this.client.listConfig();
|
|
405
|
+
}
|
|
406
|
+
async init() {
|
|
407
|
+
const listConfig = await this.listConfig();
|
|
408
|
+
this.#config = listConfig.all;
|
|
409
|
+
return this.#config;
|
|
410
|
+
}
|
|
411
|
+
async getConfig() {
|
|
412
|
+
if (this.#config) {
|
|
413
|
+
return this.#config;
|
|
414
|
+
} else {
|
|
415
|
+
return await this.init();
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
async getGitUrl() {
|
|
419
|
+
const config = await this.getConfig();
|
|
420
|
+
const x = (0, import_get_value.default)(config, "remote.origin.url");
|
|
421
|
+
if (x) {
|
|
422
|
+
return gitUrlParse(x);
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
async getRepoName() {
|
|
426
|
+
const url = await this.getGitUrl();
|
|
427
|
+
if (url) {
|
|
428
|
+
return `${url.owner}/${url.name}`;
|
|
429
|
+
}
|
|
430
|
+
}
|
|
431
|
+
async getUser() {
|
|
432
|
+
const config = await this.getConfig();
|
|
433
|
+
const name2 = (0, import_get_value.default)(config, "user.name");
|
|
434
|
+
const email = (0, import_get_value.default)(config, "user.email");
|
|
435
|
+
return {
|
|
436
|
+
name: name2,
|
|
437
|
+
email
|
|
438
|
+
};
|
|
439
|
+
}
|
|
440
|
+
};
|
|
441
|
+
|
|
672
442
|
// src/monorepo/workspace.ts
|
|
673
443
|
init_esm_shims();
|
|
674
444
|
import { findWorkspacePackages } from "@pnpm/workspace.find-packages";
|
|
@@ -743,21 +513,21 @@ var defuArrayFn = createDefu((object, key, currentValue) => {
|
|
|
743
513
|
});
|
|
744
514
|
|
|
745
515
|
// src/monorepo/workspace.ts
|
|
746
|
-
import
|
|
747
|
-
async function getWorkspacePackages(
|
|
748
|
-
const posixCwd =
|
|
516
|
+
import path3 from "pathe";
|
|
517
|
+
async function getWorkspacePackages(cwd, options) {
|
|
518
|
+
const posixCwd = path3.normalize(cwd);
|
|
749
519
|
const { ignoreRootPackage, ignorePrivatePackage } = defu(options, {
|
|
750
520
|
ignoreRootPackage: true,
|
|
751
521
|
ignorePrivatePackage: true
|
|
752
522
|
});
|
|
753
|
-
const packages = await findWorkspacePackages(
|
|
523
|
+
const packages = await findWorkspacePackages(cwd);
|
|
754
524
|
let pkgs = packages.filter((x) => {
|
|
755
525
|
if (ignorePrivatePackage && x.manifest.private) {
|
|
756
526
|
return false;
|
|
757
527
|
}
|
|
758
528
|
return true;
|
|
759
529
|
}).map((project) => {
|
|
760
|
-
const pkgJsonPath =
|
|
530
|
+
const pkgJsonPath = path3.resolve(project.rootDir, "package.json");
|
|
761
531
|
return {
|
|
762
532
|
...project,
|
|
763
533
|
pkgJsonPath
|
|
@@ -765,7 +535,7 @@ async function getWorkspacePackages(cwd2, options) {
|
|
|
765
535
|
});
|
|
766
536
|
if (ignoreRootPackage) {
|
|
767
537
|
pkgs = pkgs.filter((x) => {
|
|
768
|
-
return
|
|
538
|
+
return path3.normalize(
|
|
769
539
|
x.rootDir
|
|
770
540
|
) !== posixCwd;
|
|
771
541
|
});
|
|
@@ -778,16 +548,16 @@ init_esm_shims();
|
|
|
778
548
|
|
|
779
549
|
// src/monorepo/context.ts
|
|
780
550
|
init_esm_shims();
|
|
781
|
-
import
|
|
551
|
+
import path4 from "pathe";
|
|
782
552
|
import "@pnpm/types";
|
|
783
|
-
async function createContext(
|
|
553
|
+
async function createContext(cwd) {
|
|
784
554
|
const git = new GitClient();
|
|
785
|
-
const workspaceFilepath =
|
|
786
|
-
const projects = await getWorkspacePackages(
|
|
555
|
+
const workspaceFilepath = path4.resolve(cwd, "pnpm-workspace.yaml");
|
|
556
|
+
const projects = await getWorkspacePackages(cwd);
|
|
787
557
|
const gitUrl = await git.getGitUrl();
|
|
788
558
|
const gitUser = await git.getUser();
|
|
789
559
|
return {
|
|
790
|
-
cwd
|
|
560
|
+
cwd,
|
|
791
561
|
git,
|
|
792
562
|
gitUrl,
|
|
793
563
|
gitUser,
|
|
@@ -798,16 +568,16 @@ async function createContext(cwd2) {
|
|
|
798
568
|
|
|
799
569
|
// src/monorepo/setPkgJson.ts
|
|
800
570
|
init_esm_shims();
|
|
801
|
-
var
|
|
802
|
-
import
|
|
803
|
-
import
|
|
571
|
+
var import_set_value3 = __toESM(require_set_value(), 1);
|
|
572
|
+
import fs3 from "fs-extra";
|
|
573
|
+
import path5 from "pathe";
|
|
804
574
|
async function setPkgJson_default(ctx) {
|
|
805
|
-
const { gitUrl, gitUser, projects, cwd
|
|
806
|
-
if (gitUrl && await
|
|
575
|
+
const { gitUrl, gitUser, projects, cwd, workspaceFilepath } = ctx;
|
|
576
|
+
if (gitUrl && await fs3.exists(workspaceFilepath)) {
|
|
807
577
|
for (const project of projects) {
|
|
808
578
|
const pkgJson = project.manifest;
|
|
809
|
-
const directory =
|
|
810
|
-
(0,
|
|
579
|
+
const directory = path5.relative(cwd, project.rootDir);
|
|
580
|
+
(0, import_set_value3.default)(pkgJson, "bugs.url", `https://github.com/${gitUrl.full_name}/issues`);
|
|
811
581
|
const repository = {
|
|
812
582
|
type: "git",
|
|
813
583
|
url: `git+https://github.com/${gitUrl.full_name}.git`
|
|
@@ -815,11 +585,11 @@ async function setPkgJson_default(ctx) {
|
|
|
815
585
|
if (directory) {
|
|
816
586
|
repository.directory = directory;
|
|
817
587
|
}
|
|
818
|
-
(0,
|
|
588
|
+
(0, import_set_value3.default)(pkgJson, "repository", repository);
|
|
819
589
|
if (gitUser) {
|
|
820
|
-
(0,
|
|
590
|
+
(0, import_set_value3.default)(pkgJson, "author", `${gitUser.name} <${gitUser.email}>`);
|
|
821
591
|
}
|
|
822
|
-
await
|
|
592
|
+
await fs3.writeJSON(project.pkgJsonPath, pkgJson, {
|
|
823
593
|
spaces: 2
|
|
824
594
|
});
|
|
825
595
|
}
|
|
@@ -828,10 +598,10 @@ async function setPkgJson_default(ctx) {
|
|
|
828
598
|
|
|
829
599
|
// src/monorepo/setReadme.ts
|
|
830
600
|
init_esm_shims();
|
|
831
|
-
import
|
|
832
|
-
import
|
|
601
|
+
import fs4 from "fs-extra";
|
|
602
|
+
import path6 from "pathe";
|
|
833
603
|
async function getRows(ctx) {
|
|
834
|
-
const { projects, git, cwd
|
|
604
|
+
const { projects, git, cwd } = ctx;
|
|
835
605
|
const gitUrl = await git.getGitUrl();
|
|
836
606
|
const gitUser = await git.getUser();
|
|
837
607
|
const rows = [];
|
|
@@ -841,7 +611,7 @@ async function getRows(ctx) {
|
|
|
841
611
|
}
|
|
842
612
|
rows.push("## Projects\n");
|
|
843
613
|
for (const project of projects) {
|
|
844
|
-
const p =
|
|
614
|
+
const p = path6.relative(cwd, project.rootDirRealPath);
|
|
845
615
|
p && rows.push(`- [${project.manifest.name}](${p}) ${project.manifest.description ? `- ${project.manifest.description}` : ""}`);
|
|
846
616
|
}
|
|
847
617
|
if (gitUrl) {
|
|
@@ -866,13 +636,13 @@ async function getRows(ctx) {
|
|
|
866
636
|
}
|
|
867
637
|
async function setReadme_default(ctx) {
|
|
868
638
|
const rows = await getRows(ctx);
|
|
869
|
-
await
|
|
639
|
+
await fs4.writeFile(path6.resolve(ctx.cwd, "README.md"), `${rows.join("\n")}
|
|
870
640
|
`);
|
|
871
641
|
}
|
|
872
642
|
|
|
873
643
|
// src/monorepo/init.ts
|
|
874
|
-
async function init(
|
|
875
|
-
const ctx = await createContext(
|
|
644
|
+
async function init(cwd) {
|
|
645
|
+
const ctx = await createContext(cwd);
|
|
876
646
|
await setPkgJson_default(ctx);
|
|
877
647
|
await setReadme_default(ctx);
|
|
878
648
|
}
|
|
@@ -881,20 +651,27 @@ async function init(cwd2) {
|
|
|
881
651
|
init_esm_shims();
|
|
882
652
|
import os from "node:os";
|
|
883
653
|
import { execa } from "execa";
|
|
884
|
-
import
|
|
885
|
-
import
|
|
886
|
-
import
|
|
887
|
-
|
|
888
|
-
|
|
654
|
+
import PQueue from "p-queue";
|
|
655
|
+
import path7 from "pathe";
|
|
656
|
+
import pc from "picocolors";
|
|
657
|
+
|
|
658
|
+
// src/logger.ts
|
|
659
|
+
init_esm_shims();
|
|
660
|
+
import { createConsola } from "consola";
|
|
661
|
+
var logger = createConsola();
|
|
662
|
+
|
|
663
|
+
// src/monorepo/sync.ts
|
|
664
|
+
async function syncNpmMirror(cwd) {
|
|
665
|
+
const packages = await getWorkspacePackages(cwd);
|
|
889
666
|
logger.info(`[\u5F53\u524D\u5DE5\u4F5C\u533ARepo]:
|
|
890
|
-
${packages.map((x) => `- ${
|
|
667
|
+
${packages.map((x) => `- ${pc.green(x.manifest.name)} : ${path7.relative(cwd, x.rootDir)}`).join("\n")}
|
|
891
668
|
`);
|
|
892
669
|
const set5 = new Set(packages.map((x) => x.manifest.name));
|
|
893
670
|
logger.info(`[\u5373\u5C06\u540C\u6B65\u7684\u5305]:
|
|
894
|
-
${Array.from(set5).map((x) => `- ${
|
|
671
|
+
${Array.from(set5).map((x) => `- ${pc.green(x)}`).join("\n")}
|
|
895
672
|
`);
|
|
896
673
|
const concurrency = Math.max(os.cpus().length, 1);
|
|
897
|
-
const queue2 = new
|
|
674
|
+
const queue2 = new PQueue({ concurrency });
|
|
898
675
|
for (const pkgName of set5) {
|
|
899
676
|
if (pkgName) {
|
|
900
677
|
await queue2.add(async () => {
|
|
@@ -909,48 +686,262 @@ ${Array.from(set5).map((x) => `- ${pc2.green(x)}`).join("\n")}
|
|
|
909
686
|
// src/monorepo/index.ts
|
|
910
687
|
init_esm_shims();
|
|
911
688
|
|
|
689
|
+
// src/utils/md5.ts
|
|
690
|
+
init_esm_shims();
|
|
691
|
+
import crypto from "node:crypto";
|
|
692
|
+
function getFileHash(data) {
|
|
693
|
+
const hashSum = crypto.createHash("md5");
|
|
694
|
+
hashSum.update(data);
|
|
695
|
+
return hashSum.digest("hex");
|
|
696
|
+
}
|
|
697
|
+
function isFileChanged(src, dest) {
|
|
698
|
+
try {
|
|
699
|
+
const currentHash = getFileHash(src);
|
|
700
|
+
const previousHash = getFileHash(dest);
|
|
701
|
+
return currentHash !== previousHash;
|
|
702
|
+
} catch (err) {
|
|
703
|
+
console.error("Error calculating file hash:", err);
|
|
704
|
+
return false;
|
|
705
|
+
}
|
|
706
|
+
}
|
|
707
|
+
|
|
708
|
+
// src/utils/regexp.ts
|
|
709
|
+
init_esm_shims();
|
|
710
|
+
function escapeStringRegexp(str) {
|
|
711
|
+
return str.replace(/[|\\{}()[\]^$+*?.]/g, "\\$&").replace(/-/g, "\\x2d");
|
|
712
|
+
}
|
|
713
|
+
function isMatch(str, arr) {
|
|
714
|
+
for (const reg of arr) {
|
|
715
|
+
if (reg.test(str)) {
|
|
716
|
+
return true;
|
|
717
|
+
}
|
|
718
|
+
}
|
|
719
|
+
return false;
|
|
720
|
+
}
|
|
721
|
+
|
|
722
|
+
// src/upgrade.ts
|
|
723
|
+
init_esm_shims();
|
|
724
|
+
import process from "node:process";
|
|
725
|
+
import { fileURLToPath } from "node:url";
|
|
726
|
+
import checkbox from "@inquirer/checkbox";
|
|
727
|
+
import confirm from "@inquirer/confirm";
|
|
728
|
+
var import_get_value2 = __toESM(require_get_value(), 1);
|
|
729
|
+
var import_set_value4 = __toESM(require_set_value(), 1);
|
|
730
|
+
import fs5 from "fs-extra";
|
|
731
|
+
import klaw from "klaw";
|
|
732
|
+
import PQueue2 from "p-queue";
|
|
733
|
+
import path8 from "pathe";
|
|
734
|
+
import pc2 from "picocolors";
|
|
735
|
+
|
|
736
|
+
// src/constants.ts
|
|
737
|
+
init_esm_shims();
|
|
738
|
+
|
|
739
|
+
// package.json
|
|
740
|
+
var name = "@icebreakers/monorepo";
|
|
741
|
+
var version = "0.6.11";
|
|
742
|
+
|
|
743
|
+
// src/scripts.ts
|
|
744
|
+
init_esm_shims();
|
|
745
|
+
var scripts = {
|
|
746
|
+
"script:init": "monorepo init",
|
|
747
|
+
"script:sync": "monorepo sync",
|
|
748
|
+
"script:clean": "monorepo clean",
|
|
749
|
+
"script:mirror": "monorepo mirror"
|
|
750
|
+
};
|
|
751
|
+
var scriptsEntries = Object.entries(scripts);
|
|
752
|
+
|
|
753
|
+
// src/targets.ts
|
|
754
|
+
init_esm_shims();
|
|
755
|
+
function getAssetTargets(raw) {
|
|
756
|
+
const list = [
|
|
757
|
+
".changeset",
|
|
758
|
+
".husky",
|
|
759
|
+
".vscode",
|
|
760
|
+
".editorconfig",
|
|
761
|
+
".gitattributes",
|
|
762
|
+
".gitignore",
|
|
763
|
+
".npmrc",
|
|
764
|
+
"commitlint.config.ts",
|
|
765
|
+
"eslint.config.js",
|
|
766
|
+
"lint-staged.config.js",
|
|
767
|
+
"stylelint.config.js",
|
|
768
|
+
"package.json",
|
|
769
|
+
// pnpm
|
|
770
|
+
"pnpm-workspace.yaml",
|
|
771
|
+
// base tsconfig
|
|
772
|
+
"tsconfig.json",
|
|
773
|
+
// turbo
|
|
774
|
+
"turbo.json",
|
|
775
|
+
// vitest
|
|
776
|
+
"vitest.workspace.ts",
|
|
777
|
+
// #region docker
|
|
778
|
+
"Dockerfile",
|
|
779
|
+
".dockerignore"
|
|
780
|
+
// #endregion
|
|
781
|
+
];
|
|
782
|
+
if (!raw) {
|
|
783
|
+
list.push(".github", "LICENSE", "renovate.json", "SECURITY.md", "CODE_OF_CONDUCT.md", "CONTRIBUTING.md", "netlify.toml");
|
|
784
|
+
}
|
|
785
|
+
return list;
|
|
786
|
+
}
|
|
787
|
+
|
|
788
|
+
// src/upgrade.ts
|
|
789
|
+
var queue = new PQueue2({ concurrency: 1 });
|
|
790
|
+
var __filename2 = fileURLToPath(import.meta.url);
|
|
791
|
+
var __dirname2 = path8.dirname(__filename2);
|
|
792
|
+
var assetsDir = path8.join(__dirname2, "../assets");
|
|
793
|
+
function isWorkspace(version2) {
|
|
794
|
+
if (typeof version2 === "string") {
|
|
795
|
+
return version2.startsWith("workspace:");
|
|
796
|
+
}
|
|
797
|
+
return false;
|
|
798
|
+
}
|
|
799
|
+
function setPkgJson(sourcePkgJson, targetPkgJson) {
|
|
800
|
+
const packageManager = (0, import_get_value2.default)(sourcePkgJson, "packageManager", { default: "" });
|
|
801
|
+
const deps = (0, import_get_value2.default)(sourcePkgJson, "dependencies", { default: {} });
|
|
802
|
+
const devDeps = (0, import_get_value2.default)(sourcePkgJson, "devDependencies", { default: {} });
|
|
803
|
+
const targetDeps = (0, import_get_value2.default)(targetPkgJson, "dependencies", { default: {} });
|
|
804
|
+
const targetDevDeps = (0, import_get_value2.default)(targetPkgJson, "devDependencies", { default: {} });
|
|
805
|
+
(0, import_set_value4.default)(targetPkgJson, "packageManager", packageManager);
|
|
806
|
+
Object.entries(deps).forEach((x) => {
|
|
807
|
+
if (!isWorkspace(targetDeps[x[0]])) {
|
|
808
|
+
(0, import_set_value4.default)(targetPkgJson, `dependencies.${x[0].replaceAll(".", "\\.")}`, x[1], { preservePaths: false });
|
|
809
|
+
}
|
|
810
|
+
});
|
|
811
|
+
Object.entries(devDeps).forEach((x) => {
|
|
812
|
+
if (x[0] === name) {
|
|
813
|
+
(0, import_set_value4.default)(targetPkgJson, `devDependencies.${x[0].replaceAll(".", "\\.")}`, `^${version}`, { preservePaths: false });
|
|
814
|
+
} else {
|
|
815
|
+
if (!isWorkspace(targetDevDeps[x[0]])) {
|
|
816
|
+
(0, import_set_value4.default)(targetPkgJson, `devDependencies.${x[0].replaceAll(".", "\\.")}`, x[1], { preservePaths: false });
|
|
817
|
+
}
|
|
818
|
+
}
|
|
819
|
+
});
|
|
820
|
+
for (const [k, v] of scriptsEntries) {
|
|
821
|
+
(0, import_set_value4.default)(targetPkgJson, `scripts.${k}`, v);
|
|
822
|
+
}
|
|
823
|
+
}
|
|
824
|
+
function confirmOverwrite(filename) {
|
|
825
|
+
return confirm({ message: `${pc2.greenBright(filename)} \u6587\u4EF6\u5185\u5BB9\u53D1\u751F\u6539\u53D8,\u662F\u5426\u8986\u76D6?`, default: false });
|
|
826
|
+
}
|
|
827
|
+
async function upgradeMonorepo(opts) {
|
|
828
|
+
const { outDir, raw, interactive, cwd } = defu(opts, {
|
|
829
|
+
cwd: process.cwd(),
|
|
830
|
+
outDir: ""
|
|
831
|
+
});
|
|
832
|
+
const absOutDir = path8.isAbsolute(outDir) ? outDir : path8.join(cwd, outDir);
|
|
833
|
+
const gitClient = new GitClient({
|
|
834
|
+
baseDir: cwd
|
|
835
|
+
});
|
|
836
|
+
const repoName = await gitClient.getRepoName();
|
|
837
|
+
let targets = getAssetTargets(raw);
|
|
838
|
+
if (interactive) {
|
|
839
|
+
targets = await checkbox({
|
|
840
|
+
message: "\u9009\u62E9\u4F60\u9700\u8981\u7684\u6587\u4EF6",
|
|
841
|
+
choices: targets.map((x) => {
|
|
842
|
+
return {
|
|
843
|
+
value: x,
|
|
844
|
+
checked: true
|
|
845
|
+
};
|
|
846
|
+
})
|
|
847
|
+
});
|
|
848
|
+
}
|
|
849
|
+
const regexpArr = targets.map((x) => {
|
|
850
|
+
return new RegExp(`^${escapeStringRegexp(x)}`);
|
|
851
|
+
});
|
|
852
|
+
for await (const file of klaw(assetsDir, {
|
|
853
|
+
filter(p) {
|
|
854
|
+
const str = path8.relative(assetsDir, p);
|
|
855
|
+
return isMatch(str, regexpArr);
|
|
856
|
+
}
|
|
857
|
+
})) {
|
|
858
|
+
await queue.add(async () => {
|
|
859
|
+
if (file.stats.isFile()) {
|
|
860
|
+
const relPath = path8.relative(assetsDir, file.path);
|
|
861
|
+
const targetPath = path8.resolve(absOutDir, relPath);
|
|
862
|
+
const targetIsExisted = await fs5.exists(targetPath);
|
|
863
|
+
async function overwriteOrCopy(target) {
|
|
864
|
+
let isOverwrite = true;
|
|
865
|
+
if (targetIsExisted) {
|
|
866
|
+
const src = await fs5.readFile(file.path);
|
|
867
|
+
const dest = target ?? await fs5.readFile(targetPath);
|
|
868
|
+
if (await isFileChanged(src, dest)) {
|
|
869
|
+
isOverwrite = await confirmOverwrite(relPath);
|
|
870
|
+
}
|
|
871
|
+
}
|
|
872
|
+
return isOverwrite;
|
|
873
|
+
}
|
|
874
|
+
if (relPath === "package.json") {
|
|
875
|
+
const sourcePath = file.path;
|
|
876
|
+
if (targetIsExisted) {
|
|
877
|
+
const sourcePkgJson = await fs5.readJson(sourcePath);
|
|
878
|
+
const targetPkgJson = await fs5.readJson(targetPath);
|
|
879
|
+
setPkgJson(sourcePkgJson, targetPkgJson);
|
|
880
|
+
const data = JSON.stringify(targetPkgJson, void 0, 2);
|
|
881
|
+
await fs5.writeFile(targetPath, `${data}
|
|
882
|
+
`, "utf8");
|
|
883
|
+
logger.success(targetPath);
|
|
884
|
+
}
|
|
885
|
+
} else if (relPath === ".changeset/config.json" && repoName) {
|
|
886
|
+
const changesetJson = await fs5.readJson(file.path);
|
|
887
|
+
(0, import_set_value4.default)(changesetJson, "changelog.1.repo", repoName);
|
|
888
|
+
const data = JSON.stringify(changesetJson, void 0, 2);
|
|
889
|
+
if (await overwriteOrCopy(data)) {
|
|
890
|
+
await fs5.ensureDir(path8.dirname(targetPath));
|
|
891
|
+
await fs5.writeFile(targetPath, `${data}
|
|
892
|
+
`, "utf8");
|
|
893
|
+
logger.success(targetPath);
|
|
894
|
+
}
|
|
895
|
+
} else {
|
|
896
|
+
if (await overwriteOrCopy()) {
|
|
897
|
+
await fs5.copy(
|
|
898
|
+
file.path,
|
|
899
|
+
targetPath
|
|
900
|
+
);
|
|
901
|
+
logger.success(targetPath);
|
|
902
|
+
}
|
|
903
|
+
}
|
|
904
|
+
}
|
|
905
|
+
});
|
|
906
|
+
}
|
|
907
|
+
}
|
|
908
|
+
|
|
912
909
|
export {
|
|
910
|
+
__toESM,
|
|
913
911
|
name,
|
|
914
912
|
version,
|
|
915
913
|
init_esm_shims,
|
|
914
|
+
defu,
|
|
915
|
+
require_set_value,
|
|
916
916
|
logger,
|
|
917
|
+
setVscodeBinaryMirror,
|
|
918
|
+
cleanProjects,
|
|
917
919
|
GitClient,
|
|
920
|
+
getWorkspacePackages,
|
|
921
|
+
init,
|
|
922
|
+
syncNpmMirror,
|
|
918
923
|
getFileHash,
|
|
919
924
|
isFileChanged,
|
|
920
925
|
escapeStringRegexp,
|
|
921
926
|
isMatch,
|
|
922
927
|
setPkgJson,
|
|
923
|
-
upgradeMonorepo
|
|
924
|
-
createNewProject,
|
|
925
|
-
setVscodeBinaryMirror,
|
|
926
|
-
cleanProjects,
|
|
927
|
-
getWorkspacePackages,
|
|
928
|
-
init,
|
|
929
|
-
syncNpmMirror
|
|
928
|
+
upgradeMonorepo
|
|
930
929
|
};
|
|
931
930
|
/*! Bundled license information:
|
|
932
931
|
|
|
933
|
-
|
|
934
|
-
(*!
|
|
935
|
-
* isobject <https://github.com/jonschlinkert/isobject>
|
|
936
|
-
*
|
|
937
|
-
* Copyright (c) 2014-2017, Jon Schlinkert.
|
|
938
|
-
* Released under the MIT License.
|
|
939
|
-
*)
|
|
940
|
-
|
|
941
|
-
get-value/index.js:
|
|
932
|
+
is-primitive/index.js:
|
|
942
933
|
(*!
|
|
943
|
-
*
|
|
934
|
+
* is-primitive <https://github.com/jonschlinkert/is-primitive>
|
|
944
935
|
*
|
|
945
|
-
* Copyright (c) 2014-
|
|
936
|
+
* Copyright (c) 2014-present, Jon Schlinkert.
|
|
946
937
|
* Released under the MIT License.
|
|
947
938
|
*)
|
|
948
939
|
|
|
949
|
-
|
|
940
|
+
isobject/index.js:
|
|
950
941
|
(*!
|
|
951
|
-
*
|
|
942
|
+
* isobject <https://github.com/jonschlinkert/isobject>
|
|
952
943
|
*
|
|
953
|
-
* Copyright (c) 2014-
|
|
944
|
+
* Copyright (c) 2014-2017, Jon Schlinkert.
|
|
954
945
|
* Released under the MIT License.
|
|
955
946
|
*)
|
|
956
947
|
|
|
@@ -969,4 +960,12 @@ set-value/index.js:
|
|
|
969
960
|
* Copyright (c) Jon Schlinkert (https://github.com/jonschlinkert).
|
|
970
961
|
* Released under the MIT License.
|
|
971
962
|
*)
|
|
963
|
+
|
|
964
|
+
get-value/index.js:
|
|
965
|
+
(*!
|
|
966
|
+
* get-value <https://github.com/jonschlinkert/get-value>
|
|
967
|
+
*
|
|
968
|
+
* Copyright (c) 2014-2018, Jon Schlinkert.
|
|
969
|
+
* Released under the MIT License.
|
|
970
|
+
*)
|
|
972
971
|
*/
|