From 6424311ac75b7843822a79b0736fd0fb1d72cf91 Mon Sep 17 00:00:00 2001 From: kendo5731 Date: Sat, 6 Feb 2016 18:14:41 +0100 Subject: [PATCH] chore(): add npm scripts for automatic releases --- CHANGELOG.md | 0 README.md | 4 +++- gulpfile.js | 1 + package.json | 13 ++++++++++-- release.js | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 73 insertions(+), 3 deletions(-) create mode 100644 CHANGELOG.md create mode 100644 release.js diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..e69de29 diff --git a/README.md b/README.md index ba17937..d3feeee 100644 --- a/README.md +++ b/README.md @@ -2,4 +2,6 @@ A theme for [Hugo](https://gohugo.io/), inspired by Atom editor. -![Theme preview](static/img/theme-preview.png?raw=true "Code Editor Theme for Hugo") \ No newline at end of file +![Theme preview](static/img/theme-preview.png?raw=true "Code Editor Theme for Hugo") + +Changelog [here](https://github.com/aubm/hugo-code-editor-theme/blob/master/CHANGELOG.md) :) \ No newline at end of file diff --git a/gulpfile.js b/gulpfile.js index 95dfa82..f78a0cc 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -5,6 +5,7 @@ var cssnano = require('gulp-cssnano'); var rename = require('gulp-rename'); var uglify = require('gulp-uglify'); var concat = require('gulp-concat'); +require('./release'); gulp.task('fonts', function() { gulp.src('./node_modules/bootstrap-sass/assets/fonts/bootstrap/*') diff --git a/package.json b/package.json index 8850753..480af04 100644 --- a/package.json +++ b/package.json @@ -1,4 +1,5 @@ { + "version": "0.0.0", "description": "HTML/CSS Theme for www.aubm.net", "repository": "https://github.com/aubm/aubm-website-theme.git", "license": "MIT", @@ -7,15 +8,23 @@ }, "devDependencies": { "gulp": "^3.9.0", + "gulp-bump": "^1.0.0", "gulp-concat": "^2.6.0", + "gulp-conventional-changelog": "^0.7.0", "gulp-cssnano": "^2.1.0", + "gulp-git": "^1.7.0", "gulp-rename": "^1.2.2", "gulp-sass": "^2.1.1", "gulp-uglify": "^1.5.1", - "gulp-util": "^3.0.7" + "gulp-util": "^3.0.7", + "run-sequence": "^1.1.5", + "semver": "^5.1.0" }, "scripts": { "build": "gulp", - "watch": "gulp watch" + "watch": "gulp watch", + "release-major": "gulp release-major", + "release-minor": "gulp release-minor", + "release-patch": "gulp release-patch" } } diff --git a/release.js b/release.js new file mode 100644 index 0000000..476d9e9 --- /dev/null +++ b/release.js @@ -0,0 +1,58 @@ +var gulp = require('gulp'); +var pkg = require('./package.json'); +var semver = require('semver'); +var util = require('gulp-util'); +var bump = require('gulp-bump'); +var conventionalChangelog = require('gulp-conventional-changelog'); +var git = require('gulp-git'); +var runSequence = require('run-sequence'); + +var releaseType = ''; + +gulp.task('bump', function(cb) { + if (!semver.valid(pkg.version)) { + util.log(util.colors.red('Error: invalid version number - ' + pkg.version)); + process.exit(1); + } + + if (!releaseType.match(new RegExp(/major|minor|patch/))) { + util.log(util.colors.red('Error : required bump \'type\' is missing ! Usage : npm run release --type (major|minor|patch)'));; + return process.exit(1); + } + + pkg.version = semver.inc(pkg.version, releaseType); + gulp.src('./package.json') + .pipe(bump({ version: pkg.version })) + .pipe(gulp.dest('./')) + .on('end', cb); +}); + +gulp.task('changelog', function(cb) { + gulp.src('./CHANGELOG.md', { buffer: false }) + .pipe(conventionalChangelog({ preset: 'angular' })) + .pipe(gulp.dest('./')) + .on('end', cb); +}); + +gulp.task('commit-changelog', function(cb) { + gulp.src(['./CHANGELOG.md', './package.json']) + .pipe(git.add()) + .pipe(git.commit('chore(release): ' + pkg.version)) + .on('end', cb); +}); + +gulp.task('create-version-tag', function(cb) { + git.tag('v' + pkg.version, 'release v' + pkg.version, function(err) { if (err) throw err; cb(); }); +}); + +gulp.task('push-to-origin', function(cb) { + git.push('origin', 'master', { args: '--follow-tags' }, function(err) { if (err) throw err; cb(); }); +}); + +gulp.task('release', function(cb) { + runSequence('bump', 'changelog', 'commit-changelog', 'create-version-tag', 'push-to-origin', cb); +}); + +gulp.task('release-major', function() { releaseType = 'major'; gulp.start('release'); }); +gulp.task('release-minor', function() { releaseType = 'minor'; gulp.start('release'); }); +gulp.task('release-patch', function() { releaseType = 'patch'; gulp.start('release'); });