Skip to content

Commit af0d598

Browse files
committed
chore: wip
1 parent 0c60b40 commit af0d598

File tree

4 files changed

+20
-15
lines changed

4 files changed

+20
-15
lines changed

bin/cli.ts

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,12 @@
11
import { Buffer } from 'node:buffer'
2-
import fs from 'node:fs'
3-
import path from 'node:path'
42
import process from 'node:process'
53
import { CAC } from 'cac'
64
import { version } from '../package.json'
75
import { defaultConfig } from '../src/config'
6+
import { readCommitMessageFromFile } from '../src/utils'
87

98
const cli = new CAC('gitlint')
109

11-
// Helper function to read commit message from file
12-
function readCommitMessageFromFile(filePath: string): string {
13-
try {
14-
return fs.readFileSync(path.resolve(process.cwd(), filePath), 'utf8')
15-
}
16-
catch (error: unknown) {
17-
console.error(`Error reading commit message file: ${filePath}`)
18-
console.error(error)
19-
process.exit(1)
20-
return '' // Unreachable but needed for TypeScript
21-
}
22-
}
23-
2410
// Main lint command
2511
cli
2612
.command('[...files]', 'Lint commit message')

build.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@ await Bun.build({
44
entrypoints: ['src/index.ts'],
55
outdir: './dist',
66
plugins: [dts()],
7+
target: 'node',
78
})

src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ export * from './lint'
44
export * from './parser'
55
export * from './rules'
66
export * from './types'
7+
export * from './utils'

src/utils.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import fs from 'node:fs'
2+
import path from 'node:path'
3+
import process from 'node:process'
4+
5+
/**
6+
* Read the commit message from a file
7+
*/
8+
export function readCommitMessageFromFile(filePath: string): string {
9+
try {
10+
return fs.readFileSync(path.resolve(process.cwd(), filePath), 'utf8')
11+
}
12+
catch (error: unknown) {
13+
console.error(`Error reading commit message file: ${filePath}`)
14+
console.error(error)
15+
process.exit(1)
16+
}
17+
}

0 commit comments

Comments
 (0)