@sequencemedia/hooks 1.0.0 → 1.0.8

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,56 @@
1
+ version: 2.1
2
+
3
+ jobs:
4
+ publish:
5
+ docker:
6
+ - image: circleci/node:lts
7
+ steps:
8
+ - checkout
9
+ - run:
10
+ name: Publish to NPM
11
+ command: |
12
+ echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" > ~/.npmrc
13
+
14
+ PATTERN="([0-9]+)\.([0-9]+)\.([0-9]+)"
15
+ NAME=$(node -p "require('./package').name")
16
+ VERSION=$(node -p "require('./package').version")
17
+ PUBLISHED_VERSION=$(npm view $NAME version)
18
+
19
+ echo Version is $VERSION
20
+ echo Published version is $PUBLISHED_VERSION
21
+
22
+ [[ $VERSION =~ $PATTERN ]]
23
+
24
+ VERSION_MAJOR="${BASH_REMATCH[1]}"
25
+ VERSION_MINOR="${BASH_REMATCH[2]}"
26
+ VERSION_PATCH="${BASH_REMATCH[3]}"
27
+
28
+ [[ $PUBLISHED_VERSION =~ $PATTERN ]]
29
+
30
+ PUBLISHED_VERSION_MAJOR="${BASH_REMATCH[1]}"
31
+ PUBLISHED_VERSION_MINOR="${BASH_REMATCH[2]}"
32
+ PUBLISHED_VERSION_PATCH="${BASH_REMATCH[3]}"
33
+
34
+ if [ $VERSION_MAJOR -gt $PUBLISHED_VERSION_MAJOR ] || [ $VERSION_MINOR -gt $PUBLISHED_VERSION_MINOR ] || [ $VERSION_PATCH -gt $PUBLISHED_VERSION_PATCH ]
35
+ then
36
+ set +e
37
+
38
+ npm ci
39
+ npm publish
40
+
41
+ if [[ $? != 0 ]];
42
+ then
43
+ echo Version $VERSION was not published
44
+ else
45
+ echo Published version $VERSION
46
+ fi
47
+ fi
48
+
49
+ workflows:
50
+ version: 2
51
+ commit-workflow:
52
+ jobs:
53
+ - publish:
54
+ filters:
55
+ tags:
56
+ only: /^v.*/
package/.editorconfig ADDED
@@ -0,0 +1,16 @@
1
+ # EditorConfig is awesome: https://EditorConfig.org
2
+
3
+ # top-most EditorConfig file
4
+ root = true
5
+
6
+ # Unix-style newlines with a newline ending every file
7
+ [*.{js}]
8
+ end_of_line = lf
9
+ insert_final_newline = true
10
+
11
+ # Set default charset
12
+ charset = utf-8
13
+
14
+ # 2 space indentation
15
+ indent_style = space
16
+ indent_size = 2
package/.eslintignore ADDED
@@ -0,0 +1,4 @@
1
+ .circleci
2
+ .github
3
+ .husky
4
+ node_modules
package/.eslintrc ADDED
@@ -0,0 +1,13 @@
1
+ {
2
+ "root": true,
3
+ "extends": "standard",
4
+ "env": {
5
+ "node": true,
6
+ "es2020": true
7
+ },
8
+ "parser": "@babel/eslint-parser",
9
+ "parserOptions": {
10
+ "ecmaVersion": 2020,
11
+ "sourceType": "module"
12
+ }
13
+ }
@@ -0,0 +1,9 @@
1
+ version: 2
2
+
3
+ updates:
4
+ - package-ecosystem: "npm"
5
+ directory: "/"
6
+ schedule:
7
+ interval: "daily"
8
+ reviewers:
9
+ - sequencemedialimited
@@ -0,0 +1,4 @@
1
+ #!/bin/sh
2
+ . "$(dirname "$0")/_/husky.sh"
3
+
4
+ npm run post-commit
@@ -0,0 +1,4 @@
1
+ #!/bin/sh
2
+ . "$(dirname "$0")/_/husky.sh"
3
+
4
+ npm run pre-commit
package/babel.config.cjs CHANGED
@@ -1,21 +1,21 @@
1
- const presets = [
2
- [
3
- '@babel/env',
4
- {
5
- targets: {
6
- node: 'current'
7
- },
8
- useBuiltIns: 'usage',
9
- corejs: 3
10
- }
11
- ]
12
- ]
13
-
14
- const plugins = []
15
-
16
- module.exports = {
17
- compact: true,
18
- comments: false,
19
- presets,
20
- plugins
21
- }
1
+ const presets = [
2
+ [
3
+ '@babel/env',
4
+ {
5
+ targets: {
6
+ node: 'current'
7
+ },
8
+ useBuiltIns: 'usage',
9
+ corejs: 3
10
+ }
11
+ ]
12
+ ]
13
+
14
+ const plugins = []
15
+
16
+ module.exports = {
17
+ compact: true,
18
+ comments: false,
19
+ presets,
20
+ plugins
21
+ }
package/gulpfile.mjs ADDED
@@ -0,0 +1,9 @@
1
+ import gulp from 'gulp'
2
+
3
+ import postCommit from '#hooks/post-commit'
4
+
5
+ gulp
6
+ .task('post-commit', postCommit)
7
+
8
+ gulp
9
+ .task('default', gulp.series('post-commit'))
package/package.json CHANGED
@@ -1,52 +1,52 @@
1
- {
2
- "name": "@sequencemedia/hooks",
3
- "version": "1.0.0",
4
- "description": "Git Hooks",
5
- "keywords": [
6
- "git",
7
- "hooks"
8
- ],
9
- "main": "./index.mjs",
10
- "author": "Jonathan Perry for Sequence Media Limited <sequencemedia@sequencemedia.net>",
11
- "license": "MIT",
12
- "engines": {
13
- "node": ">=16.13.0"
14
- },
15
- "repository": {
16
- "type": "git",
17
- "url": "git://github.com/sequencemedia/hooks"
18
- },
19
- "homepage": "https://github.com/sequencemedia/hooks",
20
- "bugs": {
21
- "url": "https://github.com/sequencemedia/hooks/issues"
22
- },
23
- "scripts": {
24
- "lint": "eslint . --ext .mjs --ext .cjs",
25
- "lint:fix": "npm run lint -- --fix",
26
- "gulp": "gulp --color",
27
- "pre-commit": "npm run lint",
28
- "post-commit": "cross-env DEBUG=@sequencemedia/hooks,@sequencemedia/hooks:* npm run gulp -- post-commit",
29
- "prepare": "husky install"
30
- },
31
- "dependencies": {
32
- "cross-env": "^7.0.3",
33
- "debug": "^4.3.3"
34
- },
35
- "devDependencies": {
36
- "@babel/cli": "^7.16.0",
37
- "@babel/core": "^7.16.5",
38
- "@babel/eslint-parser": "^7.16.5",
39
- "@babel/preset-env": "^7.16.5",
40
- "core-js": "^3.20.1",
41
- "eslint": "7.32.0",
42
- "eslint-config-standard": "^16.0.3",
43
- "eslint-plugin-import": "^2.25.3",
44
- "eslint-plugin-node": "^11.1.0",
45
- "eslint-plugin-promise": "5.2.0",
46
- "gulp": "^4.0.2",
47
- "husky": "^7.0.4"
48
- },
49
- "imports": {
50
- "#hooks/*": "./src/*.mjs"
51
- }
52
- }
1
+ {
2
+ "name": "@sequencemedia/hooks",
3
+ "version": "1.0.8",
4
+ "description": "Git Hooks",
5
+ "keywords": [
6
+ "git",
7
+ "hooks"
8
+ ],
9
+ "main": "./index.mjs",
10
+ "author": "Jonathan Perry for Sequence Media Limited <sequencemedia@sequencemedia.net>",
11
+ "license": "MIT",
12
+ "engines": {
13
+ "node": ">=16.13.0"
14
+ },
15
+ "repository": {
16
+ "type": "git",
17
+ "url": "git://github.com/sequencemedia/hooks"
18
+ },
19
+ "homepage": "https://github.com/sequencemedia/hooks",
20
+ "bugs": {
21
+ "url": "https://github.com/sequencemedia/hooks/issues"
22
+ },
23
+ "scripts": {
24
+ "lint": "eslint . --ext .mjs --ext .cjs",
25
+ "lint:fix": "npm run lint -- --fix",
26
+ "gulp": "gulp --color",
27
+ "pre-commit": "npm run lint",
28
+ "post-commit": "cross-env DEBUG=@sequencemedia/hooks,@sequencemedia/hooks:* npm run gulp -- post-commit",
29
+ "prepare": "husky install"
30
+ },
31
+ "dependencies": {
32
+ "cross-env": "^7.0.3",
33
+ "debug": "^4.3.3"
34
+ },
35
+ "devDependencies": {
36
+ "@babel/cli": "^7.16.7",
37
+ "@babel/core": "^7.16.7",
38
+ "@babel/eslint-parser": "^7.16.5",
39
+ "@babel/preset-env": "^7.16.7",
40
+ "core-js": "^3.20.2",
41
+ "eslint": "7.32.0",
42
+ "eslint-config-standard": "^16.0.3",
43
+ "eslint-plugin-import": "^2.25.4",
44
+ "eslint-plugin-node": "^11.1.0",
45
+ "eslint-plugin-promise": "5.2.0",
46
+ "gulp": "^4.0.2",
47
+ "husky": "^7.0.4"
48
+ },
49
+ "imports": {
50
+ "#hooks/*": "./src/*.mjs"
51
+ }
52
+ }
package/src/common.mjs CHANGED
@@ -1,119 +1,119 @@
1
- import debug from 'debug'
2
-
3
- import {
4
- exec
5
- } from 'child_process'
6
-
7
- const log = debug('@sequencemedia/hooks:common')
8
-
9
- log('`@sequencemedia/hooks` is awake')
10
-
11
- export const OPTIONS = {
12
- maxBuffer: 1024 * 500
13
- }
14
-
15
- export const BRANCH = 'master'
16
-
17
- export const PACKAGE_VERSION_CHANGES = /\-+\s+"version":\s+"(\d+\.\d+\.\d+)",+\s+\++\s+"version":\s+"(\d+\.\d+\.\d+)",+\s+/ /* eslint-disable-line no-useless-escape */
18
-
19
- export const HAS_STAGED_CHANGES = /Changes to be committed/s
20
-
21
- export const NOT_STAGED_CHANGES = /Changes not staged for commit/s
22
-
23
- export const trim = (v = '') => String(v).split('\n').map((v) => v.trimEnd()).join('\n').trim()
24
-
25
- export function use (key) {
26
- const log = debug(`@sequencemedia/hooks:${key}`)
27
-
28
- return function use (v) {
29
- log(trim(v))
30
- }
31
- }
32
-
33
- export function getGitRemoteShowOriginHeadBranch () {
34
- log('getGitRemoteShowOriginHeadBranch')
35
-
36
- return (
37
- new Promise((resolve, reject) => {
38
- const command = 'git remote show origin | awk \'/HEAD branch/ {print $NF}\''
39
-
40
- const {
41
- stdout,
42
- stderr
43
- } = exec(command, OPTIONS, (e, v) => (!e) ? resolve(trim(v)) : reject(e))
44
-
45
- stdout.on('data', use('git-remote-show-origin-head-branch'))
46
- stderr.on('data', use('git-remote-show-origin-head-branch'))
47
- })
48
- )
49
- }
50
-
51
- export function hasGitDiffHeadPackageVersionChanges (branch = BRANCH) {
52
- log('hasGitDiffHeadPackageVersionChanges')
53
-
54
- return (
55
- new Promise((resolve, reject) => {
56
- exec(`git diff HEAD~1..HEAD~0 -- origin/${branch} package.json`, OPTIONS, async (e, v) => (!e) ? resolve(PACKAGE_VERSION_CHANGES.test(v) === true) : reject(e))
57
- })
58
- )
59
- }
60
-
61
- export function notGitDiffHeadPackageVersionChanges (branch = BRANCH) {
62
- log('notGitDiffHeadPackageVersionChanges')
63
-
64
- return (
65
- new Promise((resolve, reject) => {
66
- exec(`git diff HEAD~1..HEAD~0 -- origin/${branch} package.json`, OPTIONS, async (e, v) => (!e) ? resolve(PACKAGE_VERSION_CHANGES.test(v) !== true) : reject(e))
67
- })
68
- )
69
- }
70
-
71
- export function hasStagedChanges () {
72
- log('hasStagedChanges')
73
-
74
- return (
75
- new Promise((resolve, reject) => {
76
- exec('git status', OPTIONS, (e, v) => (!e) ? resolve(HAS_STAGED_CHANGES.test(v)) : reject(e))
77
- })
78
- )
79
- }
80
-
81
- export function notStagedChanges () {
82
- log('notStagedChanges')
83
-
84
- return (
85
- new Promise((resolve, reject) => {
86
- exec('git status', OPTIONS, (e, v) => (!e) ? resolve(NOT_STAGED_CHANGES.test(v)) : reject(e))
87
- })
88
- )
89
- }
90
-
91
- export function addPackageVersionChanges () {
92
- log('addPackageVersionChanges')
93
-
94
- return (
95
- new Promise((resolve, reject) => {
96
- exec('git add package.json package-lock.json', OPTIONS, (e) => (!e) ? resolve() : reject(e))
97
- })
98
- )
99
- }
100
-
101
- export function patchPackageVersion () {
102
- log('patchPackageVersion')
103
-
104
- return (
105
- new Promise((resolve, reject) => {
106
- exec('npm version patch -m %s -n', OPTIONS, (e) => (!e) ? resolve() : reject(e))
107
- })
108
- )
109
- }
110
-
111
- export function gitTag (a = '0.0.0', m = a) {
112
- log('gitTag')
113
-
114
- return (
115
- new Promise((resolve, reject) => {
116
- exec(`git tag -a v${a} -m "${m}"`, OPTIONS, (e, v) => (!e) ? resolve(v) : reject(e))
117
- })
118
- )
119
- }
1
+ import debug from 'debug'
2
+
3
+ import {
4
+ exec
5
+ } from 'child_process'
6
+
7
+ const log = debug('@sequencemedia/hooks:common')
8
+
9
+ log('`@sequencemedia/hooks` is awake')
10
+
11
+ export const OPTIONS = {
12
+ maxBuffer: 1024 * 500
13
+ }
14
+
15
+ export const BRANCH = 'master'
16
+
17
+ export const PACKAGE_VERSION_CHANGES = /\-+\s+"version":\s+"(\d+\.\d+\.\d+)",+\s+\++\s+"version":\s+"(\d+\.\d+\.\d+)",+\s+/ /* eslint-disable-line no-useless-escape */
18
+
19
+ export const HAS_STAGED_CHANGES = /Changes to be committed/s
20
+
21
+ export const NOT_STAGED_CHANGES = /Changes not staged for commit/s
22
+
23
+ export const trim = (v = '') => String(v).split('\n').map((v) => v.trimEnd()).join('\n').trim()
24
+
25
+ export function use (key) {
26
+ const log = debug(`@sequencemedia/hooks:${key}`)
27
+
28
+ return function use (v) {
29
+ log(trim(v))
30
+ }
31
+ }
32
+
33
+ export function getGitRemoteShowOriginHeadBranch () {
34
+ log('getGitRemoteShowOriginHeadBranch')
35
+
36
+ return (
37
+ new Promise((resolve, reject) => {
38
+ const command = 'git remote show origin | awk \'/HEAD branch/ {print $NF}\''
39
+
40
+ const {
41
+ stdout,
42
+ stderr
43
+ } = exec(command, OPTIONS, (e, v) => (!e) ? resolve(trim(v)) : reject(e))
44
+
45
+ stdout.on('data', use('git-remote-show-origin-head-branch'))
46
+ stderr.on('data', use('git-remote-show-origin-head-branch'))
47
+ })
48
+ )
49
+ }
50
+
51
+ export function hasGitDiffHeadPackageVersionChanges (branch = BRANCH) {
52
+ log('hasGitDiffHeadPackageVersionChanges')
53
+
54
+ return (
55
+ new Promise((resolve, reject) => {
56
+ exec(`git diff HEAD~1..HEAD~0 -- origin/${branch} package.json`, OPTIONS, async (e, v) => (!e) ? resolve(PACKAGE_VERSION_CHANGES.test(v) === true) : reject(e))
57
+ })
58
+ )
59
+ }
60
+
61
+ export function notGitDiffHeadPackageVersionChanges (branch = BRANCH) {
62
+ log('notGitDiffHeadPackageVersionChanges')
63
+
64
+ return (
65
+ new Promise((resolve, reject) => {
66
+ exec(`git diff HEAD~1..HEAD~0 -- origin/${branch} package.json`, OPTIONS, async (e, v) => (!e) ? resolve(PACKAGE_VERSION_CHANGES.test(v) !== true) : reject(e))
67
+ })
68
+ )
69
+ }
70
+
71
+ export function hasStagedChanges () {
72
+ log('hasStagedChanges')
73
+
74
+ return (
75
+ new Promise((resolve, reject) => {
76
+ exec('git status', OPTIONS, (e, v) => (!e) ? resolve(HAS_STAGED_CHANGES.test(v)) : reject(e))
77
+ })
78
+ )
79
+ }
80
+
81
+ export function notStagedChanges () {
82
+ log('notStagedChanges')
83
+
84
+ return (
85
+ new Promise((resolve, reject) => {
86
+ exec('git status', OPTIONS, (e, v) => (!e) ? resolve(NOT_STAGED_CHANGES.test(v)) : reject(e))
87
+ })
88
+ )
89
+ }
90
+
91
+ export function addPackageVersionChanges () {
92
+ log('addPackageVersionChanges')
93
+
94
+ return (
95
+ new Promise((resolve, reject) => {
96
+ exec('git add package.json package-lock.json', OPTIONS, (e) => (!e) ? resolve() : reject(e))
97
+ })
98
+ )
99
+ }
100
+
101
+ export function patchPackageVersion () {
102
+ log('patchPackageVersion')
103
+
104
+ return (
105
+ new Promise((resolve, reject) => {
106
+ exec('npm version patch -m %s -n', OPTIONS, (e) => (!e) ? resolve() : reject(e))
107
+ })
108
+ )
109
+ }
110
+
111
+ export function gitTag (a = '0.0.0', m = a) {
112
+ log('gitTag')
113
+
114
+ return (
115
+ new Promise((resolve, reject) => {
116
+ exec(`git tag -a v${a} -m "${m}"`, OPTIONS, (e, v) => (!e) ? resolve(v) : reject(e))
117
+ })
118
+ )
119
+ }
@@ -1,27 +1,27 @@
1
- import debug from 'debug'
2
-
3
- import {
4
- hasStagedChanges,
5
- getGitRemoteShowOriginHeadBranch,
6
- hasGitDiffHeadPackageVersionChanges,
7
- patchPackageVersion
8
- } from '#hooks/common'
9
-
10
- const log = debug('@sequencemedia/hooks:post-commit')
11
- const error = debug('@sequencemedia/hooks:post-commit:error')
12
-
13
- log('`@sequencemedia/hooks` is awake')
14
-
15
- export default async function postCommit () {
16
- log('post-commit')
17
-
18
- try {
19
- if (await hasStagedChanges()) return
20
-
21
- if (await hasGitDiffHeadPackageVersionChanges(await getGitRemoteShowOriginHeadBranch())) return
22
-
23
- await patchPackageVersion()
24
- } catch ({ code = 'NONE', message = 'No error message defined' }) {
25
- error({ code, message })
26
- }
27
- }
1
+ import debug from 'debug'
2
+
3
+ import {
4
+ hasStagedChanges,
5
+ getGitRemoteShowOriginHeadBranch,
6
+ hasGitDiffHeadPackageVersionChanges,
7
+ patchPackageVersion
8
+ } from '#hooks/common'
9
+
10
+ const log = debug('@sequencemedia/hooks:post-commit')
11
+ const error = debug('@sequencemedia/hooks:post-commit:error')
12
+
13
+ log('`@sequencemedia/hooks` is awake')
14
+
15
+ export default async function postCommit () {
16
+ log('post-commit')
17
+
18
+ try {
19
+ if (await hasStagedChanges()) return
20
+
21
+ if (await hasGitDiffHeadPackageVersionChanges(await getGitRemoteShowOriginHeadBranch())) return
22
+
23
+ await patchPackageVersion()
24
+ } catch ({ code = 'NONE', message = 'No error message defined' }) {
25
+ error({ code, message })
26
+ }
27
+ }