1
0
mirror of https://github.com/PanJiaChen/electron-vue-admin.git synced 2025-04-05 05:32:44 +08:00
2017-07-14 16:08:15 +08:00

57 lines
1.5 KiB
JavaScript

'use strict'
const config = require('../config')
const exec = require('child_process').exec
const treeKill = require('tree-kill')
const YELLOW = '\x1b[33m'
const BLUE = '\x1b[34m'
const END = '\x1b[0m'
let isElectronOpen = false
function repeat(str, times) {
return (new Array(times + 1)).join(str)
}
function format(command, data, color) {
return color + command + END +
' ' + // Two space offset
data.toString().trim().replace(/\n/g, '\n' + repeat(' ', command.length + 2)) +
'\n'
}
const children = []
function run(command, color, name) {
const child = exec(command)
child.stdout.on('data', data => {
console.log(format(name, data, color))
/**
* Start electron after successful compilation
* (prevents electron from opening a blank window that requires refreshing)
*/
if (/Compiled/g.test(data.toString().trim().replace(/\n/g, '\n' + repeat(' ', command.length + 2))) && !isElectronOpen) {
console.log(`${BLUE}Starting electron...\n${END}`)
run('cross-env NODE_ENV=development electron app/src/main/index.dev.js', BLUE, 'electron')
isElectronOpen = true
}
})
child.stderr.on('data', data => console.error(format(name, data, color)))
child.on('exit', code => exit(code))
children.push(child)
}
function exit(code) {
children.forEach(child => {
treeKill(child.pid)
})
}
console.log(`${YELLOW}Starting webpack-dev-server...\n${END}`)
run(`webpack-dev-server --hot --colors --config webpack.renderer.config.js --port ${config.port} --content-base app/dist`, YELLOW, 'webpack')