const childProcess = require('child_process')
const { syncAll } = require('./update-nested-deps')
const path = require('path')
const git = require('simple-git')(path.resolve(__dirname, '..'))

const gitOutputHandler = (command, stdout, stderr) => {
  stdout.pipe(process.stdout)
  stderr.pipe(process.stderr)
}

const BRANCH = process.env.TRAVIS_PULL_REQUEST_BRANCH || process.env.TRAVIS_BRANCH || ''
const REPO = process.env.TRAVIS_REPO_SLUG

console.log('Current branch is:', BRANCH || '(empty)')
if (!BRANCH.startsWith('greenkeeper/')) {
  console.log('Not a Greenkeeper PR, exiting.')
  process.exit(0)
}

const changedPackages = syncAll()

const run = command => console.log(childProcess.spawnSync(command).output.map(b => (b || '').toString()).join('\n'))

git
  .outputHandler(gitOutputHandler)
  .addConfig('user.email', 'travis@travis-ci.org')
  .addConfig('user.name', 'Travis CI')
  .add(changedPackages.map(p => path.join(p.folder, 'package.json')))
  .commit('chore(package): update nested deps')

  .outputHandler(() => {})
  // Silence this line to avoid revealing the secret token.
  .addRemote('gh-repo', `https://\${GH_TOKEN}@github.com/${REPO}.git`)
  .outputHandler(gitOutputHandler)

  .push('gh-pages', BRANCH, ['--set-upstream'])

@@ -1,50 +1,4 @@
-const childProcess = require('child_process')%0A
 cons
@@ -596,126 +596,8 @@
 ()%0A%0A
-const run = command =%3E console.log(childProcess.spawnSync(command).output.map(b =%3E (b %7C%7C '').toString()).join('%5Cn'))%0A%0A
 git%0A

remove unused stuff