Skip to content

Commit 6d03c27

Browse files
Switch to commit-msg hook (#5)
* Remove check command, switch to using changelog dir, use MIT license (#4) * Remove check command, switch to using changelog dir, use MIT license * Fix dependencies * Update readme * Include changelog in source control * Rename changelog directory * Changelog * Fixes * Fixes * Switch to commit-msg hook
1 parent 266fdcd commit 6d03c27

File tree

8 files changed

+19
-77
lines changed

8 files changed

+19
-77
lines changed

.changelog/01.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
breaking
2-
Fixes
2+
Switch to commit-msg hook

.husky/commit-msg

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
exec < /dev/tty
2+
if node bin/heeler.js add $(cat $1); then
3+
git add .changelog
4+
git commit --amend --no-edit --no-verify
5+
fi

.husky/pre-commit

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1 @@
1-
exec < /dev/tty
2-
node bin/heeler.js add
31
pnpm exec pretty-quick --staged

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ pnpm i --save-dev heeler husky
99

1010
pnpm exec husky
1111

12-
echo "pnpm exec heeler add" > .husky/pre-commit
12+
echo -e "exec < /dev/tty\nif node bin/heeler.js add \$(cat \$1); then\n git add .changelog\n git commit --amend --no-edit --no-verify\nfi" > .husky/commit-msg
1313
```
1414

1515
## Usage

bin/heeler.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { select } from "@inquirer/prompts";
1+
import { select, input } from "@inquirer/prompts";
22
import { addToChangelog, prepareRelease } from "../src/changelog-utils.js";
33

44
if (process.argv.length < 3) {
@@ -31,9 +31,16 @@ switch (command) {
3131
],
3232
});
3333

34-
if (answer !== "skip") {
35-
addToChangelog(answer);
34+
if (answer === "skip") {
35+
process.exit(1);
3636
}
37+
38+
let message = process.argv[3];
39+
if (!message) {
40+
message = await input({ message: "Changelog message" });
41+
}
42+
43+
addToChangelog(answer, message);
3744
break;
3845
case "prep":
3946
prepareRelease();

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@
1414
"license": "MIT",
1515
"packageManager": "pnpm@10.13.1",
1616
"dependencies": {
17-
"@inquirer/prompts": "^7.8.0",
18-
"simple-git": "^3.28.0"
17+
"@inquirer/prompts": "^7.8.0"
1918
},
2019
"devDependencies": {
2120
"husky": "^9.1.7",

pnpm-lock.yaml

Lines changed: 0 additions & 61 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/changelog-utils.js

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import fs from "node:fs";
22
import path from "node:path";
33
import semver from "semver";
4-
import simpleGit from "simple-git";
54

65
export async function addToChangelog(changeType) {
76
const changelogPath = path.resolve(process.cwd(), "./.changelog");
@@ -14,19 +13,14 @@ export async function addToChangelog(changeType) {
1413
existingFiles = [];
1514
}
1615

17-
const git = simpleGit();
18-
const mostRecentLog = await git.log({ maxCount: 1 });
19-
2016
fs.writeFileSync(
2117
path.resolve(
2218
process.cwd(),
2319
`./.changelog/${existingFiles.length < 10 ? "0" : ""}${existingFiles.length + 1}.txt`,
2420
),
25-
`${changeType}\n${mostRecentLog.latest.message}`,
21+
`${changeType}\n${message}`,
2622
"utf-8",
2723
);
28-
29-
git.add(".changelog");
3024
}
3125

3226
export async function prepareRelease() {

0 commit comments

Comments
 (0)