<commit_before>const mkdirp = require('mkdirp')
const ncp = require('ncp').ncp
const rimraf = require('rimraf')
const Promise = require('bluebird')
const webpackJs = require('./webpack.js')

var EMAIL_TPL = './extensions/enterprise/pro/emails/templates'
var BOTPRESS_EDITION = process.env.BOTPRESS_EDITION

const cleanOldBuild = cb => {
  console.log('Cleaning old build')
  // call: rm -rf lib/
  rimraf('./lib', err => {
    cb(err)
  })
}

const copyEmailTemplates = cb => {
  if (BOTPRESS_EDITION === 'pro' || BOTPRESS_EDITION === 'ultimate') {
    console.log('Copying email templates')
    // call: mkdir -p lib/emails/templates
    mkdirp('./lib/emails/templates', err => {
      if (err) {
        return cb(err)
      }

      // call: cp -a
      ncp(EMAIL_TPL, './lib/emails/templates', err => {
        cb(err)
      })
    })
  } else {
    cb()
  }
}

const bundleApp = cb => {
  console.log('Bundling app...')
  //node webpack.js --compile
  webpackJs.run(err => {
    if (err) {
      return cb(err)
    }

    console.log('Copying templates')
    // call: mkdir -p lib/cli/templates
    mkdirp('./lib/cli/templates', err => {
      if (err) {
        return cb(err)
      } else {
        // call: cp -a
        ncp('./src/cli/templates', './lib/cli/templates', err => {
          cb(err)
        })
      }
    })
  })
}

const execute = async () => {
  await Promise.fromCallback(callback => cleanOldBuild(callback))
  await Promise.fromCallback(callback => copyEmailTemplates(callback))
  await Promise.fromCallback(callback => bundleApp(callback))
  process.exit(0)
}

execute()
<commit_msg>Using proper promises and async/await<commit_after>const mkdirp = require('mkdirp')
const ncp = require('ncp').ncp
const rimraf = require('rimraf')
const Promise = require('bluebird')

const webpackJs = require('./webpack.js')

var EMAIL_TPL = './extensions/enterprise/pro/emails/templates'
var BOTPRESS_EDITION = process.env.BOTPRESS_EDITION

const rimrafAsync = Promise.promisify(rimraf)
const mkdirpAsync = Promise.promisify(mkdirp)
const ncpAsync = Promise.promisify(ncp)
const webpackAsync = Promise.promisify(webpackJs.run)

const cleanOldBuild = () => {
  console.log('Cleaning old build')
  // call: rm -rf lib/
  return rimrafAsync('./lib')
}

const copyEmailTemplates = async () => {
  if (BOTPRESS_EDITION === 'pro' || BOTPRESS_EDITION === 'ultimate') {
    console.log('Copying email templates')
    // call: mkdir -p lib/emails/templates
    await mkdirpAsync('./lib/emails/templates')

    // call: cp -a
    await ncpAsync(EMAIL_TPL, './lib/emails/templates')
  }
}

const bundleApp = async () => {
  console.log('Bundling app...')
  //node webpack.js --compile
  await webpackAsync()

  console.log('Copying templates')
  // call: mkdir -p lib/cli/templates
  await mkdirpAsync('./lib/cli/templates')
  // call: cp -a
  await ncpAsync('./src/cli/templates', './lib/cli/templates')
}

const build = async () => {
  await cleanOldBuild()
  await copyEmailTemplates()
  await bundleApp()
}

build().then(() => process.exit(0))

{'fraction_non_alphanumeric': 0.1618610747051114, 'fraction_numerical': 0.000655307994757536, 'mean_word_length': 3.182191780821918, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1604154', 'n_tokens_mistral': 1035, 'n_tokens_neox': 1038, 'n_words': 217}