@sequencemedia/hooks 1.0.623 → 1.1.0
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 -36
- package/.editorconfig +1 -1
- package/.gitattributes +9 -0
- package/.husky/post-commit +1 -3
- package/.publish/.gitattributes +3 -0
- package/.publish/README.md +20 -0
- package/babel.config.cjs +12 -14
- package/eslint.config.mjs +23 -4
- package/index.d.mts +19 -17
- package/package.json +3 -5
- package/post-commit.mjs +5 -0
- package/src/common.mjs +31 -5
- package/src/post-commit.mjs +15 -6
- package/tsconfig.json +13 -0
package/.circleci/config.yml
CHANGED
|
@@ -10,44 +10,11 @@ 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/sequencemedia/publish.git .publish
|
|
15
|
+
.publish/publish.sh
|
|
48
16
|
|
|
49
17
|
workflows:
|
|
50
|
-
version: 2
|
|
51
18
|
commit-workflow:
|
|
52
19
|
jobs:
|
|
53
20
|
- publish:
|
package/.editorconfig
CHANGED
package/.gitattributes
CHANGED
|
@@ -2,13 +2,22 @@
|
|
|
2
2
|
* text=auto
|
|
3
3
|
|
|
4
4
|
# LF line endings
|
|
5
|
+
*.yaml text eol=lf
|
|
6
|
+
*.yml text eol=lf
|
|
5
7
|
*.json text eol=lf
|
|
6
8
|
*.mjs text eol=lf
|
|
7
9
|
*.cjs text eol=lf
|
|
10
|
+
*.jsx text eol=lf
|
|
8
11
|
*.mts text eol=lf
|
|
12
|
+
*.cts text eol=lf
|
|
13
|
+
*.sh text eol=lf
|
|
9
14
|
.editorconfig text eol=lf
|
|
10
15
|
.eslintignore text eol=lf
|
|
11
16
|
.eslintrc text eol=lf
|
|
12
17
|
.gitattributes text eol=lf
|
|
13
18
|
.gitignore text eol=lf
|
|
19
|
+
.npmignore text eol=lf
|
|
20
|
+
.npmrc text eol=lf
|
|
21
|
+
.eslintrc text eol=lf
|
|
22
|
+
.babelrc text eol=lf
|
|
14
23
|
.husky/* text eol=lf
|
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=@sequencemedia/hooks* node .husky/post-commit.mjs
|
|
18
|
-
rm -rf .husky/hooks
|
|
16
|
+
npx cross-env DEBUG=@sequencemedia/hooks* node ./post-commit.mjs
|
|
19
17
|
fi
|
|
@@ -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/sequencemedia/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/3d97362bd1c87996c92f4e599aff64bd.git .publish
|
|
18
|
+
chmod +x .publish/publish.sh
|
|
19
|
+
.publish/publish.sh
|
|
20
|
+
```
|
package/babel.config.cjs
CHANGED
|
@@ -1,16 +1,14 @@
|
|
|
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
1
|
module.exports = {
|
|
15
|
-
presets
|
|
2
|
+
presets: [
|
|
3
|
+
[
|
|
4
|
+
'@babel/env',
|
|
5
|
+
{
|
|
6
|
+
targets: {
|
|
7
|
+
node: 'current'
|
|
8
|
+
},
|
|
9
|
+
useBuiltIns: 'usage',
|
|
10
|
+
corejs: 3
|
|
11
|
+
}
|
|
12
|
+
]
|
|
13
|
+
]
|
|
16
14
|
}
|
package/eslint.config.mjs
CHANGED
|
@@ -1,13 +1,32 @@
|
|
|
1
1
|
import globals from 'globals'
|
|
2
|
-
import standard from '@sequencemedia/eslint-config-standard'
|
|
2
|
+
import standard from '@sequencemedia/eslint-config-standard/configs/recommended/merge'
|
|
3
|
+
import typescript from '@sequencemedia/eslint-config-typescript/configs/recommended/merge'
|
|
3
4
|
|
|
4
5
|
export default [
|
|
5
|
-
|
|
6
|
+
/**
|
|
7
|
+
* Standard config
|
|
8
|
+
*/
|
|
9
|
+
standard({
|
|
10
|
+
files: [
|
|
11
|
+
'**/*.{mjs,cjs,mts,cts}'
|
|
12
|
+
],
|
|
6
13
|
languageOptions: {
|
|
7
14
|
globals: {
|
|
8
15
|
...globals.node
|
|
9
16
|
}
|
|
10
17
|
}
|
|
11
|
-
},
|
|
12
|
-
|
|
18
|
+
}),
|
|
19
|
+
/**
|
|
20
|
+
* TypeScript config
|
|
21
|
+
*/
|
|
22
|
+
typescript({
|
|
23
|
+
files: [
|
|
24
|
+
'**/*.{mts,cts}'
|
|
25
|
+
],
|
|
26
|
+
languageOptions: {
|
|
27
|
+
globals: {
|
|
28
|
+
...globals.node
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
})
|
|
13
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": "@sequencemedia/hooks",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "Git Hooks",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"git",
|
|
@@ -35,11 +35,9 @@
|
|
|
35
35
|
"debug": "^4.4.0"
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
|
38
|
-
"@babel/core": "^7.26.10",
|
|
39
|
-
"@babel/eslint-parser": "^7.26.10",
|
|
40
|
-
"@babel/preset-env": "^7.26.9",
|
|
41
38
|
"@sequencemedia/eslint-config-standard": "^0.2.44",
|
|
42
|
-
"
|
|
39
|
+
"@sequencemedia/eslint-config-typescript": "^0.1.65",
|
|
40
|
+
"@types/debug": "^4.1.12",
|
|
43
41
|
"eslint": "^9.23.0",
|
|
44
42
|
"globals": "^16.0.0",
|
|
45
43
|
"husky": "^9.1.7"
|
package/post-commit.mjs
ADDED
package/src/common.mjs
CHANGED
|
@@ -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(`@sequencemedia/hooks:${key}`)
|
|
30
|
+
const log = debug(`@sequencemedia/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,26 @@ 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'))
|
|
55
|
+
})
|
|
56
|
+
)
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export function getGitRevParseAbbrevRefHead () {
|
|
60
|
+
log('getGitRevParseAbbrevRefHead')
|
|
61
|
+
|
|
62
|
+
return (
|
|
63
|
+
new Promise((resolve, reject) => {
|
|
64
|
+
const command = 'git rev-parse --abbrev-ref HEAD'
|
|
65
|
+
|
|
66
|
+
const {
|
|
67
|
+
stdout,
|
|
68
|
+
stderr
|
|
69
|
+
} = exec(command, OPTIONS, (e, v) => (!e) ? resolve(trim(v)) : reject(e))
|
|
70
|
+
|
|
71
|
+
if (stdout) stdout.on('data', use('git-rev-parse-head'))
|
|
72
|
+
if (stderr) stderr.on('data', use('git-rev-parse-head'))
|
|
47
73
|
})
|
|
48
74
|
)
|
|
49
75
|
}
|
|
@@ -93,7 +119,7 @@ export function addPackageVersionChanges () {
|
|
|
93
119
|
|
|
94
120
|
return (
|
|
95
121
|
new Promise((resolve, reject) => {
|
|
96
|
-
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))
|
|
97
123
|
})
|
|
98
124
|
)
|
|
99
125
|
}
|
|
@@ -103,7 +129,7 @@ export function patchPackageVersion () {
|
|
|
103
129
|
|
|
104
130
|
return (
|
|
105
131
|
new Promise((resolve, reject) => {
|
|
106
|
-
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))
|
|
107
133
|
})
|
|
108
134
|
)
|
|
109
135
|
}
|
package/src/post-commit.mjs
CHANGED
|
@@ -3,6 +3,7 @@ import debug from 'debug'
|
|
|
3
3
|
import {
|
|
4
4
|
hasStagedChanges,
|
|
5
5
|
getGitRemoteShowOriginHeadBranch,
|
|
6
|
+
getGitRevParseAbbrevRefHead,
|
|
6
7
|
hasGitDiffHeadPackageVersionChanges,
|
|
7
8
|
patchPackageVersion
|
|
8
9
|
} from '#hooks/common'
|
|
@@ -12,18 +13,26 @@ const error = debug('@sequencemedia/hooks:post-commit:error')
|
|
|
12
13
|
|
|
13
14
|
log('`@sequencemedia/hooks` is awake')
|
|
14
15
|
|
|
16
|
+
function handleError ({
|
|
17
|
+
code = 'NONE',
|
|
18
|
+
message = 'NONE'
|
|
19
|
+
}) {
|
|
20
|
+
error({ code, message })
|
|
21
|
+
}
|
|
22
|
+
|
|
15
23
|
export default async function postCommit () {
|
|
16
24
|
log('postCommit')
|
|
17
25
|
|
|
18
26
|
try {
|
|
19
27
|
if (await hasStagedChanges()) return
|
|
20
28
|
|
|
21
|
-
|
|
29
|
+
const originHeadBranch = await getGitRemoteShowOriginHeadBranch()
|
|
30
|
+
if (originHeadBranch === await getGitRevParseAbbrevRefHead()) {
|
|
31
|
+
if (await hasGitDiffHeadPackageVersionChanges(originHeadBranch)) return
|
|
22
32
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
error(message)
|
|
33
|
+
await patchPackageVersion()
|
|
34
|
+
}
|
|
35
|
+
} catch (e) { // @ts-expect-error
|
|
36
|
+
handleError(e)
|
|
28
37
|
}
|
|
29
38
|
}
|