forked from openedshippingcontainer/euc-frontend
-
Notifications
You must be signed in to change notification settings - Fork 0
/
husky.config.js
executable file
·40 lines (33 loc) · 1.03 KB
/
husky.config.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
// eslint-disable-next-line @typescript-eslint/no-var-requires
const PackageJSON = require("./package.json");
const GetUpdateCommand = (version) => (
`npm --no-git-tag-version version ${version}`
);
const UpdatePackageVersion = () => {
// Major.Minor.Patch
const version = PackageJSON.version.split(".");
if (version.length !== 3)
throw "package.json property \"version\" must be in Major.Minor.Patch format";
const patch = +version.pop();
if (patch === undefined || isNaN(patch))
return GetUpdateCommand("patch");
const minor = +version.pop();
if (minor === undefined || isNaN(minor))
return GetUpdateCommand("minor");
// Update major if minor is >= 10
// Update minor if patch is >= 10
// Otherwise update patch
return GetUpdateCommand(
minor >= 10 ? "major" : (patch >= 10 ? "minor" : "patch")
);
}
const AsTask = (arr) => arr.join(" && ");
module.exports = {
"hooks": {
"pre-commit": AsTask([
"echo \"Updating package version\"",
UpdatePackageVersion(),
"git add ."
])
}
}