Skip to content
This repository was archived by the owner on Jan 6, 2025. It is now read-only.

Commit 96aaa78

Browse files
devversionThomasBurleson
authored andcommitted
fix(changelog): fix invalid parentheses and semver checks
* chore: fix invalid parentheses * Allow a changelog generation when the commit is not tagged.
1 parent e7f67e3 commit 96aaa78

File tree

1 file changed

+30
-13
lines changed

1 file changed

+30
-13
lines changed

tools/gulp/tasks/changelog.ts

+30-13
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ import path = require('path');
44
import minimist = require('minimist');
55
import gulpUtils = require('gulp-util');
66

7-
let changelog = require('gulp-conventional-changelog');
7+
const changelog = require('gulp-conventional-changelog');
8+
const semver = require('semver');
89

910
const args = minimist(process.argv.slice(2));
1011
const chalk = gulpUtils.colors;
@@ -19,31 +20,33 @@ const VERSION = args['version'] || require(path.join(ROOT,'package.json')).versi
1920
*/
2021
task('changelog', function() {
2122

22-
var changelogPath = path.join(ROOT, 'CHANGELOG.md');
23-
var previousTag = getLatestTag();
24-
var currentTag = 'v' + VERSION;
25-
var contextOptions = {
23+
const changelogPath = path.join(ROOT, 'CHANGELOG.md');
24+
const previousTag = getLatestTag();
25+
const currentTag = 'v' + VERSION;
26+
const fromSHA = SHA || previousTag.sha;
27+
const contextOptions = {
2628
version: VERSION,
2729
previousTag: previousTag.name,
2830
currentTag: currentTag
2931
};
32+
3033
/* Validate different fork points for the changelog generation */
3134
if (previousTag.name === currentTag && !SHA) {
3235
log(chalk.yellow('Warning: You are generating a changelog by comparing the same versions.'));
3336
} else if (SHA) {
3437
log('Generating changelog from commit ' + getShortSha(SHA) + '...');
3538
} else {
36-
var shortSha = getShortSha(previousTag.sha);
39+
let shortSha = getShortSha(previousTag.sha);
3740
log('Generating changelog from tag ' + previousTag.name + ' (' + shortSha + ')');
3841
}
3942

40-
return src(changelogPath, {
41-
buffer:false
42-
}).pipe(changelog({
43-
preset: 'angular'
44-
}, contextOptions, {
45-
from: SHA || previousTag.sha
46-
}).pipe(dest(ROOT)));
43+
return src(changelogPath)
44+
.pipe(changelog({ preset: 'angular' }, contextOptions, {
45+
from: fromSHA
46+
}, {}, {
47+
generateOn: _shouldGenerate
48+
}))
49+
.pipe(dest(ROOT));
4750

4851
});
4952

@@ -68,3 +71,17 @@ function getLatestTag() {
6871
function getShortSha(sha) {
6972
return sha.substring(0, 7);
7073
}
74+
75+
/**
76+
* Function which determines whether the conventional-changelog should create
77+
* a new section in the CHANGELOG or not.
78+
*
79+
* - If a SHA is specified, the first checked SHA will be used to generate a new section.
80+
* - By default it just checks if the commit is tagged and if the version is valid.
81+
*
82+
* @param {Object=} commit Parsed commit from the conventional-changelog-parser.
83+
*/
84+
let _isGenerated = 0;
85+
function _shouldGenerate(commit) {
86+
return SHA ? _isGenerated++ === 0 : semver.valid(commit.version);
87+
}

0 commit comments

Comments
 (0)