From 4529a026bf08e10faf2fd77ac410cbb73a04629f Mon Sep 17 00:00:00 2001 From: rafaeelricco Date: Mon, 27 Apr 2026 08:36:07 -0300 Subject: [PATCH] Consolidate update banner logic into update module - Merge `show-update-banner.ts` into `src/cli/update.ts` and remove the now-unused file. - Update import path in `index.ts` to point at the unified `@/cli/update` module. - Document the `commit update` command and update notifier behavior in the README. - Bump version to `0.2.7` in `package.json` and the README badge. - Drop redundant `as UserAction` and `as string` casts in `src/cli/commit.ts`. --- README.md | 21 ++++++++++++++++++++- index.ts | 2 +- package.json | 2 +- src/cli/commit.ts | 6 +++--- src/cli/show-update-banner.ts | 19 ------------------- src/cli/update.ts | 22 ++++++++++++++++++++-- 6 files changed, 45 insertions(+), 27 deletions(-) delete mode 100644 src/cli/show-update-banner.ts diff --git a/README.md b/README.md index 42e24d8..409f821 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # commit-tools -[![Version](https://img.shields.io/badge/version-0.2.5-blue.svg)](#) +[![Version](https://img.shields.io/badge/version-0.2.6-blue.svg)](#) Writing good commit messages _can_ have a high cognitive cost, especially when you make dozens of commits a day. That energy should be directed toward solving hard problems and shipping features, not summarizing them. @@ -142,6 +142,24 @@ Verify your installation, environment, and configuration: commit doctor ``` +### Stay Up to Date + +`commit-tools` checks the npm registry once per day and shows a banner when a newer version is available. To install the latest release, run: + +```bash +commit update +``` + +The command auto-detects your global package manager (npm, pnpm, or Yarn 1). Modern Yarn (≥ 2) does not support global installs — use npm or pnpm instead. + +To silence the update banner (e.g. for CI or scripted environments), set: + +```bash +NO_UPDATE_NOTIFIER=true +``` + +The banner is also suppressed automatically in non-interactive shells and when `CI=true`. + ## Commands To see all available commands at any time, run: @@ -159,6 +177,7 @@ commit --help | `commit doctor` | Check installation and environment | | `commit model` | Select a different AI model | | `commit effort` | Adjust the reasoning effort for the current model | +| `commit update` | Install the latest version from npm | | `commit --version`, `-v` | Show version | | `commit --help`, `-h` | Show help | diff --git a/index.ts b/index.ts index 61b0b16..3eba024 100755 --- a/index.ts +++ b/index.ts @@ -7,7 +7,7 @@ import { Update } from "@/cli/update"; import { type CliCommand, parseArgs, showHelp, showVersion } from "@/cli/parser"; import { Future } from "@/libs/future"; import { absurd } from "@/libs/types"; -import { checkUpdate } from "@/cli/show-update-banner"; +import { checkUpdate } from "@/cli/update"; import color from "picocolors"; diff --git a/package.json b/package.json index 30eba3a..61b3698 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@rafaeelricco/commit-tools", - "version": "0.2.6", + "version": "0.2.7", "type": "module", "bin": { "commit": "./dist/index.js" diff --git a/src/cli/commit.ts b/src/cli/commit.ts index 9d09f88..b9c0812 100644 --- a/src/cli/commit.ts +++ b/src/cli/commit.ts @@ -133,10 +133,10 @@ class Commit { if (p.isCancel(action) || action === "cancel") { p.outro("Operation cancelled."); - return "cancel" as UserAction; + return "cancel"; } - return action as UserAction; + return action; }); } @@ -202,7 +202,7 @@ class Commit { message: "What adjustments would you like?", placeholder: "e.g. make it more concise" }); - return p.isCancel(adj) ? Nothing() : Just(adj as string); + return p.isCancel(adj) ? Nothing() : Just(adj); }); } } diff --git a/src/cli/show-update-banner.ts b/src/cli/show-update-banner.ts deleted file mode 100644 index 58aa190..0000000 --- a/src/cli/show-update-banner.ts +++ /dev/null @@ -1,19 +0,0 @@ -export { checkUpdate }; - -import { checkForUpdate, compareVersions } from "@/infra/version-check"; -import { renderUpdateBanner } from "@/infra/ui/update-banner"; -import { version } from "@/package.json"; - -const isOptedOut = (): boolean => process.env["NO_UPDATE_NOTIFIER"] === "true"; -const isCi = (): boolean => Boolean(process.env["CI"]); -const isNonInteractive = (): boolean => !process.stdout.isTTY; - -const shouldSuppress = (): boolean => isOptedOut() || isCi() || isNonInteractive(); - -const checkUpdate = (): void => { - if (shouldSuppress()) return; - const current = version; - checkForUpdate().maybe(undefined, (latest) => { - if (compareVersions(latest, current) > 0) renderUpdateBanner({ current, latest }); - }); -}; diff --git a/src/cli/update.ts b/src/cli/update.ts index b513b8b..ebcd9d3 100644 --- a/src/cli/update.ts +++ b/src/cli/update.ts @@ -1,11 +1,15 @@ -export { Update }; +export { Update, checkUpdate }; import * as p from "@clack/prompts"; -import color from "picocolors"; +import { checkForUpdate, compareVersions } from "@/infra/version-check"; +import { renderUpdateBanner } from "@/infra/ui/update-banner"; +import { version } from "@/package.json"; import { Future } from "@/libs/future"; import { execBin, execBinInteractive } from "@/infra/shell"; +import color from "picocolors"; + const PACKAGE_NAME = "@rafaeelricco/commit-tools"; type PackageManager = { name: "pnpm" | "yarn" | "npm"; cmd: string; args: string[] }; @@ -80,3 +84,17 @@ class Update { }); } } + +const isOptedOut = (): boolean => process.env["NO_UPDATE_NOTIFIER"] === "true"; +const isCi = (): boolean => Boolean(process.env["CI"]); +const isNonInteractive = (): boolean => !process.stdout.isTTY; + +const shouldSuppress = (): boolean => isOptedOut() || isCi() || isNonInteractive(); + +const checkUpdate = (): void => { + if (shouldSuppress()) return; + const current = version; + checkForUpdate().maybe(undefined, (latest) => { + if (compareVersions(latest, current) > 0) renderUpdateBanner({ current, latest }); + }); +};