Skip to content

Commit

Permalink
feat: add conventional changelog generate function
Browse files Browse the repository at this point in the history
  • Loading branch information
aadityataparia committed May 30, 2019
1 parent 695eb77 commit ac7066a
Show file tree
Hide file tree
Showing 8 changed files with 164 additions and 9 deletions.
3 changes: 1 addition & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
## 0.0.1-rc2 (2019-05-30)
## [0.0.1-rc2](https://github.com/sifrr/sifrr-dev/compare/72d3a3c...v0.0.1-rc2) (2019-05-30 10:39:49 +0000)


### Bug Fixes
Expand All @@ -14,4 +14,3 @@




51 changes: 50 additions & 1 deletion dist/sifrr.dev.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/sifrr.dev.js.map

Large diffs are not rendered by default.

56 changes: 54 additions & 2 deletions dist/sifrr.dev.module.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/sifrr.dev.module.js.map

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ function moduleConfig(name, root, minify = false, isModule = false) {
external: id => {
const packages = [
'fs',
'path'
'path',
'conventional-changelog'
];
if (packages.indexOf(id) > -1) return true;
return /rollup-plugin/.test(id);
Expand Down
53 changes: 53 additions & 0 deletions src/generatechangelog.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
const fs = require('fs');
const path = require('path');
const conventionalChangelog = require('conventional-changelog');
const rtag = /tag:\s*[v=]?(.+?)[,)]/gi;

module.exports = ({
folder = process.cwd(),
releaseCount = 0,
changelogFile = path.join(folder, './CHANGELOG.md'),
outputUnreleased = false,
multiRepo = false
} = {}) => {
let oldChangelog = '';
const transform = function(cm, cb) {
let match = rtag.exec(cm.gitTags);
rtag.lastIndex = 0;
if (match) cm.version = match[1];
cb(null, cm);
};
const options = {
pkg: {
path: path.join(folder, './package.json'),
},
preset: 'angular',
releaseCount,
outputUnreleased,
gitRawCommitsOpts: {
path: folder
},
transform
};

if (fs.existsSync(changelogFile)) {
if (releaseCount === 0) fs.writeFileSync(changelogFile, '');
oldChangelog = fs.readFileSync(changelogFile, 'utf-8');
}
if (multiRepo) {
options.transform = (cm, cb) => {
if (cm.scope && cm.scope === multiRepo) cm.scope = null;
else cm.type = 'chore';
transform(cm, cb);
};
}
return new Promise((res, rej) => {
conventionalChangelog(options)
.pipe(fs.createWriteStream(changelogFile))
.on('error', rej)
.on('finish', () => {
fs.appendFileSync(changelogFile, oldChangelog);
res(changelogFile);
});
});
};
3 changes: 2 additions & 1 deletion src/sifrr.dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@ module.exports = {
eslintrc: require('./eslintrc'),
loadDir: require('./loaddir'),
deepMerge: require('./deepmerge'),
getRollupConfig: require('./getrollupconfig')
getRollupConfig: require('./getrollupconfig'),
generateChangelog: require('./generatechangelog')
};

0 comments on commit ac7066a

Please sign in to comment.