ezchangelog
Advanced tools
Comparing version 3.0.5 to 4.0.0
@@ -5,4 +5,4 @@ #!/usr/bin/env node | ||
var minimist = require('minimist') | ||
var parser = require('../lib/parser') | ||
var format = require('../lib/format') | ||
var changeLog = require('..') | ||
var path = require('path') | ||
@@ -12,7 +12,11 @@ var argv = minimist( | ||
{ | ||
string: ['file'], | ||
boolean: ['print'], | ||
string: ['out'], | ||
boolean: ['print', 'incremental'], | ||
default: { | ||
incremental: true, | ||
}, | ||
alias: { | ||
p: 'print', | ||
f: 'file', | ||
o: 'out', | ||
inc: 'incremental', | ||
}, | ||
@@ -22,25 +26,26 @@ } | ||
Promise.resolve(argv.file) | ||
.then(function (file) { | ||
if (file) { | ||
return file | ||
} | ||
return require('../lib/config')().changelog | ||
}) | ||
.catch(function () { | ||
}) | ||
.then(function (file) { | ||
file = file || 'changelog.md' | ||
return readFile(file) | ||
getConfig(argv.out) | ||
.then(function (conf) { | ||
return readFile(conf.out) | ||
.then(function (src) { | ||
return { file: file, source: src } | ||
conf.source = src | ||
return conf | ||
}) | ||
}) | ||
.then(function (row) { | ||
.then(function (conf) { | ||
var dest = argv.print | ||
? process.stdout | ||
: fs.createWriteStream(row.file) | ||
: fs.createWriteStream(conf.out) | ||
var formatter = changeLog.format({ history: conf.source }) | ||
if (!argv.incremental) { | ||
formatter.get('filter').pop() | ||
formatter.get('wrap').pop() | ||
} else if (argv.print) { | ||
formatter.get('wrap').pop() | ||
} | ||
process.stdin | ||
.pipe(parser()) | ||
.pipe(format(row.source)) | ||
.pipe(changeLog.parse({ | ||
baseUrl: conf.baseUrl, | ||
})) | ||
.pipe(formatter) | ||
.pipe(dest) | ||
@@ -56,1 +61,19 @@ }) | ||
} | ||
function getConfig(out) { | ||
var noop = function () {} | ||
return new Promise(function (resolve) { | ||
resolve( | ||
require(path.resolve('package.json')).changelog | ||
) | ||
}) | ||
.catch(noop) | ||
.then(function (conf) { | ||
conf = conf || {} | ||
if (out) { | ||
conf.out = out | ||
} | ||
conf.out = conf.out || 'changelog.md' | ||
return conf | ||
}) | ||
} |
var thr = require('through2') | ||
var combine = require('stream-combiner2') | ||
var stringify = require('./stringify') | ||
var splicer = require('labeled-stream-splicer') | ||
var formatter = require('./formatter') | ||
@@ -9,8 +9,23 @@ var HEADER_PREFIX = '<!-- LATEST ' | ||
module.exports = function (history) { | ||
module.exports = function (opts) { | ||
var history = opts && opts.history | ||
var header | ||
var hasNewHeader = false | ||
var lastCommit = history && getLastCommit(history) | ||
var lastCommit = getLastCommit(history) | ||
function prepend(s, _, next) { | ||
function filter(ci, _, next) { | ||
if (lastCommit && lastCommit === ci.commit.short) { | ||
return this.push(null) | ||
} | ||
next(null, ci) | ||
} | ||
function collectHeader(ci, _, next) { | ||
if (!header) { | ||
header = getHeader(ci.commit.short) | ||
} | ||
next(null, ci) | ||
} | ||
function pushHeader(buf, _, next) { | ||
if (!hasNewHeader && header) { | ||
@@ -20,2 +35,6 @@ hasNewHeader = true | ||
} | ||
next(null, buf) | ||
} | ||
function prepend(s, _, next) { | ||
next(null, s) | ||
@@ -35,17 +54,8 @@ } | ||
function filter(ci, _, next) { | ||
var hash = ci.commit.short | ||
if (lastCommit && lastCommit === hash) { | ||
return this.push(null) | ||
} | ||
if (!header) { | ||
header = getHeader(hash) | ||
} | ||
next(null, ci) | ||
} | ||
return combine.obj([ | ||
thr.obj(filter), | ||
stringify(), | ||
thr(prepend, append), | ||
return splicer.obj([ | ||
'filter', [ thr.obj(filter) ], | ||
'header', [ thr.obj(collectHeader) ], | ||
'format', [ formatter() ], | ||
'pushHeader', [ thr(pushHeader) ], | ||
'wrap', [ thr(prepend, append) ], | ||
]) | ||
@@ -63,4 +73,6 @@ } | ||
function getLastCommit(history) { | ||
return hasHeader(history) && history.substring(HASH_OFFSET, HASH_OFFSET + 7) | ||
return history && | ||
hasHeader(history) && | ||
history.substring(HASH_OFFSET, HASH_OFFSET + 7) | ||
} | ||
@@ -1,131 +0,102 @@ | ||
var split = require('split2') | ||
var combine = require('stream-combiner2') | ||
var splicer = require('labeled-stream-splicer') | ||
var thr = require('through2') | ||
var getTags = require('./tags') | ||
var exec = require('child_process').exec | ||
module.exports = function () { | ||
return combine.obj(split(), parse()) | ||
module.exports = function (opts) { | ||
return splicer.obj([ | ||
'hash', [ hashParser() ], | ||
'tag', [ tagParser() ], | ||
'url', [ urlParser(opts) ], | ||
'committer', [ committerParser() ], | ||
'message', [ messageParser() ], | ||
]) | ||
} | ||
function parse() { | ||
var commit | ||
var tags = getTagList() | ||
var stream = thr.obj(write, end) | ||
function push(ci) { | ||
var messages = ci.messages.map(function (s) { | ||
return s.trim() | ||
}).filter(Boolean) | ||
ci.subject = messages[0] | ||
ci.body = messages.slice(1).join('\n') | ||
stream.push(ci) | ||
} | ||
function write(buf, _, next) { | ||
var msg = buf.toString('utf8') | ||
var hash = parseHash(msg) | ||
if (hash) { | ||
if (commit) { | ||
push(commit) | ||
function urlParser(opts) { | ||
opts = opts || {} | ||
var dir = opts.baseUrl && Promise.resolve(opts.baseUrl) || getGithubCommitDir() | ||
dir = dir.catch(function () {}) | ||
.then(function (baseUrl) { | ||
if (baseUrl && baseUrl.slice(-1) !== '/') { | ||
baseUrl += '/' | ||
} | ||
return tags.then(function (tag) { | ||
commit = { | ||
commit: { | ||
long: hash, | ||
short: hash.slice(0, 7), | ||
}, | ||
tag: tag[hash], | ||
messages: [], | ||
committer: {}, | ||
} | ||
next() | ||
}) | ||
} | ||
var committer = parseCommitter(msg) | ||
if (committer) { | ||
commit.committer = committer | ||
return next() | ||
} | ||
var date = parseDate(msg) | ||
if (date) { | ||
commit.committer.date = date | ||
return next() | ||
} | ||
commit.messages.push(msg) | ||
next() | ||
} | ||
function end(done) { | ||
if (commit) { | ||
push(commit) | ||
} | ||
done() | ||
} | ||
return stream | ||
return baseUrl | ||
}) | ||
return thr.obj(function (ci, _, next) { | ||
dir.then(function (baseUrl) { | ||
if (baseUrl) { | ||
ci.url = baseUrl + ci.commit.short | ||
} | ||
next(null, ci) | ||
}) | ||
}) | ||
} | ||
function parseHash(msg) { | ||
var info = msg.split(/\s+/) | ||
if (info[0] === 'commit') { | ||
return info[1] | ||
} | ||
return null | ||
function hashParser() { | ||
return thr.obj(function (ci, _, next) { | ||
ci.commit = {} | ||
ci.commit.long = ci.raws[0].slice(-40) | ||
ci.commit.short = ci.commit.long.slice(0, 7) | ||
next(null, ci) | ||
}) | ||
} | ||
function parseCommitter(msg) { | ||
var info = msg.split(/\s+/) | ||
if (info[0] === 'Author:') { | ||
return { | ||
name: info.slice(1, -1).join(' '), | ||
email: info[info.length - 1].slice(1, -1), | ||
function committerParser() { | ||
var DATE_LINE = /^Date: / | ||
return thr.obj(function (ci, _, next) { | ||
var line = ci.raws.filter(function (msg) { | ||
return DATE_LINE.test(msg) | ||
})[0] | ||
if (line) { | ||
var parsed = line.split(/\s+/) | ||
ci.committer = {} | ||
ci.committer.date = new Date(parsed.slice(1).join(' ')) | ||
} | ||
} | ||
return null | ||
next(null, ci) | ||
}) | ||
} | ||
function parseDate(msg) { | ||
var info = msg.split(/\s+/) | ||
if (info[0] === 'Date:') { | ||
return new Date(info.slice(1).join(' ')) | ||
} | ||
return null | ||
function messageParser() { | ||
var BODY_LINE = /^\s+/ | ||
return thr.obj(function (ci, _, next) { | ||
var lines = ci.raws.filter(function (msg) { | ||
return BODY_LINE.test(msg) | ||
}) | ||
var body = [] | ||
lines.forEach(function (line) { | ||
if (ci.subject) { | ||
return body.push(line) | ||
} | ||
ci.subject = line.trim() | ||
}) | ||
ci.body = body.join('\n') | ||
next(null, ci) | ||
}) | ||
} | ||
function getTagList() { | ||
return new Promise(function (resolve) { | ||
exec('git tag -l', function (err, lines) { | ||
var tags = [] | ||
if (lines) { | ||
tags = lines.split('\n') | ||
.map(function (s) { | ||
return s.trim() | ||
}) | ||
.filter(Boolean) | ||
} | ||
resolve(tags) | ||
function tagParser() { | ||
var tags = getTags() | ||
var noop = function () {} | ||
return thr.obj(function (ci, _, next) { | ||
tags.then(function (o) { | ||
ci.tag = o[ci.commit.long] | ||
}, noop) | ||
.then(function () { | ||
next(null, ci) | ||
}) | ||
}) | ||
.then(function (tags) { | ||
return tags.map(resolveTagHash) | ||
}) | ||
.then(Promise.all.bind(Promise)) | ||
.then(function (tags) { | ||
return tags.reduce(function (o, tag) { | ||
if (tag.hash) { | ||
o[tag.hash] = tag.name | ||
} | ||
return o | ||
}, {}) | ||
}) | ||
} | ||
function resolveTagHash(tag) { | ||
function getGithubCommitDir() { | ||
return new Promise(function (resolve) { | ||
exec('git show-ref --dereference ' + tag + ' | tail -n1 | awk \'{print $1}\'', function (err, line) { | ||
var hash = '' | ||
if (line) { | ||
hash = line.trim() | ||
exec('git remote -v | head -n1', function (err, line) { | ||
if (!line) { | ||
return resolve() | ||
} | ||
resolve({ name: tag, hash: hash }) | ||
var repo = line.split(/\s+/)[1] | ||
repo = repo.slice(repo.indexOf(':') + 1, -4) | ||
resolve( | ||
'https://github.com/' + repo + '/commit/' | ||
) | ||
}) | ||
@@ -132,0 +103,0 @@ }) |
{ | ||
"name": "ezchangelog", | ||
"version": "3.0.5", | ||
"version": "4.0.0", | ||
"description": "changelog", | ||
"bin": { | ||
"ezchangelog": "./bin/ezchangelog", | ||
"ezchangelog-stream": "./bin/stream.js" | ||
"ezchangelog": "./bin/cmd", | ||
"ezchangelogStream": "./bin/stream.js" | ||
}, | ||
@@ -28,7 +28,7 @@ "scripts": { | ||
"dependencies": { | ||
"labeled-stream-splicer": "^2.0.0", | ||
"minimist": "^1.2.0", | ||
"split2": "^1.0.0", | ||
"stream-combiner2": "^1.1.1", | ||
"through2": "^2.0.0", | ||
"util-mix": "^3.0.2" | ||
"through2": "^2.0.0" | ||
}, | ||
@@ -35,0 +35,0 @@ "devDependencies": { |
@@ -47,5 +47,5 @@ # ezchangelog | ||
`p, --print`: print the changelog contents rather than write to disk. | ||
`-p, --print`: print the changelog contents rather than write to disk. | ||
`f, --file`: specify the changelog file path. | ||
`-f, --file`: specify the changelog file path. | ||
@@ -68,3 +68,3 @@ ## package.json | ||
`changelog`: specify you changelog file path | ||
`changelog`: specify the changelog file path | ||
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
11037
11
327
3
+ Addedlabeled-stream-splicer@2.0.2(transitive)
+ Addedstream-splicer@2.0.1(transitive)
- Removedutil-mix@^3.0.2
- Removedutil-mix@3.0.2(transitive)