From 622e4db0afdf19c060525fdb7893631fec0dc689 Mon Sep 17 00:00:00 2001 From: typicode Date: Fri, 28 Apr 2023 12:19:18 +0200 Subject: [PATCH] refactor: comments (#1257) Co-authored-by: Pascal Jufer --- src/bin.ts | 2 +- src/index.ts | 12 ++++++++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/bin.ts b/src/bin.ts index 7ce15e3ad..47e511091 100644 --- a/src/bin.ts +++ b/src/bin.ts @@ -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 diff --git a/src/index.ts b/src/index.ts index c91ac19f5..5f160b6f0 100644 --- a/src/index.ts +++ b/src/index.ts @@ -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 => 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 @@ -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)) { @@ -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`) @@ -89,6 +92,7 @@ export function add(file: string, cmd: string): void { } } +// Uninstall husky export function uninstall(): void { git(['config', '--unset', 'core.hooksPath']) }