diff --git a/src/commands/init.ts b/src/commands/init.ts index 1157f0cdc..527d57da7 100644 --- a/src/commands/init.ts +++ b/src/commands/init.ts @@ -1,6 +1,7 @@ import fs from 'fs' import { PackageJson } from 'type-fest' +import { l } from '../log' import { install } from './install' import { set } from './set_add' @@ -29,7 +30,7 @@ export function init(isYarn2: boolean): void { // Write package.json const indent = regex.exec(str)?.[0] fs.writeFileSync('package.json', `${JSON.stringify(pkg, null, indent)}\n`) - console.log('husky - updated package.json') + l('updated package.json') // Install husky install() diff --git a/src/commands/install.ts b/src/commands/install.ts index 7b564c37d..bfd76ccb5 100644 --- a/src/commands/install.ts +++ b/src/commands/install.ts @@ -2,11 +2,13 @@ import cp from 'child_process' import fs from 'fs' import path from 'path' +import { l } from '../log' + export function install(dir = '.husky'): void { // Ensure that we're inside a git repository if (cp.spawnSync('git', ['rev-parse']).status !== 0) { // Do not fail to let projects downloaded as zip files have their dependencies installed - console.log('husky - not a Git repository, skipping hooks installation') + l('not a Git repository, skipping hooks installation') return } @@ -40,9 +42,9 @@ export function install(dir = '.husky'): void { throw error } } catch (e) { - console.log('husky - Git hooks failed to install') + l('Git hooks failed to install') throw e } - console.log('husky - Git hooks installed') + l('Git hooks installed') } diff --git a/src/commands/set_add.ts b/src/commands/set_add.ts index 0a5ec98d9..d160fba42 100644 --- a/src/commands/set_add.ts +++ b/src/commands/set_add.ts @@ -1,6 +1,8 @@ import fs from 'fs' import path from 'path' +import { l } from '../log' + function data(cmd: string) { return `#!/bin/sh . "$(dirname "$0")/_/husky.sh" @@ -9,6 +11,7 @@ ${cmd} ` } +// Show "./file" instead of just "file" function format(file: string): string { return `${path.dirname(file)}${path.sep}${path.basename(file)}` } @@ -21,14 +24,13 @@ export function set(file: string, cmd: string): void { fs.writeFileSync(file, data(cmd), { mode: 0o0755 }) - // Show "./file" instead of just "file" - console.log(`husky - created ${format(file)}`) + l(`created ${format(file)}`) } export function add(file: string, cmd: string): void { if (fs.existsSync(file)) { fs.appendFileSync(file, `${cmd}\n`) - console.log(`husky - updated ${format(file)}`) + l(`updated ${format(file)}`) } else { set(file, cmd) } diff --git a/src/log.ts b/src/log.ts new file mode 100644 index 000000000..d5280fd79 --- /dev/null +++ b/src/log.ts @@ -0,0 +1,3 @@ +export function l(msg: string): void { + console.log(`husky - ${msg}`) +}