commitplease
Advanced tools
Comparing version 0.2.0 to 0.3.0
#!/usr/bin/env node | ||
require( "colors" ); | ||
var fs = require( "fs" ); | ||
var commitplease = require( "commitplease" ); | ||
var message = fs.readFileSync( process.argv[ 2 ] ).toString(); | ||
var errors = commitplease( message ); | ||
if ( errors ) { | ||
console.error( "Invalid commit message, please fix the following issues:\n" ); | ||
console.error( "- " + errors.join( "\n- " ).red ); | ||
console.error(); | ||
console.error( "Commit message was:"); | ||
console.error(); | ||
console.error( message.green ); | ||
process.exit( 1 ); | ||
} | ||
require( "commitplease" )( process.argv[ 2 ] ); |
52
index.js
@@ -1,38 +0,16 @@ | ||
var merge = require( "mout/object/merge" ), | ||
defaults = { | ||
component: true, | ||
limits: { | ||
subject: 50, | ||
other: 72 | ||
} | ||
}; | ||
module.exports = function( message, options ) { | ||
options = merge( defaults, options ); | ||
var errors = []; | ||
message.split(/\n/).forEach(function ( line, index ) { | ||
if ( index === 0 ) { | ||
if ( line.length > options.limits.subject ) { | ||
errors.push( "First line (subject) must be no longer than " + | ||
options.limits.subject + " characters" ); | ||
} | ||
if ( options.component && line.indexOf( ":" ) < 1 ) { | ||
errors.push( "First line (subject) must indicate the component " + | ||
"(or subsystem)" ); | ||
} | ||
} | ||
if ( index === 1 && line.length > 0 ) { | ||
errors.push("Second line must always be empty"); | ||
} | ||
if ( index > 1 && line.length > options.limits.other ) { | ||
errors.push( "Commit message line " + index + " too long: " + | ||
line.length + " characters, only " + options.limits.other + | ||
" allowed. Was: " + line.substring( 0, 20 ) + "[...]" ); | ||
} | ||
}); | ||
return errors; | ||
require( "colors" ); | ||
var fs = require( "fs" ), | ||
validate = require( "lib/validate" ); | ||
module.exports = function( messageFile ) { | ||
var message = fs.readFileSync( messageFile ).toString(); | ||
var errors = validate( message ); | ||
if ( errors ) { | ||
console.error( "Invalid commit message, please fix the following issues:\n" ); | ||
console.error( "- " + errors.join( "\n- " ).red ); | ||
console.error(); | ||
console.error( "Commit message was:"); | ||
console.error(); | ||
console.error( message.green ); | ||
process.exit( 1 ); | ||
} | ||
}; |
@@ -6,4 +6,2 @@ // based on install.js by bahmutov | ||
console.log(pkg.name, pkg.version); | ||
console.log("cwd\t\t", process.cwd()); | ||
console.log("__dirname\t", __dirname); | ||
@@ -35,2 +33,3 @@ (function avoidSelfInstall() { | ||
var name = "commit-msg"; | ||
console.log('installing hook', name); | ||
@@ -53,3 +52,4 @@ | ||
// make it executable. | ||
fs.writeFileSync(hook, hookContent); | ||
fs.chmodSync(hook, '755'); | ||
fs.symlinkSync(path.resolve("./commit-msg-hook.js"), hook); | ||
// fs.writeFileSync(hook, hookContent); | ||
// fs.chmodSync(hook, '755'); |
{ | ||
"name": "commitplease", | ||
"version": "0.2.0", | ||
"version": "0.3.0", | ||
"description": "Validates strings as commit messages", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
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
6597
9
158