skypager-project-types-electron-app
Version:
skypager electron app project type
41 lines (34 loc) • 1.21 kB
JavaScript
process.noAsar = true
try {
const project = require(process.env.SKYPAGER_FRAMEWORK_PATH).default.load(process.cwd())
process.on('message', function(message = {}) {
const { type } = message
try {
if (type === 'RUN_CODE') {
project.createSandboxedScriptRunner(message.code)(message).then((result) => {
if (typeof result === 'object' && typeof result.then === 'function') {
Promise.resolve(result).then((r) => {
process.send(Object.assign({}, message, {result: r}))
}).catch(error => {
process.send(Object.assign({}, message, {result: error}))
})
} else {
process.send(Object.assign({}, message, {result}))
}
})
} else if (type === 'SELECT') {
process.send(Object.assign({}, message, {result: project.select(message.selector, ...(message.args || []))}))
}
} catch(error) {
require('fs').writeFileSync('message.error.json', JSON.stringify({message,error}, null, 2), 'utf8')
}
})
} catch(error) {
console.error('ERROR in WORKER', error)
try {
require('fs').writeFileSync('worker.error', error.message, 'utf8')
} catch(error) {
process.exit(88)
}
process.exit(9)
}