2019-03-12 23:53:32 +03:00
|
|
|
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) => {
|
2020-08-04 16:59:55 +03:00
|
|
|
execa.sync(command, {cwd: options.folder || this.folder, shell: true});
|
2019-03-12 23:53:32 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
sort() {
|
2020-08-04 16:59:55 +03:00
|
|
|
execa.sync(`sort -r ${this.changelogPath} -o ${this.changelogPath}`, {cwd: this.folder, shell: true});
|
2019-03-12 23:53:32 +03:00
|
|
|
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
clean() {
|
2020-08-04 16:59:55 +03:00
|
|
|
execa.sync(`sed -i.bk -E 's/^[0-9]{10} //g' ${this.changelogPath}`, {cwd: this.folder, shell: true});
|
2019-03-12 23:53:32 +03:00
|
|
|
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = Changelog;
|