feat(pre): add option to provide own commit message analyzer
This commit is contained in:
parent
29469e0b8a
commit
e445effdcf
@ -1,6 +1,8 @@
|
||||
#!/usr/bin/env node
|
||||
'use strict'
|
||||
|
||||
var readFile = require('fs').readFileSync
|
||||
|
||||
var abbrev = require('abbrev')
|
||||
var minimist = require('minimist')
|
||||
|
||||
@ -21,6 +23,8 @@ var argv = minimist(process.argv.slice(2), {
|
||||
}
|
||||
})
|
||||
|
||||
var plugins = JSON.parse(readFile('./package.json')).release || {}
|
||||
|
||||
var npmArgv = process.env.npm_config_argv ?
|
||||
minimist(JSON.parse(process.env.npm_config_argv).cooked) :
|
||||
{_: []}
|
||||
@ -46,7 +50,7 @@ if (~argv._.indexOf('pre')) {
|
||||
// require a correct setup during publish
|
||||
if (publish && !argv.debug && !require('../src/verify')(argv)) process.exit(1)
|
||||
|
||||
require('../src/pre')(argv, efh(function (result) {
|
||||
require('../src/pre')(argv, plugins, efh(function (result) {
|
||||
if (!result) {
|
||||
console.log('Nothing changed. Not publishing.')
|
||||
process.exit(1)
|
||||
|
@ -1,9 +1,21 @@
|
||||
'use strict'
|
||||
|
||||
var parseRawCommit = require('conventional-changelog/lib/git').parseRawCommit
|
||||
|
||||
module.exports = function (commits) {
|
||||
var type = null
|
||||
|
||||
commits.every(function (commit) {
|
||||
commits
|
||||
|
||||
.map(function (commit) {
|
||||
return parseRawCommit(commit.hash + '\n' + commit.message)
|
||||
})
|
||||
|
||||
.filter(function (commit) {
|
||||
return !!commit
|
||||
})
|
||||
|
||||
.every(function (commit) {
|
||||
if (commit.breaks.length) {
|
||||
type = 'major'
|
||||
return false
|
27
lib/commits.js
Normal file
27
lib/commits.js
Normal file
@ -0,0 +1,27 @@
|
||||
'use strict'
|
||||
|
||||
var exec = require('child_process').exec
|
||||
|
||||
var efh = require('./error').efh
|
||||
|
||||
module.exports = function (from, cb) {
|
||||
var range = (from ? from + '..' : '') + 'HEAD'
|
||||
exec(
|
||||
'git log -E --format=%H==SPLIT==%s==END== ' + range,
|
||||
efh(cb)(function (stdout) {
|
||||
cb(null, String(stdout).split('==END==\n')
|
||||
|
||||
.filter(function (raw) {
|
||||
return !!raw.trim()
|
||||
})
|
||||
|
||||
.map(function (raw) {
|
||||
var data = raw.split('==SPLIT==')
|
||||
return {
|
||||
hash: data[0],
|
||||
message: data[1]
|
||||
}
|
||||
}))
|
||||
})
|
||||
)
|
||||
}
|
@ -1,15 +0,0 @@
|
||||
'use strict'
|
||||
|
||||
var git = require('conventional-changelog/lib/git')
|
||||
|
||||
var efh = require('../error').efh
|
||||
|
||||
module.exports = function (from, cb) {
|
||||
git.getCommits({
|
||||
log: console.log.bind(console),
|
||||
warn: console.warn.bind(console),
|
||||
from: from
|
||||
}, efh(cb)(function (commits) {
|
||||
cb(null, commits)
|
||||
}))
|
||||
}
|
@ -1,11 +0,0 @@
|
||||
'use strict'
|
||||
|
||||
var analyze = require('./analyze')
|
||||
var commits = require('./commits')
|
||||
var efh = require('../error').efh
|
||||
|
||||
module.exports = function (gitHead, cb) {
|
||||
commits(gitHead, efh(cb)(function (commits) {
|
||||
cb(null, analyze(commits))
|
||||
}))
|
||||
}
|
11
src/pre.js
11
src/pre.js
@ -4,16 +4,21 @@ var fs = require('fs')
|
||||
|
||||
var semver = require('semver')
|
||||
|
||||
var type = require('../lib/type')
|
||||
var getCommits = require('../lib/commits')
|
||||
var npmInfo = require('../lib/npm-info')
|
||||
var efh = require('../lib/error').efh
|
||||
|
||||
module.exports = function (options, cb) {
|
||||
module.exports = function (options, plugins, cb) {
|
||||
var path = './package.json'
|
||||
var pkg = JSON.parse(fs.readFileSync(path))
|
||||
|
||||
if (!pkg.name) return cb(new Error('Package must have a name'))
|
||||
|
||||
npmInfo(pkg.name, efh(cb)(function (res) {
|
||||
type(res.gitHead, efh(cb)(function (type) {
|
||||
getCommits(res.gitHead, efh(cb)(function (commits) {
|
||||
var analyzer = require(plugins.analyzer || '../lib/analyzer')
|
||||
var type = analyzer(commits)
|
||||
|
||||
if (!type) return cb(null, null)
|
||||
pkg.version = !res.version ? '1.0.0' : semver.inc(res.version, type)
|
||||
if (!options.debug) fs.writeFileSync(path, JSON.stringify(pkg, null, 2))
|
||||
|
Loading…
x
Reference in New Issue
Block a user