Ghost/ghost/release-utils/lib/changelog.js

54 lines
1.2 KiB
JavaScript
Raw Normal View History

const execa = require('execa');
const _ = require('lodash');
const localUtils = require('./utils');
class Changelog {
constructor(options = {}) {
localUtils.checkMissingOptions(options,
'folder',
'changelogPath'
);
this.changelogPath = options.changelogPath;
this.folder = options.folder;
}
write(options = {}) {
localUtils.checkMissingOptions(options,
'githubRepoPath',
'lastVersion'
);
let sign = '>';
if (options.append) {
sign = '>>';
}
const commands = [
`git log --no-merges --pretty=tformat:'%at * [%h](${options.githubRepoPath}/commit/%h) %s - %an' ${options.lastVersion}.. ${sign} ${this.changelogPath}`
];
_.each(commands, (command) => {
execa.shellSync(command, {cwd: options.folder || this.folder});
});
return this;
}
sort() {
execa.shellSync(`sort -r ${this.changelogPath} -o ${this.changelogPath}`, {cwd: this.folder});
return this;
}
clean() {
execa.shellSync(`sed -i.bk -E 's/^[0-9]{10} //g' ${this.changelogPath}`, {cwd: this.folder});
return this;
}
}
module.exports = Changelog;