var inquirer = require('inquirer')
var semver = require('semver')
var shell = require('shelljs')
var fs = require('fs')

var pkg = require('./package.json')

console.log('')
console.log('Wellcome to servable release utility!')
console.log('----------------------------------------------------------------')
console.log('')

var questions = [
  {
    type: 'list',
    name: 'version',
    message: 'Which version will it be? (current is ' + pkg.version + ')',
    choices: [
      semver.inc(pkg.version, 'patch'),
      semver.inc(pkg.version, 'minor'),
      semver.inc(pkg.version, 'major'),
      semver.inc(pkg.version, 'premajor', 'rc'),
    ],
  },
  {
    type: 'list',
    name: 'dryRun',
    message: 'Do you want to release, or just see what would happen if you do?',
    choices: ['Just see', 'Release!'],
  },
]

inquirer.prompt(questions).then(function(answers) {
  var newVerison = answers.version
  var dryRun = answers.dryRun === 'Just see'

  pkg.version = newVerison

  console.log('')
  if (dryRun) {
    console.log('Ok, here is what would happen:')
  } else {
    console.log('Doing actual release:')
  }
  console.log('')

  // run('npm test', dryRun) &&
    bumpVersion('package.json', pkg, dryRun) &&
    run('npm run build', dryRun) &&
    run('git add .', dryRun) &&
    run('git commit -m "' + newVerison + '"', dryRun) &&
    run('git push', dryRun) &&
    run('git tag -a ' + newVerison + ' -m "v' + newVerison + '"', dryRun) &&
    run('git push origin --tags', dryRun) &&
    run('npm publish', dryRun)
});

function bumpVersion(fileName, obj, dry) {
  console.log('Bumping version in `' + fileName + '` to ' + obj.version)
  if (!dry) {
    try {
      fs.writeFileSync(fileName, JSON.stringify(obj, null, '  ') + '\n')
      console.log('... ok')
    } catch (e) {
      console.error(e)
      return false
    }
  }
  return true
}

function run(cmd, dry) {
  console.log('Running `' + cmd + '`')
  if (!dry) {
    if (shell.exec(cmd, {silent: false}).code === 0) {
      console.log('... ok')
    } else {
      console.error('... fail!')
      return false
    }
  }
  return true
}

@@ -1179,256 +1179,60 @@
     
-bumpVersion('package.json', pkg, dryRun) &&%0A    run('npm run build', dryRun) &&%0A    run('git add .', dryRun) &&%0A    run('git commit -m %22' + newVerison + '%22', dryRun) &&%0A    run('git push', dryRun) &&%0A    run('git tag -a ' + newVerison + ' -m %22v' + 
+run('yarn build', dryRun) &&%0A    run(%60npm version $%7B
 newV
@@ -1241,14 +1241,10 @@
 ison
- + '%22'
+%7D%60
 , dr
@@ -1337,336 +1337,8 @@
 );%0A%0A
-function bumpVersion(fileName, obj, dry) %7B%0A  console.log('Bumping version in %60' + fileName + '%60 to ' + obj.version)%0A  if (!dry) %7B%0A    try %7B%0A      fs.writeFileSync(fileName, JSON.stringify(obj, null, '  ') + '%5Cn')%0A      console.log('... ok')%0A    %7D catch (e) %7B%0A      console.error(e)%0A      return false%0A    %7D%0A  %7D%0A  return true%0A%7D%0A%0A
 func

Update release script