'use strict'

const gulp = require('gulp')
const $ = require('gulp-load-plugins')()
const runSequence = require('run-sequence')
const semver = require('semver')
const fs = require('fs')
const exec = require('child_process').exec

function getCurrentVersion () {
  return JSON.parse(fs.readFileSync('./package.json', 'utf8')).version
}

function npmPublish (done) {
  exec('npm publish', (err, stdout, stderr) => {
    if (err) throw err
    $.util.log('Published to npm')
  })
}

function fail (msg) {
  $.util.log($.util.colors.red(msg))
  process.exit(1)
}

function getType () {
  if ($.util.env.major) return 'major'
  if ($.util.env.minor) return 'minor'

  return 'patch'
}

gulp.task('release:build', ['build'], () => {
  return gulp.src('./dist')
    .pipe($.git.add())
    .pipe($.git.commit('chore: build', {args: '-n'}))
})

gulp.task('release:bump', () => {
  const type = getType()
  const newVersion = semver.inc(getCurrentVersion(), type)

  return gulp.src('./package.json')
    .pipe($.bump({version: newVersion}))
    .pipe(gulp.dest('./'))
    .pipe($.git.add())
    .pipe($.git.commit(`chore: release version v${newVersion}`, {args: '-n'}))
    .pipe($.filter('package.json'))
    .pipe($.tagVersion())
})

gulp.task('release:push', done => {
  const remote = $.util.remote || 'origin'

  $.git.push(remote, 'master', {args: '--tags'}, err => {
    if (err) return fail(err.message)

    $.util.log(`Pushed to git ${remote}:master`)
    done()
  })
})

gulp.task('release:publish', done => {
  $.git.status({args: '-s'}, (err, stdout) => {
    if (err) return fail(err.message)

    const isDirty = stdout.trim().length > 0

    if (isDirty) {
      return fail('Dirt workspace, cannot push to npm')
    }

    npmPublish(done)
  })
})

gulp.task('release', done => {
  runSequence(
    'lint',
    'test',
    'release:build',
    'release:bump',
    'release:push',
    'release:publish',
    done
  )
})

@@ -185,20 +185,21 @@
 )%0Aconst 
-exec
+spawn
  = requi
@@ -218,20 +218,21 @@
 ocess').
-exec
+spawn
 %0A%0Afuncti
@@ -344,99 +344,330 @@
 ion 
-npmPublish (done) %7B%0A  exec('npm publish', (err, stdout, stderr) =%3E %7B%0A    if (err) throw err
+fail (msg) %7B%0A  $.util.log($.util.colors.red(msg))%0A  process.exit(1)%0A%7D%0A%0Afunction npmPublish (done) %7B%0A  const publish = spawn('npm', %5B'publish'%5D)%0A  publish.stdout.pipe(process.stdout)%0A  publish.stderr.pipe(process.stderr)%0A  publish.on('close', code =%3E %7B%0A    if (code !== 0) return fail(%60npm publish. Exiting with $%7Bcode%7D.%60)%0A
 %0A   
@@ -699,94 +699,26 @@
  npm
+.
 ')%0A  
-%7D)%0A%7D%0A%0Afunction fail (msg) %7B%0A  $.util.log($.util.colors.red(msg))%0A  process.exit(1
+  done()%0A  %7D
 )%0A%7D%0A
@@ -1464,16 +1464,49 @@
 origin'%0A
+  $.util.log('Pushing to git...')
 %0A  $.git
@@ -1918,16 +1918,55 @@
 %0A    %7D%0A%0A
+    $.util.log('Publishing to npm...')%0A
     npmP

Use spawn instead of exec