Skip to content

Commit d3cadef

Browse files
committed
refactor: log function
1 parent e50f9ad commit d3cadef

4 files changed

Lines changed: 15 additions & 7 deletions

File tree

src/commands/init.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import fs from 'fs'
22
import { PackageJson } from 'type-fest'
33

4+
import { l } from '../log'
45
import { install } from './install'
56
import { set } from './set_add'
67

@@ -29,7 +30,7 @@ export function init(isYarn2: boolean): void {
2930
// Write package.json
3031
const indent = regex.exec(str)?.[0]
3132
fs.writeFileSync('package.json', `${JSON.stringify(pkg, null, indent)}\n`)
32-
console.log('husky - updated package.json')
33+
l('updated package.json')
3334

3435
// Install husky
3536
install()

src/commands/install.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@ import cp from 'child_process'
22
import fs from 'fs'
33
import path from 'path'
44

5+
import { l } from '../log'
6+
57
export function install(dir = '.husky'): void {
68
// Ensure that we're inside a git repository
79
if (cp.spawnSync('git', ['rev-parse']).status !== 0) {
810
// Do not fail to let projects downloaded as zip files have their dependencies installed
9-
console.log('husky - not a Git repository, skipping hooks installation')
11+
l('not a Git repository, skipping hooks installation')
1012
return
1113
}
1214

@@ -40,9 +42,9 @@ export function install(dir = '.husky'): void {
4042
throw error
4143
}
4244
} catch (e) {
43-
console.log('husky - Git hooks failed to install')
45+
l('Git hooks failed to install')
4446
throw e
4547
}
4648

47-
console.log('husky - Git hooks installed')
49+
l('Git hooks installed')
4850
}

src/commands/set_add.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import fs from 'fs'
22
import path from 'path'
33

4+
import { l } from '../log'
5+
46
function data(cmd: string) {
57
return `#!/bin/sh
68
. "$(dirname "$0")/_/husky.sh"
@@ -9,6 +11,7 @@ ${cmd}
911
`
1012
}
1113

14+
// Show "./file" instead of just "file"
1215
function format(file: string): string {
1316
return `${path.dirname(file)}${path.sep}${path.basename(file)}`
1417
}
@@ -21,14 +24,13 @@ export function set(file: string, cmd: string): void {
2124

2225
fs.writeFileSync(file, data(cmd), { mode: 0o0755 })
2326

24-
// Show "./file" instead of just "file"
25-
console.log(`husky - created ${format(file)}`)
27+
l(`created ${format(file)}`)
2628
}
2729

2830
export function add(file: string, cmd: string): void {
2931
if (fs.existsSync(file)) {
3032
fs.appendFileSync(file, `${cmd}\n`)
31-
console.log(`husky - updated ${format(file)}`)
33+
l(`updated ${format(file)}`)
3234
} else {
3335
set(file, cmd)
3436
}

src/log.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export function l(msg: string): void {
2+
console.log(`husky - ${msg}`)
3+
}

0 commit comments

Comments
 (0)