options.script use function in nodejs will print markdown
Closed this issue · 3 comments
`const releaseNotes = require('git-release-notes')
const OPTIONS = {
branch: 'master',
script: (data, callback) => {
callback({
...data,
});
},
};
const RANGE = 'v1.0.0..v2.0.0';
const TEMPLATE = './markdown.ejs';
releaseNotes(OPTIONS, RANGE, TEMPLATE).then(changelog => {
console.log(Changelog between ${RANGE}\n\n${changelog}
);
}).catch(ex => {
console.error(ex);
process.exit(1);
});`
`var line = 1
, lines = "2020年03月11日21:59:51\n<%\nvar groupCommits = [{\n name: 'features',\n show: true,\n list: []\n}, {\n name: 'bugfix',\n show: true,\n list: []\n}, {\n name: 'refactoring',\n show: true,\n list: []\n}, {\n name: 'other',\n show: true,\n list: []\n}]\n\ncommits.forEach(function (commit) {\n\n\tvar result = (commit.title).match(/^(\w*)(\((.)\))?\: (.)$/);\n\n\tvar type = result && result[1];\n\tvar scope = result && result[3];\n\tvar title = result && result[4];\n\n\tif(type == 'fix' || type == 'fixed'){\n groupCommits.find(item => item.name === 'bugfix').list.push({\n\t\t\ttype: type,\n\t\t\tscope: scope,\n\t\t\ttitle: title,\n\t\t\tcommit: commit\n\t\t})\n\t} else if(type == 'feat' || type == 'feature'){\n groupCommits.find(item => item.name === 'features').list.push({\n\t\t\ttype: type,\n\t\t\tscope: scope,\n\t\t\ttitle: title,\n\t\t\tcommit: commit\n\t\t})\n\t} else if(type == 'refactor'){\n groupCommits.find(item => item.name === 'refactoring').list.push({\n\t\t\ttype: type,\n\t\t\tscope: scope,\n\t\t\ttitle: title,\n\t\t\tcommit: commit\n })\n\t} else {\n groupCommits.find(item => item.name === 'other').list.push({\n\t\t\ttype: type,\n\t\t\tscope: scope,\n\t\t\ttitle: title,\n\t\t\tcommit: commit\n })\n\t}\n});\n\n\nvar listCommits = function(list, key){\n\n\tlist.forEach(function (ct) {\n\n\tvar type = ct.type;\n\tvar scope = ct.scope;\n\tvar title = '';\n\tvar commit = ct.commit;\n\n\tif(type){\n\t\tif(key != 'other'){\n\t\t\ttitle = (scope? ''+scope+': ':'') + ct.title;\n\t\t}else{\n\t\t\ttitle = '' + type + (scope? '('+scope+')':'') + ' : ' + ct.title;\n\t\t}\n\t}else{\n\t\ttitle = commit.title;\n\t}\n%> - <% if(typeof commitHref === 'undefined' || commitHref === '') { %>[<%=commit.sha1.slice(0,8)%>
]<% } else { %>[[```<%=commit.sha1.slice(0,8)%>```](<%=commitHref%><%=commit.sha1%>)]<%}%> - <%=title%> (<%= commit.authorName %>)\n<% })}\n\n\nfor(var i of groupCommits){\n if(i.list.length == 0) continue;\n\n\tif (i.name === 'bugfix' && i.show) { %>\n### Bug fixes\n\n<%\t} else if( i.name === 'features' && i.show) { %>\n\n### Features\n\n<%\t} else if(i.name === 'refactoring' && i.show) { %>\n\n### Code Refactoring\n\n<%\t} else if (i.name === 'other' && i.show) { %>\n\n### Other commits\n\n<%\t}\ni.show && listCommits(i.list, i);\n\n} %>\n"
, __filename = undefined;
try {
var __output = [], __append = __output.push.bind(__output);
with (locals || {}) {
; __append("2020年03月11日21:59:51\n")
; __line = 2
;
var groupCommits = [{
name: 'features',
show: true,
list: []
}, {
name: 'bugfix',
show: true,
list: []
}, {
name: 'refactoring',
show: true,
list: []
}, {
name: 'other',
show: true,
list: []
}]
commits.forEach(function (commit) {
var result = (commit.title).match(/^(\w*)(\((.*)\))?\: (.*)$/);
var type = result && result[1];
var scope = result && result[3];
var title = result && result[4];
if(type == 'fix' || type == 'fixed'){
groupCommits.find(item => item.name === 'bugfix').list.push({
type: type,
scope: scope,
title: title,
commit: commit
})
} else if(type == 'feat' || type == 'feature'){
groupCommits.find(item => item.name === 'features').list.push({
type: type,
scope: scope,
title: title,
commit: commit
})
} else if(type == 'refactor'){
groupCommits.find(item => item.name === 'refactoring').list.push({
type: type,
scope: scope,
title: title,
commit: commit
})
} else {
groupCommits.find(item => item.name === 'other').list.push({
type: type,
scope: scope,
title: title,
commit: commit
})
}
});
var listCommits = function(list, key){
list.forEach(function (ct) {
var type = ct.type;
var scope = ct.scope;
var title = '';
var commit = ct.commit;
if(type){
if(key != 'other'){
title = (scope? '__'+scope+'__: ':'') + ct.title;
}else{
title = '__' + type + (scope? '('+scope+')':'') + '__ : ' + ct.title;
}
}else{
title = commit.title;
}
; __line = 79
; __append(" - ")
; if(typeof commitHref === 'undefined' || commitHref === '') {
; __append("[```")
; __append(escapeFn(commit.sha1.slice(0,8)))
; __append("```]")
; } else {
; __append("[[```")
; __append(escapeFn(commit.sha1.slice(0,8)))
; __append("```](")
; __append(escapeFn(commitHref))
; __append(escapeFn(commit.sha1))
; __append(")]")
; }
; __append(" __-__ ")
; __append(escapeFn(title))
; __append(" (")
; __append(escapeFn( commit.authorName ))
; __append(")\n")
; __line = 80
; })}
for(var i of groupCommits){
if(i.list.length == 0) continue;
if (i.name === 'bugfix' && i.show) {
; __line = 86
; __append("\n### Bug fixes\n\n")
; __line = 89
; } else if( i.name === 'features' && i.show) {
; __append("\n\n### Features\n\n")
; __line = 93
; } else if(i.name === 'refactoring' && i.show) {
; __append("\n\n### Code Refactoring\n\n")
; __line = 97
; } else if (i.name === 'other' && i.show) {
; __append("\n\n### Other commits\n\n")
; __line = 101
; }
i.show && listCommits(i.list, i);
}
; __line = 104
; __append("\n")
; __line = 105
}
return __output.join("");
} catch (e) {
rethrow(e, __lines, __filename, __line, escapeFn);
}
Changelog between v1.0.0..v2.0.0`
script: (data, callback) => { delete data.debug callback({ ...data }); },
can solve this problem
script: (data, callback) => {callback({ ...data, debug: false }); } will be work