diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 00000000..c28c0ac7 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,4 @@ +# Changelog + + + diff --git a/build-utils/grunt-config/run.js b/build-utils/grunt-config/run.js index bce0f9e1..d247dffb 100644 --- a/build-utils/grunt-config/run.js +++ b/build-utils/grunt-config/run.js @@ -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: { @@ -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)` } }; diff --git a/build-utils/grunt-tasks/changelog-custom.js b/build-utils/grunt-tasks/changelog-custom.js index 38edabd4..b2d10d34 100644 --- a/build-utils/grunt-tasks/changelog-custom.js +++ b/build-utils/grunt-tasks/changelog-custom.js @@ -1,15 +1,26 @@ -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 = ""; @@ -17,27 +28,28 @@ module.exports = function(grunt){ 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 }); - -} \ No newline at end of file +}; diff --git a/build-utils/release.sh b/build-utils/release.sh index 2afed0be..894729ab 100644 --- a/build-utils/release.sh +++ b/build-utils/release.sh @@ -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 @@ -12,6 +14,7 @@ echo "Start Github release for ${VERSION}..." CHANGELOG="${CHANGELOG:-}" +API_JSON=$(printf '{"body": "%s"}' "${CHANGELOG}") ### # Github Release @@ -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" \