Skip to content

Commit

Permalink
#137 Fix changelog format and escaping
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Mrowetz committed Feb 4, 2017
1 parent 522ba06 commit c1b10ea
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 20 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Changelog



4 changes: 2 additions & 2 deletions build-utils/grunt-config/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ module.exports = {
--rootDir src/ts/
--declaration true
--declarationDir ./build/npm/types
`.replace(/\n[\t ]+/g,' ').split(' ').filter(x => x != '')
`.replace(/\n[\t ]+/g, ' ').split(' ').filter(x => x != '')
},
npmPublish: {
options: {
Expand All @@ -27,6 +27,6 @@ module.exports = {
options: {
cwd: process.cwd()
},
exec: `(export VERSION=<%= package.version %> && export CHANGELOG="<%= changelog %>" && bash build-utils/release.sh)`
exec: `(export VERSION='<%= package.version %>' && export CHANGELOG='<%= changelog %>' && bash build-utils/release.sh)`
}
};
42 changes: 27 additions & 15 deletions build-utils/grunt-tasks/changelog-custom.js
Original file line number Diff line number Diff line change
@@ -1,43 +1,55 @@
let fs = require('fs')
let fs = require('fs');
let conventionalChangelog = require('conventional-changelog');

/**
* Escape string to be used as bash argument
* assumes strong quoting (using single qotes)
* @param {string} str
*/
const escapeForBash = (str) => {
return JSON.stringify(str)
.replace(/^"|"$/g, '') //remove JSON-string double quotes
.replace(/'/g, '\'"\'"\''); //escape single quotes the ugly bash way
};

/**
* @param {IGrunt} grunt - Grunt instance
*/
module.exports = function(grunt){
module.exports = function (grunt) {
let PassThroughStream = require('stream').PassThrough;

grunt.registerTask('changelog-custom', 'Custom version of changelog', function() {
grunt.registerTask('changelog-custom', 'Custom version of changelog', function () {
const done = this.async();
const options = this.options()
const options = this.options();
let readDataStream = new PassThroughStream();
let tmpBuffer = "";

// extract data
readDataStream
.on('data', (chunk) => tmpBuffer += chunk)
.on('end', () => {
grunt.config.data.changelog = tmpBuffer
readDataStream.end()
})
let 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'})
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}`)
grunt.log.ok(`${options.file} updated with latest changelog for ${options.version}`);
done();
})
});

// get changelog
conventionalChangelog({
config: {
warn : grunt.warn,
warn: grunt.warn,
pkg: grunt.package
}
}, {
version: options.version
}).pipe(readDataStream).pipe(appenFileStream) // or any writable stream
version: options.version
}).pipe(readDataStream).pipe(appenFileStream); // or any writable stream
});

}
};
6 changes: 3 additions & 3 deletions build-utils/release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
# release.sh
# assumes to run in repo root

set -e #exit on errors

# load (private) environment variables like RELEASE_KEY from non-commited file
. ./ENV_VARS

Expand All @@ -12,6 +14,7 @@
echo "Start Github release for ${VERSION}..."

CHANGELOG="${CHANGELOG:-}"
API_JSON=$(printf '{"body": "%s"}' "${CHANGELOG}")

###
# Github Release
Expand Down Expand Up @@ -39,9 +42,6 @@ git tag "v$VERSION"
git push --follow-tags

echo "make Github release"
# make releases
# TODO: make final not draft once confirmed working
# TODO: add Changelog
API_JSON=$(printf '{"tag_name": "v%s", "target_commitish": "release", "name": "v%s", "body": "%s", "draft": false, "prerelease": false}' $VERSION $VERSION $CHANGELOG)
curl \
--data "$API_JSON" \
Expand Down

0 comments on commit c1b10ea

Please sign in to comment.