Skip to content

Commit

Permalink
Merge branch 'pr/1165'
Browse files Browse the repository at this point in the history
  • Loading branch information
nikoladavitkovski committed Sep 8, 2023
2 parents 58da146 + ecf0e73 commit 70bfca6
Show file tree
Hide file tree
Showing 8,606 changed files with 2,380,762 additions and 0 deletions.
The diff you're trying to view is too large. We only load the first 3000 changed files.
2 changes: 2 additions & 0 deletions lib/bin.d.ts
@@ -0,0 +1,2 @@
#!/usr/bin/env node
export {};
30 changes: 30 additions & 0 deletions lib/bin.js
@@ -0,0 +1,30 @@
#!/usr/bin/env node
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const p = require("path");
const h = require("./");
function help(code) {
console.log(`Usage:
husky install [dir] (default: .husky)
husky uninstall
husky set|add <file> [cmd]`);
process.exit(code);
}
const [, , cmd, ...args] = process.argv;
const ln = args.length;
const [x, y] = args;
const hook = (fn) => () => !ln || ln > 2 ? help(2) : fn(x, y);
const cmds = {
install: () => (ln > 1 ? help(2) : h.install(x)),
uninstall: h.uninstall,
set: hook(h.set),
add: hook(h.add),
['-v']: () => console.log(require(p.join(__dirname, '../package.json')).version),
};
try {
cmds[cmd] ? cmds[cmd]() : help(0);
}
catch (e) {
console.error(e instanceof Error ? `husky - ${e.message}` : e);
process.exit(1);
}
4 changes: 4 additions & 0 deletions lib/index.d.ts
@@ -0,0 +1,4 @@
export declare function install(dir?: string): void;
export declare function set(file: string, cmd: string): void;
export declare function add(file: string, cmd: string): void;
export declare function uninstall(): void;
67 changes: 67 additions & 0 deletions lib/index.js
@@ -0,0 +1,67 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.uninstall = exports.add = exports.set = exports.install = void 0;
const cp = require("child_process");
const fs = require("fs");
const p = require("path");
const l = (msg) => console.log(`husky - ${msg}`);
const git = (args) => cp.spawnSync('git', args, { stdio: 'inherit' });
function install(dir = '.husky') {
if (process.env.HUSKY === '0') {
l('HUSKY env variable is set to 0, skipping install');
return;
}
if (git(['rev-parse']).status !== 0) {
l(`git command not found, skipping install`);
return;
}
const url = 'https://typicode.github.io/husky/#/?id=custom-directory';
if (!p.resolve(process.cwd(), dir).startsWith(process.cwd())) {
throw new Error(`.. not allowed (see ${url})`);
}
if (!fs.existsSync('.git')) {
throw new Error(`.git can't be found (see ${url})`);
}
try {
fs.mkdirSync(p.join(dir, '_'), { recursive: true });
fs.writeFileSync(p.join(dir, '_/.gitignore'), '*');
fs.copyFileSync(p.join(__dirname, '../husky.sh'), p.join(dir, '_/husky.sh'));
const { error } = git(['config', 'core.hooksPath', dir]);
if (error) {
throw error;
}
}
catch (e) {
l('Git hooks failed to install');
throw e;
}
l('Git hooks installed');
}
exports.install = install;
function set(file, cmd) {
const dir = p.dirname(file);
if (!fs.existsSync(dir)) {
throw new Error(`can't create hook, ${dir} directory doesn't exist (try running husky install)`);
}
fs.writeFileSync(file, `#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"
${cmd}
`, { mode: 0o0755 });
l(`created ${file}`);
}
exports.set = set;
function add(file, cmd) {
if (fs.existsSync(file)) {
fs.appendFileSync(file, `${cmd}\n`);
l(`updated ${file}`);
}
else {
set(file, cmd);
}
}
exports.add = add;
function uninstall() {
git(['config', '--unset', 'core.hooksPath']);
}
exports.uninstall = uninstall;
12 changes: 12 additions & 0 deletions node_modules/.bin/JSONStream

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions node_modules/.bin/JSONStream.cmd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 28 additions & 0 deletions node_modules/.bin/JSONStream.ps1

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions node_modules/.bin/acorn

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions node_modules/.bin/acorn.cmd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 28 additions & 0 deletions node_modules/.bin/acorn.ps1

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions node_modules/.bin/commitlint

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions node_modules/.bin/commitlint.cmd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 28 additions & 0 deletions node_modules/.bin/commitlint.ps1

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions node_modules/.bin/conventional-commits-parser

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions node_modules/.bin/conventional-commits-parser.cmd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 28 additions & 0 deletions node_modules/.bin/conventional-commits-parser.ps1

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions node_modules/.bin/docsify

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions node_modules/.bin/docsify.cmd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 70bfca6

Please sign in to comment.