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