Skip to content

Commit

Permalink
#137 reverse changelog
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Mrowetz committed Feb 5, 2017
1 parent c502781 commit 8a97f5d
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 23 deletions.
23 changes: 10 additions & 13 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@



<a name="v0.3.3"></a>
## v0.3.3 (2017-02-05)
<a name="v0.3.5"></a>
## v0.3.5 (2017-02-05)

* #137 Fix changelog format and escaping ([c1b10ea](https://github.com/micmro/PerfCascade/commit/c1b10ea))
* #137 automatic changelog creation added ([6ced761](https://github.com/micmro/PerfCascade/commit/6ced761))
* #137 speed up release branch checkout ([522ba06](https://github.com/micmro/PerfCascade/commit/522ba06))
* format fix ([39acd2f](https://github.com/micmro/PerfCascade/commit/39acd2f))
* #137 ensure CHANGELOG.md is committed ([645e53f](https://github.com/micmro/PerfCascade/commit/645e53f))
* append missing v0.3.4 changelog ([c794281](https://github.com/micmro/PerfCascade/commit/c794281))



Expand All @@ -20,11 +18,10 @@



<a name="v0.3.5"></a>
## v0.3.5 (2017-02-05)

* #137 ensure CHANGELOG.md is committed ([645e53f](https://github.com/micmro/PerfCascade/commit/645e53f))
* append missing v0.3.4 changelog ([c794281](https://github.com/micmro/PerfCascade/commit/c794281))


<a name="v0.3.3"></a>
## v0.3.3 (2017-02-05)

* #137 Fix changelog format and escaping ([c1b10ea](https://github.com/micmro/PerfCascade/commit/c1b10ea))
* #137 automatic changelog creation added ([6ced761](https://github.com/micmro/PerfCascade/commit/6ced761))
* #137 speed up release branch checkout ([522ba06](https://github.com/micmro/PerfCascade/commit/522ba06))
* format fix ([39acd2f](https://github.com/micmro/PerfCascade/commit/39acd2f))
52 changes: 42 additions & 10 deletions build-utils/grunt-tasks/changelog-custom.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,40 @@ const escapeForBash = (str) => {
.replace(/'/g, '\'"\'"\''); //escape single quotes the ugly bash way
};

/**
* Writes a log to a file
* @param {string} path filename/path to write to
* @param {string} newLog new Changelog entry to add
* @param {number} headerLineCount Number of lines the header occupies
*/
function appendLogToFileStream(path, newLog, headerLineCount) {
let wStr = fs.createWriteStream(path)

fs.readFile(path, (err, data) => {
if (err) {
wStr.emit('error', err);
return;
}
/** existing changelog */
let oldChangelog = data.toString().split('\n');
/** lines used by the default header */
let logHeader = oldChangelog.slice(0, headerLineCount);
/** previous changelog entries */
let prevLogs = oldChangelog.slice(headerLineCount);

var s = new Readable;
s.pipe(wStr);
s.push(logHeader.join('\n') + '\n'); // the string you want
s.push(newLog);
s.push(prevLogs.join('\n'));
// s.push('c aaa bbbb cccc') // the string you want
s.push(null); // indicates end-of-file basically - the end of the stream)
});

return wStr;
};


/**
* @param {IGrunt} grunt - Grunt instance
*/
Expand All @@ -28,18 +62,16 @@ module.exports = function (grunt) {
readDataStream
.on('data', (chunk) => tmpBuffer += chunk)
.on('end', () => {
let lines = tmpBuffer.split("\n");
const lines = tmpBuffer.split('\n');
lines.shift(); //remove the html-ancor tag in the first line
grunt.config.data.changelog = escapeForBash(lines.join('\n'));
readDataStream.end();
});

// changlog file writer
let appenFileStream = fs.createWriteStream(options.file, { 'flags': 'a' })
.on('error', grunt.log.error)
.on('close', () => {
grunt.log.ok(`${options.file} updated with latest changelog for ${options.version}`);
done();
appendLogToFileStream(options.file, lines.join('\n'), 5)
.on('error', grunt.log.error)
.on('close', () => {
grunt.log.ok(`${options.file} updated with latest changelog for ${options.version}`);
done();
});
});

// get changelog
Expand All @@ -50,6 +82,6 @@ module.exports = function (grunt) {
}
}, {
version: options.version
}).pipe(readDataStream).pipe(appenFileStream); // or any writable stream
}).pipe(readDataStream); // or any writable stream
});
};

0 comments on commit 8a97f5d

Please sign in to comment.