@rachel_rotenberg/ai-contribution-tracker 1.0.22 → 1.0.23
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.
- package/cli.js +16 -11
- package/package.json +1 -1
package/cli.js
CHANGED
|
@@ -21,6 +21,12 @@ const { execSync, execFileSync } = require("child_process");
|
|
|
21
21
|
const PLUGIN_NAME = "@rachel_rotenberg/ai-contribution-tracker";
|
|
22
22
|
const HOOK_BEGIN = "# BEGIN ai-contribution-tracker-cli";
|
|
23
23
|
const HOOK_END = "# END ai-contribution-tracker-cli";
|
|
24
|
+
const HOOK_DELEGATION = [
|
|
25
|
+
'LOCAL_HOOK="$(git rev-parse --git-dir)/hooks/commit-msg"',
|
|
26
|
+
'if [ -f "$LOCAL_HOOK" ] && [ -x "$LOCAL_HOOK" ]; then',
|
|
27
|
+
' "$LOCAL_HOOK" "$@" || exit $?',
|
|
28
|
+
'fi',
|
|
29
|
+
].join("\n");
|
|
24
30
|
|
|
25
31
|
// ─── Logging helpers ────────────────────────────────────────
|
|
26
32
|
function ok(msg) { console.log(` \u2713 ${msg}`); }
|
|
@@ -55,23 +61,22 @@ function appendOrCreateHook(hooksDir) {
|
|
|
55
61
|
const hookPath = path.join(hooksDir, "commit-msg");
|
|
56
62
|
|
|
57
63
|
if (fs.existsSync(hookPath)) {
|
|
58
|
-
|
|
64
|
+
let existing = fs.readFileSync(hookPath, "utf8");
|
|
59
65
|
if (existing.includes(HOOK_BEGIN)) {
|
|
60
|
-
|
|
66
|
+
if (!existing.includes(HOOK_DELEGATION.split("\n")[0])) {
|
|
67
|
+
const firstLine = existing.split("\n")[0];
|
|
68
|
+
existing = firstLine + "\n" + HOOK_DELEGATION + "\n" + existing.split("\n").slice(1).join("\n");
|
|
69
|
+
fs.writeFileSync(hookPath, existing.replace(/\r\n/g, "\n"));
|
|
70
|
+
ok(`Added local hook delegation to: ${hookPath}`);
|
|
71
|
+
} else {
|
|
72
|
+
skip(`commit-msg hook already up to date: ${hookPath}`);
|
|
73
|
+
}
|
|
61
74
|
return;
|
|
62
75
|
}
|
|
63
76
|
fs.appendFileSync(hookPath, "\n" + HOOK_BODY + "\n");
|
|
64
77
|
ok(`Appended AI tracker snippet to existing hook: ${hookPath}`);
|
|
65
78
|
} else {
|
|
66
|
-
const
|
|
67
|
-
"#!/bin/sh",
|
|
68
|
-
'LOCAL_HOOK="$(git rev-parse --git-dir)/hooks/commit-msg"',
|
|
69
|
-
'if [ -f "$LOCAL_HOOK" ] && [ -x "$LOCAL_HOOK" ]; then',
|
|
70
|
-
' "$LOCAL_HOOK" "$@" || exit $?',
|
|
71
|
-
'fi',
|
|
72
|
-
"",
|
|
73
|
-
].join("\n");
|
|
74
|
-
const content = (delegation + HOOK_BODY + "\n").replace(/\r\n/g, "\n");
|
|
79
|
+
const content = ("#!/bin/sh\n" + HOOK_DELEGATION + "\n\n" + HOOK_BODY + "\n").replace(/\r\n/g, "\n");
|
|
75
80
|
fs.writeFileSync(hookPath, content);
|
|
76
81
|
ok(`Created commit-msg hook: ${hookPath}`);
|
|
77
82
|
}
|
package/package.json
CHANGED