feat(pre): add initial version of command
This commit is contained in:
parent
f31a5dfd04
commit
0ee9cc31e9
20
lib/type/analyze.js
Normal file
20
lib/type/analyze.js
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
'use strict'
|
||||||
|
|
||||||
|
module.exports = function (commits) {
|
||||||
|
var type = null
|
||||||
|
|
||||||
|
commits.every(function (commit) {
|
||||||
|
if (commit.breaks.length) {
|
||||||
|
type = 'major'
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
if (commit.type === 'feat') type = 'minor'
|
||||||
|
|
||||||
|
if (!type && commit.type === 'fix') type = 'patch'
|
||||||
|
|
||||||
|
return true
|
||||||
|
})
|
||||||
|
|
||||||
|
return type
|
||||||
|
}
|
14
lib/type/commits.js
Normal file
14
lib/type/commits.js
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
'use strict'
|
||||||
|
|
||||||
|
var git = require('conventional-changelog/lib/git')
|
||||||
|
|
||||||
|
module.exports = function (cb) {
|
||||||
|
git.latestTag(function (err, from) {
|
||||||
|
if (err) return cb(err)
|
||||||
|
|
||||||
|
git.getCommits({from: from}, function (err, commits) {
|
||||||
|
if (err) return cb(err)
|
||||||
|
cb(null, commits)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
12
lib/type/index.js
Normal file
12
lib/type/index.js
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
'use strict'
|
||||||
|
|
||||||
|
var commits = require('./commits')
|
||||||
|
var analyze = require('./analyze')
|
||||||
|
|
||||||
|
module.exports = function (cb) {
|
||||||
|
commits(function (err, commits) {
|
||||||
|
if (err) return cb(err)
|
||||||
|
|
||||||
|
cb(null, analyze(commits))
|
||||||
|
})
|
||||||
|
}
|
18
lib/version.js
Normal file
18
lib/version.js
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
'use strict'
|
||||||
|
|
||||||
|
var exec = require('child_process').exec
|
||||||
|
var unlink = require('fs').unlinkSync
|
||||||
|
|
||||||
|
module.exports = function (pkg, cb) {
|
||||||
|
if (!pkg.name) return cb('Package must have a name')
|
||||||
|
|
||||||
|
exec('npm show ' + pkg.name + ' version', function(err, stdout, stderr) {
|
||||||
|
if (err) unlink('./npm-debug.log')
|
||||||
|
|
||||||
|
if (err && /is not in the npm registry/m.test(stderr)) return cb(null, null, true)
|
||||||
|
|
||||||
|
if (err) return cb(err)
|
||||||
|
|
||||||
|
cb(null, stdout.trim())
|
||||||
|
})
|
||||||
|
}
|
26
src/pre.js
Normal file
26
src/pre.js
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
'use strict'
|
||||||
|
|
||||||
|
var fs = require('fs')
|
||||||
|
|
||||||
|
var semver = require('semver')
|
||||||
|
|
||||||
|
var type = require('../lib/type')
|
||||||
|
var version = require('../lib/version')
|
||||||
|
|
||||||
|
module.exports = function (options, cb) {
|
||||||
|
type(function (err, type) {
|
||||||
|
if (err) return cb(err)
|
||||||
|
if (!type) return cb(null, null)
|
||||||
|
|
||||||
|
var path = './package.json'
|
||||||
|
var pkg = JSON.parse(fs.readFileSync(path))
|
||||||
|
version(pkg, function (err, version, unpublished) {
|
||||||
|
if (err) return cb(err)
|
||||||
|
|
||||||
|
pkg.version = unpublished ? '1.0.0' : semver.inc(version, type)
|
||||||
|
if (!options.debug) fs.writeFileSync(path, JSON.stringify(pkg, null, 2))
|
||||||
|
|
||||||
|
cb(null, pkg.version)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user