2021-03-19 11:50:25 +01:00
|
|
|
#!/usr/bin/env node
|
2023-05-02 17:22:43 +02:00
|
|
|
process.env.DISABLE_PINO_LOGGER = "1"
|
2023-03-02 19:21:45 +01:00
|
|
|
import "./environment"
|
|
|
|
import { getCommands } from "./options"
|
|
|
|
import { Command } from "commander"
|
2024-01-02 18:45:19 +01:00
|
|
|
import { getHelpDescription, error } from "./utils"
|
2023-05-16 11:00:49 +02:00
|
|
|
import { version } from "../package.json"
|
2021-02-24 18:32:45 +01:00
|
|
|
|
2021-02-25 15:42:50 +01:00
|
|
|
// add hosting config
|
2021-02-26 12:46:48 +01:00
|
|
|
async function init() {
|
2021-02-25 15:42:50 +01:00
|
|
|
const program = new Command()
|
2021-02-26 12:46:48 +01:00
|
|
|
.addHelpCommand("help", getHelpDescription("Help with Budibase commands."))
|
|
|
|
.helpOption(false)
|
2023-05-16 11:00:49 +02:00
|
|
|
.version(version)
|
2021-02-26 12:46:48 +01:00
|
|
|
// add commands
|
|
|
|
for (let command of getCommands()) {
|
|
|
|
command.configure(program)
|
2021-02-25 15:42:50 +01:00
|
|
|
}
|
2021-02-26 12:46:48 +01:00
|
|
|
// this will stop the program if no command found
|
|
|
|
await program.parseAsync(process.argv)
|
2021-02-25 15:42:50 +01:00
|
|
|
}
|
2021-02-26 12:46:48 +01:00
|
|
|
|
2024-01-02 18:45:19 +01: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 12:32:22 +02:00
|
|
|
init().catch(err => {
|
2021-02-26 12:46:48 +01:00
|
|
|
console.error(`Unexpected error - `, err)
|
|
|
|
})
|