Comparing version 0.9.3 to 0.10.0
{ | ||
"name": "husky", | ||
"version": "0.9.3", | ||
"version": "0.10.0", | ||
"description": "Prevents bad commit or push (git hooks, pre-commit/precommit, pre-push/prepush, post-merge/postmerge and all that stuff...)", | ||
@@ -36,2 +36,3 @@ "main": "index.js", | ||
"devDependencies": { | ||
"mkdirp": "^0.5.1", | ||
"rimraf": "^2.2.8" | ||
@@ -38,0 +39,0 @@ }, |
@@ -7,3 +7,3 @@ var fs = require('fs') | ||
module.exports = { | ||
isHusky: function(filename) { | ||
isHusky: function (filename) { | ||
var data = fs.readFileSync(filename, 'utf-8') | ||
@@ -13,4 +13,4 @@ return data.indexOf('# husky') !== -1 | ||
hooksDir: function(callback) { | ||
exec('git rev-parse --git-dir', function(error, stdout, stderr) { | ||
hooksDir: function (callback) { | ||
exec('git rev-parse --git-dir', function (error, stdout, stderr) { | ||
if (error) { | ||
@@ -24,3 +24,3 @@ callback(stderr, null) | ||
write: function(filename, data) { | ||
write: function (filename, data) { | ||
fs.writeFileSync(filename, data) | ||
@@ -30,11 +30,12 @@ fs.chmodSync(filename, 0755) | ||
create: function(dir, name, cmd) { | ||
create: function (dir, name, cmd) { | ||
var filename = dir + '/' + name | ||
var data = | ||
'#!/bin/sh\n' | ||
+ '# husky\n' | ||
var arr = [ | ||
'#!/bin/sh', | ||
'# husky' | ||
] | ||
// Needed on OS X / Linux when nvm is used and committing from Sublime Text | ||
if (process.platform !== 'win32') { | ||
data += 'PATH="' + process.env.PATH + '"\n' | ||
arr.push('PATH="' + process.env.PATH + '"') | ||
} | ||
@@ -55,16 +56,18 @@ | ||
data += | ||
'cd ' + normalizedPath + '\n' | ||
// Fix for issue #16 #24 | ||
// Test if script is defined in package.json | ||
+ '[ -f package.json ] && cat package.json | grep -q \'"' + cmd + '"\\s*:\'\n' | ||
// package.json or script can't be found exit | ||
+ '[ $? -ne 0 ] && exit 0\n' | ||
+ 'npm run ' + cmd + ' --silent\n' | ||
+ 'if [ $? -ne 0 ]; then\n' | ||
+ ' echo\n' | ||
+ ' echo "husky - ' + name + ' hook failed (add --no-verify to bypass)"\n' | ||
+ ' echo\n' | ||
+ ' exit 1\n' | ||
+ 'fi\n' | ||
// Hook script | ||
arr = arr.concat([ | ||
'cd ' + normalizedPath, | ||
// Fix for issue #16 #24 | ||
// Test if script is defined in package.json | ||
'[ -f package.json ] && cat package.json | grep -q \'"' + cmd + '"\\s*:\'', | ||
// package.json or script can't be found exit | ||
'[ $? -ne 0 ] && exit 0', | ||
'npm run ' + cmd + ' --silent -- "$@"', | ||
'if [ $? -ne 0 ]; then', | ||
' echo', | ||
' echo "husky - ' + name + ' hook failed (add --no-verify to bypass)"', | ||
' echo', | ||
' exit 1', | ||
'fi' | ||
]) | ||
@@ -75,2 +78,3 @@ // Create hooks directory if needed | ||
// Create hook file | ||
var data = arr.join('\n') | ||
if (!fs.existsSync(filename)) { | ||
@@ -87,3 +91,3 @@ this.write(filename, data) | ||
remove: function(dir, name) { | ||
remove: function (dir, name) { | ||
var filename = dir + '/' + name | ||
@@ -90,0 +94,0 @@ |
var assert = require('assert') | ||
var fs = require('fs') | ||
var path = require('path') | ||
var rm = require('rimraf') | ||
var husky = require('../src/') | ||
var fs = require('fs') | ||
var path = require('path') | ||
var rmrf = require('rimraf') | ||
var mkdirp = require('mkdirp') | ||
var husky = require('../src/') | ||
@@ -10,3 +11,3 @@ // Some very basic tests... | ||
// should return git hooks path | ||
husky.hooksDir(function(err, dir) { | ||
husky.hooksDir(function (err, dir) { | ||
assert.equal(err, null) | ||
@@ -17,4 +18,4 @@ assert.equal(dir, '.git/hooks') | ||
// Reset tmp dir | ||
rm.sync('../tmp') | ||
fs.mkdirSync('../tmp') | ||
rmrf.sync(path.join(__dirname, '../tmp')) | ||
mkdirp.sync(path.join(__dirname, '../tmp')) | ||
@@ -24,7 +25,7 @@ var dir = '../tmp/hooks' | ||
// husky should be able to create a hook and update it | ||
assert.doesNotThrow(function() { | ||
assert.doesNotThrow(function () { | ||
husky.create(dir, 'pre-commit', 'foo') | ||
}) | ||
assert.doesNotThrow(function() { | ||
assert.doesNotThrow(function () { | ||
husky.create(dir, 'pre-commit', 'bar') | ||
@@ -45,2 +46,2 @@ }) | ||
assert.equal(fs.readFileSync(dir + '/user-pre-commit', 'utf-8'), '') | ||
assert.equal(fs.readFileSync(dir + '/user-pre-commit', 'utf-8'), '') |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
7728
156
2