Skip to content

Commit 2078b2d

Browse files
committed
chore: improve cli build
1 parent 91d8756 commit 2078b2d

File tree

4 files changed

+24
-13
lines changed

4 files changed

+24
-13
lines changed

bin/cli.ts

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/usr/bin/env node
1+
#!/usr/bin/env bun
22
import process from 'node:process'
33
import { CAC } from 'cac'
44
import { version } from '../package.json'
@@ -16,17 +16,24 @@ if (['1', 'true'].includes(SKIP_INSTALL_GIT_HOOKS || '')) {
1616
cli
1717
.command('[configPath]', 'Install git hooks, optionally from specified config file')
1818
.option('--verbose', 'Enable verbose logging')
19-
.example('bun-git-hooks')
20-
.example('bun-git-hooks ../src/config.ts')
21-
.example('bun-git-hooks --verbose')
19+
.example('git-hooks')
20+
.example('git-hooks ../src/config.ts')
21+
.example('git-hooks --verbose')
2222
.action(async (configPath?: string, options?: { verbose?: boolean }) => {
2323
try {
2424
if (options?.verbose) {
2525
console.log('[DEBUG] Config path:', configPath || 'using default')
2626
console.log('[DEBUG] Working directory:', process.cwd())
2727
}
2828

29-
setHooksFromConfig(process.cwd(), { configFile: configPath })
29+
if (configPath) {
30+
const config = await import(configPath)
31+
setHooksFromConfig(process.cwd(), { configFile: config })
32+
}
33+
else {
34+
setHooksFromConfig(process.cwd())
35+
}
36+
3037
console.log('[INFO] Successfully set all git hooks')
3138
}
3239
catch (err) {
@@ -37,11 +44,11 @@ cli
3744

3845
cli
3946
.command('uninstall', 'Remove all git hooks')
40-
.alias('remove') // Add alias for uninstall
47+
.alias('remove')
4148
.option('--verbose', 'Enable verbose logging')
42-
.example('bun-git-hooks uninstall')
43-
.example('bunx bun-git-hooks remove')
44-
.example('bunx git-hooks uninstall --verbose')
49+
.example('git-hooks uninstall')
50+
.example('git-hooks remove')
51+
.example('git-hooks uninstall --verbose')
4552
.action(async (options?: { verbose?: boolean }) => {
4653
try {
4754
if (options?.verbose) {
@@ -59,4 +66,6 @@ cli
5966

6067
cli.version(version)
6168
cli.help()
69+
70+
// Parse CLI args
6271
cli.parse()

build.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@ await Bun.build({
1212
await Bun.build({
1313
entrypoints: ['bin/cli.ts'],
1414
target: 'bun',
15-
outdir: './dist',
15+
outdir: './dist/bin',
1616
plugins: [dts()],
1717
})

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,10 @@
3838
"module": "./dist/index.js",
3939
"types": "./dist/index.d.ts",
4040
"bin": {
41-
"git-hooks": "./bin/git-hooks",
42-
"bun-git-hooks": "./bin/git-hooks"
41+
"git-hooks": "./dist/bin/cli.js",
42+
"bun-git-hooks": "./dist/bin/cli.js"
4343
},
44-
"files": ["README.md", "bin", "dist"],
44+
"files": ["README.md", "dist"],
4545
"scripts": {
4646
"build": "bun build.ts && bun run compile",
4747
"compile": "bun build ./bin/cli.ts --compile --minify --outfile bin/git-hooks",

scripts/postinstall.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,11 @@ async function postinstall() {
2828

2929
const sourcePath = join(process.cwd(), 'dist', 'bin', 'cli.js')
3030
const targetPath = join(binDir, 'bun-git-hooks')
31+
const targetPath2 = join(binDir, 'git-hooks')
3132

3233
try {
3334
await symlink(sourcePath, targetPath, 'file')
35+
await symlink(sourcePath, targetPath2, 'file')
3436
}
3537
catch (err) {
3638
if ((err as NodeJS.ErrnoException).code !== 'EEXIST') {

0 commit comments

Comments
 (0)