Ghost/ghost/release-utils/lib/changelog.js
Daniel Lockyer 7f8ded6057 Updated execa to v4 with code modifications
- `shellSync` was removed in execa v2
- this commit switches the usage to the recommended replacement; `sync`
- also adds a test for changelog, the part of code which uses execa
2020-08-04 14:59:55 +01:00

54 lines
1.3 KiB
JavaScript

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.sync(command, {cwd: options.folder || this.folder, shell: true});
});
return this;
}
sort() {
execa.sync(`sort -r ${this.changelogPath} -o ${this.changelogPath}`, {cwd: this.folder, shell: true});
return this;
}
clean() {
execa.sync(`sed -i.bk -E 's/^[0-9]{10} //g' ${this.changelogPath}`, {cwd: this.folder, shell: true});
return this;
}
}
module.exports = Changelog;