@itcase/config 1.6.67 → 1.6.69
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 +24 -14
- package/husky-hooks/install-launcher.js +34 -11
- package/package.json +4 -3
package/README.md
CHANGED
|
@@ -18,7 +18,7 @@ npm install --save-dev @itcase/config
|
|
|
18
18
|
- `commitlint/commitizenAdapter.js` — адаптер Commitizen (type → scope → subScope → subject)
|
|
19
19
|
|
|
20
20
|
- **Husky** — общие git-хуки в `husky-hooks/`
|
|
21
|
-
-
|
|
21
|
+
- В git только `.husky/config`; обёртки и `_run.sh` создаёт `itcase-config-husky-install` при `npm i`
|
|
22
22
|
|
|
23
23
|
- **Lint-staged** — запуск линтеров для измененных файлов
|
|
24
24
|
- `lint-staged/index.js` — базовая конфигурация
|
|
@@ -85,30 +85,40 @@ npm install --save-dev commitizen @commitlint/cz-commitlint
|
|
|
85
85
|
|
|
86
86
|
## Подключение Husky
|
|
87
87
|
|
|
88
|
-
В
|
|
88
|
+
В git кладите только `.husky/config`. Обёртки хуков и `_run.sh` создаёт `itcase-config-husky-install` при `npm i`. Логика хуков живёт в `@itcase/config/husky-hooks`.
|
|
89
89
|
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
90
|
+
```json
|
|
91
|
+
{
|
|
92
|
+
"scripts": {
|
|
93
|
+
"prepare": "husky && itcase-config-husky-install"
|
|
94
|
+
}
|
|
95
|
+
}
|
|
94
96
|
```
|
|
95
97
|
|
|
96
|
-
|
|
98
|
+
Пока бинарь ещё не в установленной версии пакета:
|
|
97
99
|
|
|
98
|
-
|
|
100
|
+
```json
|
|
101
|
+
{
|
|
102
|
+
"scripts": {
|
|
103
|
+
"prepare": "husky && node node_modules/@itcase/config/husky-hooks/install-launcher.js"
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
```
|
|
99
107
|
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
108
|
+
В `.gitignore`:
|
|
109
|
+
|
|
110
|
+
```gitignore
|
|
111
|
+
.husky/*
|
|
112
|
+
!.husky/config
|
|
103
113
|
```
|
|
104
114
|
|
|
105
|
-
|
|
115
|
+
`itcase-config-husky-install` копирует `_run.sh`, создаёт обёртки и при отсутствии восстанавливает `config` из `config.example`. Свои полные хуки не перезаписывает. `npm i --ignore-scripts` файлы не создаст.
|
|
106
116
|
|
|
107
|
-
|
|
117
|
+
`.husky/config`:
|
|
108
118
|
|
|
109
119
|
```bash
|
|
110
120
|
PROTECTED_BRANCHES="master"
|
|
111
121
|
RELEASE_BRANCHES="master"
|
|
112
122
|
```
|
|
113
123
|
|
|
114
|
-
|
|
124
|
+
Образец: `husky-hooks/config.example`.
|
|
@@ -56,6 +56,13 @@ function isOldItcaseHook(text) {
|
|
|
56
56
|
return text.includes('GIT_WORKFLOW') && text.includes('/config')
|
|
57
57
|
}
|
|
58
58
|
|
|
59
|
+
function isEmptyHuskyDir(huskyDir) {
|
|
60
|
+
const names = fs
|
|
61
|
+
.readdirSync(huskyDir)
|
|
62
|
+
.filter((name) => name !== '_' && name !== '.DS_Store')
|
|
63
|
+
return names.length === 0
|
|
64
|
+
}
|
|
65
|
+
|
|
59
66
|
function isItcaseHuskyDir(huskyDir) {
|
|
60
67
|
if (fs.existsSync(path.join(huskyDir, 'config'))) {
|
|
61
68
|
return true
|
|
@@ -65,6 +72,10 @@ function isItcaseHuskyDir(huskyDir) {
|
|
|
65
72
|
return true
|
|
66
73
|
}
|
|
67
74
|
|
|
75
|
+
if (isEmptyHuskyDir(huskyDir)) {
|
|
76
|
+
return true
|
|
77
|
+
}
|
|
78
|
+
|
|
68
79
|
const hookContents = GIT_HOOKS.map((name) => readHook(huskyDir, name))
|
|
69
80
|
return hookContents.some(
|
|
70
81
|
(text) => text?.includes('_run.sh') || isOldItcaseHook(text),
|
|
@@ -75,9 +86,23 @@ function shouldWriteWrapper(text) {
|
|
|
75
86
|
return text === null || text.includes('_run.sh') || isOldItcaseHook(text)
|
|
76
87
|
}
|
|
77
88
|
|
|
78
|
-
function
|
|
79
|
-
|
|
80
|
-
|
|
89
|
+
function writeExecutable(dest, contents) {
|
|
90
|
+
fs.writeFileSync(dest, contents)
|
|
91
|
+
try {
|
|
92
|
+
fs.chmodSync(dest, 0o755)
|
|
93
|
+
} catch {
|
|
94
|
+
// Windows may not support chmod; Git Bash still runs the file via sh.
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
function ensureConfig(huskyDir) {
|
|
99
|
+
const dest = path.join(huskyDir, 'config')
|
|
100
|
+
if (fs.existsSync(dest)) {
|
|
101
|
+
return
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
const example = path.join(import.meta.dirname, 'config.example')
|
|
105
|
+
fs.copyFileSync(example, dest)
|
|
81
106
|
try {
|
|
82
107
|
fs.chmodSync(dest, 0o755)
|
|
83
108
|
} catch {
|
|
@@ -91,16 +116,14 @@ if (!fs.existsSync(huskyDir) || !isItcaseHuskyDir(huskyDir)) {
|
|
|
91
116
|
process.exit(0)
|
|
92
117
|
}
|
|
93
118
|
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
// Windows may not support chmod; Git Bash still runs the file via sh.
|
|
100
|
-
}
|
|
119
|
+
writeExecutable(
|
|
120
|
+
path.join(huskyDir, '_run.sh'),
|
|
121
|
+
fs.readFileSync(path.join(import.meta.dirname, '_run.sh')),
|
|
122
|
+
)
|
|
123
|
+
ensureConfig(huskyDir)
|
|
101
124
|
|
|
102
125
|
for (const name of GIT_HOOKS) {
|
|
103
126
|
if (shouldWriteWrapper(readHook(huskyDir, name))) {
|
|
104
|
-
|
|
127
|
+
writeExecutable(path.join(huskyDir, name), WRAPPER)
|
|
105
128
|
}
|
|
106
129
|
}
|
package/package.json
CHANGED
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@itcase/config",
|
|
3
|
-
"version": "1.6.
|
|
3
|
+
"version": "1.6.69",
|
|
4
4
|
"author": "ITCase",
|
|
5
5
|
"description": "ITCase Config",
|
|
6
6
|
"engines": {
|
|
7
7
|
"node": ">=22.0.0"
|
|
8
8
|
},
|
|
9
9
|
"bin": {
|
|
10
|
-
"itcase-config-husky-hooks": "./husky-hooks/run.js"
|
|
10
|
+
"itcase-config-husky-hooks": "./husky-hooks/run.js",
|
|
11
|
+
"itcase-config-husky-install": "./husky-hooks/install-launcher.js"
|
|
11
12
|
},
|
|
12
13
|
"scripts": {
|
|
13
|
-
"prepare": "husky",
|
|
14
|
+
"prepare": "husky && node ./husky-hooks/install-launcher.js",
|
|
14
15
|
"postinstall": "node ./husky-hooks/install-launcher.js",
|
|
15
16
|
"semantic-release": "semantic-release"
|
|
16
17
|
},
|