diff --git a/.husky/commit-msg b/.husky/commit-msg new file mode 100755 index 0000000..6fb5205 --- /dev/null +++ b/.husky/commit-msg @@ -0,0 +1,10 @@ +#!/bin/bash + +VERSION=$(grep -o '"version": "[^"]*"' package.json | cut -d'"' -f4) +COMMIT_MSG_FILE=$1 +COMMIT_MSG=$(cat "$COMMIT_MSG_FILE") + +# Only prepend version if it's not already there +if [[ ! $COMMIT_MSG =~ ^$VERSION ]]; then + echo "$VERSION - $COMMIT_MSG" > "$COMMIT_MSG_FILE" +fi diff --git a/.husky/prepare-commit-msg b/.husky/prepare-commit-msg deleted file mode 100755 index a24a924..0000000 --- a/.husky/prepare-commit-msg +++ /dev/null @@ -1,13 +0,0 @@ -#!/bin/bash - -COMMIT_MSG_FILE=$1 -COMMIT_SOURCE=$2 -VERSION=$(grep -o '"version": "[^"]*"' package.json | cut -d'"' -f4) - -# Only add version if this is a new commit message (not amend, merge, etc) -if [ -z "$COMMIT_SOURCE" ]; then - COMMIT_MSG=$(cat "$COMMIT_MSG_FILE") - if [[ ! $COMMIT_MSG =~ ^$VERSION ]]; then - echo "$VERSION - $(cat $COMMIT_MSG_FILE)" > "$COMMIT_MSG_FILE" - fi -fi diff --git a/README.md b/README.md index 4cd4ee4..bc11b11 100644 --- a/README.md +++ b/README.md @@ -18,4 +18,4 @@ https://www.npmjs.com/package/@risc0/ui | Statements | Branches | Functions | Lines | | --------------------------- | ----------------------- | ------------------------- | ----------------- | -| ![Statements](https://img.shields.io/badge/statements-41.79%25-red.svg?style=flat) | ![Branches](https://img.shields.io/badge/branches-79.71%25-red.svg?style=flat) | ![Functions](https://img.shields.io/badge/functions-73.8%25-red.svg?style=flat) | ![Lines](https://img.shields.io/badge/lines-41.79%25-red.svg?style=flat) | +| ![Statements](https://img.shields.io/badge/statements-41.01%25-red.svg?style=flat) | ![Branches](https://img.shields.io/badge/branches-78.57%25-red.svg?style=flat) | ![Functions](https://img.shields.io/badge/functions-72.09%25-red.svg?style=flat) | ![Lines](https://img.shields.io/badge/lines-41.01%25-red.svg?style=flat) | diff --git a/commit.js b/commit.js new file mode 100644 index 0000000..a868990 --- /dev/null +++ b/commit.js @@ -0,0 +1,23 @@ +import { execSync } from "child_process"; +import { readFileSync } from "fs"; + +const packageJson = JSON.parse(readFileSync("./package.json", "utf8")); +const version = packageJson.version; + +// Get the commit message from command line arguments +const commitMessage = process.argv.slice(2).join(" "); + +if (!commitMessage) { + console.error("Please provide a commit message"); + process.exit(1); +} + +// Create the versioned commit message +const versionedMessage = `${version} - ${commitMessage}`; + +// Execute the git commit command +try { + execSync(`git commit -m "${versionedMessage}"`, { stdio: "inherit" }); +} catch (_error) { + process.exit(1); +} diff --git a/package.json b/package.json index 77e854f..3cc4c47 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@risc0/ui", - "version": "0.0.257", + "version": "0.0.258", "private": false, "sideEffects": false, "type": "module", @@ -9,6 +9,7 @@ "check:test": "vitest run --silent --coverage && istanbul-badges-readme", "check:types": "tsc", "check:version": "bunx changelogen --bump --no-output", + "commit": "node scripts/commit.js", "pre-commit": "run-p check:*", "prepare": "npx husky", "sort-package": "bunx sort-package-json 'package.json'",