1
0
Fork 0
mirror of synced 2024-09-21 03:43:21 +12:00
budibase/packages/cli/src/index.ts

43 lines
1.1 KiB
TypeScript
Raw Normal View History

2021-03-19 23:50:25 +13:00
#!/usr/bin/env node
// have to import this before anything else
import "./environment"
import { getCommands } from "./options"
import { Command } from "commander"
import { getHelpDescription, error } from "./utils"
import { version } from "../package.json"
2021-02-25 06:32:45 +13:00
2021-02-26 03:42:50 +13:00
// add hosting config
async function init() {
2021-02-26 03:42:50 +13:00
const program = new Command()
.addHelpCommand("help", getHelpDescription("Help with Budibase commands."))
.helpOption(false)
.version(version)
// add commands
for (let command of getCommands()) {
command.configure(program)
2021-02-26 03:42:50 +13:00
}
// this will stop the program if no command found
await program.parseAsync(process.argv)
2021-02-26 03:42:50 +13:00
}
const events = ["exit", "SIGINT", "SIGUSR1", "SIGUSR2", "uncaughtException"]
events.forEach(event => {
process.on(event, (evt?: number) => {
if (evt && !isNaN(evt)) {
return
}
if (evt) {
console.error(
error(
"Failed to run CLI command - please report with the following message:"
)
)
console.error(error(evt))
}
})
})
2021-05-04 22:32:22 +12:00
init().catch(err => {
console.error(`Unexpected error - `, err)
})