Listing_SuggestPrice/backend/ace.js

53 lines
1.5 KiB
JavaScript

/*
|--------------------------------------------------------------------------
| JavaScript entrypoint for running ace commands
|--------------------------------------------------------------------------
|
| Boots the AdonisJS application configured inside "bin/console.ts" file.
|
*/
import 'reflect-metadata'
/**
* Register the TypeScript loader so ace can import the app's command files
* (commands/*.ts) when run against the TypeScript source in development.
* In a compiled production build this dev dependency is absent, so the
* failure is ignored and ace runs the already-compiled JavaScript.
*/
try {
await import('ts-node-maintained/register/esm')
} catch {}
import { Ignitor, prettyPrintError } from '@adonisjs/core'
/**
* URL to the application root. AdonisJS need it to resolve paths to file and
* directories for scaffolding commands
*/
const APP_ROOT = new URL('./', import.meta.url)
/**
* The importer is used to import files in context of the application.
*/
const IMPORTER = (filePath) => {
if (filePath.startsWith('./') || filePath.startsWith('../')) {
return import(new URL(filePath, APP_ROOT).href)
}
return import(filePath)
}
new Ignitor(APP_ROOT, { importer: IMPORTER })
.tap((app) => {
app.booting(async () => {
await import('#start/env')
})
app.listen('SIGTERM', () => app.terminate())
app.listenIf(app.managedByPm2, 'SIGINT', () => app.terminate())
})
.ace()
.handle(process.argv.splice(2))
.catch((error) => {
process.exitCode = 1
prettyPrintError(error)
})