-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Andy Merskin
committed
Jul 19, 2017
0 parents
commit 1d973df
Showing
50 changed files
with
10,289 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
{ | ||
"comments": false, | ||
"env": { | ||
"main": { | ||
"presets": [ | ||
["env", { | ||
"targets": { "node": 7 } | ||
}], | ||
"stage-0" | ||
] | ||
}, | ||
"renderer": { | ||
"presets": [ | ||
["env", { | ||
"modules": false | ||
}], | ||
"stage-0" | ||
] | ||
}, | ||
"web": { | ||
"presets": [ | ||
["env", { | ||
"modules": false | ||
}], | ||
"stage-0" | ||
] | ||
} | ||
}, | ||
"plugins": ["transform-runtime"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
'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') | ||
const Multispinner = require('multispinner') | ||
|
||
|
||
const mainConfig = require('./webpack.main.config') | ||
const rendererConfig = require('./webpack.renderer.config') | ||
const webConfig = require('./webpack.web.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 if (process.env.BUILD_TARGET === 'web') web() | ||
else build() | ||
|
||
function clean () { | ||
del.sync(['build/*', '!build/icons', '!build/icons/icon.*']) | ||
console.log(`\n${doneLog}\n`) | ||
process.exit() | ||
} | ||
|
||
function build () { | ||
greeting() | ||
|
||
del.sync(['dist/electron/*', '!.gitkeep']) | ||
|
||
const tasks = ['main', 'renderer'] | ||
const m = new Multispinner(tasks, { | ||
preText: 'building', | ||
postText: 'process' | ||
}) | ||
|
||
let results = '' | ||
|
||
m.on('success', () => { | ||
process.stdout.write('\x1B[2J\x1B[0f') | ||
console.log(`\n\n${results}`) | ||
console.log(`${okayLog}take it away ${chalk.yellow('`electron-builder`')}\n`) | ||
process.exit() | ||
}) | ||
|
||
pack(mainConfig).then(result => { | ||
results += result + '\n\n' | ||
m.success('main') | ||
}).catch(err => { | ||
m.error('main') | ||
console.log(`\n ${errorLog}failed to build main process`) | ||
console.error(`\n${err}\n`) | ||
process.exit(1) | ||
}) | ||
|
||
pack(rendererConfig).then(result => { | ||
results += result + '\n\n' | ||
m.success('renderer') | ||
}).catch(err => { | ||
m.error('renderer') | ||
console.log(`\n ${errorLog}failed to build renderer 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 | ||
})) | ||
} | ||
}) | ||
}) | ||
} | ||
|
||
function web () { | ||
del.sync(['dist/web/*', '!.gitkeep']) | ||
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() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
const hotClient = require('webpack-hot-middleware/client?noInfo=true&reload=true') | ||
|
||
hotClient.subscribe(event => { | ||
/** | ||
* Reload browser when HTMLWebpackPlugin emits a new index.html | ||
*/ | ||
if (event.action === 'reload') { | ||
window.location.reload() | ||
} | ||
|
||
/** | ||
* Notify `mainWindow` when `main` process is compiling, | ||
* giving notice for an expected reload of the `electron` process | ||
*/ | ||
if (event.action === 'compiling') { | ||
document.body.innerHTML += ` | ||
<style> | ||
#dev-client { | ||
background: #4fc08d; | ||
border-radius: 4px; | ||
bottom: 20px; | ||
box-shadow: 0 4px 5px 0 rgba(0, 0, 0, 0.14), 0 1px 10px 0 rgba(0, 0, 0, 0.12), 0 2px 4px -1px rgba(0, 0, 0, 0.3); | ||
color: #fff; | ||
font-family: 'Source Sans Pro', sans-serif; | ||
left: 20px; | ||
padding: 8px 12px; | ||
position: absolute; | ||
} | ||
</style> | ||
<div id="dev-client"> | ||
Compiling Main Process... | ||
</div> | ||
` | ||
} | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,178 @@ | ||
'use strict' | ||
|
||
const chalk = require('chalk') | ||
const electron = require('electron') | ||
const path = require('path') | ||
const { say } = require('cfonts') | ||
const { spawn } = require('child_process') | ||
const webpack = require('webpack') | ||
const WebpackDevServer = require('webpack-dev-server') | ||
const webpackHotMiddleware = require('webpack-hot-middleware') | ||
|
||
const mainConfig = require('./webpack.main.config') | ||
const rendererConfig = require('./webpack.renderer.config') | ||
|
||
let electronProcess = null | ||
let manualRestart = false | ||
let hotMiddleware | ||
|
||
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 startRenderer () { | ||
return new Promise((resolve, reject) => { | ||
rendererConfig.entry.renderer = [path.join(__dirname, 'dev-client')].concat(rendererConfig.entry.renderer) | ||
|
||
const compiler = webpack(rendererConfig) | ||
hotMiddleware = webpackHotMiddleware(compiler, { | ||
log: false, | ||
heartbeat: 2500 | ||
}) | ||
|
||
compiler.plugin('compilation', compilation => { | ||
compilation.plugin('html-webpack-plugin-after-emit', (data, cb) => { | ||
hotMiddleware.publish({ action: 'reload' }) | ||
cb() | ||
}) | ||
}) | ||
|
||
compiler.plugin('done', stats => { | ||
logStats('Renderer', stats) | ||
}) | ||
|
||
const server = new WebpackDevServer( | ||
compiler, | ||
{ | ||
contentBase: path.join(__dirname, '../'), | ||
quiet: true, | ||
setup (app, ctx) { | ||
app.use(hotMiddleware) | ||
ctx.middleware.waitUntilValid(() => { | ||
resolve() | ||
}) | ||
} | ||
} | ||
) | ||
|
||
server.listen(9080) | ||
}) | ||
} | ||
|
||
function startMain () { | ||
return new Promise((resolve, reject) => { | ||
mainConfig.entry.main = [path.join(__dirname, '../src/main/index.dev.js')].concat(mainConfig.entry.main) | ||
|
||
const compiler = webpack(mainConfig) | ||
|
||
compiler.plugin('watch-run', (compilation, done) => { | ||
logStats('Main', chalk.white.bold('compiling...')) | ||
hotMiddleware.publish({ action: 'compiling' }) | ||
done() | ||
}) | ||
|
||
compiler.watch({}, (err, stats) => { | ||
if (err) { | ||
console.log(err) | ||
return | ||
} | ||
|
||
logStats('Main', stats) | ||
|
||
if (electronProcess && electronProcess.kill) { | ||
manualRestart = true | ||
process.kill(electronProcess.pid) | ||
electronProcess = null | ||
startElectron() | ||
|
||
setTimeout(() => { | ||
manualRestart = false | ||
}, 5000) | ||
} | ||
|
||
resolve() | ||
}) | ||
}) | ||
} | ||
|
||
function startElectron () { | ||
electronProcess = spawn(electron, ['--inspect=5858', path.join(__dirname, '../dist/electron/main.js')]) | ||
|
||
electronProcess.stdout.on('data', data => { | ||
electronLog(data, 'blue') | ||
}) | ||
electronProcess.stderr.on('data', data => { | ||
electronLog(data, 'red') | ||
}) | ||
|
||
electronProcess.on('close', () => { | ||
if (!manualRestart) process.exit() | ||
}) | ||
} | ||
|
||
function electronLog (data, color) { | ||
let log = '' | ||
data = data.toString().split(/\r?\n/) | ||
data.forEach(line => { | ||
log += ` ${line}\n` | ||
}) | ||
if (/[0-9A-z]+/.test(log)) { | ||
console.log( | ||
chalk[color].bold('┏ Electron -------------------') + | ||
'\n\n' + | ||
log + | ||
chalk[color].bold('┗ ----------------------------') + | ||
'\n' | ||
) | ||
} | ||
} | ||
|
||
function greeting () { | ||
const cols = process.stdout.columns | ||
let text = '' | ||
|
||
if (cols > 104) text = 'electron-vue' | ||
else if (cols > 76) text = 'electron-|vue' | ||
else text = false | ||
|
||
if (text) { | ||
say(text, { | ||
colors: ['yellow'], | ||
font: 'simple3d', | ||
space: false | ||
}) | ||
} else console.log(chalk.yellow.bold('\n electron-vue')) | ||
console.log(chalk.blue(' getting ready...') + '\n') | ||
} | ||
|
||
function init () { | ||
greeting() | ||
|
||
Promise.all([startRenderer(), startMain()]) | ||
.then(() => { | ||
startElectron() | ||
}) | ||
.catch(err => { | ||
console.error(err) | ||
}) | ||
} | ||
|
||
init() |
Oops, something went wrong.