Skip to content

Commit 19cdd56

Browse files
committed
add git hooks to check json
1 parent 1cbcecc commit 19cdd56

4 files changed

Lines changed: 38 additions & 1 deletion

File tree

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,9 @@
328328
"generate:icons": "node ./build/generateIcons.js",
329329
"generate:changelog": "node ./build/generateChangelog.js",
330330
"json:check": "prettier --ignore-path .prettierignore --check \"./**/*.json\"",
331-
"json:write": "prettier --ignore-path .prettierignore --write \"./**/*.json\""
331+
"json:write": "prettier --ignore-path .prettierignore --write \"./**/*.json\"",
332+
"preinstall": "npm run githooks:setup",
333+
"githooks:setup": "node ./utility/githooks/setup.js"
332334
},
333335
"author": "GeoSolutions",
334336
"license": "BSD-2-Clause"

utility/githooks/pre-commit

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/bin/sh
2+
3+
node ./utility/githooks/pre-commit.js

utility/githooks/pre-commit.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
2+
const { execSync } = require('child_process');
3+
4+
try {
5+
execSync('npm run json:check');
6+
} catch (e) {
7+
throw new Error(`
8+
9+
#################################
10+
11+
Error: json file not formatted correctly, please run:
12+
13+
14+
npm run json:write
15+
16+
17+
and then commit
18+
19+
#################################
20+
21+
`);
22+
}

utility/githooks/setup.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
2+
const fs = require('fs');
3+
const path = require('path');
4+
5+
['pre-commit'].forEach((githook) => {
6+
fs.copyFileSync(
7+
path.join(__dirname, githook),
8+
path.join(__dirname, '..', '..', '.git', 'hooks', githook)
9+
);
10+
});

0 commit comments

Comments
 (0)