File tree Expand file tree Collapse file tree 4 files changed +20
-15
lines changed Expand file tree Collapse file tree 4 files changed +20
-15
lines changed Original file line number Diff line number Diff line change 1
1
import { Buffer } from 'node:buffer'
2
- import fs from 'node:fs'
3
- import path from 'node:path'
4
2
import process from 'node:process'
5
3
import { CAC } from 'cac'
6
4
import { version } from '../package.json'
7
5
import { defaultConfig } from '../src/config'
6
+ import { readCommitMessageFromFile } from '../src/utils'
8
7
9
8
const cli = new CAC ( 'gitlint' )
10
9
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
-
24
10
// Main lint command
25
11
cli
26
12
. command ( '[...files]' , 'Lint commit message' )
Original file line number Diff line number Diff line change @@ -4,4 +4,5 @@ await Bun.build({
4
4
entrypoints : [ 'src/index.ts' ] ,
5
5
outdir : './dist' ,
6
6
plugins : [ dts ( ) ] ,
7
+ target : 'node' ,
7
8
} )
Original file line number Diff line number Diff line change @@ -4,3 +4,4 @@ export * from './lint'
4
4
export * from './parser'
5
5
export * from './rules'
6
6
export * from './types'
7
+ export * from './utils'
Original file line number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments