bun-git-hooks 0.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/README.md +202 -0
- package/dist/cli.js +1082 -0
- package/dist/config.d.ts +4 -0
- package/dist/git-hooks.d.ts +50 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +831 -0
- package/dist/types.d.ts +43 -0
- package/package.json +92 -0
package/README.md
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
<p align="center"><img src=".github/art/cover.jpg" alt="Social Card of this repo"></p>
|
|
2
|
+
|
|
3
|
+
[![npm version][npm-version-src]][npm-version-href]
|
|
4
|
+
[![GitHub Actions][github-actions-src]][github-actions-href]
|
|
5
|
+
[](http://commitizen.github.io/cz-cli/)
|
|
6
|
+
<!-- [![npm downloads][npm-downloads-src]][npm-downloads-href] -->
|
|
7
|
+
<!-- [![Codecov][codecov-src]][codecov-href] -->
|
|
8
|
+
|
|
9
|
+
# bun-git-hooks
|
|
10
|
+
|
|
11
|
+
> A Bun-optimized TypeScript library for managing Git hooks with a robust set of configuration options.
|
|
12
|
+
|
|
13
|
+
## Features
|
|
14
|
+
|
|
15
|
+
- ๐ฏ **Simple Configuration**: Easy setup through multiple config file formats
|
|
16
|
+
- ๐ **Automatic Installation**: Hooks are installed on package installation
|
|
17
|
+
- ๐ก๏ธ **Type Safe**: Written in TypeScript with comprehensive type definitions
|
|
18
|
+
- ๐ง **Flexible Config**: Supports `.ts`, `.js`, `.mjs`, `.json` configurations
|
|
19
|
+
- ๐ช **Robust**: Handles complex Git workspace configurations
|
|
20
|
+
- ๐ซ **Skip Option**: Environment variable to skip hook installation
|
|
21
|
+
- ๐งน **Cleanup**: Optional cleanup of unused hooks
|
|
22
|
+
- ๐ฆ **Zero Dependencies**: Minimal footprint
|
|
23
|
+
- โก **Fast**: Built for Bun with performance in mind
|
|
24
|
+
- ๐ **Verbose Mode**: Detailed logging for troubleshooting
|
|
25
|
+
|
|
26
|
+
## Installation
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
bun add -D bun-git-hooks
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## Usage
|
|
33
|
+
|
|
34
|
+
### Basic Configuration
|
|
35
|
+
|
|
36
|
+
Create a `git-hooks.config.ts` (or `.js`, `.mjs`, `.cjs`, `.mts`, `.cts`, `.json`) file in your project root:
|
|
37
|
+
|
|
38
|
+
```ts
|
|
39
|
+
export default {
|
|
40
|
+
'pre-commit': 'bun run lint && bun run test',
|
|
41
|
+
'commit-msg': 'bun commitlint --edit $1',
|
|
42
|
+
'pre-push': 'bun run build'
|
|
43
|
+
}
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
Or add to your `package.json`:
|
|
47
|
+
|
|
48
|
+
```json
|
|
49
|
+
{
|
|
50
|
+
"git-hooks": {
|
|
51
|
+
"pre-commit": "bun run lint && bun run test",
|
|
52
|
+
"commit-msg": "bun commitlint --edit $1",
|
|
53
|
+
"pre-push": "bun run build"
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
### CLI Usage
|
|
59
|
+
|
|
60
|
+
```bash
|
|
61
|
+
# Install hooks from config
|
|
62
|
+
git-hooks
|
|
63
|
+
|
|
64
|
+
# alternatively, trigger the CLI with bunx
|
|
65
|
+
bunx git-hooks
|
|
66
|
+
bunx bun-git-hooks
|
|
67
|
+
|
|
68
|
+
# Use specific config file
|
|
69
|
+
git-hooks ./custom-config.ts
|
|
70
|
+
|
|
71
|
+
# Remove all hooks
|
|
72
|
+
git-hooks uninstall
|
|
73
|
+
|
|
74
|
+
# Enable verbose logging
|
|
75
|
+
git-hooks --verbose
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
### Environment Variables
|
|
79
|
+
|
|
80
|
+
Skip hook installation when needed:
|
|
81
|
+
|
|
82
|
+
```bash
|
|
83
|
+
# Skip hook installation
|
|
84
|
+
SKIP_INSTALL_GIT_HOOKS=1 bun install
|
|
85
|
+
|
|
86
|
+
# Set custom environment for hooks
|
|
87
|
+
BUN_GIT_HOOKS_RC=/path/to/env git-hooks
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
### Advanced Configuration
|
|
91
|
+
|
|
92
|
+
```ts
|
|
93
|
+
export default {
|
|
94
|
+
// Hook commands
|
|
95
|
+
'pre-commit': 'bun run lint && bun run test',
|
|
96
|
+
'commit-msg': 'bun commitlint --edit $1',
|
|
97
|
+
|
|
98
|
+
// Preserve specific unused hooks
|
|
99
|
+
'preserveUnused': ['post-merge', 'post-checkout'],
|
|
100
|
+
|
|
101
|
+
// Configure multiple hooks
|
|
102
|
+
'pre-push': [
|
|
103
|
+
'bun run build',
|
|
104
|
+
'bun run test:e2e'
|
|
105
|
+
].join(' && ')
|
|
106
|
+
}
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
### Error Handling
|
|
110
|
+
|
|
111
|
+
The library provides clear error messages:
|
|
112
|
+
|
|
113
|
+
```ts
|
|
114
|
+
try {
|
|
115
|
+
await setHooksFromConfig()
|
|
116
|
+
}
|
|
117
|
+
catch (err) {
|
|
118
|
+
if (err.message.includes('Config was not found')) {
|
|
119
|
+
console.error('Missing configuration file')
|
|
120
|
+
}
|
|
121
|
+
else if (err.message.includes('git root')) {
|
|
122
|
+
console.error('Not a Git repository')
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
### TypeScript Support
|
|
128
|
+
|
|
129
|
+
Full TypeScript support with detailed type definitions:
|
|
130
|
+
|
|
131
|
+
```ts
|
|
132
|
+
interface GitHooksConfig {
|
|
133
|
+
'pre-commit'?: string
|
|
134
|
+
'pre-push'?: string
|
|
135
|
+
'commit-msg'?: string
|
|
136
|
+
'post-merge'?: string
|
|
137
|
+
// ... other git hooks
|
|
138
|
+
'preserveUnused'?: Array<string> | boolean
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
// Types are automatically inferred
|
|
142
|
+
const config: GitHooksConfig = {
|
|
143
|
+
'pre-commit': 'bun run test',
|
|
144
|
+
'preserveUnused': ['post-checkout']
|
|
145
|
+
}
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
## Testing
|
|
149
|
+
|
|
150
|
+
```bash
|
|
151
|
+
bun test
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
## Changelog
|
|
155
|
+
|
|
156
|
+
Please see our [releases](https://github.com/stackjs/bun-git-hooks/releases) page for more information on what has changed recently.
|
|
157
|
+
|
|
158
|
+
## Contributing
|
|
159
|
+
|
|
160
|
+
Please see [CONTRIBUTING](.github/CONTRIBUTING.md) for details.
|
|
161
|
+
|
|
162
|
+
## Community
|
|
163
|
+
|
|
164
|
+
For help, discussion about best practices, or any other conversation that would benefit from being searchable:
|
|
165
|
+
|
|
166
|
+
[Discussions on GitHub](https://github.com/stacksjs/bun-git-hooks/discussions)
|
|
167
|
+
|
|
168
|
+
For casual chit-chat with others using this package:
|
|
169
|
+
|
|
170
|
+
[Join the Stacks Discord Server](https://discord.gg/stacksjs)
|
|
171
|
+
|
|
172
|
+
## Postcardware
|
|
173
|
+
|
|
174
|
+
Stacks OSS will always stay open-sourced, and we will always love to receive postcards from wherever Stacks is used! _And we also publish them on our website._
|
|
175
|
+
|
|
176
|
+
Our address: Stacks.js, 12665 Village Ln #2306, Playa Vista, CA 90094, United States ๐
|
|
177
|
+
|
|
178
|
+
## Credits
|
|
179
|
+
|
|
180
|
+
Many thanks to [`simple-git-hooks`](https://github.com/toplenboren/simple-git-hooks) and its contributors for inspiring this project.
|
|
181
|
+
|
|
182
|
+
## Sponsors
|
|
183
|
+
|
|
184
|
+
We would like to extend our thanks to the following sponsors for funding Stacks development. If you are interested in becoming a sponsor, please reach out to us.
|
|
185
|
+
|
|
186
|
+
- [JetBrains](https://www.jetbrains.com/)
|
|
187
|
+
- [The Solana Foundation](https://solana.com/)
|
|
188
|
+
|
|
189
|
+
## License
|
|
190
|
+
|
|
191
|
+
The MIT License (MIT). Please see [LICENSE](LICENSE.md) for more information.
|
|
192
|
+
|
|
193
|
+
Made with ๐
|
|
194
|
+
|
|
195
|
+
<!-- Badges -->
|
|
196
|
+
[npm-version-src]: https://img.shields.io/npm/v/bun-git-hooks?style=flat-square
|
|
197
|
+
[npm-version-href]: https://npmjs.com/package/bun-git-hooks
|
|
198
|
+
[github-actions-src]: https://img.shields.io/github/actions/workflow/status/stacksjs/bun-git-hooks/ci.yml?style=flat-square&branch=main
|
|
199
|
+
[github-actions-href]: https://github.com/stacksjs/bun-git-hooks/actions?query=workflow%3Aci
|
|
200
|
+
|
|
201
|
+
<!-- [codecov-src]: https://img.shields.io/codecov/c/gh/stacksjs/bun-git-hooks/main?style=flat-square
|
|
202
|
+
[codecov-href]: https://codecov.io/gh/stacksjs/bun-git-hooks -->
|