@itcase/config 1.6.65 → 1.6.67
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/README.md +2 -2
- package/husky-hooks/install-launcher.js +60 -21
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -87,13 +87,13 @@ npm install --save-dev commitizen @commitlint/cz-commitlint
|
|
|
87
87
|
|
|
88
88
|
В репозитории остаются файлы, на которые опираются git и husky. Логика лежит в `@itcase/config/husky-hooks`. При установке пакета npm кладёт бинарь `itcase-config-husky-hooks` в `node_modules/.bin` — husky уже добавляет этот путь в `PATH`.
|
|
89
89
|
|
|
90
|
-
При `npm i` пакет
|
|
90
|
+
При `npm i` пакет копирует `.husky/_run.sh` и создаёт недостающие обёртки хуков. Свои полные хуки не перезаписывает. Добавьте в `.gitignore`:
|
|
91
91
|
|
|
92
92
|
```gitignore
|
|
93
93
|
.husky/_run.sh
|
|
94
94
|
```
|
|
95
95
|
|
|
96
|
-
Репы без обёрток скрипт не трогает. `npm i --ignore-scripts`
|
|
96
|
+
Репы без обёрток и без одного только `.husky/config` скрипт не трогает. `npm i --ignore-scripts` файлы не создаст.
|
|
97
97
|
|
|
98
98
|
В каждом git-hook оставьте обёртку:
|
|
99
99
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
/**
|
|
3
|
-
* Copies husky-hooks/_run.sh into the project .husky/ on install
|
|
4
|
-
*
|
|
3
|
+
* Copies husky-hooks/_run.sh into the project .husky/ on install
|
|
4
|
+
* and creates missing git-hook wrappers. Does not overwrite custom hooks.
|
|
5
5
|
*/
|
|
6
6
|
import fs from 'node:fs'
|
|
7
7
|
import path from 'node:path'
|
|
@@ -16,7 +16,18 @@ const GIT_HOOKS = [
|
|
|
16
16
|
'set-release-message',
|
|
17
17
|
]
|
|
18
18
|
|
|
19
|
+
const WRAPPER = `#!/usr/bin/env sh
|
|
20
|
+
. "$(dirname "$0")/_run.sh"
|
|
21
|
+
`
|
|
22
|
+
|
|
19
23
|
function projectRoot() {
|
|
24
|
+
const cwd = process.cwd()
|
|
25
|
+
const marker = `${path.sep}node_modules${path.sep}@itcase${path.sep}config`
|
|
26
|
+
const index = cwd.lastIndexOf(marker)
|
|
27
|
+
if (index !== -1) {
|
|
28
|
+
return cwd.slice(0, index)
|
|
29
|
+
}
|
|
30
|
+
|
|
20
31
|
const initCwd = process.env.INIT_CWD
|
|
21
32
|
if (
|
|
22
33
|
initCwd &&
|
|
@@ -26,42 +37,70 @@ function projectRoot() {
|
|
|
26
37
|
return initCwd
|
|
27
38
|
}
|
|
28
39
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
40
|
+
return cwd
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function readHook(huskyDir, name) {
|
|
44
|
+
try {
|
|
45
|
+
return fs.readFileSync(path.join(huskyDir, name), 'utf8')
|
|
46
|
+
} catch {
|
|
47
|
+
return null
|
|
34
48
|
}
|
|
49
|
+
}
|
|
35
50
|
|
|
36
|
-
|
|
51
|
+
function isOldItcaseHook(text) {
|
|
52
|
+
if (!text || text.includes('_run.sh')) {
|
|
53
|
+
return false
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
return text.includes('GIT_WORKFLOW') && text.includes('/config')
|
|
37
57
|
}
|
|
38
58
|
|
|
39
|
-
function
|
|
59
|
+
function isItcaseHuskyDir(huskyDir) {
|
|
60
|
+
if (fs.existsSync(path.join(huskyDir, 'config'))) {
|
|
61
|
+
return true
|
|
62
|
+
}
|
|
63
|
+
|
|
40
64
|
if (fs.existsSync(path.join(huskyDir, '_run.sh'))) {
|
|
41
65
|
return true
|
|
42
66
|
}
|
|
43
67
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
68
|
+
const hookContents = GIT_HOOKS.map((name) => readHook(huskyDir, name))
|
|
69
|
+
return hookContents.some(
|
|
70
|
+
(text) => text?.includes('_run.sh') || isOldItcaseHook(text),
|
|
71
|
+
)
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function shouldWriteWrapper(text) {
|
|
75
|
+
return text === null || text.includes('_run.sh') || isOldItcaseHook(text)
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
function writeWrapper(huskyDir, name) {
|
|
79
|
+
const dest = path.join(huskyDir, name)
|
|
80
|
+
fs.writeFileSync(dest, WRAPPER)
|
|
81
|
+
try {
|
|
82
|
+
fs.chmodSync(dest, 0o755)
|
|
83
|
+
} catch {
|
|
84
|
+
// Windows may not support chmod; Git Bash still runs the file via sh.
|
|
85
|
+
}
|
|
52
86
|
}
|
|
53
87
|
|
|
54
88
|
const root = projectRoot()
|
|
55
89
|
const huskyDir = path.join(root, '.husky')
|
|
56
|
-
if (!fs.existsSync(huskyDir) || !
|
|
90
|
+
if (!fs.existsSync(huskyDir) || !isItcaseHuskyDir(huskyDir)) {
|
|
57
91
|
process.exit(0)
|
|
58
92
|
}
|
|
59
93
|
|
|
60
94
|
const src = path.join(import.meta.dirname, '_run.sh')
|
|
61
|
-
|
|
62
|
-
fs.copyFileSync(src, dest)
|
|
95
|
+
fs.copyFileSync(src, path.join(huskyDir, '_run.sh'))
|
|
63
96
|
try {
|
|
64
|
-
fs.chmodSync(
|
|
97
|
+
fs.chmodSync(path.join(huskyDir, '_run.sh'), 0o755)
|
|
65
98
|
} catch {
|
|
66
99
|
// Windows may not support chmod; Git Bash still runs the file via sh.
|
|
67
100
|
}
|
|
101
|
+
|
|
102
|
+
for (const name of GIT_HOOKS) {
|
|
103
|
+
if (shouldWriteWrapper(readHook(huskyDir, name))) {
|
|
104
|
+
writeWrapper(huskyDir, name)
|
|
105
|
+
}
|
|
106
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@itcase/config",
|
|
3
|
-
"version": "1.6.
|
|
3
|
+
"version": "1.6.67",
|
|
4
4
|
"author": "ITCase",
|
|
5
5
|
"description": "ITCase Config",
|
|
6
6
|
"engines": {
|
|
@@ -60,7 +60,7 @@
|
|
|
60
60
|
"autoprefixer": "^10.5.4",
|
|
61
61
|
"chokidar-cli": "^3.0.0",
|
|
62
62
|
"commitizen": "^4.3.2",
|
|
63
|
-
"conventional-changelog-conventionalcommits": "
|
|
63
|
+
"conventional-changelog-conventionalcommits": "9.3.1",
|
|
64
64
|
"cssnano": "^8.0.5",
|
|
65
65
|
"cssnano-preset-default": "^8.0.5",
|
|
66
66
|
"inquirer": "^14.0.2",
|
|
@@ -105,7 +105,7 @@
|
|
|
105
105
|
"semantic-release-lerna": "^3.6.1"
|
|
106
106
|
},
|
|
107
107
|
"devDependencies": {
|
|
108
|
-
"@itcase/lint": "^1.1.
|
|
108
|
+
"@itcase/lint": "^1.1.122",
|
|
109
109
|
"eslint": "9.39.2",
|
|
110
110
|
"husky": "^9.1.7",
|
|
111
111
|
"inquirer": "^14.0.2",
|
|
@@ -113,6 +113,6 @@
|
|
|
113
113
|
"prettier": "^3.9.6",
|
|
114
114
|
"storybook": "^10.5.8",
|
|
115
115
|
"stylelint": "^17.14.1",
|
|
116
|
-
"typescript": "^6.0.
|
|
116
|
+
"typescript": "^6.0.3"
|
|
117
117
|
}
|
|
118
118
|
}
|