@modernpoacher/hooks 1.0.512 → 1.1.1
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/.circleci/config.yml +3 -35
- package/.editorconfig +1 -1
- package/.husky/post-commit +1 -3
- package/.publish/.gitattributes +1 -0
- package/.publish/README.md +20 -0
- package/eslint.config.mjs +32 -0
- package/index.d.mts +19 -17
- package/package.json +7 -8
- package/{.husky/post-commit.mjs → post-commit.mjs} +2 -0
- package/src/common.mjs +16 -8
- package/src/post-commit.mjs +11 -7
- package/tsconfig.json +13 -0
- package/.eslintignore +0 -3
- package/.eslintrc +0 -12
- package/babel.config.cjs +0 -14
package/.circleci/config.yml
CHANGED
|
@@ -10,41 +10,9 @@ jobs:
|
|
|
10
10
|
name: Publish to NPM
|
|
11
11
|
command: |
|
|
12
12
|
echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" > ~/.npmrc
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
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
|
|
13
|
+
echo ".publish/publish.sh" >> .npmignore
|
|
14
|
+
git clone https://github.com/modernpoacher/publish.git .publish
|
|
15
|
+
.publish/publish.sh
|
|
48
16
|
|
|
49
17
|
workflows:
|
|
50
18
|
commit-workflow:
|
package/.editorconfig
CHANGED
package/.husky/post-commit
CHANGED
|
@@ -13,7 +13,5 @@ has_package_changes () {
|
|
|
13
13
|
|
|
14
14
|
if has_package_changes;
|
|
15
15
|
then
|
|
16
|
-
|
|
17
|
-
npx cross-env DEBUG=@modernpoacher/hooks* node .husky/post-commit.mjs
|
|
18
|
-
rm -rf .husky/hooks
|
|
16
|
+
npx cross-env DEBUG=@modernpoacher/hooks* node ./post-commit.mjs
|
|
19
17
|
fi
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
* text eol=lf
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# Publish to NPM
|
|
2
|
+
|
|
3
|
+
For CircleCI or the shell
|
|
4
|
+
|
|
5
|
+
If you need an _authentication token_ to publish then you should resolve that before executing this script
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
echo ".publish/publish.sh" >> .npmignore
|
|
9
|
+
git clone https://github.com/modernpoacher/publish.git .publish
|
|
10
|
+
.publish/publish.sh
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
A Gist with the same content as `publish.sh` may need an additional step
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
echo ".publish/publish.sh" >> .npmignore
|
|
17
|
+
git clone https://gist.github.com/efd85e2b8da1ee830dd637f134994a9d.git .publish
|
|
18
|
+
chmod +x .publish/publish.sh
|
|
19
|
+
.publish/publish.sh
|
|
20
|
+
```
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import globals from 'globals'
|
|
2
|
+
import standard from '@sequencemedia/eslint-config-standard/configs/recommended/merge'
|
|
3
|
+
import typescript from '@sequencemedia/eslint-config-typescript/configs/recommended/merge'
|
|
4
|
+
|
|
5
|
+
export default [
|
|
6
|
+
/**
|
|
7
|
+
* Standard config
|
|
8
|
+
*/
|
|
9
|
+
standard({
|
|
10
|
+
files: [
|
|
11
|
+
'**/*.{mjs,cjs,mts,cts}'
|
|
12
|
+
],
|
|
13
|
+
languageOptions: {
|
|
14
|
+
globals: {
|
|
15
|
+
...globals.node
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
}),
|
|
19
|
+
/**
|
|
20
|
+
* TypeScript config
|
|
21
|
+
*/
|
|
22
|
+
typescript({
|
|
23
|
+
files: [
|
|
24
|
+
'**/*.{mts,cts}'
|
|
25
|
+
],
|
|
26
|
+
languageOptions: {
|
|
27
|
+
globals: {
|
|
28
|
+
...globals.node
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
})
|
|
32
|
+
]
|
package/index.d.mts
CHANGED
|
@@ -1,22 +1,24 @@
|
|
|
1
1
|
declare module '@sequencemedia/hooks' {
|
|
2
|
-
|
|
3
|
-
export const common: {
|
|
2
|
+
interface CommonType {
|
|
4
3
|
OPTIONS: {
|
|
5
4
|
maxBuffer: number
|
|
6
|
-
}
|
|
7
|
-
BRANCH: string
|
|
8
|
-
PACKAGE_VERSION_CHANGES: RegExp
|
|
9
|
-
HAS_STAGED_CHANGES: RegExp
|
|
10
|
-
NOT_STAGED_CHANGES: RegExp
|
|
11
|
-
use ()
|
|
12
|
-
trim ()
|
|
13
|
-
getGitRemoteShowOriginHeadBranch ()
|
|
14
|
-
hasGitDiffHeadPackageVersionChanges ()
|
|
15
|
-
notGitDiffHeadPackageVersionChanges ()
|
|
16
|
-
hasStagedChanges ()
|
|
17
|
-
notStagedChanges ()
|
|
18
|
-
addPackageVersionChanges ()
|
|
19
|
-
patchPackageVersion ()
|
|
20
|
-
gitTag (a:string, m?:string)
|
|
5
|
+
}
|
|
6
|
+
BRANCH: string
|
|
7
|
+
PACKAGE_VERSION_CHANGES: RegExp
|
|
8
|
+
HAS_STAGED_CHANGES: RegExp
|
|
9
|
+
NOT_STAGED_CHANGES: RegExp
|
|
10
|
+
use: () => Promise<void>
|
|
11
|
+
trim: () => string
|
|
12
|
+
getGitRemoteShowOriginHeadBranch: () => Promise<void>
|
|
13
|
+
hasGitDiffHeadPackageVersionChanges: () => Promise<void>
|
|
14
|
+
notGitDiffHeadPackageVersionChanges: () => Promise<void>
|
|
15
|
+
hasStagedChanges: () => Promise<void>
|
|
16
|
+
notStagedChanges: () => Promise<void>
|
|
17
|
+
addPackageVersionChanges: () => Promise<void>
|
|
18
|
+
patchPackageVersion: () => Promise<void>
|
|
19
|
+
gitTag: (a:string, m?:string) => Promise<void>
|
|
21
20
|
}
|
|
21
|
+
|
|
22
|
+
export function postCommit (): string
|
|
23
|
+
export const common: CommonType
|
|
22
24
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@modernpoacher/hooks",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.1",
|
|
4
4
|
"description": "Git Hooks",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"git",
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
"url": "https://github.com/modernpoacher/hooks/issues"
|
|
28
28
|
},
|
|
29
29
|
"scripts": {
|
|
30
|
-
"lint": "eslint .
|
|
30
|
+
"lint": "eslint .",
|
|
31
31
|
"lint:fix": "npm run lint -- --fix",
|
|
32
32
|
"prepare": "husky"
|
|
33
33
|
},
|
|
@@ -35,12 +35,11 @@
|
|
|
35
35
|
"debug": "^4.4.0"
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
|
38
|
-
"@
|
|
39
|
-
"@
|
|
40
|
-
"@
|
|
41
|
-
"
|
|
42
|
-
"
|
|
43
|
-
"eslint-config-standard": "^17.1.0",
|
|
38
|
+
"@sequencemedia/eslint-config-standard": "^0.2.45",
|
|
39
|
+
"@sequencemedia/eslint-config-typescript": "^0.1.66",
|
|
40
|
+
"@types/debug": "^4.1.12",
|
|
41
|
+
"eslint": "^9.23.0",
|
|
42
|
+
"globals": "^16.0.0",
|
|
44
43
|
"husky": "^9.1.7"
|
|
45
44
|
},
|
|
46
45
|
"imports": {
|
package/src/common.mjs
CHANGED
|
@@ -4,7 +4,7 @@ import {
|
|
|
4
4
|
exec
|
|
5
5
|
} from 'child_process'
|
|
6
6
|
|
|
7
|
-
const log = debug('@modernpoacher/hooks
|
|
7
|
+
const log = debug('@modernpoacher/hooks:common')
|
|
8
8
|
|
|
9
9
|
log('`@modernpoacher/hooks` is awake')
|
|
10
10
|
|
|
@@ -22,9 +22,17 @@ export const NOT_STAGED_CHANGES = /Changes not staged for commit/s
|
|
|
22
22
|
|
|
23
23
|
export const trim = (v = '') => String(v).split('\n').map((v) => v.trimEnd()).join('\n').trim()
|
|
24
24
|
|
|
25
|
+
/**
|
|
26
|
+
* @param {string} key
|
|
27
|
+
* @returns {(v: string) => void}
|
|
28
|
+
*/
|
|
25
29
|
export function use (key) {
|
|
26
|
-
const log = debug(`@modernpoacher/hooks
|
|
30
|
+
const log = debug(`@modernpoacher/hooks:common:${key}`)
|
|
27
31
|
|
|
32
|
+
/**
|
|
33
|
+
* @param {string} v
|
|
34
|
+
* @returns {void}
|
|
35
|
+
*/
|
|
28
36
|
return function use (v) {
|
|
29
37
|
log(trim(v))
|
|
30
38
|
}
|
|
@@ -42,8 +50,8 @@ export function getGitRemoteShowOriginHeadBranch () {
|
|
|
42
50
|
stderr
|
|
43
51
|
} = exec(command, OPTIONS, (e, v) => (!e) ? resolve(trim(v)) : reject(e))
|
|
44
52
|
|
|
45
|
-
stdout.on('data', use('git-remote-show-origin-head-branch'))
|
|
46
|
-
stderr.on('data', use('git-remote-show-origin-head-branch'))
|
|
53
|
+
if (stdout) stdout.on('data', use('git-remote-show-origin-head-branch'))
|
|
54
|
+
if (stderr) stderr.on('data', use('git-remote-show-origin-head-branch'))
|
|
47
55
|
})
|
|
48
56
|
)
|
|
49
57
|
}
|
|
@@ -60,8 +68,8 @@ export function getGitRevParseAbbrevRefHead () {
|
|
|
60
68
|
stderr
|
|
61
69
|
} = exec(command, OPTIONS, (e, v) => (!e) ? resolve(trim(v)) : reject(e))
|
|
62
70
|
|
|
63
|
-
stdout.on('data', use('git-rev-parse-head'))
|
|
64
|
-
stderr.on('data', use('git-rev-parse-head'))
|
|
71
|
+
if (stdout) stdout.on('data', use('git-rev-parse-head'))
|
|
72
|
+
if (stderr) stderr.on('data', use('git-rev-parse-head'))
|
|
65
73
|
})
|
|
66
74
|
)
|
|
67
75
|
}
|
|
@@ -111,7 +119,7 @@ export function addPackageVersionChanges () {
|
|
|
111
119
|
|
|
112
120
|
return (
|
|
113
121
|
new Promise((resolve, reject) => {
|
|
114
|
-
exec('git add package.json package-lock.json', OPTIONS, (e) => (!e) ? resolve() : reject(e))
|
|
122
|
+
exec('git add package.json package-lock.json', OPTIONS, (e, v) => (!e) ? resolve(v) : reject(e))
|
|
115
123
|
})
|
|
116
124
|
)
|
|
117
125
|
}
|
|
@@ -121,7 +129,7 @@ export function patchPackageVersion () {
|
|
|
121
129
|
|
|
122
130
|
return (
|
|
123
131
|
new Promise((resolve, reject) => {
|
|
124
|
-
exec('npm version patch -m "%s" -n --no-commit-hooks', OPTIONS, (e) => (!e) ? resolve() : reject(e))
|
|
132
|
+
exec('npm version patch -m "%s" -n --no-commit-hooks', OPTIONS, (e, v) => (!e) ? resolve(v) : reject(e))
|
|
125
133
|
})
|
|
126
134
|
)
|
|
127
135
|
}
|
package/src/post-commit.mjs
CHANGED
|
@@ -8,11 +8,18 @@ import {
|
|
|
8
8
|
patchPackageVersion
|
|
9
9
|
} from '#hooks/common'
|
|
10
10
|
|
|
11
|
-
const log = debug('@modernpoacher/hooks
|
|
12
|
-
const error = debug('@modernpoacher/hooks
|
|
11
|
+
const log = debug('@modernpoacher/hooks:post-commit')
|
|
12
|
+
const error = debug('@modernpoacher/hooks:post-commit:error')
|
|
13
13
|
|
|
14
14
|
log('`@modernpoacher/hooks` is awake')
|
|
15
15
|
|
|
16
|
+
function handleError ({
|
|
17
|
+
code = 'NONE',
|
|
18
|
+
message = 'NONE'
|
|
19
|
+
}) {
|
|
20
|
+
error({ code, message })
|
|
21
|
+
}
|
|
22
|
+
|
|
16
23
|
export default async function postCommit () {
|
|
17
24
|
log('postCommit')
|
|
18
25
|
|
|
@@ -25,10 +32,7 @@ export default async function postCommit () {
|
|
|
25
32
|
|
|
26
33
|
await patchPackageVersion()
|
|
27
34
|
}
|
|
28
|
-
} catch ({
|
|
29
|
-
|
|
30
|
-
message = 'No error message defined'
|
|
31
|
-
}) {
|
|
32
|
-
error({ code, message })
|
|
35
|
+
} catch (e) { // @ts-expect-error
|
|
36
|
+
handleError(e)
|
|
33
37
|
}
|
|
34
38
|
}
|
package/tsconfig.json
ADDED
package/.eslintignore
DELETED
package/.eslintrc
DELETED