Refactor scripts (#2465)
* Refactor all kinds of scripts * Update docs to ensure linter passes
This commit is contained in:
parent
62172cbe08
commit
48e7fd1711
23 changed files with 1695 additions and 340 deletions
36
scripts/_command.js
Normal file
36
scripts/_command.js
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
"use strict"
|
||||
|
||||
process.on("unhandledRejection", (e) => { throw e })
|
||||
|
||||
function reportExec(e) {
|
||||
if (!e.stdout || !e.stderr) return false
|
||||
console.error(e.stack)
|
||||
|
||||
if (e.stdout && e.stdout.length) {
|
||||
console.error(e.stdout.toString("utf-8"))
|
||||
}
|
||||
if (e.stderr && e.stderr.length) {
|
||||
console.error(e.stderr.toString("utf-8"))
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
exports.exec = (mod, init) => {
|
||||
if (require.main === mod) {
|
||||
// Skip the first tick.
|
||||
Promise.resolve().then(init).catch((e) => {
|
||||
// eslint-disable-next-line no-process-exit
|
||||
if (reportExec(e)) process.exit(1)
|
||||
else throw e
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
exports.run = async (init) => {
|
||||
try {
|
||||
await init()
|
||||
} catch (e) {
|
||||
if (!reportExec(e)) console.error(e)
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue