commit-sheriff 1.1.1 → 1.3.0
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/README.md +78 -52
- package/bin/commit-sheriff.js +43 -9
- package/package.json +1 -31
- package/templates/commit-msg +8 -3
- package/templates/eslintrc.module-boundaries.js +16 -5
- package/templates/pre-commit +8 -3
package/README.md
CHANGED
|
@@ -20,7 +20,7 @@ npx commit-sheriff add-eslint-react # optional — TypeScript/React + module-b
|
|
|
20
20
|
- [What `init` does](#what-init-does)
|
|
21
21
|
- [Commit message format](#commit-message-format)
|
|
22
22
|
- [Branch name format](#branch-name-format)
|
|
23
|
-
- [Configuration (`
|
|
23
|
+
- [Configuration (`.commitsheriffrc.json`)](#configuration-commitsheriffrcjson)
|
|
24
24
|
- [`useModules`](#usemodules)
|
|
25
25
|
- [`project`](#project)
|
|
26
26
|
- [`modules`](#modules)
|
|
@@ -38,7 +38,7 @@ npx commit-sheriff add-eslint-react # optional — TypeScript/React + module-b
|
|
|
38
38
|
|
|
39
39
|
## Why
|
|
40
40
|
|
|
41
|
-
Different repos tend to drift into different commit-message and branch-naming conventions, which makes changelogs, ticket tracing, and code review harder. `commit-sheriff` gives every project the same two git hooks (`commit-msg`, `pre-commit`) driven by one small
|
|
41
|
+
Different repos tend to drift into different commit-message and branch-naming conventions, which makes changelogs, ticket tracing, and code review harder. `commit-sheriff` gives every project the same two git hooks (`commit-msg`, `pre-commit`) driven by one small root-level `.commitsheriffrc.json` config file, so:
|
|
42
42
|
|
|
43
43
|
- Every commit message references a ticket and a change type.
|
|
44
44
|
- Every branch name reflects the same ticket and change type.
|
|
@@ -74,11 +74,12 @@ Run this once per repo, from the repo root (where `package.json` lives). This wo
|
|
|
74
74
|
|
|
75
75
|
1. Initializes Husky if it isn't already set up (runs `npx husky init` when `.husky/_/husky.sh` is missing).
|
|
76
76
|
2. Copies the hook scripts into `.husky/commit-msg` and `.husky/pre-commit` (overwriting any existing files with those exact names) and makes them executable.
|
|
77
|
-
3.
|
|
77
|
+
3. Creates a default `.commitsheriffrc.json` file at the repo root **only if one doesn't already exist** (and only if there's no legacy `package.json` → `commitGuard` block either — see [Configuration](#configuration-commitsheriffrcjson)) — re-running `init` never overwrites your customized config.
|
|
78
78
|
4. Adds a default `lint-staged` block to `package.json` **only if one doesn't already exist**.
|
|
79
79
|
5. Adds a `"prepare": "husky"` npm script if missing, so hooks are (re)installed automatically after `npm install`.
|
|
80
|
+
6. If `react` and `typescript` are both present in your `dependencies`/`devDependencies`, also runs [`add-eslint-react`](#advanced-eslint-module-boundary-template-typescriptreact) automatically. Otherwise it's skipped and you can add it manually later.
|
|
80
81
|
|
|
81
|
-
Re-running `npx commit-sheriff init` later (e.g. after updating the package) is safe: it refreshes the two hook scripts to the latest version but leaves your `
|
|
82
|
+
Re-running `npx commit-sheriff init` later (e.g. after updating the package) is safe: it refreshes the two hook scripts to the latest version but leaves your `.commitsheriffrc.json` / `lint-staged` config alone.
|
|
82
83
|
|
|
83
84
|
## Commit message format
|
|
84
85
|
|
|
@@ -139,46 +140,48 @@ improvement/PRO-PROJ-609-correct-husky-pre-commit-validation # only with useMo
|
|
|
139
140
|
|
|
140
141
|
The check is skipped on a detached `HEAD` (e.g. mid-rebase, mid-cherry-pick), so it never blocks those operations.
|
|
141
142
|
|
|
142
|
-
## Configuration (`
|
|
143
|
+
## Configuration (`.commitsheriffrc.json`)
|
|
143
144
|
|
|
144
|
-
Add/edit this
|
|
145
|
+
Add/edit this file at your project's **root** (next to `package.json`) — the `init` command creates a default one for you:
|
|
145
146
|
|
|
146
147
|
```json
|
|
147
148
|
{
|
|
148
|
-
"
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
"
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
"
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
]
|
|
177
|
-
}
|
|
149
|
+
"useModules": false,
|
|
150
|
+
"project": "PROJ",
|
|
151
|
+
"branchTypes": [
|
|
152
|
+
"feature",
|
|
153
|
+
"bugfix",
|
|
154
|
+
"hotfix",
|
|
155
|
+
"improvement",
|
|
156
|
+
"refactor",
|
|
157
|
+
"release",
|
|
158
|
+
"chore",
|
|
159
|
+
"docs",
|
|
160
|
+
"test",
|
|
161
|
+
"spike"
|
|
162
|
+
],
|
|
163
|
+
"types": [
|
|
164
|
+
"feat",
|
|
165
|
+
"feature",
|
|
166
|
+
"fix",
|
|
167
|
+
"docs",
|
|
168
|
+
"style",
|
|
169
|
+
"refactor",
|
|
170
|
+
"test",
|
|
171
|
+
"chore",
|
|
172
|
+
"perf",
|
|
173
|
+
"ci",
|
|
174
|
+
"build",
|
|
175
|
+
"revert"
|
|
176
|
+
]
|
|
178
177
|
}
|
|
179
178
|
```
|
|
180
179
|
|
|
181
|
-
All keys are optional; anything you omit falls back to the default shown above.
|
|
180
|
+
All keys are optional; anything you omit falls back to the default shown above. Edit this file whenever you like — the hooks read it fresh on every commit, so changes take effect immediately, no reinstall or `init` re-run needed.
|
|
181
|
+
|
|
182
|
+
### Legacy `package.json` → `commitGuard` (backward compatibility)
|
|
183
|
+
|
|
184
|
+
Versions of `commit-sheriff` before this config-file change stored the same settings under a `commitGuard` key in `package.json` instead. That still works: if no `.commitsheriffrc.json` file exists, the hooks (and the `add-eslint-react` template) fall back to reading `package.json`'s `commitGuard` block automatically, so existing installs keep working without any changes required. New installs (and any project without an existing `commitGuard` block) get the new `.commitsheriffrc.json` file instead — this is the recommended location going forward. To migrate an existing project by hand, move the contents of `commitGuard` out into a new root-level `.commitsheriffrc.json` file and delete the `commitGuard` key from `package.json`.
|
|
182
185
|
|
|
183
186
|
### `useModules`
|
|
184
187
|
|
|
@@ -199,7 +202,7 @@ The project key used in the **branch name** check (`<type>/<PROJECT>-<NUMBER>-..
|
|
|
199
202
|
Only relevant when `useModules: true`. If you want to restrict commits/branches to a specific, known set of module codes, list them explicitly:
|
|
200
203
|
|
|
201
204
|
```json
|
|
202
|
-
|
|
205
|
+
{
|
|
203
206
|
"useModules": true,
|
|
204
207
|
"project": "PROJ",
|
|
205
208
|
"modules": ["AUTH", "BILLING", "REPORTS"]
|
|
@@ -261,11 +264,12 @@ This copies two templates into your repo root, **without overwriting** anything
|
|
|
261
264
|
testing-library/jest/vitest rules) with a module-boundary `no-restricted-imports` rule.
|
|
262
265
|
- `.prettierrc.js` — matching Prettier config.
|
|
263
266
|
|
|
264
|
-
The module list for the boundary rule isn't hardcoded — it's read straight from
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
267
|
+
The module list for the boundary rule isn't hardcoded — it's read straight from the `modules`
|
|
268
|
+
array in your root `.commitsheriffrc.json` (the same list the commit-msg/branch-name hooks use
|
|
269
|
+
for the `[MODULE]` tag), lowercased. For older installs still using `package.json`'s
|
|
270
|
+
`commitGuard.modules`, that's used as a fallback. If neither is set, a small illustrative default
|
|
271
|
+
(`auth`, `billing`, `reports`, `settings`) is used — open `.eslintrc.js` and replace it, or just
|
|
272
|
+
fill in `modules` in `.commitsheriffrc.json` and it picks it up automatically.
|
|
269
273
|
|
|
270
274
|
This template assumes a `src/app/<module>/...` folder layout with `<module>.public.ts` barrel
|
|
271
275
|
files; adjust the paths inside `.eslintrc.js` if your structure differs.
|
|
@@ -281,13 +285,24 @@ npm install --save-dev typescript @typescript-eslint/parser @typescript-eslint/e
|
|
|
281
285
|
|
|
282
286
|
## Examples
|
|
283
287
|
|
|
284
|
-
**Minimal project (no modules)
|
|
288
|
+
**Minimal project (no modules)** — `.commitsheriffrc.json`:
|
|
285
289
|
|
|
286
290
|
```json
|
|
287
|
-
|
|
291
|
+
{
|
|
288
292
|
"useModules": false,
|
|
289
293
|
"project": "PROJ",
|
|
290
|
-
"branchTypes": [
|
|
294
|
+
"branchTypes": [
|
|
295
|
+
"feature",
|
|
296
|
+
"bugfix",
|
|
297
|
+
"hotfix",
|
|
298
|
+
"improvement",
|
|
299
|
+
"refactor",
|
|
300
|
+
"release",
|
|
301
|
+
"chore",
|
|
302
|
+
"docs",
|
|
303
|
+
"test",
|
|
304
|
+
"spike"
|
|
305
|
+
],
|
|
291
306
|
"types": ["feat", "fix", "docs", "chore", "test"]
|
|
292
307
|
}
|
|
293
308
|
```
|
|
@@ -297,14 +312,25 @@ git checkout -b bugfix/PROJ-1093-fix-validation
|
|
|
297
312
|
git commit -m "(PROJ-1093) fix: correct validation on empty input"
|
|
298
313
|
```
|
|
299
314
|
|
|
300
|
-
**Project split into modules, with a locked list
|
|
315
|
+
**Project split into modules, with a locked list** — `.commitsheriffrc.json`:
|
|
301
316
|
|
|
302
317
|
```json
|
|
303
|
-
|
|
318
|
+
{
|
|
304
319
|
"useModules": true,
|
|
305
320
|
"project": "ACME",
|
|
306
321
|
"modules": ["AUTH", "BILLING", "REPORTS"],
|
|
307
|
-
"branchTypes": [
|
|
322
|
+
"branchTypes": [
|
|
323
|
+
"feature",
|
|
324
|
+
"bugfix",
|
|
325
|
+
"hotfix",
|
|
326
|
+
"improvement",
|
|
327
|
+
"refactor",
|
|
328
|
+
"release",
|
|
329
|
+
"chore",
|
|
330
|
+
"docs",
|
|
331
|
+
"test",
|
|
332
|
+
"spike"
|
|
333
|
+
],
|
|
308
334
|
"types": ["feat", "fix", "docs", "chore", "test"]
|
|
309
335
|
}
|
|
310
336
|
```
|
|
@@ -323,7 +349,7 @@ npm install commit-sheriff@latest --save-dev
|
|
|
323
349
|
npx commit-sheriff init
|
|
324
350
|
```
|
|
325
351
|
|
|
326
|
-
`npm install` updates the package; `npx commit-sheriff init` re-copies the (possibly changed) `.husky/commit-msg` and `.husky/pre-commit` scripts. It will **not** touch your existing `commitGuard` or `lint-staged` config
|
|
352
|
+
`npm install` updates the package; `npx commit-sheriff init` re-copies the (possibly changed) `.husky/commit-msg` and `.husky/pre-commit` scripts. It will **not** touch your existing `.commitsheriffrc.json` (or legacy `commitGuard` in `package.json`) or `lint-staged` config.
|
|
327
353
|
|
|
328
354
|
## Skipping / bypassing hooks
|
|
329
355
|
|
|
@@ -338,7 +364,7 @@ Merge, revert, `fixup!`, and `squash!` commits are already exempted from the com
|
|
|
338
364
|
## Troubleshooting
|
|
339
365
|
|
|
340
366
|
**"Could not load commitGuard config — is Node.js installed and is this running from the repo root?"**
|
|
341
|
-
The hook runs `node -e "..."` against `./package.json
|
|
367
|
+
The hook runs `node -e "..."` against `./.commitsheriffrc.json` (falling back to `./package.json`'s `commitGuard` block for older installs). Make sure Node.js is on your `PATH` and that you're committing from the repository root (or that your Git client runs hooks with the repo root as the working directory — some GUI clients get this wrong).
|
|
342
368
|
|
|
343
369
|
**A commit is accepted even though the message looks wrong**
|
|
344
370
|
Check which branch/tool you actually committed from — hooks only run for the local Git client that has Husky's `core.hooksPath` configured (`git config core.hooksPath` should print `.husky/_`). GUI clients or CI systems that bypass local hooks (or commit via the GitHub/GitLab API) will not trigger them.
|
|
@@ -347,7 +373,7 @@ Check which branch/tool you actually committed from — hooks only run for the l
|
|
|
347
373
|
Detached HEAD is exempt, but a normal new branch is checked immediately on first commit — rename it with `git branch -m <valid-name>` and try again.
|
|
348
374
|
|
|
349
375
|
**`useModules: true` but every module code is accepted**
|
|
350
|
-
That's expected if `
|
|
376
|
+
That's expected if `modules` is empty/omitted in `.commitsheriffrc.json` — see [`modules`](#modules). Add an explicit list to restrict it.
|
|
351
377
|
|
|
352
378
|
## Releasing this package
|
|
353
379
|
|
package/bin/commit-sheriff.js
CHANGED
|
@@ -43,6 +43,8 @@ const DEFAULT_LINT_STAGED = {
|
|
|
43
43
|
"*.{json,md,css,scss,html}": ["prettier --write"],
|
|
44
44
|
};
|
|
45
45
|
|
|
46
|
+
const CONFIG_FILE_NAME = ".commitsheriffrc.json";
|
|
47
|
+
|
|
46
48
|
function readPackageJson() {
|
|
47
49
|
const pkgPath = path.join(cwd, "package.json");
|
|
48
50
|
if (!fs.existsSync(pkgPath)) {
|
|
@@ -70,17 +72,31 @@ function copyHook(name) {
|
|
|
70
72
|
console.log(`✔ .husky/${name} yazıldı`);
|
|
71
73
|
}
|
|
72
74
|
|
|
75
|
+
function ensureConfigFile() {
|
|
76
|
+
const configPath = path.join(cwd, CONFIG_FILE_NAME);
|
|
77
|
+
const { pkg } = readPackageJson();
|
|
78
|
+
|
|
79
|
+
if (fs.existsSync(configPath)) {
|
|
80
|
+
console.log(`• ${CONFIG_FILE_NAME} artıq var, toxunulmadı`);
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
if (pkg.commitGuard) {
|
|
85
|
+
console.log(
|
|
86
|
+
`• package.json-da köhnə tərzli 'commitGuard' bloku tapıldı — ${CONFIG_FILE_NAME} yaradılmadı, köhnə konfiqurasiya işləməyə davam edir.`,
|
|
87
|
+
);
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
fs.writeFileSync(configPath, JSON.stringify(DEFAULT_COMMIT_GUARD, null, 2) + "\n");
|
|
92
|
+
console.log(`✔ ${CONFIG_FILE_NAME} yazıldı`);
|
|
93
|
+
}
|
|
94
|
+
|
|
73
95
|
function mergeConfig() {
|
|
74
96
|
const { pkgPath, pkg } = readPackageJson();
|
|
75
97
|
let changed = false;
|
|
76
98
|
|
|
77
|
-
|
|
78
|
-
pkg.commitGuard = DEFAULT_COMMIT_GUARD;
|
|
79
|
-
changed = true;
|
|
80
|
-
console.log("✔ package.json → commitGuard konfiqurasiyası əlavə olundu");
|
|
81
|
-
} else {
|
|
82
|
-
console.log("• package.json-da commitGuard artıq var, toxunulmadı");
|
|
83
|
-
}
|
|
99
|
+
ensureConfigFile();
|
|
84
100
|
|
|
85
101
|
if (!pkg["lint-staged"]) {
|
|
86
102
|
pkg["lint-staged"] = DEFAULT_LINT_STAGED;
|
|
@@ -101,13 +117,31 @@ function mergeConfig() {
|
|
|
101
117
|
}
|
|
102
118
|
}
|
|
103
119
|
|
|
120
|
+
function isReactTypescriptProject() {
|
|
121
|
+
const { pkg } = readPackageJson();
|
|
122
|
+
const deps = Object.assign({}, pkg.dependencies, pkg.devDependencies);
|
|
123
|
+
return Boolean(deps.react && deps.typescript);
|
|
124
|
+
}
|
|
125
|
+
|
|
104
126
|
function init() {
|
|
105
127
|
ensureHusky();
|
|
106
128
|
copyHook("commit-msg");
|
|
107
129
|
copyHook("pre-commit");
|
|
108
130
|
mergeConfig();
|
|
131
|
+
|
|
132
|
+
if (isReactTypescriptProject()) {
|
|
133
|
+
console.log(
|
|
134
|
+
"\n• react + typescript aşkarlandı → TS/React modul-sərhəd ESLint şablonu da əlavə olunur:",
|
|
135
|
+
);
|
|
136
|
+
addEslintReact();
|
|
137
|
+
} else {
|
|
138
|
+
console.log(
|
|
139
|
+
"\n(Layihə TS/React kimi aşkarlanmadı — istəsəniz `npx commit-sheriff add-eslint-react` ilə əlavə edə bilərsiniz.)",
|
|
140
|
+
);
|
|
141
|
+
}
|
|
142
|
+
|
|
109
143
|
console.log(
|
|
110
|
-
|
|
144
|
+
`\nHazırdır. ${CONFIG_FILE_NAME} faylında 'project' və lazım olsa 'modules' dəyərlərini tənzimləyin.\n`,
|
|
111
145
|
);
|
|
112
146
|
}
|
|
113
147
|
|
|
@@ -144,7 +178,7 @@ function addEslintReact() {
|
|
|
144
178
|
copyTemplateIfMissing("prettier.module-boundaries.js", ".prettierrc.js");
|
|
145
179
|
console.log(
|
|
146
180
|
"\nBu şablon TypeScript/React + modul-sərhəd (module-boundary) qaydaları üçündür.\n" +
|
|
147
|
-
|
|
181
|
+
`Modul siyahısı ${CONFIG_FILE_NAME}.modules-dən avtomatik oxunur (boşdursa nümunə\n` +
|
|
148
182
|
"siyahı istifadə olunur — .eslintrc.js içindəki şərhi oxuyun).\n\n" +
|
|
149
183
|
"Lazımi devDependencies (özünüz quraşdırın, layihənizin real versiyalarına uyğun):\n" +
|
|
150
184
|
` npm install --save-dev ${ESLINT_REACT_DEV_DEPS.join(" ")}\n`,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "commit-sheriff",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.0",
|
|
4
4
|
"description": "Shared husky commit-msg / pre-commit hooks enforcing ticket-based commit messages and branch naming",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"bin": {
|
|
@@ -50,35 +50,5 @@
|
|
|
50
50
|
"*.{json,md,css,scss,html}": [
|
|
51
51
|
"prettier --write"
|
|
52
52
|
]
|
|
53
|
-
},
|
|
54
|
-
"commitGuard": {
|
|
55
|
-
"useModules": false,
|
|
56
|
-
"project": "PROJ",
|
|
57
|
-
"branchTypes": [
|
|
58
|
-
"feature",
|
|
59
|
-
"bugfix",
|
|
60
|
-
"hotfix",
|
|
61
|
-
"improvement",
|
|
62
|
-
"refactor",
|
|
63
|
-
"release",
|
|
64
|
-
"chore",
|
|
65
|
-
"docs",
|
|
66
|
-
"test",
|
|
67
|
-
"spike"
|
|
68
|
-
],
|
|
69
|
-
"types": [
|
|
70
|
-
"feat",
|
|
71
|
-
"feature",
|
|
72
|
-
"fix",
|
|
73
|
-
"docs",
|
|
74
|
-
"style",
|
|
75
|
-
"refactor",
|
|
76
|
-
"test",
|
|
77
|
-
"chore",
|
|
78
|
-
"perf",
|
|
79
|
-
"ci",
|
|
80
|
-
"build",
|
|
81
|
-
"revert"
|
|
82
|
-
]
|
|
83
53
|
}
|
|
84
54
|
}
|
package/templates/commit-msg
CHANGED
|
@@ -8,12 +8,17 @@ case "$commit_msg" in
|
|
|
8
8
|
;;
|
|
9
9
|
esac
|
|
10
10
|
|
|
11
|
-
# ── Load config
|
|
12
|
-
#
|
|
11
|
+
# ── Load config: .commitsheriffrc.json at repo root (falls back to package.json → "commitGuard"
|
|
12
|
+
# ── for older installs, then to sane defaults) ──────────────────────────────
|
|
13
|
+
# .commitsheriffrc.json: { "useModules": true, "modules": [...], "types": [...] }
|
|
13
14
|
eval "$(node -e "
|
|
14
15
|
const fs = require('fs');
|
|
15
16
|
let cfg = {};
|
|
16
|
-
try {
|
|
17
|
+
try {
|
|
18
|
+
cfg = JSON.parse(fs.readFileSync('.commitsheriffrc.json', 'utf8'));
|
|
19
|
+
} catch (e) {
|
|
20
|
+
try { cfg = (JSON.parse(fs.readFileSync('package.json', 'utf8')).commitGuard) || {}; } catch (e2) {}
|
|
21
|
+
}
|
|
17
22
|
const useModules = cfg.useModules !== undefined ? cfg.useModules : true;
|
|
18
23
|
const modules = (cfg.modules && cfg.modules.length ? cfg.modules.join('|') : '[A-Z]+');
|
|
19
24
|
const types = (cfg.types || ['feat','feature','fix','docs','style','refactor','test','chore','perf','ci','build','revert']).join('|');
|
|
@@ -16,17 +16,28 @@
|
|
|
16
16
|
* are the one place allowed to import every module directly (that's the whole point of a
|
|
17
17
|
* router/registry), so the boundary rule is turned off just for those two files.
|
|
18
18
|
*
|
|
19
|
-
* Module list: instead of hardcoding module names, this reads `
|
|
20
|
-
*
|
|
21
|
-
* README), so the two conventions (module tags in commits/branches, and module
|
|
22
|
-
* imports) stay in sync automatically.
|
|
23
|
-
*
|
|
19
|
+
* Module list: instead of hardcoding module names, this reads `modules` from the repo's
|
|
20
|
+
* `.commitsheriffrc.json` (the same list used by the commit-sheriff commit-msg/branch-name
|
|
21
|
+
* hooks — see README), so the two conventions (module tags in commits/branches, and module
|
|
22
|
+
* boundaries in imports) stay in sync automatically. For older installs that still keep their
|
|
23
|
+
* config under `package.json`'s `commitGuard` block, that location is used as a fallback. If
|
|
24
|
+
* neither is found, a small illustrative default is used instead — replace it with your real
|
|
25
|
+
* module names.
|
|
24
26
|
*/
|
|
25
27
|
|
|
26
28
|
const fs = require("fs");
|
|
27
29
|
const path = require("path");
|
|
28
30
|
|
|
29
31
|
function loadAppModules() {
|
|
32
|
+
try {
|
|
33
|
+
const rcPath = path.join(__dirname, ".commitsheriffrc.json");
|
|
34
|
+
const rc = JSON.parse(fs.readFileSync(rcPath, "utf8"));
|
|
35
|
+
if (Array.isArray(rc.modules) && rc.modules.length) {
|
|
36
|
+
return rc.modules.map((m) => String(m).toLowerCase());
|
|
37
|
+
}
|
|
38
|
+
} catch {
|
|
39
|
+
// fall through to the legacy package.json lookup below
|
|
40
|
+
}
|
|
30
41
|
try {
|
|
31
42
|
const pkgPath = path.join(__dirname, "package.json");
|
|
32
43
|
const pkg = JSON.parse(fs.readFileSync(pkgPath, "utf8"));
|
package/templates/pre-commit
CHANGED
|
@@ -1,11 +1,16 @@
|
|
|
1
1
|
local_branch="$(git rev-parse --abbrev-ref HEAD 2>/dev/null)" || true
|
|
2
2
|
|
|
3
|
-
# ── Load config
|
|
4
|
-
#
|
|
3
|
+
# ── Load config: .commitsheriffrc.json at repo root (falls back to package.json → "commitGuard"
|
|
4
|
+
# ── for older installs, then to sane defaults) ──────────────────────────────
|
|
5
|
+
# .commitsheriffrc.json: { "useModules": true, "project": "PROJ", "modules": [...], "branchTypes": [...] }
|
|
5
6
|
eval "$(node -e "
|
|
6
7
|
const fs = require('fs');
|
|
7
8
|
let cfg = {};
|
|
8
|
-
try {
|
|
9
|
+
try {
|
|
10
|
+
cfg = JSON.parse(fs.readFileSync('.commitsheriffrc.json', 'utf8'));
|
|
11
|
+
} catch (e) {
|
|
12
|
+
try { cfg = (JSON.parse(fs.readFileSync('package.json', 'utf8')).commitGuard) || {}; } catch (e2) {}
|
|
13
|
+
}
|
|
9
14
|
const useModules = cfg.useModules !== undefined ? cfg.useModules : true;
|
|
10
15
|
const project = cfg.project || 'PROJ';
|
|
11
16
|
const modules = (cfg.modules && cfg.modules.length ? cfg.modules.join('|') : '[A-Z]+');
|