Skip to content

Commit

Permalink
refactor: comments (#1257)
Browse files Browse the repository at this point in the history
Co-authored-by: Pascal Jufer <pascal-jufer@bluewin.ch>
  • Loading branch information
typicode and paescuj committed Apr 28, 2023
1 parent 3749193 commit 622e4db
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/bin.ts
Expand Up @@ -18,7 +18,7 @@ const [x, y] = args

// Set or add command in hook
const hook = (fn: (a1: string, a2: string) => void) => (): void =>
// Show usage if no arguments are provided or more than 2
// Show usage if no arguments or more than 2 are provided
!ln || ln > 2 ? help(2) : fn(x, y)

// CLI commands
Expand Down
12 changes: 8 additions & 4 deletions src/index.ts
Expand Up @@ -5,19 +5,20 @@ import p = require('path')
// Logger
const l = (msg: string): void => console.log(`husky - ${msg}`)

// Git command
// Execute Git command
const git = (args: string[]): cp.SpawnSyncReturns<Buffer> =>
cp.spawnSync('git', args, { stdio: 'inherit' })

// Install husky
export function install(dir = '.husky'): void {
if (process.env.HUSKY === '0') {
l('HUSKY env variable is set to 0, skipping install')
return
}

// Ensure that we're inside a git repository
// If git command is not found, status is null and we should return.
// That's why status value needs to be checked explicitly.
// Ensure that we're inside a Git repository
// If git command is not found, status is null and we should return
// That's why status value needs to be checked explicitly
if (git(['rev-parse']).status !== 0) {
l(`git command not found, skipping install`)
return
Expand Down Expand Up @@ -59,6 +60,7 @@ export function install(dir = '.husky'): void {
l('Git hooks installed')
}

// Create a hook file if it doesn't exist or overwrite it
export function set(file: string, cmd: string): void {
const dir = p.dirname(file)
if (!fs.existsSync(dir)) {
Expand All @@ -80,6 +82,7 @@ ${cmd}
l(`created ${file}`)
}

// Create a hook if it doesn't exist or append command to it
export function add(file: string, cmd: string): void {
if (fs.existsSync(file)) {
fs.appendFileSync(file, `${cmd}\n`)
Expand All @@ -89,6 +92,7 @@ export function add(file: string, cmd: string): void {
}
}

// Uninstall husky
export function uninstall(): void {
git(['config', '--unset', 'core.hooksPath'])
}

0 comments on commit 622e4db

Please sign in to comment.