Clean up build.js script

This commit is contained in:
AkiraFukushima 2023-01-14 11:19:04 +09:00
parent cc627ca854
commit 8b56af8738
No known key found for this signature in database
GPG Key ID: B6E51BAC4DE1A957
1 changed files with 9 additions and 62 deletions

View File

@ -11,7 +11,6 @@ const Listr = require('listr')
const mainConfig = require('./webpack.main.config') const mainConfig = require('./webpack.main.config')
const rendererConfig = require('./webpack.renderer.config') const rendererConfig = require('./webpack.renderer.config')
const webConfig = require('./webpack.web.config')
const doneLog = chalk.bgGreen.white(' DONE ') + ' ' const doneLog = chalk.bgGreen.white(' DONE ') + ' '
const errorLog = chalk.bgRed.white(' ERROR ') + ' ' const errorLog = chalk.bgRed.white(' ERROR ') + ' '
@ -19,7 +18,6 @@ const okayLog = chalk.bgBlue.white(' OKAY ') + ' '
const isCI = process.env.CI || false const isCI = process.env.CI || false
if (process.env.BUILD_TARGET === 'clean') clean() if (process.env.BUILD_TARGET === 'clean') clean()
else if (process.env.BUILD_TARGET === 'web') web()
else build() else build()
function clean() { function clean() {
@ -30,8 +28,6 @@ function clean() {
} }
async function build() { async function build() {
greeting()
del.sync(['dist/electron/*', '!.gitkeep']) del.sync(['dist/electron/*', '!.gitkeep'])
let results = '' let results = ''
@ -41,27 +37,19 @@ async function build() {
{ {
title: 'building master process', title: 'building master process',
task: async () => { task: async () => {
await pack(mainConfig) await pack(mainConfig).catch(err => {
.then(result => { console.log(`\n ${errorLog}failed to build main process`)
results += result + '\n\n' console.error(`\n${err}\n`)
}) })
.catch(err => {
console.log(`\n ${errorLog}failed to build main process`)
console.error(`\n${err}\n`)
})
} }
}, },
{ {
title: 'building renderer process', title: 'building renderer process',
task: async () => { task: async () => {
await pack(rendererConfig) await pack(rendererConfig).catch(err => {
.then(result => { console.log(`\n ${errorLog}failed to build renderer process`)
results += result + '\n\n' console.error(`\n${err}\n`)
}) })
.catch(err => {
console.log(`\n ${errorLog}failed to build renderer process`)
console.error(`\n${err}\n`)
})
} }
} }
], ],
@ -73,7 +61,6 @@ async function build() {
.then(() => { .then(() => {
process.stdout.write('\x1B[2J\x1B[0f') process.stdout.write('\x1B[2J\x1B[0f')
console.log(`\n\n${results}`) console.log(`\n\n${results}`)
console.log(`${okayLog}take it away ${chalk.yellow('`electron-builder`')}\n`)
process.exit() process.exit()
}) })
.catch(err => { .catch(err => {
@ -101,48 +88,8 @@ function pack(config) {
reject(err) reject(err)
} else { } else {
resolve( resolve(null)
stats.toString({
chunks: false,
colors: true
})
)
} }
}) })
}) })
} }
function web() {
del.sync(['dist/web/*', '!.gitkeep'])
webConfig.mode = 'production'
webpack(webConfig, (err, stats) => {
if (err || stats.hasErrors()) console.log(err)
console.log(
stats.toString({
chunks: false,
colors: true
})
)
process.exit()
})
}
function greeting() {
const cols = process.stdout.columns
let text = ''
if (cols > 85) text = 'lets-build'
else if (cols > 60) text = 'lets-|build'
else text = false
if (text && !isCI) {
say(text, {
colors: ['yellow'],
font: 'simple3d',
space: false
})
} else console.log(chalk.yellow.bold('\n lets-build'))
console.log()
}