@chanom/cli 0.1.0 → 0.1.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.
Files changed (2) hide show
  1. package/dist/index.js +30 -2
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -102,7 +102,8 @@ var Git = class extends Effect.Service()("cli/Git", { effect: Effect.gen(functio
102
102
  "--quiet"
103
103
  ], cwd).pipe(Effect.map((clean) => !clean)),
104
104
  isRepo: (cwd) => fs.exists(path.join(cwd, ".git")),
105
- writeGitignore: (cwd, contents = "node_modules\n") => fs.writeFileString(path.join(cwd, ".gitignore"), contents)
105
+ writeGitignore: (cwd, contents = "node_modules\n") => fs.writeFileString(path.join(cwd, ".gitignore"), contents),
106
+ readGitignore: (cwd) => fs.readFileString(path.join(cwd, ".gitignore"))
106
107
  };
107
108
  }) }) {};
108
109
  //#endregion
@@ -499,6 +500,21 @@ function planPackages(pkg, toppings, sweetness, versions) {
499
500
  if (sweetness === "medium") packages.push(...getPackages$4(pkg), ...getPackages$2(pkg), ...getPackages$5(pkg));
500
501
  return [...new Set(packages)];
501
502
  }
503
+ /** True when the .gitignore content already has the entry as its own line. */
504
+ function hasGitignoreEntry(content, entry) {
505
+ const forms = /* @__PURE__ */ new Set([
506
+ entry,
507
+ `${entry}/`,
508
+ `/${entry}`,
509
+ `/${entry}/`
510
+ ]);
511
+ return content.split(/\r?\n/).some((line) => forms.has(line.trim()));
512
+ }
513
+ /** .gitignore content with the entry appended, preserving existing lines and newline termination. */
514
+ function appendGitignoreEntry(content, entry) {
515
+ if (content === "") return `${entry}\n`;
516
+ return content.endsWith("\n") ? `${content}${entry}\n` : `${content}\n${entry}\n`;
517
+ }
502
518
  function selectedLinters(toppings) {
503
519
  return toppings.filter((t) => t === "oxlint");
504
520
  }
@@ -515,9 +531,20 @@ const ensureGitRepo = (cwd) => Effect.gen(function* () {
515
531
  }
516
532
  const s = yield* (yield* Prompter).spinner("Git not found, initializing repository...");
517
533
  yield* git.init(cwd);
518
- yield* git.writeGitignore(cwd);
519
534
  yield* s.stop("Git initialized");
520
535
  }).pipe(Effect.withSpan("brew.ensureGitRepo"));
536
+ const ensureGitIgnore = (cwd) => Effect.gen(function* () {
537
+ const git = yield* Git;
538
+ const prompter = yield* Prompter;
539
+ const existing = yield* git.readGitignore(cwd).pipe(Effect.catchTag("SystemError", (e) => e.reason === "NotFound" ? Effect.succeed(void 0) : Effect.fail(e)));
540
+ if (existing !== void 0 && hasGitignoreEntry(existing, "node_modules")) {
541
+ yield* Effect.logDebug("node_modules already present in .gitignore");
542
+ return;
543
+ }
544
+ const s = yield* prompter.spinner(existing === void 0 ? "Creating .gitignore..." : "Adding node_modules to .gitignore...");
545
+ yield* git.writeGitignore(cwd, appendGitignoreEntry(existing ?? "", "node_modules")).pipe(Effect.tapError(() => s.stop(pc.red("Could not update .gitignore"))));
546
+ yield* s.stop(existing === void 0 ? ".gitignore created" : "node_modules added to .gitignore");
547
+ }).pipe(Effect.withSpan("brew.ensureGitIgnore"));
521
548
  const askRecipe = () => Effect.gen(function* () {
522
549
  const prompter = yield* Prompter;
523
550
  return {
@@ -612,6 +639,7 @@ const brew = (cwd = process.cwd()) => Effect.gen(function* () {
612
639
  const prompter = yield* Prompter;
613
640
  yield* prompter.intro(pc.magenta("🧋 Chanom - Let's brew your project!"));
614
641
  yield* ensureGitRepo(cwd);
642
+ yield* ensureGitIgnore(cwd);
615
643
  const pm = yield* detectPm(cwd);
616
644
  yield* Effect.logDebug(`detected package manager: ${pm}`);
617
645
  const { pkg, pkgPath } = yield* readPkg(cwd);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@chanom/cli",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "",
5
5
  "keywords": [],
6
6
  "repository": {