elgg-conventional-changelog
Advanced tools
Comparing version
57
index.js
@@ -16,2 +16,3 @@ | ||
log: console.log.bind(console), | ||
notes: '', | ||
}, options || {}); | ||
@@ -23,7 +24,32 @@ | ||
git.getTags(function(err, tags) { | ||
if (err || !tags) return done('Failed to read git tags.\n'+err); | ||
writeChangelog(tags); | ||
readNotes(options.notes, options.file).then(function (notes) { | ||
options.notes = notes; | ||
git.getTags(function(err, tags) { | ||
if (err || !tags) { | ||
return done('Failed to read git tags.\n'+err); | ||
} | ||
writeChangelog(tags); | ||
}); | ||
}); | ||
// consider anything before first anchor as release notes | ||
function readNotes(notes, file) { | ||
return new Promise(function (resolve, reject) { | ||
if (notes || !file || !fs.existsSync(file)) { | ||
resolve(notes); | ||
return; | ||
} | ||
fs.readFile(file, {encoding:'UTF-8'}, function(err, contents) { | ||
if (err) { | ||
return done('Failed to read ' + file + '.\n'+err); | ||
} | ||
var idx = contents.indexOf('<a name="'); | ||
resolve(idx ? contents.substr(0, idx) : ''); | ||
}); | ||
}); | ||
} | ||
function writeChangelog(tags) { | ||
@@ -36,7 +62,9 @@ options.exclude = options.exclude || tags; | ||
git.getLog({ | ||
exclude: options.exclude, | ||
exclude: options.exclude, | ||
to: options.to, | ||
}, function(err, gitLog) { | ||
if (err) return done('Failed to read git log.\n'+err); | ||
if (err) { | ||
return done('Failed to read git log.\n'+err); | ||
} | ||
writeGitLog(gitLog); | ||
@@ -49,10 +77,18 @@ }); | ||
options.log('Parsed %d contributors.', gitLog.contributors.length); | ||
writer.writeLog(gitLog, options, function(err, changelog) { | ||
if (err) return done('Failed to write changelog.\n'+err); | ||
if (err) { | ||
return done('Failed to write changelog.\n'+err); | ||
} | ||
if (options.file && fs.existsSync(options.file)) { | ||
fs.readFile(options.file, {encoding:'UTF-8'}, function(err, contents) { | ||
if (err) return done('Failed to read ' + options.file + '.\n'+err); | ||
done(null, changelog + '\n' + String(contents)); | ||
if (err) { | ||
return done('Failed to read ' + options.file + '.\n'+err); | ||
} | ||
// clear out release notes (already captured in log) | ||
var idx = contents.indexOf('<a name="'); | ||
done(null, changelog + '\n' + String(contents.substring(idx))); | ||
}); | ||
@@ -65,2 +101,1 @@ } else { | ||
} | ||
@@ -32,2 +32,3 @@ var es = require('event-stream'); | ||
types: {}, | ||
notes: '', | ||
}, options || {}); | ||
@@ -76,3 +77,5 @@ | ||
writer.header(options.version); | ||
stream.write(options.notes); | ||
writer.contributors(gitLog.contributors); | ||
@@ -107,3 +110,3 @@ | ||
}; | ||
this.contributors = function(contributors) { | ||
@@ -110,0 +113,0 @@ stream.write('#### Contributors\n'); |
{ | ||
"name": "elgg-conventional-changelog", | ||
"version": "0.1.3", | ||
"version": "0.1.4", | ||
"description": "Generate a markdown changelog from git commit metadata", | ||
@@ -43,5 +43,6 @@ "main": "index.js", | ||
"chai": "~1.7.2", | ||
"sinon": "~1.7.3", | ||
"shelljs": "~0.2.6" | ||
"mocha": "^2.4.5", | ||
"shelljs": "~0.2.6", | ||
"sinon": "~1.7.3" | ||
} | ||
} |
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
23541
20.21%9
12.5%507
6.74%4
33.33%