2018-03-07 14:28:48 +01:00
|
|
|
'use strict'
|
|
|
|
|
|
|
|
process.env.NODE_ENV = 'production'
|
|
|
|
|
|
|
|
const { say } = require('cfonts')
|
|
|
|
const chalk = require('chalk')
|
|
|
|
const del = require('del')
|
|
|
|
const { spawn } = require('child_process')
|
|
|
|
const webpack = require('webpack')
|
2019-09-17 13:41:12 +02:00
|
|
|
const Listr = require('listr')
|
2018-03-07 14:28:48 +01:00
|
|
|
|
|
|
|
const mainConfig = require('./webpack.main.config')
|
|
|
|
const rendererConfig = require('./webpack.renderer.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.env.BUILD_TARGET === 'clean') clean()
|
|
|
|
else build()
|
|
|
|
|
2019-09-17 06:24:50 +02:00
|
|
|
function clean() {
|
2023-03-15 10:56:01 +01:00
|
|
|
del.sync(['build/*', '!build/icons', '!build/icons/icon.*', '!build/sounds', '!build/sounds/*', '!build/notarize.js'])
|
|
|
|
del.sync(['packages/*', '!packages/universal.js', '!packages/packager.js', "!packages/socialwhalebirdapp_MAS.provisionprofile"])
|
2018-03-07 14:28:48 +01:00
|
|
|
console.log(`\n${doneLog}\n`)
|
|
|
|
process.exit()
|
|
|
|
}
|
|
|
|
|
2019-09-17 06:24:50 +02:00
|
|
|
async function build() {
|
2018-03-07 14:28:48 +01:00
|
|
|
del.sync(['dist/electron/*', '!.gitkeep'])
|
|
|
|
|
|
|
|
let results = ''
|
|
|
|
|
2019-09-17 13:41:12 +02:00
|
|
|
const tasks = new Listr(
|
|
|
|
[
|
|
|
|
{
|
|
|
|
title: 'building master process',
|
|
|
|
task: async () => {
|
2023-01-14 03:19:04 +01:00
|
|
|
await pack(mainConfig).catch(err => {
|
|
|
|
console.log(`\n ${errorLog}failed to build main process`)
|
|
|
|
console.error(`\n${err}\n`)
|
|
|
|
})
|
2019-09-17 13:41:12 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: 'building renderer process',
|
|
|
|
task: async () => {
|
2023-01-14 03:19:04 +01:00
|
|
|
await pack(rendererConfig).catch(err => {
|
|
|
|
console.log(`\n ${errorLog}failed to build renderer process`)
|
|
|
|
console.error(`\n${err}\n`)
|
|
|
|
})
|
2019-09-17 13:41:12 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
],
|
|
|
|
{ concurrent: 2 }
|
|
|
|
)
|
2018-03-07 14:28:48 +01:00
|
|
|
|
2019-09-17 13:41:12 +02:00
|
|
|
await tasks
|
|
|
|
.run()
|
|
|
|
.then(() => {
|
|
|
|
process.stdout.write('\x1B[2J\x1B[0f')
|
|
|
|
console.log(`\n\n${results}`)
|
|
|
|
process.exit()
|
2019-09-17 06:24:50 +02:00
|
|
|
})
|
|
|
|
.catch(err => {
|
|
|
|
process.exit(1)
|
|
|
|
})
|
2018-03-07 14:28:48 +01:00
|
|
|
}
|
|
|
|
|
2019-09-17 06:24:50 +02:00
|
|
|
function pack(config) {
|
2018-03-07 14:28:48 +01:00
|
|
|
return new Promise((resolve, reject) => {
|
2018-11-12 15:54:39 +01:00
|
|
|
config.mode = 'production'
|
2018-03-07 14:28:48 +01:00
|
|
|
webpack(config, (err, stats) => {
|
|
|
|
if (err) reject(err.stack || err)
|
|
|
|
else if (stats.hasErrors()) {
|
|
|
|
let err = ''
|
|
|
|
|
2019-09-17 06:24:50 +02:00
|
|
|
stats
|
|
|
|
.toString({
|
|
|
|
chunks: false,
|
|
|
|
colors: true
|
|
|
|
})
|
|
|
|
.split(/\r?\n/)
|
|
|
|
.forEach(line => {
|
|
|
|
err += ` ${line}\n`
|
|
|
|
})
|
2018-03-07 14:28:48 +01:00
|
|
|
|
|
|
|
reject(err)
|
|
|
|
} else {
|
2023-01-14 03:19:04 +01:00
|
|
|
resolve(null)
|
2018-03-07 14:28:48 +01:00
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|