
const gulp = require('gulp');
const git = require('gulp-git');
const bump = require('gulp-bump');
const filter = require('gulp-filter');
const tagVersion = require('gulp-tag-version');

const getPaths = require('./_common').getPaths;
const currentTag = require('./_common').currentTag;

const versionSources = ['./bower.json', './package.json'];

const versionStream = (type) => {
  return gulp.src(versionSources)
    .pipe(bump({ type: type }))
    .pipe(gulp.dest('./'))
    .pipe(filter('package.json'))
    .pipe(tagVersion({ prefix: '' }));
};

const commitStream = (type) => {
  var tag = currentTag();
  return gulp.src(versionSources.concat('CHANGELOG.md'))
    .pipe(git.commit(`chore(version): release ${type} version ${tag}`, function() {
      git.push();
      git.push('origin', 'master', { args: '--tags' });
    }));
};

const pushStream = () => {
  git.push();
  git.push('origin', 'master', { args: '--tags' });
};

gulp.task('bump:patch:tag', () => versionStream('patch'));
gulp.task('bump:minor:tag', () => versionStream('minor'));
gulp.task('bump:major:tag', () => versionStream('major'));

gulp.task('bump:patch:commit', ['bump:patch:tag', 'generate:changelog'], () => commitStream('patch') && pushStream());
gulp.task('bump:minor:commit', ['bump:minor:tag', 'generate:changelog'], () => commitStream('minor') && pushStream());
gulp.task('bump:major:commit', ['bump:major:tag', 'generate:changelog'], () => commitStream('major') && pushStream());
@@ -178,16 +178,61 @@
 rsion');
+%0Aconst runSequence = require('run-sequence');
 %0A%0Aconst 
@@ -629,11 +629,13 @@
 %7B%0A  
-var
+const
  tag
@@ -1181,25 +1181,42 @@
 ch:commit', 
-%5B
+() =%3E runSequence(
 'bump:patch:
@@ -1233,33 +1233,32 @@
 erate:changelog'
-%5D
 , () =%3E commitSt
@@ -1279,32 +1279,33 @@
 && pushStream())
+)
 ;%0Agulp.task('bum
@@ -1317,25 +1317,42 @@
 or:commit', 
-%5B
+() =%3E runSequence(
 'bump:minor:
@@ -1369,33 +1369,32 @@
 erate:changelog'
-%5D
 , () =%3E commitSt
@@ -1423,16 +1423,17 @@
 tream())
+)
 ;%0Agulp.t
@@ -1457,17 +1457,34 @@
 ommit', 
-%5B
+() =%3E runSequence(
 'bump:ma
@@ -1513,17 +1513,16 @@
 angelog'
-%5D
 , () =%3E 
@@ -1559,9 +1559,10 @@
 tream())
+)
 ;

fix version order