@modernpoacher/nunjucks 3.0.76 → 3.0.80

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.
@@ -0,0 +1,4 @@
1
+ #!/bin/sh
2
+ . "$(dirname "$0")/_/husky.sh"
3
+
4
+ npm run post-commit
package/.husky/pre-commit CHANGED
@@ -1,4 +1,4 @@
1
1
  #!/bin/sh
2
2
  . "$(dirname "$0")/_/husky.sh"
3
3
 
4
- npm run pre-commit
4
+ npm run pre-commit
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@modernpoacher/nunjucks",
3
- "version": "3.0.76",
3
+ "version": "3.0.80",
4
4
  "description": "Nunjucks for Hapi",
5
5
  "keywords": [
6
6
  "hapi",
@@ -19,7 +19,8 @@
19
19
  "lint": "eslint .",
20
20
  "lint:fix": "npm run lint -- --fix",
21
21
  "gulp": "gulp --color",
22
- "pre-commit": "npm run lint && git add *.js && npm run gulp -- pre-commit"
22
+ "pre-commit": "npm run lint && git add *.js",
23
+ "post-commit": "cross-env DEBUG=@modernpoacher/hooks,@modernpoacher/hooks:* npm run gulp -- post-commit"
23
24
  },
24
25
  "dependencies": {
25
26
  "debug": "^4.3.3"
@@ -30,6 +31,7 @@
30
31
  "@babel/eslint-parser": "^7.16.5",
31
32
  "@babel/preset-env": "^7.16.7",
32
33
  "@babel/register": "^7.16.7",
34
+ "@modernpoacher/hooks": "^1.0.0",
33
35
  "babel-loader": "^8.2.3",
34
36
  "core-js": "^3.20.2",
35
37
  "eslint": "7.32.0",
@@ -1,78 +0,0 @@
1
- import debug from 'debug'
2
-
3
- import {
4
- exec
5
- } from 'child_process'
6
-
7
- const log = debug('@modernpoacher/nunjucks:build:gulp:pre-commit')
8
-
9
- log('`@modernpoacher/nunjucks` is awake')
10
-
11
- const PACKAGE_VERSION_CHANGES = /-+\s+"version":\s"(\d+\.\d+\.\d+)",\s+\++\s+"version":\s"(\d+\.\d+\.\d+)",\s+/s
12
-
13
- const HAS_STAGED_CHANGES = /Changes to be committed/s
14
-
15
- const NOT_STAGED_CHANGES = /Changes not staged for commit/s
16
-
17
- const OPTIONS = {
18
- maxBuffer: 1024 * 500
19
- }
20
-
21
- export const hasPackageVersionChanges = () => (
22
- new Promise((resolve, reject) => {
23
- exec('git diff HEAD origin/master package.json', OPTIONS, (e, v) => (!e) ? resolve(PACKAGE_VERSION_CHANGES.test(v)) : reject(e))
24
- })
25
- )
26
-
27
- export const notPackageVersionChanges = () => (
28
- new Promise((resolve, reject) => {
29
- exec('git diff HEAD origin/master package.json', OPTIONS, (e, v) => (!e) ? resolve(PACKAGE_VERSION_CHANGES.test(v) !== true) : reject(e))
30
- })
31
- )
32
-
33
- export const hasStagedChanges = () => (
34
- new Promise((resolve, reject) => {
35
- exec('git status', OPTIONS, (e, v) => (!e) ? resolve(HAS_STAGED_CHANGES.test(v)) : reject(e))
36
- })
37
- )
38
-
39
- export const notStagedChanges = () => (
40
- new Promise((resolve, reject) => {
41
- exec('git status', OPTIONS, (e, v) => (!e) ? resolve(NOT_STAGED_CHANGES.test(v)) : reject(e))
42
- })
43
- )
44
-
45
- export const notPushedChanges = () => (
46
- new Promise((resolve, reject) => {
47
- exec('git log origin/master..HEAD', OPTIONS, (e, v) => (!e) ? resolve(!!v) : reject(e))
48
- })
49
- )
50
-
51
- export const patchPackageVersion = () => (
52
- new Promise((resolve, reject) => {
53
- exec('npm version patch -m %s -n --no-git-tag-version --no-verify', OPTIONS, (e) => (!e) ? resolve() : reject(e))
54
- })
55
- )
56
-
57
- export const addPackageVersionChanges = () => (
58
- new Promise((resolve, reject) => {
59
- exec('git add package.json package-lock.json', OPTIONS, (e) => (!e) ? resolve() : reject(e))
60
- })
61
- )
62
-
63
- export default async function preCommit () {
64
- log('pre-commit')
65
-
66
- try {
67
- if (await notStagedChanges()) return
68
-
69
- if (await hasStagedChanges()) {
70
- if (await notPackageVersionChanges()) {
71
- await patchPackageVersion()
72
- await addPackageVersionChanges()
73
- }
74
- }
75
- } catch ({ code = 'NONE', message = 'No error message defined' }) {
76
- log({ code, message })
77
- }
78
- }