Refactor the scripts to work as advertised

- Correct docs generation to always fetch its dependency
- Don't try to close a handle that's already been closed by other methods
- Allow the release script to actually be testable.
This commit is contained in:
Isiah Meadows 2019-08-17 15:22:35 -04:00
parent 30ad45caa1
commit 22e6d37a26
12 changed files with 483 additions and 241 deletions

View file

@ -1,8 +1,7 @@
"use strict"
process.on("unhandledRejection", (e) => { throw e })
function reportExec(e) {
process.on("unhandledRejection", function (e) {
process.exitCode = 1
if (!e.stdout || !e.stderr) return false
console.error(e.stack)
@ -14,23 +13,23 @@ function reportExec(e) {
}
return true
}
})
exports.exec = (mod, init) => {
if (require.main === mod) {
// Skip the first tick.
Promise.resolve().then(init).catch((e) => {
module.exports = ({exec, watch}) => {
const index = process.argv.indexOf("--watch")
if (index >= 0) {
process.argv.splice(index, 1)
if (watch == null) {
console.error("Watching this script is not supported!")
// eslint-disable-next-line no-process-exit
if (reportExec(e)) process.exit(1)
else throw e
process.exit(1)
}
watch()
} else {
Promise.resolve(exec()).then((code) => {
if (code != null) process.exitCode = code
})
}
}
exports.run = async (init) => {
try {
await init()
} catch (e) {
if (!reportExec(e)) console.error(e)
}
}