@icebreakers/monorepo 0.4.0 → 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.
@@ -314,7 +314,7 @@ import process from "node:process";
314
314
  import { fileURLToPath } from "node:url";
315
315
  import checkbox from "@inquirer/checkbox";
316
316
  import confirm from "@inquirer/confirm";
317
- import fs2 from "fs-extra";
317
+ import fs from "fs-extra";
318
318
  import klaw from "klaw";
319
319
  import PQueue from "p-queue";
320
320
  import path from "pathe";
@@ -378,13 +378,12 @@ var logger = createConsola();
378
378
  // src/md5.ts
379
379
  init_esm_shims();
380
380
  import crypto from "node:crypto";
381
- import fs from "fs-extra";
382
381
  function getFileHash(data) {
383
382
  const hashSum = crypto.createHash("md5");
384
383
  hashSum.update(data);
385
384
  return hashSum.digest("hex");
386
385
  }
387
- function hasFileBufferChanged(src, dest) {
386
+ function isFileChanged(src, dest) {
388
387
  try {
389
388
  const currentHash = getFileHash(src);
390
389
  const previousHash = getFileHash(dest);
@@ -394,9 +393,6 @@ function hasFileBufferChanged(src, dest) {
394
393
  return false;
395
394
  }
396
395
  }
397
- async function hasFileChanged(src, dest) {
398
- return hasFileBufferChanged(await fs.readFile(src), await fs.readFile(dest));
399
- }
400
396
 
401
397
  // src/targets.ts
402
398
  init_esm_shims();
@@ -500,7 +496,7 @@ async function main(opts) {
500
496
  const removeDirs = ["scripts/monorepo"];
501
497
  for (const dir of removeDirs) {
502
498
  if (targets.includes(dir)) {
503
- await fs2.remove(path.resolve(absOutDir, dir));
499
+ await fs.remove(path.resolve(absOutDir, dir));
504
500
  }
505
501
  }
506
502
  const regexpArr = targets.map((x) => {
@@ -516,35 +512,42 @@ async function main(opts) {
516
512
  if (file.stats.isFile()) {
517
513
  const relPath = path.relative(assetsDir, file.path);
518
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
+ }
519
527
  if (relPath === "package.json") {
520
528
  const sourcePath = file.path;
521
- if (await fs2.exists(targetPath) && await fs2.exists(sourcePath)) {
522
- const sourcePkgJson = await fs2.readJson(sourcePath);
523
- const targetPkgJson = await fs2.readJson(targetPath);
529
+ if (targetIsExisted) {
530
+ const sourcePkgJson = await fs.readJson(sourcePath);
531
+ const targetPkgJson = await fs.readJson(targetPath);
524
532
  setPkgJson(sourcePkgJson, targetPkgJson);
525
- await fs2.writeJson(targetPath, targetPkgJson, {
526
- spaces: 2
527
- });
528
- 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
+ }
529
538
  }
530
- } else if (relPath === ".changeset/config.json" && repoName && await fs2.exists(file.path)) {
531
- const changesetJson = await fs2.readJson(file.path);
539
+ } else if (relPath === ".changeset/config.json" && repoName) {
540
+ const changesetJson = await fs.readJson(file.path);
532
541
  (0, import_set_value.default)(changesetJson, "changelog.1.repo", repoName);
533
- await fs2.ensureDir(path.dirname(targetPath));
534
- await fs2.writeJson(targetPath, changesetJson, {
535
- spaces: 2
536
- });
537
- logger.success(targetPath);
538
- } else {
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
- }
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);
545
547
  }
546
- if (isOverwrite) {
547
- await fs2.copy(
548
+ } else {
549
+ if (await overwriteOrCopy()) {
550
+ await fs.copy(
548
551
  file.path,
549
552
  targetPath
550
553
  );
package/dist/cli.cjs CHANGED
@@ -316,7 +316,7 @@ var import_commander = require("commander");
316
316
 
317
317
  // package.json
318
318
  var name = "@icebreakers/monorepo";
319
- var version = "0.4.0";
319
+ var version = "0.4.1";
320
320
 
321
321
  // src/lib.ts
322
322
  init_cjs_shims();
@@ -324,7 +324,7 @@ 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
326
  var import_confirm = __toESM(require("@inquirer/confirm"), 1);
327
- var import_fs_extra2 = __toESM(require("fs-extra"), 1);
327
+ var import_fs_extra = __toESM(require("fs-extra"), 1);
328
328
  var import_get_value2 = __toESM(require_get_value(), 1);
329
329
  var import_klaw = __toESM(require("klaw"), 1);
330
330
  var import_p_queue = __toESM(require("p-queue"), 1);
@@ -390,13 +390,12 @@ var logger = (0, import_consola.createConsola)();
390
390
  // src/md5.ts
391
391
  init_cjs_shims();
392
392
  var import_node_crypto = __toESM(require("crypto"), 1);
393
- var import_fs_extra = __toESM(require("fs-extra"), 1);
394
393
  function getFileHash(data) {
395
394
  const hashSum = import_node_crypto.default.createHash("md5");
396
395
  hashSum.update(data);
397
396
  return hashSum.digest("hex");
398
397
  }
399
- function hasFileBufferChanged(src, dest) {
398
+ function isFileChanged(src, dest) {
400
399
  try {
401
400
  const currentHash = getFileHash(src);
402
401
  const previousHash = getFileHash(dest);
@@ -406,9 +405,6 @@ function hasFileBufferChanged(src, dest) {
406
405
  return false;
407
406
  }
408
407
  }
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
408
 
413
409
  // src/targets.ts
414
410
  init_cjs_shims();
@@ -512,7 +508,7 @@ async function main(opts) {
512
508
  const removeDirs = ["scripts/monorepo"];
513
509
  for (const dir of removeDirs) {
514
510
  if (targets.includes(dir)) {
515
- await import_fs_extra2.default.remove(import_pathe.default.resolve(absOutDir, dir));
511
+ await import_fs_extra.default.remove(import_pathe.default.resolve(absOutDir, dir));
516
512
  }
517
513
  }
518
514
  const regexpArr = targets.map((x) => {
@@ -528,35 +524,42 @@ async function main(opts) {
528
524
  if (file.stats.isFile()) {
529
525
  const relPath = import_pathe.default.relative(assetsDir, file.path);
530
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
+ }
531
539
  if (relPath === "package.json") {
532
540
  const sourcePath = file.path;
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);
541
+ if (targetIsExisted) {
542
+ const sourcePkgJson = await import_fs_extra.default.readJson(sourcePath);
543
+ const targetPkgJson = await import_fs_extra.default.readJson(targetPath);
536
544
  setPkgJson(sourcePkgJson, targetPkgJson);
537
- await import_fs_extra2.default.writeJson(targetPath, targetPkgJson, {
538
- spaces: 2
539
- });
540
- 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
+ }
541
550
  }
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);
551
+ } else if (relPath === ".changeset/config.json" && repoName) {
552
+ const changesetJson = await import_fs_extra.default.readJson(file.path);
544
553
  (0, import_set_value.default)(changesetJson, "changelog.1.repo", repoName);
545
- await import_fs_extra2.default.ensureDir(import_pathe.default.dirname(targetPath));
546
- await import_fs_extra2.default.writeJson(targetPath, changesetJson, {
547
- spaces: 2
548
- });
549
- logger.success(targetPath);
550
- } else {
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
- }
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);
557
559
  }
558
- if (isOverwrite) {
559
- await import_fs_extra2.default.copy(
560
+ } else {
561
+ if (await overwriteOrCopy()) {
562
+ await import_fs_extra.default.copy(
560
563
  file.path,
561
564
  targetPath
562
565
  );
package/dist/cli.js CHANGED
@@ -2,7 +2,7 @@ import {
2
2
  init_esm_shims,
3
3
  logger,
4
4
  main
5
- } from "./chunk-GSEOTDU7.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.4.0";
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
@@ -327,7 +327,7 @@ 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
329
  var import_confirm = __toESM(require("@inquirer/confirm"), 1);
330
- var import_fs_extra2 = __toESM(require("fs-extra"), 1);
330
+ var import_fs_extra = __toESM(require("fs-extra"), 1);
331
331
  var import_get_value2 = __toESM(require_get_value(), 1);
332
332
  var import_klaw = __toESM(require("klaw"), 1);
333
333
  var import_p_queue = __toESM(require("p-queue"), 1);
@@ -393,13 +393,12 @@ var logger = (0, import_consola.createConsola)();
393
393
  // src/md5.ts
394
394
  init_cjs_shims();
395
395
  var import_node_crypto = __toESM(require("crypto"), 1);
396
- var import_fs_extra = __toESM(require("fs-extra"), 1);
397
396
  function getFileHash(data) {
398
397
  const hashSum = import_node_crypto.default.createHash("md5");
399
398
  hashSum.update(data);
400
399
  return hashSum.digest("hex");
401
400
  }
402
- function hasFileBufferChanged(src, dest) {
401
+ function isFileChanged(src, dest) {
403
402
  try {
404
403
  const currentHash = getFileHash(src);
405
404
  const previousHash = getFileHash(dest);
@@ -409,9 +408,6 @@ function hasFileBufferChanged(src, dest) {
409
408
  return false;
410
409
  }
411
410
  }
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
411
 
416
412
  // src/targets.ts
417
413
  init_cjs_shims();
@@ -515,7 +511,7 @@ async function main(opts) {
515
511
  const removeDirs = ["scripts/monorepo"];
516
512
  for (const dir of removeDirs) {
517
513
  if (targets.includes(dir)) {
518
- await import_fs_extra2.default.remove(import_pathe.default.resolve(absOutDir, dir));
514
+ await import_fs_extra.default.remove(import_pathe.default.resolve(absOutDir, dir));
519
515
  }
520
516
  }
521
517
  const regexpArr = targets.map((x) => {
@@ -531,35 +527,42 @@ async function main(opts) {
531
527
  if (file.stats.isFile()) {
532
528
  const relPath = import_pathe.default.relative(assetsDir, file.path);
533
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
+ }
534
542
  if (relPath === "package.json") {
535
543
  const sourcePath = file.path;
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);
544
+ if (targetIsExisted) {
545
+ const sourcePkgJson = await import_fs_extra.default.readJson(sourcePath);
546
+ const targetPkgJson = await import_fs_extra.default.readJson(targetPath);
539
547
  setPkgJson(sourcePkgJson, targetPkgJson);
540
- await import_fs_extra2.default.writeJson(targetPath, targetPkgJson, {
541
- spaces: 2
542
- });
543
- 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
+ }
544
553
  }
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);
554
+ } else if (relPath === ".changeset/config.json" && repoName) {
555
+ const changesetJson = await import_fs_extra.default.readJson(file.path);
547
556
  (0, import_set_value.default)(changesetJson, "changelog.1.repo", repoName);
548
- await import_fs_extra2.default.ensureDir(import_pathe.default.dirname(targetPath));
549
- await import_fs_extra2.default.writeJson(targetPath, changesetJson, {
550
- spaces: 2
551
- });
552
- logger.success(targetPath);
553
- } else {
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
- }
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);
560
562
  }
561
- if (isOverwrite) {
562
- await import_fs_extra2.default.copy(
563
+ } else {
564
+ if (await overwriteOrCopy()) {
565
+ await import_fs_extra.default.copy(
563
566
  file.path,
564
567
  targetPath
565
568
  );
package/dist/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  main,
3
3
  setPkgJson
4
- } from "./chunk-GSEOTDU7.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.4.0",
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",