@icebreakers/monorepo 0.3.12 → 0.4.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.
@@ -37,7 +37,7 @@
37
37
  "@commitlint/config-conventional": "^19.5.0",
38
38
  "@commitlint/prompt-cli": "^19.5.0",
39
39
  "@commitlint/types": "^19.5.0",
40
- "@icebreakers/eslint-config": "^0.4.5",
40
+ "@icebreakers/eslint-config": "^0.5.0",
41
41
  "@icebreakers/stylelint-config": "^0.0.3",
42
42
  "@pnpm/workspace.find-packages": "^4.0.10",
43
43
  "@types/fs-extra": "^11.0.4",
@@ -313,10 +313,12 @@ var import_set_value = __toESM(require_set_value(), 1);
313
313
  import process from "node:process";
314
314
  import { fileURLToPath } from "node:url";
315
315
  import checkbox from "@inquirer/checkbox";
316
+ import confirm from "@inquirer/confirm";
316
317
  import fs from "fs-extra";
317
318
  import klaw from "klaw";
318
319
  import PQueue from "p-queue";
319
320
  import path from "pathe";
321
+ import pc from "picocolors";
320
322
 
321
323
  // ../../scripts/monorepo/git.ts
322
324
  init_esm_shims();
@@ -373,6 +375,25 @@ init_esm_shims();
373
375
  import { createConsola } from "consola";
374
376
  var logger = createConsola();
375
377
 
378
+ // src/md5.ts
379
+ init_esm_shims();
380
+ import crypto from "node:crypto";
381
+ function getFileHash(data) {
382
+ const hashSum = crypto.createHash("md5");
383
+ hashSum.update(data);
384
+ return hashSum.digest("hex");
385
+ }
386
+ function isFileChanged(src, dest) {
387
+ try {
388
+ const currentHash = getFileHash(src);
389
+ const previousHash = getFileHash(dest);
390
+ return currentHash !== previousHash;
391
+ } catch (err) {
392
+ console.error("Error calculating file hash:", err);
393
+ return false;
394
+ }
395
+ }
396
+
376
397
  // src/targets.ts
377
398
  init_esm_shims();
378
399
  function getTargets(raw) {
@@ -450,6 +471,9 @@ function setPkgJson(sourcePkgJson, targetPkgJson) {
450
471
  (0, import_set_value.default)(targetPkgJson, `scripts.${k}`, v);
451
472
  }
452
473
  }
474
+ function confirmOverwrite(filename) {
475
+ return confirm({ message: `${pc.greenBright(filename)} \u6587\u4EF6\u5185\u5BB9\u53D1\u751F\u6539\u53D8,\u662F\u5426\u8986\u76D6?`, default: false });
476
+ }
453
477
  async function main(opts) {
454
478
  const { outDir = "", raw, interactive } = opts;
455
479
  const absOutDir = path.isAbsolute(outDir) ? outDir : path.join(cwd, outDir);
@@ -488,37 +512,47 @@ async function main(opts) {
488
512
  if (file.stats.isFile()) {
489
513
  const relPath = path.relative(assetsDir, file.path);
490
514
  const targetPath = path.resolve(absOutDir, relPath);
515
+ const targetIsExisted = await fs.exists(targetPath);
516
+ async function overwriteOrCopy(target) {
517
+ let isOverwrite = true;
518
+ if (targetIsExisted) {
519
+ const src = await fs.readFile(file.path);
520
+ const dest = target ?? await fs.readFile(targetPath);
521
+ if (await isFileChanged(src, dest)) {
522
+ isOverwrite = await confirmOverwrite(relPath);
523
+ }
524
+ }
525
+ return isOverwrite;
526
+ }
491
527
  if (relPath === "package.json") {
492
528
  const sourcePath = file.path;
493
- if (await fs.exists(targetPath) && await fs.exists(sourcePath)) {
529
+ if (targetIsExisted) {
494
530
  const sourcePkgJson = await fs.readJson(sourcePath);
495
531
  const targetPkgJson = await fs.readJson(targetPath);
496
532
  setPkgJson(sourcePkgJson, targetPkgJson);
497
- await fs.writeJson(targetPath, targetPkgJson, {
498
- spaces: 2
499
- });
500
- logger.success(targetPath);
533
+ const data = JSON.stringify(targetPkgJson, void 0, 2);
534
+ if (await overwriteOrCopy(data)) {
535
+ await fs.writeFile(targetPath, data, "utf8");
536
+ logger.success(targetPath);
537
+ }
501
538
  }
502
- } else if (relPath === ".changeset/config.json" && repoName && await fs.exists(file.path)) {
539
+ } else if (relPath === ".changeset/config.json" && repoName) {
503
540
  const changesetJson = await fs.readJson(file.path);
504
541
  (0, import_set_value.default)(changesetJson, "changelog.1.repo", repoName);
505
- await fs.ensureDir(path.dirname(targetPath));
506
- await fs.writeJson(targetPath, changesetJson, {
507
- spaces: 2
508
- });
509
- logger.success(targetPath);
510
- } else if (relPath === "Dockerfile" && !await fs.exists(targetPath)) {
511
- await fs.copy(
512
- file.path,
513
- targetPath
514
- );
515
- logger.success(targetPath);
542
+ const data = JSON.stringify(changesetJson, void 0, 2);
543
+ if (await overwriteOrCopy(data)) {
544
+ await fs.ensureDir(path.dirname(targetPath));
545
+ await fs.writeFile(targetPath, data, "utf8");
546
+ logger.success(targetPath);
547
+ }
516
548
  } else {
517
- await fs.copy(
518
- file.path,
519
- targetPath
520
- );
521
- logger.success(targetPath);
549
+ if (await overwriteOrCopy()) {
550
+ await fs.copy(
551
+ file.path,
552
+ targetPath
553
+ );
554
+ logger.success(targetPath);
555
+ }
522
556
  }
523
557
  }
524
558
  });
package/dist/cli.cjs CHANGED
@@ -316,18 +316,20 @@ var import_commander = require("commander");
316
316
 
317
317
  // package.json
318
318
  var name = "@icebreakers/monorepo";
319
- var version = "0.3.12";
319
+ var version = "0.4.1";
320
320
 
321
321
  // src/lib.ts
322
322
  init_cjs_shims();
323
323
  var import_node_process = __toESM(require("process"), 1);
324
324
  var import_node_url = require("url");
325
325
  var import_checkbox = __toESM(require("@inquirer/checkbox"), 1);
326
+ var import_confirm = __toESM(require("@inquirer/confirm"), 1);
326
327
  var import_fs_extra = __toESM(require("fs-extra"), 1);
327
328
  var import_get_value2 = __toESM(require_get_value(), 1);
328
329
  var import_klaw = __toESM(require("klaw"), 1);
329
330
  var import_p_queue = __toESM(require("p-queue"), 1);
330
331
  var import_pathe = __toESM(require("pathe"), 1);
332
+ var import_picocolors = __toESM(require("picocolors"), 1);
331
333
  var import_set_value = __toESM(require_set_value(), 1);
332
334
 
333
335
  // ../../scripts/monorepo/git.ts
@@ -385,6 +387,25 @@ init_cjs_shims();
385
387
  var import_consola = require("consola");
386
388
  var logger = (0, import_consola.createConsola)();
387
389
 
390
+ // src/md5.ts
391
+ init_cjs_shims();
392
+ var import_node_crypto = __toESM(require("crypto"), 1);
393
+ function getFileHash(data) {
394
+ const hashSum = import_node_crypto.default.createHash("md5");
395
+ hashSum.update(data);
396
+ return hashSum.digest("hex");
397
+ }
398
+ function isFileChanged(src, dest) {
399
+ try {
400
+ const currentHash = getFileHash(src);
401
+ const previousHash = getFileHash(dest);
402
+ return currentHash !== previousHash;
403
+ } catch (err) {
404
+ console.error("Error calculating file hash:", err);
405
+ return false;
406
+ }
407
+ }
408
+
388
409
  // src/targets.ts
389
410
  init_cjs_shims();
390
411
  function getTargets(raw) {
@@ -462,6 +483,9 @@ function setPkgJson(sourcePkgJson, targetPkgJson) {
462
483
  (0, import_set_value.default)(targetPkgJson, `scripts.${k}`, v);
463
484
  }
464
485
  }
486
+ function confirmOverwrite(filename) {
487
+ 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 });
488
+ }
465
489
  async function main(opts) {
466
490
  const { outDir = "", raw, interactive } = opts;
467
491
  const absOutDir = import_pathe.default.isAbsolute(outDir) ? outDir : import_pathe.default.join(cwd, outDir);
@@ -500,37 +524,47 @@ async function main(opts) {
500
524
  if (file.stats.isFile()) {
501
525
  const relPath = import_pathe.default.relative(assetsDir, file.path);
502
526
  const targetPath = import_pathe.default.resolve(absOutDir, relPath);
527
+ const targetIsExisted = await import_fs_extra.default.exists(targetPath);
528
+ async function overwriteOrCopy(target) {
529
+ let isOverwrite = true;
530
+ if (targetIsExisted) {
531
+ const src = await import_fs_extra.default.readFile(file.path);
532
+ const dest = target ?? await import_fs_extra.default.readFile(targetPath);
533
+ if (await isFileChanged(src, dest)) {
534
+ isOverwrite = await confirmOverwrite(relPath);
535
+ }
536
+ }
537
+ return isOverwrite;
538
+ }
503
539
  if (relPath === "package.json") {
504
540
  const sourcePath = file.path;
505
- if (await import_fs_extra.default.exists(targetPath) && await import_fs_extra.default.exists(sourcePath)) {
541
+ if (targetIsExisted) {
506
542
  const sourcePkgJson = await import_fs_extra.default.readJson(sourcePath);
507
543
  const targetPkgJson = await import_fs_extra.default.readJson(targetPath);
508
544
  setPkgJson(sourcePkgJson, targetPkgJson);
509
- await import_fs_extra.default.writeJson(targetPath, targetPkgJson, {
510
- spaces: 2
511
- });
512
- logger.success(targetPath);
545
+ const data = JSON.stringify(targetPkgJson, void 0, 2);
546
+ if (await overwriteOrCopy(data)) {
547
+ await import_fs_extra.default.writeFile(targetPath, data, "utf8");
548
+ logger.success(targetPath);
549
+ }
513
550
  }
514
- } else if (relPath === ".changeset/config.json" && repoName && await import_fs_extra.default.exists(file.path)) {
551
+ } else if (relPath === ".changeset/config.json" && repoName) {
515
552
  const changesetJson = await import_fs_extra.default.readJson(file.path);
516
553
  (0, import_set_value.default)(changesetJson, "changelog.1.repo", repoName);
517
- await import_fs_extra.default.ensureDir(import_pathe.default.dirname(targetPath));
518
- await import_fs_extra.default.writeJson(targetPath, changesetJson, {
519
- spaces: 2
520
- });
521
- logger.success(targetPath);
522
- } else if (relPath === "Dockerfile" && !await import_fs_extra.default.exists(targetPath)) {
523
- await import_fs_extra.default.copy(
524
- file.path,
525
- targetPath
526
- );
527
- logger.success(targetPath);
554
+ const data = JSON.stringify(changesetJson, void 0, 2);
555
+ if (await overwriteOrCopy(data)) {
556
+ await import_fs_extra.default.ensureDir(import_pathe.default.dirname(targetPath));
557
+ await import_fs_extra.default.writeFile(targetPath, data, "utf8");
558
+ logger.success(targetPath);
559
+ }
528
560
  } else {
529
- await import_fs_extra.default.copy(
530
- file.path,
531
- targetPath
532
- );
533
- logger.success(targetPath);
561
+ if (await overwriteOrCopy()) {
562
+ await import_fs_extra.default.copy(
563
+ file.path,
564
+ targetPath
565
+ );
566
+ logger.success(targetPath);
567
+ }
534
568
  }
535
569
  }
536
570
  });
package/dist/cli.js CHANGED
@@ -2,7 +2,7 @@ import {
2
2
  init_esm_shims,
3
3
  logger,
4
4
  main
5
- } from "./chunk-ZKGFPINA.js";
5
+ } from "./chunk-WMH6CIOP.js";
6
6
 
7
7
  // src/cli.ts
8
8
  init_esm_shims();
@@ -13,7 +13,7 @@ import { program } from "commander";
13
13
 
14
14
  // package.json
15
15
  var name = "@icebreakers/monorepo";
16
- var version = "0.3.12";
16
+ var version = "0.4.1";
17
17
 
18
18
  // src/program.ts
19
19
  program.name(name).version(version);
package/dist/index.cjs CHANGED
@@ -326,11 +326,13 @@ init_cjs_shims();
326
326
  var import_node_process = __toESM(require("process"), 1);
327
327
  var import_node_url = require("url");
328
328
  var import_checkbox = __toESM(require("@inquirer/checkbox"), 1);
329
+ var import_confirm = __toESM(require("@inquirer/confirm"), 1);
329
330
  var import_fs_extra = __toESM(require("fs-extra"), 1);
330
331
  var import_get_value2 = __toESM(require_get_value(), 1);
331
332
  var import_klaw = __toESM(require("klaw"), 1);
332
333
  var import_p_queue = __toESM(require("p-queue"), 1);
333
334
  var import_pathe = __toESM(require("pathe"), 1);
335
+ var import_picocolors = __toESM(require("picocolors"), 1);
334
336
  var import_set_value = __toESM(require_set_value(), 1);
335
337
 
336
338
  // ../../scripts/monorepo/git.ts
@@ -388,6 +390,25 @@ init_cjs_shims();
388
390
  var import_consola = require("consola");
389
391
  var logger = (0, import_consola.createConsola)();
390
392
 
393
+ // src/md5.ts
394
+ init_cjs_shims();
395
+ var import_node_crypto = __toESM(require("crypto"), 1);
396
+ function getFileHash(data) {
397
+ const hashSum = import_node_crypto.default.createHash("md5");
398
+ hashSum.update(data);
399
+ return hashSum.digest("hex");
400
+ }
401
+ function isFileChanged(src, dest) {
402
+ try {
403
+ const currentHash = getFileHash(src);
404
+ const previousHash = getFileHash(dest);
405
+ return currentHash !== previousHash;
406
+ } catch (err) {
407
+ console.error("Error calculating file hash:", err);
408
+ return false;
409
+ }
410
+ }
411
+
391
412
  // src/targets.ts
392
413
  init_cjs_shims();
393
414
  function getTargets(raw) {
@@ -465,6 +486,9 @@ function setPkgJson(sourcePkgJson, targetPkgJson) {
465
486
  (0, import_set_value.default)(targetPkgJson, `scripts.${k}`, v);
466
487
  }
467
488
  }
489
+ function confirmOverwrite(filename) {
490
+ 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 });
491
+ }
468
492
  async function main(opts) {
469
493
  const { outDir = "", raw, interactive } = opts;
470
494
  const absOutDir = import_pathe.default.isAbsolute(outDir) ? outDir : import_pathe.default.join(cwd, outDir);
@@ -503,37 +527,47 @@ async function main(opts) {
503
527
  if (file.stats.isFile()) {
504
528
  const relPath = import_pathe.default.relative(assetsDir, file.path);
505
529
  const targetPath = import_pathe.default.resolve(absOutDir, relPath);
530
+ const targetIsExisted = await import_fs_extra.default.exists(targetPath);
531
+ async function overwriteOrCopy(target) {
532
+ let isOverwrite = true;
533
+ if (targetIsExisted) {
534
+ const src = await import_fs_extra.default.readFile(file.path);
535
+ const dest = target ?? await import_fs_extra.default.readFile(targetPath);
536
+ if (await isFileChanged(src, dest)) {
537
+ isOverwrite = await confirmOverwrite(relPath);
538
+ }
539
+ }
540
+ return isOverwrite;
541
+ }
506
542
  if (relPath === "package.json") {
507
543
  const sourcePath = file.path;
508
- if (await import_fs_extra.default.exists(targetPath) && await import_fs_extra.default.exists(sourcePath)) {
544
+ if (targetIsExisted) {
509
545
  const sourcePkgJson = await import_fs_extra.default.readJson(sourcePath);
510
546
  const targetPkgJson = await import_fs_extra.default.readJson(targetPath);
511
547
  setPkgJson(sourcePkgJson, targetPkgJson);
512
- await import_fs_extra.default.writeJson(targetPath, targetPkgJson, {
513
- spaces: 2
514
- });
515
- logger.success(targetPath);
548
+ const data = JSON.stringify(targetPkgJson, void 0, 2);
549
+ if (await overwriteOrCopy(data)) {
550
+ await import_fs_extra.default.writeFile(targetPath, data, "utf8");
551
+ logger.success(targetPath);
552
+ }
516
553
  }
517
- } else if (relPath === ".changeset/config.json" && repoName && await import_fs_extra.default.exists(file.path)) {
554
+ } else if (relPath === ".changeset/config.json" && repoName) {
518
555
  const changesetJson = await import_fs_extra.default.readJson(file.path);
519
556
  (0, import_set_value.default)(changesetJson, "changelog.1.repo", repoName);
520
- await import_fs_extra.default.ensureDir(import_pathe.default.dirname(targetPath));
521
- await import_fs_extra.default.writeJson(targetPath, changesetJson, {
522
- spaces: 2
523
- });
524
- logger.success(targetPath);
525
- } else if (relPath === "Dockerfile" && !await import_fs_extra.default.exists(targetPath)) {
526
- await import_fs_extra.default.copy(
527
- file.path,
528
- targetPath
529
- );
530
- logger.success(targetPath);
557
+ const data = JSON.stringify(changesetJson, void 0, 2);
558
+ if (await overwriteOrCopy(data)) {
559
+ await import_fs_extra.default.ensureDir(import_pathe.default.dirname(targetPath));
560
+ await import_fs_extra.default.writeFile(targetPath, data, "utf8");
561
+ logger.success(targetPath);
562
+ }
531
563
  } else {
532
- await import_fs_extra.default.copy(
533
- file.path,
534
- targetPath
535
- );
536
- logger.success(targetPath);
564
+ if (await overwriteOrCopy()) {
565
+ await import_fs_extra.default.copy(
566
+ file.path,
567
+ targetPath
568
+ );
569
+ logger.success(targetPath);
570
+ }
537
571
  }
538
572
  }
539
573
  });
package/dist/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  main,
3
3
  setPkgJson
4
- } from "./chunk-ZKGFPINA.js";
4
+ } from "./chunk-WMH6CIOP.js";
5
5
  export {
6
6
  main,
7
7
  setPkgJson
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@icebreakers/monorepo",
3
3
  "type": "module",
4
- "version": "0.3.12",
4
+ "version": "0.4.1",
5
5
  "description": "icebreaker's monorepo config generator",
6
6
  "author": "ice breaker <1324318532@qq.com>",
7
7
  "license": "MIT",
@@ -34,6 +34,7 @@
34
34
  ],
35
35
  "dependencies": {
36
36
  "@inquirer/checkbox": "^2.5.0",
37
+ "@inquirer/confirm": "^3.2.0",
37
38
  "commander": "^12.1.0",
38
39
  "consola": "^3.2.3",
39
40
  "fs-extra": "^11.2.0",
@@ -41,6 +42,7 @@
41
42
  "klaw": "^4.1.0",
42
43
  "p-queue": "^8.0.1",
43
44
  "pathe": "^1.1.2",
45
+ "picocolors": "^1.1.0",
44
46
  "simple-git": "^3.26.0"
45
47
  },
46
48
  "devDependencies": {