Commit dbf08282 authored by Isabella Skořepová's avatar Isabella Skořepová
Browse files

Fix end and possible race conditions

parent 394b33a5
......@@ -2,33 +2,32 @@
const { spawnSync, spawn } = require('child_process')
const config = require('./sitegin/config')
function onBabelExit(code) {
setTimeout(() => {
runBabel({ watch: true })
}, 500)
}
function runBabel({ watch = false }) {
function runBabel({ onExit, opts = [] }) {
const babel = spawn(
'./node_modules/.bin/babel',
[
'theme-source',
'-d',
'theme',
'--delete-dir-on-start',
watch ? '--watch' : null,
].filter(a => a),
['theme-source', '-d', 'theme', ...opts].filter(a => a),
{ stdio: 'inherit', cwd: __dirname },
)
if (watch) babel.on('exit', onBabelExit)
if (onExit) babel.on('exit', onExit)
}
function runBabelWatch() {
runBabel({
onExit: () => {
setTimeout(() => runBabelWatch(), 500)
},
opts: ['--skip-initial-build', '--watch'],
})
}
;(async () => {
const opts = await config()
runBabel({ watch: !opts.nowatch })
if (opts.config.options.nowatch) {
require('./sitegin/index.js')
} else {
await new Promise(res =>
runBabel({ onExit: res, opts: ['--delete-dir-on-start'] }),
)
const watch = !opts.config.options.nowatch
if (watch) {
runBabelWatch()
spawnSync(
process.argv[0],
[
......@@ -40,5 +39,7 @@ function runBabel({ watch = false }) {
],
{ stdio: ['inherit', 'inherit', 'inherit'] },
)
} else {
require('./sitegin/index.js')
}
})()
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment