const pify = require('pify')
const rimraf = require('rimraf')
const execute = require('../utils/execute')
const pushBranch = require('./push-branch')

const log = console.log // eslint-disable-line
const removeDir = pify(rimraf)

const version = process.argv[2]

;(async () => {
  log('Resetting the current branch...')
  await execute('git fetch')
  await execute('git checkout .')

  log(`Pulling the latest dist branch from Github...`)
  await execute('git pull origin --rebase')

  log('Deleting the current dist folder...')
  await removeDir('dist')

  log('Running the build...')
  await execute('yarn build')

  log('Committing the dist dir...')
  await execute(`git add --force dist/ && git commit -m "chore: add dist for ${version}"`)

  await pushBranch('dist')

  log('OK!')
})().catch(console.error)

@@ -283,28 +283,28 @@
 og('
-Resetting the curren
+Switching to the dis
 t br
@@ -338,47 +338,36 @@
 git 
-fetch')%0A  await execute('git checkout .
+checkout -B dist origin/dist
 ')%0A%0A
@@ -376,21 +376,23 @@
 log(
-%60Pull
+'Resett
 ing the 
 late
@@ -391,42 +391,18 @@
 the 
-latest dist branch from Github...%60
+branch...'
 )%0A  
@@ -424,28 +424,18 @@
 git 
-pull origin --rebase
+checkout .
 ')%0A%0A

fix resetting branch before building