text: 'use strict'
  
  process.env.NODE_ENV = 'production'
  
  const chalk = require('chalk')
  const del = require('del')
  const { spawn } = require('child_process')
  const webpack = require('webpack')
  
  const mainConfig = require('./webpack.main.config')
  const rendererConfig = require('./webpack.renderer.config')
  const preloadConfig = require('./webpack.preload.config')
  
  const doneLog = chalk.bgGreen.white(' DONE ') + ' '
  const errorLog = chalk.bgRed.white(' ERROR ') + ' '
  const okayLog = chalk.bgBlue.white(' OKAY ') + ' '
  const isCI = process.env.CI || false
  
  if (process.argv.splice(2).some(arg => arg === '--clean')) clean()
  else build()
  
  function clean () {
    del.sync(['build/*', '!build/icons', '!build/icons/icon.*'])
    console.log(`\n${doneLog}\n`)
    process.exit()
  }
  
  function logStats (proc, data) {
    let log = ''
  
    log += chalk.yellow.bold(`┏ ${proc} Process ${new Array((19 - proc.length) + 1).join('-')}`)
    log += '\n\n'
  
    if (typeof data === 'object') {
      data.toString({
        colors: true,
        chunks: false
      }).split(/\r?\n/).forEach(line => {
        log += '  ' + line + '\n'
      })
    } else {
      log += `  ${data}\n`
    }
  
    log += '\n' + chalk.yellow.bold(`┗ ${new Array(28 + 1).join('-')}`) + '\n'
  
    console.log(log)
  }
  
  function build () {
    // greeting
    console.log(chalk.yellow.bold('\n  let\'s build'), 'electron-vue', '\n')
  
    del.sync(['dist/muon/*', '!.gitkeep'])
  
    pack(mainConfig).then(result => {
      logStats('Main', result)
    }).catch(err => {
      console.log(`\n  ${errorLog}failed to build main process`)
      console.error(`\n${err}\n`)
      process.exit(1)
    })
  
    pack(rendererConfig).then(result => {
      logStats('Renderer', result)
    }).catch(err => {
      console.log(`\n  ${errorLog}failed to build renderer process`)
      console.error(`\n${err}\n`)
      process.exit(1)
    })
  
    pack(preloadConfig).then(result => {
      logStats('Preload', result)
    }).catch(err => {
      console.log(`\n  ${errorLog}failed to build preload process`)
      console.error(`\n${err}\n`)
      process.exit(1)
    })
  }
  
  function pack (config) {
    return new Promise((resolve, reject) => {
      webpack(config, (err, stats) => {
        if (err) reject(err.stack || err)
        else if (stats.hasErrors()) {
          let err = ''
  
          stats.toString({
            chunks: false,
            colors: true
          })
          .split(/\r?\n/)
          .forEach(line => {
            err += `    ${line}\n`
          })
  
          reject(err)
        } else {
          resolve(stats.toString({
            chunks: false,
            colors: true
          }))
        }
      })
    })
  }
  