@icebreakers/monorepo 0.3.11 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -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",
@@ -2,8 +2,5 @@
2
2
  "$schema": "https://docs.renovatebot.com/renovate-schema.json",
3
3
  "extends": [
4
4
  "config:recommended"
5
- ],
6
- "ignoreDeps": [
7
- "@dcloudio/*"
8
5
  ]
9
6
  }
@@ -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 fs from "fs-extra";
316
+ import confirm from "@inquirer/confirm";
317
+ import fs2 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,29 @@ 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
+ import fs from "fs-extra";
382
+ function getFileHash(data) {
383
+ const hashSum = crypto.createHash("md5");
384
+ hashSum.update(data);
385
+ return hashSum.digest("hex");
386
+ }
387
+ function hasFileBufferChanged(src, dest) {
388
+ try {
389
+ const currentHash = getFileHash(src);
390
+ const previousHash = getFileHash(dest);
391
+ return currentHash !== previousHash;
392
+ } catch (err) {
393
+ console.error("Error calculating file hash:", err);
394
+ return false;
395
+ }
396
+ }
397
+ async function hasFileChanged(src, dest) {
398
+ return hasFileBufferChanged(await fs.readFile(src), await fs.readFile(dest));
399
+ }
400
+
376
401
  // src/targets.ts
377
402
  init_esm_shims();
378
403
  function getTargets(raw) {
@@ -450,6 +475,9 @@ function setPkgJson(sourcePkgJson, targetPkgJson) {
450
475
  (0, import_set_value.default)(targetPkgJson, `scripts.${k}`, v);
451
476
  }
452
477
  }
478
+ function confirmOverwrite(filename) {
479
+ return confirm({ message: `${pc.greenBright(filename)} \u6587\u4EF6\u5185\u5BB9\u53D1\u751F\u6539\u53D8,\u662F\u5426\u8986\u76D6?`, default: false });
480
+ }
453
481
  async function main(opts) {
454
482
  const { outDir = "", raw, interactive } = opts;
455
483
  const absOutDir = path.isAbsolute(outDir) ? outDir : path.join(cwd, outDir);
@@ -472,7 +500,7 @@ async function main(opts) {
472
500
  const removeDirs = ["scripts/monorepo"];
473
501
  for (const dir of removeDirs) {
474
502
  if (targets.includes(dir)) {
475
- await fs.remove(path.resolve(absOutDir, dir));
503
+ await fs2.remove(path.resolve(absOutDir, dir));
476
504
  }
477
505
  }
478
506
  const regexpArr = targets.map((x) => {
@@ -490,35 +518,38 @@ async function main(opts) {
490
518
  const targetPath = path.resolve(absOutDir, relPath);
491
519
  if (relPath === "package.json") {
492
520
  const sourcePath = file.path;
493
- if (await fs.exists(targetPath) && await fs.exists(sourcePath)) {
494
- const sourcePkgJson = await fs.readJson(sourcePath);
495
- const targetPkgJson = await fs.readJson(targetPath);
521
+ if (await fs2.exists(targetPath) && await fs2.exists(sourcePath)) {
522
+ const sourcePkgJson = await fs2.readJson(sourcePath);
523
+ const targetPkgJson = await fs2.readJson(targetPath);
496
524
  setPkgJson(sourcePkgJson, targetPkgJson);
497
- await fs.writeJson(targetPath, targetPkgJson, {
525
+ await fs2.writeJson(targetPath, targetPkgJson, {
498
526
  spaces: 2
499
527
  });
500
528
  logger.success(targetPath);
501
529
  }
502
- } else if (relPath === ".changeset/config.json" && repoName && await fs.exists(file.path)) {
503
- const changesetJson = await fs.readJson(file.path);
530
+ } else if (relPath === ".changeset/config.json" && repoName && await fs2.exists(file.path)) {
531
+ const changesetJson = await fs2.readJson(file.path);
504
532
  (0, import_set_value.default)(changesetJson, "changelog.1.repo", repoName);
505
- await fs.ensureDir(path.dirname(targetPath));
506
- await fs.writeJson(targetPath, changesetJson, {
533
+ await fs2.ensureDir(path.dirname(targetPath));
534
+ await fs2.writeJson(targetPath, changesetJson, {
507
535
  spaces: 2
508
536
  });
509
537
  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);
516
538
  } else {
517
- await fs.copy(
518
- file.path,
519
- targetPath
520
- );
521
- logger.success(targetPath);
539
+ let isOverwrite = true;
540
+ const targetIsExisted = await fs2.exists(targetPath);
541
+ if (targetIsExisted) {
542
+ if (await hasFileChanged(file.path, targetPath)) {
543
+ isOverwrite = await confirmOverwrite(relPath);
544
+ }
545
+ }
546
+ if (isOverwrite) {
547
+ await fs2.copy(
548
+ file.path,
549
+ targetPath
550
+ );
551
+ logger.success(targetPath);
552
+ }
522
553
  }
523
554
  }
524
555
  });
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.11";
319
+ var version = "0.4.0";
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_fs_extra = __toESM(require("fs-extra"), 1);
326
+ var import_confirm = __toESM(require("@inquirer/confirm"), 1);
327
+ var import_fs_extra2 = __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,29 @@ 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
+ var import_fs_extra = __toESM(require("fs-extra"), 1);
394
+ function getFileHash(data) {
395
+ const hashSum = import_node_crypto.default.createHash("md5");
396
+ hashSum.update(data);
397
+ return hashSum.digest("hex");
398
+ }
399
+ function hasFileBufferChanged(src, dest) {
400
+ try {
401
+ const currentHash = getFileHash(src);
402
+ const previousHash = getFileHash(dest);
403
+ return currentHash !== previousHash;
404
+ } catch (err) {
405
+ console.error("Error calculating file hash:", err);
406
+ return false;
407
+ }
408
+ }
409
+ async function hasFileChanged(src, dest) {
410
+ return hasFileBufferChanged(await import_fs_extra.default.readFile(src), await import_fs_extra.default.readFile(dest));
411
+ }
412
+
388
413
  // src/targets.ts
389
414
  init_cjs_shims();
390
415
  function getTargets(raw) {
@@ -462,6 +487,9 @@ function setPkgJson(sourcePkgJson, targetPkgJson) {
462
487
  (0, import_set_value.default)(targetPkgJson, `scripts.${k}`, v);
463
488
  }
464
489
  }
490
+ function confirmOverwrite(filename) {
491
+ 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 });
492
+ }
465
493
  async function main(opts) {
466
494
  const { outDir = "", raw, interactive } = opts;
467
495
  const absOutDir = import_pathe.default.isAbsolute(outDir) ? outDir : import_pathe.default.join(cwd, outDir);
@@ -484,7 +512,7 @@ async function main(opts) {
484
512
  const removeDirs = ["scripts/monorepo"];
485
513
  for (const dir of removeDirs) {
486
514
  if (targets.includes(dir)) {
487
- await import_fs_extra.default.remove(import_pathe.default.resolve(absOutDir, dir));
515
+ await import_fs_extra2.default.remove(import_pathe.default.resolve(absOutDir, dir));
488
516
  }
489
517
  }
490
518
  const regexpArr = targets.map((x) => {
@@ -502,35 +530,38 @@ async function main(opts) {
502
530
  const targetPath = import_pathe.default.resolve(absOutDir, relPath);
503
531
  if (relPath === "package.json") {
504
532
  const sourcePath = file.path;
505
- if (await import_fs_extra.default.exists(targetPath) && await import_fs_extra.default.exists(sourcePath)) {
506
- const sourcePkgJson = await import_fs_extra.default.readJson(sourcePath);
507
- const targetPkgJson = await import_fs_extra.default.readJson(targetPath);
533
+ if (await import_fs_extra2.default.exists(targetPath) && await import_fs_extra2.default.exists(sourcePath)) {
534
+ const sourcePkgJson = await import_fs_extra2.default.readJson(sourcePath);
535
+ const targetPkgJson = await import_fs_extra2.default.readJson(targetPath);
508
536
  setPkgJson(sourcePkgJson, targetPkgJson);
509
- await import_fs_extra.default.writeJson(targetPath, targetPkgJson, {
537
+ await import_fs_extra2.default.writeJson(targetPath, targetPkgJson, {
510
538
  spaces: 2
511
539
  });
512
540
  logger.success(targetPath);
513
541
  }
514
- } else if (relPath === ".changeset/config.json" && repoName && await import_fs_extra.default.exists(file.path)) {
515
- const changesetJson = await import_fs_extra.default.readJson(file.path);
542
+ } else if (relPath === ".changeset/config.json" && repoName && await import_fs_extra2.default.exists(file.path)) {
543
+ const changesetJson = await import_fs_extra2.default.readJson(file.path);
516
544
  (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, {
545
+ await import_fs_extra2.default.ensureDir(import_pathe.default.dirname(targetPath));
546
+ await import_fs_extra2.default.writeJson(targetPath, changesetJson, {
519
547
  spaces: 2
520
548
  });
521
549
  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);
528
550
  } else {
529
- await import_fs_extra.default.copy(
530
- file.path,
531
- targetPath
532
- );
533
- logger.success(targetPath);
551
+ let isOverwrite = true;
552
+ const targetIsExisted = await import_fs_extra2.default.exists(targetPath);
553
+ if (targetIsExisted) {
554
+ if (await hasFileChanged(file.path, targetPath)) {
555
+ isOverwrite = await confirmOverwrite(relPath);
556
+ }
557
+ }
558
+ if (isOverwrite) {
559
+ await import_fs_extra2.default.copy(
560
+ file.path,
561
+ targetPath
562
+ );
563
+ logger.success(targetPath);
564
+ }
534
565
  }
535
566
  }
536
567
  });
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-GSEOTDU7.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.11";
16
+ var version = "0.4.0";
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_fs_extra = __toESM(require("fs-extra"), 1);
329
+ var import_confirm = __toESM(require("@inquirer/confirm"), 1);
330
+ var import_fs_extra2 = __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,29 @@ 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
+ var import_fs_extra = __toESM(require("fs-extra"), 1);
397
+ function getFileHash(data) {
398
+ const hashSum = import_node_crypto.default.createHash("md5");
399
+ hashSum.update(data);
400
+ return hashSum.digest("hex");
401
+ }
402
+ function hasFileBufferChanged(src, dest) {
403
+ try {
404
+ const currentHash = getFileHash(src);
405
+ const previousHash = getFileHash(dest);
406
+ return currentHash !== previousHash;
407
+ } catch (err) {
408
+ console.error("Error calculating file hash:", err);
409
+ return false;
410
+ }
411
+ }
412
+ async function hasFileChanged(src, dest) {
413
+ return hasFileBufferChanged(await import_fs_extra.default.readFile(src), await import_fs_extra.default.readFile(dest));
414
+ }
415
+
391
416
  // src/targets.ts
392
417
  init_cjs_shims();
393
418
  function getTargets(raw) {
@@ -465,6 +490,9 @@ function setPkgJson(sourcePkgJson, targetPkgJson) {
465
490
  (0, import_set_value.default)(targetPkgJson, `scripts.${k}`, v);
466
491
  }
467
492
  }
493
+ function confirmOverwrite(filename) {
494
+ 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 });
495
+ }
468
496
  async function main(opts) {
469
497
  const { outDir = "", raw, interactive } = opts;
470
498
  const absOutDir = import_pathe.default.isAbsolute(outDir) ? outDir : import_pathe.default.join(cwd, outDir);
@@ -487,7 +515,7 @@ async function main(opts) {
487
515
  const removeDirs = ["scripts/monorepo"];
488
516
  for (const dir of removeDirs) {
489
517
  if (targets.includes(dir)) {
490
- await import_fs_extra.default.remove(import_pathe.default.resolve(absOutDir, dir));
518
+ await import_fs_extra2.default.remove(import_pathe.default.resolve(absOutDir, dir));
491
519
  }
492
520
  }
493
521
  const regexpArr = targets.map((x) => {
@@ -505,35 +533,38 @@ async function main(opts) {
505
533
  const targetPath = import_pathe.default.resolve(absOutDir, relPath);
506
534
  if (relPath === "package.json") {
507
535
  const sourcePath = file.path;
508
- if (await import_fs_extra.default.exists(targetPath) && await import_fs_extra.default.exists(sourcePath)) {
509
- const sourcePkgJson = await import_fs_extra.default.readJson(sourcePath);
510
- const targetPkgJson = await import_fs_extra.default.readJson(targetPath);
536
+ if (await import_fs_extra2.default.exists(targetPath) && await import_fs_extra2.default.exists(sourcePath)) {
537
+ const sourcePkgJson = await import_fs_extra2.default.readJson(sourcePath);
538
+ const targetPkgJson = await import_fs_extra2.default.readJson(targetPath);
511
539
  setPkgJson(sourcePkgJson, targetPkgJson);
512
- await import_fs_extra.default.writeJson(targetPath, targetPkgJson, {
540
+ await import_fs_extra2.default.writeJson(targetPath, targetPkgJson, {
513
541
  spaces: 2
514
542
  });
515
543
  logger.success(targetPath);
516
544
  }
517
- } else if (relPath === ".changeset/config.json" && repoName && await import_fs_extra.default.exists(file.path)) {
518
- const changesetJson = await import_fs_extra.default.readJson(file.path);
545
+ } else if (relPath === ".changeset/config.json" && repoName && await import_fs_extra2.default.exists(file.path)) {
546
+ const changesetJson = await import_fs_extra2.default.readJson(file.path);
519
547
  (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, {
548
+ await import_fs_extra2.default.ensureDir(import_pathe.default.dirname(targetPath));
549
+ await import_fs_extra2.default.writeJson(targetPath, changesetJson, {
522
550
  spaces: 2
523
551
  });
524
552
  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);
531
553
  } else {
532
- await import_fs_extra.default.copy(
533
- file.path,
534
- targetPath
535
- );
536
- logger.success(targetPath);
554
+ let isOverwrite = true;
555
+ const targetIsExisted = await import_fs_extra2.default.exists(targetPath);
556
+ if (targetIsExisted) {
557
+ if (await hasFileChanged(file.path, targetPath)) {
558
+ isOverwrite = await confirmOverwrite(relPath);
559
+ }
560
+ }
561
+ if (isOverwrite) {
562
+ await import_fs_extra2.default.copy(
563
+ file.path,
564
+ targetPath
565
+ );
566
+ logger.success(targetPath);
567
+ }
537
568
  }
538
569
  }
539
570
  });
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-GSEOTDU7.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.11",
4
+ "version": "0.4.0",
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": {