diff --git a/package.json b/package.json index 78fd3f3..8d9297b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@athenna/core", - "version": "5.30.0", + "version": "5.31.0", "description": "One foundation for multiple applications.", "license": "MIT", "author": "João Lenon ", diff --git a/src/ignite/Ignite.ts b/src/ignite/Ignite.ts index 2aa705b..860ed59 100644 --- a/src/ignite/Ignite.ts +++ b/src/ignite/Ignite.ts @@ -35,6 +35,7 @@ import { Repl as ReplApp } from '#src/applications/Repl' import { parse as semverParse, satisfies as semverSatisfies } from 'semver' import { Is, Path, File, Module, Options, Macroable } from '@athenna/common' import { NotSatisfiedNodeVersion } from '#src/exceptions/NotSatisfiedNodeVersion' +import { debug } from '#src/debug/index' export class Ignite extends Macroable { /** @@ -57,6 +58,11 @@ export class Ignite extends Macroable { */ public options: IgniteOptions + /** + * Holds if Ignite has already been fired. + */ + public hasFired: boolean = false + /** * Install source maps support if the --enable-source-maps * flag is not set. @@ -167,7 +173,7 @@ export class Ignite extends Macroable { try { this.options.environments.push('http') - await this.fire() + await this.fire(options?.forceIgniteFire) return await Http.boot(options) } catch (err) { @@ -182,7 +188,7 @@ export class Ignite extends Macroable { try { this.options.environments.push('cron') - await this.fire() + await this.fire(options?.forceIgniteFire) return await Cron.boot(options) } catch (err) { @@ -197,7 +203,7 @@ export class Ignite extends Macroable { try { this.options.environments.push('worker') - await this.fire() + await this.fire(options?.forceIgniteFire) return await Worker.boot(options) } catch (err) { @@ -209,7 +215,17 @@ export class Ignite extends Macroable { * Fire the application configuring the env variables file, configuration files * providers and preload files. */ - public async fire() { + public async fire(forceIgniteFire?: boolean) { + if (this.hasFired && !forceIgniteFire) { + debug( + 'application already fired. if you need to refire use forceIgniteFire option in your application bootstrap.' + ) + + return + } + + this.hasFired = true + try { this.setEnvVariablesFile() await this.setConfigurationFiles() diff --git a/src/types/CronOptions.ts b/src/types/CronOptions.ts index bcc88df..6474f5f 100644 --- a/src/types/CronOptions.ts +++ b/src/types/CronOptions.ts @@ -8,6 +8,15 @@ */ export type CronOptions = { + /** + * Force ignite to fire. If running multiple applications, Athenna will + * fire Ignite only on the first application bootstrap. Use this option + * if you want to force the Ignite fire for a specific application. + * + * @default false + */ + forceIgniteFire: boolean + /** * The path to the cron routes. * diff --git a/src/types/HttpOptions.ts b/src/types/HttpOptions.ts index 3152ced..1de082f 100644 --- a/src/types/HttpOptions.ts +++ b/src/types/HttpOptions.ts @@ -8,6 +8,15 @@ */ export type HttpOptions = { + /** + * Force ignite to fire. If running multiple applications, Athenna will + * fire Ignite only on the first application bootstrap. Use this option + * if you want to force the Ignite fire for a specific application. + * + * @default false + */ + forceIgniteFire: boolean + /** * Only initialize the server without booting it. Useful when you want to * deploy your application in a serverless environment. diff --git a/src/types/WorkerOptions.ts b/src/types/WorkerOptions.ts index 5cfba0b..c7c823c 100644 --- a/src/types/WorkerOptions.ts +++ b/src/types/WorkerOptions.ts @@ -8,6 +8,15 @@ */ export type WorkerOptions = { + /** + * Force ignite to fire. If running multiple applications, Athenna will + * fire Ignite only on the first application bootstrap. Use this option + * if you want to force the Ignite fire for a specific application. + * + * @default false + */ + forceIgniteFire: boolean + /** * The path to the worker routes. *