Files
cypress/scripts/watch.js
Cesar 1762caccd8 feat: add state for global mode (#18085)
* add state for global mode

* use GlobalEmpty over GlobalPage

* Add comment to clarify global type

Co-authored-by: Jessica Sachs <jess@jessicasachs.io>

* Update server.ts

* make global non nullable

* move GlobalEmpty to Main.vue

* update ClientTestContext to have global

Co-authored-by: Jessica Sachs <jess@jessicasachs.io>
2021-09-15 10:40:06 +10:00

69 lines
1.2 KiB
JavaScript

const chokidar = require('chokidar')
const childProcess = require('child_process')
const path = require('path')
const pDefer = require('p-defer')
const watcher = chokidar.watch('packages/graphql/src/**/*.{js,ts}', {
cwd: path.join(__dirname, '..'),
ignored: '**/nxs.gen.ts',
ignoreInitial: true,
})
/**
* @type {childProcess.ChildProcess}
*/
let child
let isClosing = false
let isRestarting = false
function runServer () {
if (child) {
child.removeAllListeners()
}
child = childProcess.fork(path.join(__dirname, 'start.js'), [...process.argv, '--devWatch'], {
stdio: 'inherit',
})
child.on('exit', (code) => {
if (isClosing) {
process.exit(code)
}
})
child.on('disconnect', () => {
child = null
})
}
async function restartServer () {
if (isRestarting) {
return
}
const dfd = pDefer()
if (child) {
child.on('exit', dfd.resolve)
isRestarting = true
child.send('close')
} else {
dfd.resolve()
}
await dfd.promise
isRestarting = false
runServer()
}
watcher.on('add', restartServer)
watcher.on('change', restartServer)
runServer()
process.on('beforeExit', () => {
isClosing = true
child?.send('close')
})