2022-11-08 22:29:58 -05:00
|
|
|
import { fileURLToPath } from 'node:url'
|
|
|
|
|
|
|
|
const isMain = (meta) => {
|
|
|
|
const path = fileURLToPath(meta.url)
|
|
|
|
|
|
|
|
return path.includes(process.argv[1])
|
|
|
|
}
|
|
|
|
|
2023-09-30 04:54:07 -04:00
|
|
|
import { errorreporter, summaryreporter } from '../index.js'
|
|
|
|
const runifmain = async (meta, fn, ...args) => {
|
|
|
|
if (!isMain(meta)) return
|
|
|
|
|
2023-09-30 04:56:59 -04:00
|
|
|
if (fn.name === 'runner' && fn.run) {
|
|
|
|
if (args.length == 0) args.push(summaryreporter(), errorreporter())
|
|
|
|
await fn.run(...args)
|
|
|
|
} else {
|
|
|
|
await fn(...args)
|
|
|
|
}
|
2022-11-08 22:29:58 -05:00
|
|
|
}
|
|
|
|
|
2023-09-30 04:54:07 -04:00
|
|
|
export { runifmain }
|