@adonisjs/application
Advanced tools
Comparing version 7.1.2-5 to 7.1.2-6
@@ -1,6 +0,13 @@ | ||
/// <reference types="node" resolution-mode="require"/> | ||
/// <reference types="@types/node" resolution-mode="require"/> | ||
import { Application } from '../src/application.js'; | ||
import type { AppEnvironments, Importer } from '../src/types.js'; | ||
/** | ||
* App factory is used to generate application class instances for | ||
* testing | ||
*/ | ||
export declare class AppFactory { | ||
#private; | ||
/** | ||
* Merge parameters accepted by the AppFactory | ||
*/ | ||
merge(params: Partial<{ | ||
@@ -10,4 +17,6 @@ environment: AppEnvironments; | ||
}>): this; | ||
/** | ||
* Create application class instance | ||
*/ | ||
create(appRoot: URL, importer: Importer): Application<Record<any, any>>; | ||
} | ||
//# sourceMappingURL=app.d.ts.map |
@@ -0,4 +1,19 @@ | ||
/* | ||
* @adonisjs/application | ||
* | ||
* (c) AdonisJS | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
import { Application } from '../src/application.js'; | ||
/** | ||
* App factory is used to generate application class instances for | ||
* testing | ||
*/ | ||
export class AppFactory { | ||
#parameters = {}; | ||
/** | ||
* Merge parameters accepted by the AppFactory | ||
*/ | ||
merge(params) { | ||
@@ -8,2 +23,5 @@ Object.assign(this.#parameters, params); | ||
} | ||
/** | ||
* Create application class instance | ||
*/ | ||
create(appRoot, importer) { | ||
@@ -10,0 +28,0 @@ return new Application(appRoot, Object.assign({ importer }, { environment: 'web' }, this.#parameters)); |
export { AppFactory } from './app.js'; | ||
//# sourceMappingURL=main.d.ts.map |
@@ -0,1 +1,9 @@ | ||
/* | ||
* @adonisjs/application | ||
* | ||
* (c) AdonisJS | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
export { AppFactory } from './app.js'; |
@@ -6,2 +6,1 @@ export { Stub } from './src/stubs/stub.js'; | ||
export { RcFileParser } from './src/rc_file/parser.js'; | ||
//# sourceMappingURL=index.d.ts.map |
@@ -0,1 +1,9 @@ | ||
/* | ||
* @adonisjs/application | ||
* | ||
* (c) AdonisJS | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
export { Stub } from './src/stubs/stub.js'; | ||
@@ -2,0 +10,0 @@ export * as errors from './src/exceptions.js'; |
@@ -1,3 +0,3 @@ | ||
/// <reference types="node" resolution-mode="require"/> | ||
/// <reference types="node" resolution-mode="require"/> | ||
/// <reference types="@types/node" resolution-mode="require"/> | ||
/// <reference types="@types/node" resolution-mode="require"/> | ||
import { Container } from '@adonisjs/fold'; | ||
@@ -7,21 +7,89 @@ import type { HookHandler } from '@poppinss/hooks/types'; | ||
import type { Importer, SemverNode, AppEnvironments, ApplicationStates } from './types.js'; | ||
/** | ||
* Application class manages the state of an AdonisJS application. It includes | ||
* | ||
* - Setting up the base features like importing config and setting up logger. | ||
* - Parsing the ".adonisrc.json" file | ||
* - Setting up the IoC container | ||
* - Registering an booting providers | ||
* - Invoking lifecycle methods on the providers and hooks | ||
*/ | ||
export declare class Application<ContainerBindings extends Record<any, any>> { | ||
#private; | ||
/** | ||
* Store info metadata about the app. | ||
*/ | ||
info: Map<'appName' | 'version' | 'adonisVersion' | string, any>; | ||
/** | ||
* Returns the application name from the info map | ||
*/ | ||
get appName(): any; | ||
/** | ||
* Returns the application version from the info map | ||
*/ | ||
get version(): SemverNode | null; | ||
/** | ||
* The parsed version for the "@adonisjs/core" package. | ||
*/ | ||
get adonisVersion(): SemverNode | null; | ||
/** | ||
* The URL for the root of the application | ||
*/ | ||
get appRoot(): URL; | ||
/** | ||
* A boolean to know if the application has been booted | ||
*/ | ||
get isBooted(): boolean; | ||
/** | ||
* A boolean to know if the application is ready | ||
*/ | ||
get isReady(): boolean; | ||
/** | ||
* A boolean to know if the application has been terminated | ||
*/ | ||
get isTerminated(): boolean; | ||
/** | ||
* A boolean to know if the application is in the middle of getting | ||
* terminating | ||
*/ | ||
get isTerminating(): boolean; | ||
/** | ||
* Reference to the config class. The value is defined | ||
* after the "init" method call | ||
*/ | ||
get config(): import("@adonisjs/config").Config; | ||
/** | ||
* Reference to the parsed rc file. The value is defined | ||
* after the "init" method call | ||
*/ | ||
get rcFile(): import("./types.js").RcFile; | ||
/** | ||
* Reference to the rcFile editor. The value is defined | ||
* after the "init" method call | ||
*/ | ||
get rcFileEditor(): import("./rc_file/editor.js").RcFileEditor; | ||
/** | ||
* Normalized current NODE_ENV | ||
*/ | ||
get nodeEnvironment(): string; | ||
/** | ||
* Return true when `this.nodeEnvironment === 'production'` | ||
*/ | ||
get inProduction(): boolean; | ||
/** | ||
* Return true when `this.nodeEnvironment === 'development'` | ||
*/ | ||
get inDev(): boolean; | ||
/** | ||
* Returns true when `this.nodeEnvironment === 'test'` | ||
*/ | ||
get inTest(): boolean; | ||
/** | ||
* Find if the process is managed and run under | ||
* pm2 | ||
*/ | ||
get managedByPm2(): boolean; | ||
/** | ||
* Reference to scaffolding generators | ||
*/ | ||
get generators(): { | ||
@@ -71,2 +139,6 @@ singularControllerNames: string[]; | ||
stubs: StubsManager; | ||
/** | ||
* Reference to the AdonisJS IoC container. The value is defined | ||
* after the "init" method call | ||
*/ | ||
container: Container<ContainerBindings>; | ||
@@ -77,53 +149,237 @@ constructor(appRoot: URL, options: { | ||
}); | ||
/** | ||
* The current environment in which the application | ||
* is running | ||
*/ | ||
getEnvironment(): AppEnvironments; | ||
/** | ||
* Switch the environment in which the app is running. The | ||
* environment can only be changed before the app is | ||
* booted. | ||
*/ | ||
setEnvironment(environment: AppEnvironments): this; | ||
/** | ||
* The current state of the application. | ||
*/ | ||
getState(): ApplicationStates; | ||
/** | ||
* Specify the contents of the ".adonisrc.json" file as | ||
* an object. Calling this method will disable loading | ||
* the ".adonisrc.json" file from the disk. | ||
*/ | ||
rcContents(value: Record<string, any>): this; | ||
/** | ||
* Define the config values to use when booting the | ||
* config provider. Calling this method disables | ||
* reading files from the config directory. | ||
*/ | ||
useConfig(values: Record<any, any>): this; | ||
/** | ||
* Notify the parent process when the Node.js process is spawned with an IPC channel. | ||
* The arguments accepted are same as "process.send" | ||
*/ | ||
notify(message: any, sendHandle?: any, options?: { | ||
swallowErrors?: boolean | undefined; | ||
}, callback?: (error: Error | null) => void): void; | ||
/** | ||
* Listen for a process signal. This method is same as calling | ||
* "process.on(signal)" | ||
*/ | ||
listen(signal: NodeJS.Signals, callback: NodeJS.SignalsListener): this; | ||
/** | ||
* Listen for a process signal once. This method is same as calling | ||
* "process.once(signal)" | ||
*/ | ||
listenOnce(signal: NodeJS.Signals, callback: NodeJS.SignalsListener): this; | ||
/** | ||
* Listen for a process signal conditionally. | ||
*/ | ||
listenIf(conditional: boolean, signal: NodeJS.Signals, callback: NodeJS.SignalsListener): this; | ||
/** | ||
* Listen for a process signal once conditionally. | ||
*/ | ||
listenOnceIf(conditional: boolean, signal: NodeJS.Signals, callback: NodeJS.SignalsListener): this; | ||
/** | ||
* Register hooks that are called before the app starts | ||
* the initiating process | ||
*/ | ||
initiating(handler: HookHandler<[Application<ContainerBindings>], [Application<ContainerBindings>]>): this; | ||
/** | ||
* Initiate the application. Calling this method performs following | ||
* operations. | ||
* | ||
* - Parses the ".adonisrc.json" file | ||
* - Validate and set environment variables | ||
* - Loads the application config from the configured config dir. | ||
* - Configures the logger | ||
* - Instantiates the IoC container | ||
*/ | ||
init(): Promise<void>; | ||
/** | ||
* Register hooks that are called before the app boot | ||
* process starts | ||
*/ | ||
booting(handler: HookHandler<[Application<ContainerBindings>], [Application<ContainerBindings>]>): this; | ||
/** | ||
* Boot the application. Calling this method performs the following | ||
* operations. | ||
* | ||
* - Resolve providers and call the "register" method on them. | ||
* - Call the "boot" method on providers | ||
* - Run the "booted" hooks | ||
*/ | ||
boot(): Promise<void>; | ||
/** | ||
* Register a hook to get notified when the application has | ||
* been booted. | ||
* | ||
* The hook will be called immediately if the app has already | ||
* been booted. | ||
*/ | ||
booted(handler: HookHandler<[Application<ContainerBindings>], [Application<ContainerBindings>]>): Promise<void>; | ||
/** | ||
* Register hooks that are called when the app is starting | ||
*/ | ||
starting(handler: HookHandler<[Application<ContainerBindings>], [Application<ContainerBindings>]>): this; | ||
/** | ||
* Start the application. Calling this method performs the following | ||
* operations. | ||
* | ||
* - Run the "start" lifecycle hooks on all the providers | ||
* - Start the application by invoking the supplied callback | ||
* - Run the "ready" lifecycle hooks on all the providers | ||
* - Run the "ready" application hooks | ||
*/ | ||
start(callback: (app: this) => void | Promise<void>): Promise<void>; | ||
/** | ||
* Register hooks that are called when the app is | ||
* ready | ||
*/ | ||
ready(handler: HookHandler<[Application<ContainerBindings>], [Application<ContainerBindings>]>): Promise<void>; | ||
/** | ||
* Register hooks that are called before the app is | ||
* terminated. | ||
*/ | ||
terminating(handler: HookHandler<[Application<ContainerBindings>], [Application<ContainerBindings>]>): this; | ||
/** | ||
* Terminate application gracefully. Calling this method performs | ||
* the following operations. | ||
* | ||
* - Run "shutdown" hooks on all the providers | ||
* - Run "terminating" app lifecycle hooks | ||
*/ | ||
terminate(): Promise<void>; | ||
/** | ||
* Returns relative path to a file from the app root | ||
*/ | ||
relativePath(absolutePath: string): string; | ||
/** | ||
* Returns URL to a path from the application root. | ||
*/ | ||
makeURL(...paths: string[]): URL; | ||
/** | ||
* Returns file system path from the application root. | ||
*/ | ||
makePath(...paths: string[]): string; | ||
/** | ||
* Makes path to the config directory | ||
*/ | ||
configPath(...paths: string[]): string; | ||
/** | ||
* Makes path to the public directory | ||
*/ | ||
publicPath(...paths: string[]): string; | ||
/** | ||
* Makes path to the providers directory | ||
*/ | ||
providersPath(...paths: string[]): string; | ||
/** | ||
* Makes path to the factories directory | ||
*/ | ||
factoriesPath(...paths: string[]): string; | ||
/** | ||
* Makes path to the migrations directory | ||
*/ | ||
migrationsPath(...paths: string[]): string; | ||
/** | ||
* Makes path to the seeders directory | ||
*/ | ||
seedersPath(...paths: string[]): string; | ||
/** | ||
* Makes path to the language files directory | ||
*/ | ||
languageFilesPath(...paths: string[]): string; | ||
/** | ||
* Makes path to the views directory | ||
*/ | ||
viewsPath(...paths: string[]): string; | ||
/** | ||
* Makes path to the start directory | ||
*/ | ||
startPath(...paths: string[]): string; | ||
/** | ||
* Makes path to the tmp directory | ||
*/ | ||
tmpPath(...paths: string[]): string; | ||
/** | ||
* Makes path to the contracts directory | ||
*/ | ||
contractsPath(...paths: string[]): string; | ||
/** | ||
* Makes path to the http controllers directory | ||
*/ | ||
httpControllersPath(...paths: string[]): string; | ||
/** | ||
* Makes path to the models directory | ||
*/ | ||
modelsPath(...paths: string[]): string; | ||
/** | ||
* Makes path to the services directory | ||
*/ | ||
servicesPath(...paths: string[]): string; | ||
/** | ||
* Makes path to the exceptions directory | ||
*/ | ||
exceptionsPath(...paths: string[]): string; | ||
/** | ||
* Makes path to the mailers directory | ||
*/ | ||
mailersPath(...paths: string[]): string; | ||
/** | ||
* Makes path to the middleware directory | ||
*/ | ||
middlewarePath(...paths: string[]): string; | ||
/** | ||
* Makes path to the policies directory | ||
*/ | ||
policiesPath(...paths: string[]): string; | ||
/** | ||
* Makes path to the validators directory | ||
*/ | ||
validatorsPath(...paths: string[]): string; | ||
/** | ||
* Makes path to the commands directory | ||
*/ | ||
commandsPath(...paths: string[]): string; | ||
/** | ||
* Makes path to the events directory | ||
*/ | ||
eventsPath(...paths: string[]): string; | ||
/** | ||
* Makes path to the listeners directory | ||
*/ | ||
listenersPath(...paths: string[]): string; | ||
/** | ||
* Import a module by identifier | ||
*/ | ||
import(moduleIdentifier: string): any; | ||
/** | ||
* Import a module by identifier | ||
*/ | ||
importDefault<T extends object>(moduleIdentifier: string): Promise<T extends { | ||
default: infer A; | ||
} ? A : never>; | ||
/** | ||
* JSON representation of the application | ||
*/ | ||
toJSON(): { | ||
@@ -139,2 +395,1 @@ isReady: boolean; | ||
} | ||
//# sourceMappingURL=application.d.ts.map |
@@ -0,1 +1,9 @@ | ||
/* | ||
* @adonisjs/application | ||
* | ||
* (c) AdonisJS | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
import Hooks from '@poppinss/hooks'; | ||
@@ -14,11 +22,44 @@ import { fileURLToPath } from 'node:url'; | ||
import { ProvidersManager } from './managers/providers.js'; | ||
/** | ||
* Application class manages the state of an AdonisJS application. It includes | ||
* | ||
* - Setting up the base features like importing config and setting up logger. | ||
* - Parsing the ".adonisrc.json" file | ||
* - Setting up the IoC container | ||
* - Registering an booting providers | ||
* - Invoking lifecycle methods on the providers and hooks | ||
*/ | ||
export class Application { | ||
/** | ||
* Importer function to import modules from the application | ||
* context | ||
*/ | ||
#importer; | ||
/** | ||
* Flag to know when we have started the termination | ||
* process | ||
*/ | ||
#terminating = false; | ||
/** | ||
* The environment in which the app is running. Currently we track | ||
* pm2 only | ||
*/ | ||
#surroundedEnvironment = { | ||
pm2: false, | ||
}; | ||
/** | ||
* Application root. The path must end with '/' | ||
*/ | ||
#appRoot; | ||
/** | ||
* Current application environment | ||
*/ | ||
#environment; | ||
/** | ||
* Current state of the application | ||
*/ | ||
#state = 'created'; | ||
/** | ||
* Managers for sub-features | ||
*/ | ||
#configManager; | ||
@@ -29,52 +70,114 @@ #rcFileManager; | ||
#providersManager; | ||
/** | ||
* Lifecycle hooks | ||
*/ | ||
#hooks = new Hooks(); | ||
/** | ||
* Store info metadata about the app. | ||
*/ | ||
info = new Map(); | ||
/** | ||
* Returns the application name from the info map | ||
*/ | ||
get appName() { | ||
return this.info.get('appName') || 'adonisjs_app'; | ||
} | ||
/** | ||
* Returns the application version from the info map | ||
*/ | ||
get version() { | ||
return this.info.get('version') || null; | ||
} | ||
/** | ||
* The parsed version for the "@adonisjs/core" package. | ||
*/ | ||
get adonisVersion() { | ||
return this.info.get('adonisVersion') || null; | ||
} | ||
/** | ||
* The URL for the root of the application | ||
*/ | ||
get appRoot() { | ||
return this.#appRoot; | ||
} | ||
/** | ||
* A boolean to know if the application has been booted | ||
*/ | ||
get isBooted() { | ||
return this.#state !== 'created' && this.#state !== 'initiated'; | ||
} | ||
/** | ||
* A boolean to know if the application is ready | ||
*/ | ||
get isReady() { | ||
return this.#state === 'ready'; | ||
} | ||
/** | ||
* A boolean to know if the application has been terminated | ||
*/ | ||
get isTerminated() { | ||
return this.#state === 'terminated'; | ||
} | ||
/** | ||
* A boolean to know if the application is in the middle of getting | ||
* terminating | ||
*/ | ||
get isTerminating() { | ||
return this.#terminating && this.#state !== 'terminated'; | ||
} | ||
/** | ||
* Reference to the config class. The value is defined | ||
* after the "init" method call | ||
*/ | ||
get config() { | ||
return this.#configManager.config; | ||
} | ||
/** | ||
* Reference to the parsed rc file. The value is defined | ||
* after the "init" method call | ||
*/ | ||
get rcFile() { | ||
return this.#rcFileManager.rcFile; | ||
} | ||
/** | ||
* Reference to the rcFile editor. The value is defined | ||
* after the "init" method call | ||
*/ | ||
get rcFileEditor() { | ||
return this.#rcFileManager.rcFileEditor; | ||
} | ||
/** | ||
* Normalized current NODE_ENV | ||
*/ | ||
get nodeEnvironment() { | ||
return this.#nodeEnvManager.nodeEnvironment; | ||
} | ||
/** | ||
* Return true when `this.nodeEnvironment === 'production'` | ||
*/ | ||
get inProduction() { | ||
return this.nodeEnvironment === 'production'; | ||
} | ||
/** | ||
* Return true when `this.nodeEnvironment === 'development'` | ||
*/ | ||
get inDev() { | ||
return this.nodeEnvironment === 'development'; | ||
} | ||
/** | ||
* Returns true when `this.nodeEnvironment === 'test'` | ||
*/ | ||
get inTest() { | ||
return this.nodeEnvironment === 'test'; | ||
} | ||
/** | ||
* Find if the process is managed and run under | ||
* pm2 | ||
*/ | ||
get managedByPm2() { | ||
return this.#surroundedEnvironment.pm2; | ||
} | ||
/** | ||
* Reference to scaffolding generators | ||
*/ | ||
get generators() { | ||
@@ -84,2 +187,6 @@ return generators; | ||
stubs; | ||
/** | ||
* Reference to the AdonisJS IoC container. The value is defined | ||
* after the "init" method call | ||
*/ | ||
container; | ||
@@ -112,11 +219,26 @@ constructor(appRoot, options) { | ||
} | ||
/** | ||
* Instantiate the application container | ||
*/ | ||
#instantiateContainer() { | ||
this.container = new Container(); | ||
} | ||
/** | ||
* Instantiates the stubs manager | ||
*/ | ||
#instantiateStubsManager() { | ||
this.stubs = new StubsManager(this, this.makePath(this.rcFile.directories.stubs)); | ||
} | ||
/** | ||
* The current environment in which the application | ||
* is running | ||
*/ | ||
getEnvironment() { | ||
return this.#environment; | ||
} | ||
/** | ||
* Switch the environment in which the app is running. The | ||
* environment can only be changed before the app is | ||
* booted. | ||
*/ | ||
setEnvironment(environment) { | ||
@@ -130,5 +252,13 @@ if (this.#state !== 'created' && this.#state !== 'initiated') { | ||
} | ||
/** | ||
* The current state of the application. | ||
*/ | ||
getState() { | ||
return this.#state; | ||
} | ||
/** | ||
* Specify the contents of the ".adonisrc.json" file as | ||
* an object. Calling this method will disable loading | ||
* the ".adonisrc.json" file from the disk. | ||
*/ | ||
rcContents(value) { | ||
@@ -138,2 +268,7 @@ this.#rcFileManager.rcContents(value); | ||
} | ||
/** | ||
* Define the config values to use when booting the | ||
* config provider. Calling this method disables | ||
* reading files from the config directory. | ||
*/ | ||
useConfig(values) { | ||
@@ -143,2 +278,6 @@ this.#configManager.useConfig(values); | ||
} | ||
/** | ||
* Notify the parent process when the Node.js process is spawned with an IPC channel. | ||
* The arguments accepted are same as "process.send" | ||
*/ | ||
notify(message, sendHandle, options, callback) { | ||
@@ -149,2 +288,6 @@ if (process.send) { | ||
} | ||
/** | ||
* Listen for a process signal. This method is same as calling | ||
* "process.on(signal)" | ||
*/ | ||
listen(signal, callback) { | ||
@@ -154,2 +297,6 @@ process.on(signal, callback); | ||
} | ||
/** | ||
* Listen for a process signal once. This method is same as calling | ||
* "process.once(signal)" | ||
*/ | ||
listenOnce(signal, callback) { | ||
@@ -159,2 +306,5 @@ process.once(signal, callback); | ||
} | ||
/** | ||
* Listen for a process signal conditionally. | ||
*/ | ||
listenIf(conditional, signal, callback) { | ||
@@ -166,2 +316,5 @@ if (conditional) { | ||
} | ||
/** | ||
* Listen for a process signal once conditionally. | ||
*/ | ||
listenOnceIf(conditional, signal, callback) { | ||
@@ -173,2 +326,6 @@ if (conditional) { | ||
} | ||
/** | ||
* Register hooks that are called before the app starts | ||
* the initiating process | ||
*/ | ||
initiating(handler) { | ||
@@ -178,2 +335,12 @@ this.#hooks.add('initiating', handler); | ||
} | ||
/** | ||
* Initiate the application. Calling this method performs following | ||
* operations. | ||
* | ||
* - Parses the ".adonisrc.json" file | ||
* - Validate and set environment variables | ||
* - Loads the application config from the configured config dir. | ||
* - Configures the logger | ||
* - Instantiates the IoC container | ||
*/ | ||
async init() { | ||
@@ -185,9 +352,26 @@ if (this.#state !== 'created') { | ||
debug('initiating app'); | ||
/** | ||
* Metadata management is not considering part | ||
* of initiating the app | ||
*/ | ||
this.#instantiateContainer(); | ||
/** | ||
* Notify we are about to initiate the app | ||
*/ | ||
await this.#hooks.runner('initiating').run(this); | ||
/** | ||
* Initiate essentials | ||
*/ | ||
await this.#rcFileManager.process(); | ||
this.#instantiateStubsManager(); | ||
/** | ||
* Cleanup registered hooks | ||
*/ | ||
this.#hooks.clear('initiating'); | ||
this.#state = 'initiated'; | ||
} | ||
/** | ||
* Register hooks that are called before the app boot | ||
* process starts | ||
*/ | ||
booting(handler) { | ||
@@ -197,2 +381,10 @@ this.#hooks.add('booting', handler); | ||
} | ||
/** | ||
* Boot the application. Calling this method performs the following | ||
* operations. | ||
* | ||
* - Resolve providers and call the "register" method on them. | ||
* - Call the "boot" method on providers | ||
* - Run the "booted" hooks | ||
*/ | ||
async boot() { | ||
@@ -204,9 +396,21 @@ if (this.#state !== 'initiated') { | ||
debug('booting app'); | ||
/** | ||
* Execute booting hooks | ||
*/ | ||
await this.#hooks.runner('booting').run(this); | ||
this.#hooks.clear('booting'); | ||
/** | ||
* Process node env and config files | ||
*/ | ||
this.#nodeEnvManager.process(); | ||
await this.#configManager.process(this.rcFile.directories.config); | ||
/** | ||
* Boot providers | ||
*/ | ||
this.#providersManager.use(this.rcFile.providers); | ||
await this.#providersManager.register(); | ||
await this.#providersManager.boot(); | ||
/** | ||
* Notify the app is booted | ||
*/ | ||
await this.#hooks.runner('booted').run(this); | ||
@@ -216,2 +420,9 @@ this.#hooks.clear('booted'); | ||
} | ||
/** | ||
* Register a hook to get notified when the application has | ||
* been booted. | ||
* | ||
* The hook will be called immediately if the app has already | ||
* been booted. | ||
*/ | ||
async booted(handler) { | ||
@@ -225,2 +436,5 @@ if (this.isBooted) { | ||
} | ||
/** | ||
* Register hooks that are called when the app is starting | ||
*/ | ||
starting(handler) { | ||
@@ -230,2 +444,11 @@ this.#hooks.add('starting', handler); | ||
} | ||
/** | ||
* Start the application. Calling this method performs the following | ||
* operations. | ||
* | ||
* - Run the "start" lifecycle hooks on all the providers | ||
* - Start the application by invoking the supplied callback | ||
* - Run the "ready" lifecycle hooks on all the providers | ||
* - Run the "ready" application hooks | ||
*/ | ||
async start(callback) { | ||
@@ -237,2 +460,5 @@ if (this.#state !== 'booted') { | ||
debug('starting app'); | ||
/** | ||
* Pre start phase | ||
*/ | ||
await this.#providersManager.start(); | ||
@@ -242,10 +468,26 @@ await this.#hooks.runner('starting').run(this); | ||
await this.#preloadsManager.use(this.rcFile.preloads).import(); | ||
/** | ||
* Callback to perform start of the application | ||
*/ | ||
await callback(this); | ||
/** | ||
* Post start phase | ||
*/ | ||
await this.#providersManager.ready(); | ||
await this.#hooks.runner('ready').run(this); | ||
this.#hooks.clear('ready'); | ||
/** | ||
* App ready | ||
*/ | ||
this.#state = 'ready'; | ||
/** | ||
* Notify process is ready | ||
*/ | ||
debug('application ready'); | ||
this.notify('ready'); | ||
} | ||
/** | ||
* Register hooks that are called when the app is | ||
* ready | ||
*/ | ||
async ready(handler) { | ||
@@ -259,2 +501,6 @@ if (this.isReady) { | ||
} | ||
/** | ||
* Register hooks that are called before the app is | ||
* terminated. | ||
*/ | ||
terminating(handler) { | ||
@@ -264,2 +510,9 @@ this.#hooks.add('terminating', handler); | ||
} | ||
/** | ||
* Terminate application gracefully. Calling this method performs | ||
* the following operations. | ||
* | ||
* - Run "shutdown" hooks on all the providers | ||
* - Run "terminating" app lifecycle hooks | ||
*/ | ||
async terminate() { | ||
@@ -277,83 +530,167 @@ if (!this.isBooted || this.#state === 'terminated') { | ||
} | ||
/** | ||
* Returns relative path to a file from the app root | ||
*/ | ||
relativePath(absolutePath) { | ||
return relative(fileURLToPath(this.appRoot), absolutePath); | ||
} | ||
/** | ||
* Returns URL to a path from the application root. | ||
*/ | ||
makeURL(...paths) { | ||
return new URL(join(...paths), this.#appRoot); | ||
} | ||
/** | ||
* Returns file system path from the application root. | ||
*/ | ||
makePath(...paths) { | ||
return fileURLToPath(this.makeURL(...paths)); | ||
} | ||
/** | ||
* Makes path to the config directory | ||
*/ | ||
configPath(...paths) { | ||
return this.makePath(this.rcFile.directories.config, ...paths); | ||
} | ||
/** | ||
* Makes path to the public directory | ||
*/ | ||
publicPath(...paths) { | ||
return this.makePath(this.rcFile.directories.public, ...paths); | ||
} | ||
/** | ||
* Makes path to the providers directory | ||
*/ | ||
providersPath(...paths) { | ||
return this.makePath(this.rcFile.directories.providers, ...paths); | ||
} | ||
/** | ||
* Makes path to the factories directory | ||
*/ | ||
factoriesPath(...paths) { | ||
return this.makePath(this.rcFile.directories.factories, ...paths); | ||
} | ||
/** | ||
* Makes path to the migrations directory | ||
*/ | ||
migrationsPath(...paths) { | ||
return this.makePath(this.rcFile.directories.migrations, ...paths); | ||
} | ||
/** | ||
* Makes path to the seeders directory | ||
*/ | ||
seedersPath(...paths) { | ||
return this.makePath(this.rcFile.directories.seeders, ...paths); | ||
} | ||
/** | ||
* Makes path to the language files directory | ||
*/ | ||
languageFilesPath(...paths) { | ||
return this.makePath(this.rcFile.directories.languageFiles, ...paths); | ||
} | ||
/** | ||
* Makes path to the views directory | ||
*/ | ||
viewsPath(...paths) { | ||
return this.makePath(this.rcFile.directories.views, ...paths); | ||
} | ||
/** | ||
* Makes path to the start directory | ||
*/ | ||
startPath(...paths) { | ||
return this.makePath(this.rcFile.directories.start, ...paths); | ||
} | ||
/** | ||
* Makes path to the tmp directory | ||
*/ | ||
tmpPath(...paths) { | ||
return this.makePath(this.rcFile.directories.tmp, ...paths); | ||
} | ||
/** | ||
* Makes path to the contracts directory | ||
*/ | ||
contractsPath(...paths) { | ||
return this.makePath(this.rcFile.directories.contracts, ...paths); | ||
} | ||
/** | ||
* Makes path to the http controllers directory | ||
*/ | ||
httpControllersPath(...paths) { | ||
return this.makePath(this.rcFile.directories.httpControllers, ...paths); | ||
} | ||
/** | ||
* Makes path to the models directory | ||
*/ | ||
modelsPath(...paths) { | ||
return this.makePath(this.rcFile.directories.models, ...paths); | ||
} | ||
/** | ||
* Makes path to the services directory | ||
*/ | ||
servicesPath(...paths) { | ||
return this.makePath(this.rcFile.directories.services, ...paths); | ||
} | ||
/** | ||
* Makes path to the exceptions directory | ||
*/ | ||
exceptionsPath(...paths) { | ||
return this.makePath(this.rcFile.directories.exceptions, ...paths); | ||
} | ||
/** | ||
* Makes path to the mailers directory | ||
*/ | ||
mailersPath(...paths) { | ||
return this.makePath(this.rcFile.directories.mailers, ...paths); | ||
} | ||
/** | ||
* Makes path to the middleware directory | ||
*/ | ||
middlewarePath(...paths) { | ||
return this.makePath(this.rcFile.directories.middleware, ...paths); | ||
} | ||
/** | ||
* Makes path to the policies directory | ||
*/ | ||
policiesPath(...paths) { | ||
return this.makePath(this.rcFile.directories.policies, ...paths); | ||
} | ||
/** | ||
* Makes path to the validators directory | ||
*/ | ||
validatorsPath(...paths) { | ||
return this.makePath(this.rcFile.directories.validators, ...paths); | ||
} | ||
/** | ||
* Makes path to the commands directory | ||
*/ | ||
commandsPath(...paths) { | ||
return this.makePath(this.rcFile.directories.commands, ...paths); | ||
} | ||
/** | ||
* Makes path to the events directory | ||
*/ | ||
eventsPath(...paths) { | ||
return this.makePath(this.rcFile.directories.events, ...paths); | ||
} | ||
/** | ||
* Makes path to the listeners directory | ||
*/ | ||
listenersPath(...paths) { | ||
return this.makePath(this.rcFile.directories.listeners, ...paths); | ||
} | ||
/** | ||
* Import a module by identifier | ||
*/ | ||
import(moduleIdentifier) { | ||
return this.#importer(moduleIdentifier); | ||
} | ||
/** | ||
* Import a module by identifier | ||
*/ | ||
importDefault(moduleIdentifier) { | ||
return importDefault(() => this.#importer(moduleIdentifier)); | ||
} | ||
/** | ||
* JSON representation of the application | ||
*/ | ||
toJSON() { | ||
@@ -360,0 +697,0 @@ return { |
@@ -1,4 +0,3 @@ | ||
/// <reference types="node" resolution-mode="require"/> | ||
/// <reference types="@types/node" resolution-mode="require"/> | ||
declare const _default: import("util").DebugLogger; | ||
export default _default; | ||
//# sourceMappingURL=debug.d.ts.map |
@@ -0,2 +1,10 @@ | ||
/* | ||
* @adonisjs/application | ||
* | ||
* (c) AdonisJS | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
import { debuglog } from 'node:util'; | ||
export default debuglog('adonisjs:app'); |
import type { DirectoriesNode } from './types.js'; | ||
/** | ||
* List of default directories | ||
*/ | ||
export declare const directories: DirectoriesNode; | ||
//# sourceMappingURL=directories.d.ts.map |
@@ -0,1 +1,12 @@ | ||
/* | ||
* @adonisjs/application | ||
* | ||
* (c) AdonisJS | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
/** | ||
* List of default directories | ||
*/ | ||
export const directories = { | ||
@@ -2,0 +13,0 @@ config: 'config', |
@@ -0,9 +1,40 @@ | ||
/** | ||
* The exception is raised when the "pattern" property is missing | ||
* in the meta file object. | ||
*/ | ||
export declare const E_MISSING_METAFILE_PATTERN: new (args: [fileProperty: string], options?: ErrorOptions | undefined) => import("@poppinss/utils").Exception; | ||
/** | ||
* The exception is raised when the "file" property is missing | ||
* in the preload file object | ||
*/ | ||
export declare const E_MISSING_PRELOAD_FILE: new (args: [preloadProperty: string], options?: ErrorOptions | undefined) => import("@poppinss/utils").Exception; | ||
/** | ||
* The exception is raised when the "file" property is missing | ||
* in the provider object | ||
*/ | ||
export declare const E_MISSING_PROVIDER_FILE: new (args: [preloadProperty: string], options?: ErrorOptions | undefined) => import("@poppinss/utils").Exception; | ||
/** | ||
* The exception is raised when the "name" property is missing | ||
* in the suite object | ||
*/ | ||
export declare const E_MISSING_SUITE_NAME: new (args: [suiteProperty: string], options?: ErrorOptions | undefined) => import("@poppinss/utils").Exception; | ||
/** | ||
* The exception is raised when the "files" property is missing | ||
* in the suite object | ||
*/ | ||
export declare const E_MISSING_SUITE_FILES: new (args: [suiteProperty: string], options?: ErrorOptions | undefined) => import("@poppinss/utils").Exception; | ||
/** | ||
* The exception is raised when the "devServerCommand" is missing | ||
* in assetsBundler object | ||
*/ | ||
export declare const E_MISSING_BUNDLER_DEV_COMMAND: new (args?: any, options?: ErrorOptions | undefined) => import("@poppinss/utils").Exception; | ||
/** | ||
* The exception is raised when the "buildCommand" is missing | ||
* in assetsBundler object | ||
*/ | ||
export declare const E_MISSING_BUNDLER_BUILD_COMMAND: new (args?: any, options?: ErrorOptions | undefined) => import("@poppinss/utils").Exception; | ||
/** | ||
* The exception is raised when the "name" is missing | ||
* in assetsBundler object | ||
*/ | ||
export declare const E_MISSING_BUNDLER_NAME: new (args?: any, options?: ErrorOptions | undefined) => import("@poppinss/utils").Exception; | ||
//# sourceMappingURL=exceptions.d.ts.map |
@@ -0,9 +1,49 @@ | ||
/* | ||
* @adonisjs/application | ||
* | ||
* (c) AdonisJS | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
import { createError } from '@poppinss/utils'; | ||
/** | ||
* The exception is raised when the "pattern" property is missing | ||
* in the meta file object. | ||
*/ | ||
export const E_MISSING_METAFILE_PATTERN = createError('Invalid metafile entry "%s". Missing pattern property', 'E_MISSING_METAFILE_PATTERN'); | ||
/** | ||
* The exception is raised when the "file" property is missing | ||
* in the preload file object | ||
*/ | ||
export const E_MISSING_PRELOAD_FILE = createError('Invalid preload entry "%s". Missing file property', 'E_MISSING_PRELOAD_FILE'); | ||
/** | ||
* The exception is raised when the "file" property is missing | ||
* in the provider object | ||
*/ | ||
export const E_MISSING_PROVIDER_FILE = createError('Invalid provider entry "%s". Missing file property', 'E_MISSING_PROVIDER_FILE'); | ||
/** | ||
* The exception is raised when the "name" property is missing | ||
* in the suite object | ||
*/ | ||
export const E_MISSING_SUITE_NAME = createError('Invalid suite entry "%s". Missing name property', 'E_MISSING_SUITE_NAME'); | ||
/** | ||
* The exception is raised when the "files" property is missing | ||
* in the suite object | ||
*/ | ||
export const E_MISSING_SUITE_FILES = createError('Invalid suite entry "%s". Missing files property', 'E_MISSING_SUITE_FILES'); | ||
export const E_MISSING_BUNDLER_DEV_COMMAND = createError('Invalid assetsBundler entry. Missing devServerCommand property', 'E_MISSING_BUNDLER_DEV_COMMAND'); | ||
export const E_MISSING_BUNDLER_BUILD_COMMAND = createError('Invalid assetsBundler entry. Missing buildCommand property', 'E_MISSING_BUNDLER_BUILD_COMMAND'); | ||
/** | ||
* The exception is raised when the "devServerCommand" is missing | ||
* in assetsBundler object | ||
*/ | ||
export const E_MISSING_BUNDLER_DEV_COMMAND = createError('Invalid assetsBundler entry. Missing devServer property', 'E_MISSING_BUNDLER_DEV_COMMAND'); | ||
/** | ||
* The exception is raised when the "buildCommand" is missing | ||
* in assetsBundler object | ||
*/ | ||
export const E_MISSING_BUNDLER_BUILD_COMMAND = createError('Invalid assetsBundler entry. Missing build property', 'E_MISSING_BUNDLER_BUILD_COMMAND'); | ||
/** | ||
* The exception is raised when the "name" is missing | ||
* in assetsBundler object | ||
*/ | ||
export const E_MISSING_BUNDLER_NAME = createError('Invalid assetsBundler entry. Missing name property', 'E_MISSING_BUNDLER_NAME'); |
@@ -0,3 +1,14 @@ | ||
/** | ||
* Generators used for scaffolding | ||
*/ | ||
declare const generators: { | ||
/** | ||
* The given controller names will always be generated | ||
* in singular form | ||
*/ | ||
singularControllerNames: string[]; | ||
/** | ||
* Creates the entity path and name from the user | ||
* input. | ||
*/ | ||
createEntity(entityName: string): { | ||
@@ -7,33 +18,129 @@ path: string; | ||
}; | ||
/** | ||
* Construct paths to make an import path | ||
*/ | ||
importPath(...paths: string[]): string; | ||
/** | ||
* Converts an entity name to database table name | ||
*/ | ||
tableName(entityName: string): string; | ||
/** | ||
* Converts an entity name to model name | ||
*/ | ||
modelName(entityName: string): string; | ||
/** | ||
* Converts an entity name to model file name | ||
*/ | ||
modelFileName(entityName: string): string; | ||
/** | ||
* Converts an entity name to a controller name | ||
*/ | ||
controllerName(entityName: string, singular?: boolean): string; | ||
/** | ||
* Converts an entity name to a controller file name | ||
*/ | ||
controllerFileName(entityName: string, singular?: boolean): string; | ||
/** | ||
* Converts an entity name to an event name | ||
*/ | ||
eventName(entityName: string): string; | ||
/** | ||
* Converts an entity name to an event file name | ||
*/ | ||
eventFileName(entityName: string): string; | ||
/** | ||
* Converts an entity name to listener name | ||
*/ | ||
listenerName(entityName: string): string; | ||
/** | ||
* Converts an entity name to listener file name | ||
*/ | ||
listenerFileName(entityName: string): string; | ||
/** | ||
* Converts an entity name to middleware name | ||
*/ | ||
middlewareName(entityName: string): string; | ||
/** | ||
* Converts an entity name to middleware file name | ||
*/ | ||
middlewareFileName(entityName: string): string; | ||
/** | ||
* Converts an entity name to provider name | ||
*/ | ||
providerName(entityName: string): string; | ||
/** | ||
* Converts an entity name to provider file name | ||
*/ | ||
providerFileName(entityName: string): string; | ||
/** | ||
* Converts an entity name to policy name | ||
*/ | ||
policyName(entityName: string): string; | ||
/** | ||
* Converts an entity name to policy file name | ||
*/ | ||
policyFileName(entityName: string): string; | ||
/** | ||
* Converts an entity name to factory name | ||
*/ | ||
factoryName(entityName: string): string; | ||
/** | ||
* Converts an entity name to factory file name | ||
*/ | ||
factoryFileName(entityName: string): string; | ||
/** | ||
* Converts an entity name to service name | ||
*/ | ||
serviceName(entityName: string): string; | ||
/** | ||
* Converts an entity name to service file name | ||
*/ | ||
serviceFileName(entityName: string): string; | ||
/** | ||
* Converts an entity name to seeder name | ||
*/ | ||
seederName(entityName: string): string; | ||
/** | ||
* Converts an entity name to seeder file name | ||
*/ | ||
seederFileName(entityName: string): string; | ||
/** | ||
* Converts an entity name to command terminal name | ||
*/ | ||
commandTerminalName(entityName: string): string; | ||
/** | ||
* Converts an entity name to command name | ||
*/ | ||
commandName(entityName: string): string; | ||
/** | ||
* Converts an entity name to command file name | ||
*/ | ||
commandFileName(entityName: string): string; | ||
/** | ||
* Converts an entity name to validator name | ||
*/ | ||
validatorName(entityName: string): string; | ||
/** | ||
* Converts an entity name to validator file name | ||
*/ | ||
validatorFileName(entityName: string): string; | ||
/** | ||
* Converts an entity name to exception name | ||
*/ | ||
exceptionName(entityName: string): string; | ||
/** | ||
* Converts an entity name to exception file name | ||
*/ | ||
exceptionFileName(entityName: string): string; | ||
/** | ||
* Converts an entity name to mailer name | ||
*/ | ||
mailerName(entityName: string, type?: 'notification' | 'provision'): string; | ||
/** | ||
* Converts an entity name to mailer file name | ||
*/ | ||
mailerFileName(entityName: string, type?: 'notification' | 'provision'): string; | ||
/** | ||
* Converts an entity to test group name | ||
*/ | ||
testGroupName(entity: { | ||
@@ -43,5 +150,7 @@ path: string; | ||
}): string; | ||
/** | ||
* Converts an entity name to test file name | ||
*/ | ||
testFileName(entityName: string): string; | ||
}; | ||
export default generators; | ||
//# sourceMappingURL=generators.d.ts.map |
@@ -0,1 +1,9 @@ | ||
/* | ||
* @adonisjs/application | ||
* | ||
* (c) AdonisJS | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
import { slash } from '@poppinss/utils'; | ||
@@ -5,3 +13,10 @@ import { extname, join } from 'node:path'; | ||
import StringBuilder from '@poppinss/utils/string_builder'; | ||
/** | ||
* Generators used for scaffolding | ||
*/ | ||
const generators = { | ||
/** | ||
* The given controller names will always be generated | ||
* in singular form | ||
*/ | ||
singularControllerNames: [ | ||
@@ -22,6 +37,22 @@ 'home', | ||
], | ||
/** | ||
* Creates the entity path and name from the user | ||
* input. | ||
*/ | ||
createEntity(entityName) { | ||
/** | ||
* Get rid of extensions | ||
*/ | ||
entityName = entityName.replace(new RegExp(`${extname(entityName)}$`), ''); | ||
/** | ||
* Split to see if we are dealing with a path | ||
*/ | ||
const parts = entityName.split('/'); | ||
/** | ||
* Last part is always the entity name | ||
*/ | ||
const [name] = parts.splice(-1); | ||
/** | ||
* Still have parts? Join them back | ||
*/ | ||
if (parts.length) { | ||
@@ -33,2 +64,5 @@ return { | ||
} | ||
/** | ||
* Use relative current dir | ||
*/ | ||
return { | ||
@@ -39,5 +73,11 @@ path: './', | ||
}, | ||
/** | ||
* Construct paths to make an import path | ||
*/ | ||
importPath(...paths) { | ||
return slash(join(...paths)); | ||
}, | ||
/** | ||
* Converts an entity name to database table name | ||
*/ | ||
tableName(entityName) { | ||
@@ -49,2 +89,5 @@ return new StringBuilder(this.modelName(new StringBuilder(entityName).removeSuffix('table').toString())) | ||
}, | ||
/** | ||
* Converts an entity name to model name | ||
*/ | ||
modelName(entityName) { | ||
@@ -58,5 +101,11 @@ return new StringBuilder(entityName) | ||
}, | ||
/** | ||
* Converts an entity name to model file name | ||
*/ | ||
modelFileName(entityName) { | ||
return new StringBuilder(this.modelName(entityName)).snakeCase().ext('.ts').toString(); | ||
}, | ||
/** | ||
* Converts an entity name to a controller name | ||
*/ | ||
controllerName(entityName, singular = false) { | ||
@@ -75,2 +124,5 @@ const controller = new StringBuilder(entityName).removeExtension().removeSuffix('controller'); | ||
}, | ||
/** | ||
* Converts an entity name to a controller file name | ||
*/ | ||
controllerFileName(entityName, singular = false) { | ||
@@ -82,2 +134,5 @@ return new StringBuilder(this.controllerName(entityName, singular)) | ||
}, | ||
/** | ||
* Converts an entity name to an event name | ||
*/ | ||
eventName(entityName) { | ||
@@ -90,5 +145,11 @@ return new StringBuilder(entityName) | ||
}, | ||
/** | ||
* Converts an entity name to an event file name | ||
*/ | ||
eventFileName(entityName) { | ||
return new StringBuilder(this.eventName(entityName)).snakeCase().ext('.ts').toString(); | ||
}, | ||
/** | ||
* Converts an entity name to listener name | ||
*/ | ||
listenerName(entityName) { | ||
@@ -101,5 +162,11 @@ return new StringBuilder(entityName) | ||
}, | ||
/** | ||
* Converts an entity name to listener file name | ||
*/ | ||
listenerFileName(entityName) { | ||
return new StringBuilder(this.listenerName(entityName)).snakeCase().ext('.ts').toString(); | ||
}, | ||
/** | ||
* Converts an entity name to middleware name | ||
*/ | ||
middlewareName(entityName) { | ||
@@ -113,5 +180,11 @@ return new StringBuilder(entityName) | ||
}, | ||
/** | ||
* Converts an entity name to middleware file name | ||
*/ | ||
middlewareFileName(entityName) { | ||
return new StringBuilder(this.middlewareName(entityName)).snakeCase().ext('.ts').toString(); | ||
}, | ||
/** | ||
* Converts an entity name to provider name | ||
*/ | ||
providerName(entityName) { | ||
@@ -126,5 +199,11 @@ return new StringBuilder(entityName) | ||
}, | ||
/** | ||
* Converts an entity name to provider file name | ||
*/ | ||
providerFileName(entityName) { | ||
return new StringBuilder(this.providerName(entityName)).snakeCase().ext('.ts').toString(); | ||
}, | ||
/** | ||
* Converts an entity name to policy name | ||
*/ | ||
policyName(entityName) { | ||
@@ -140,5 +219,11 @@ return new StringBuilder(entityName) | ||
}, | ||
/** | ||
* Converts an entity name to policy file name | ||
*/ | ||
policyFileName(entityName) { | ||
return new StringBuilder(this.policyName(entityName)).snakeCase().ext('.ts').toString(); | ||
}, | ||
/** | ||
* Converts an entity name to factory name | ||
*/ | ||
factoryName(entityName) { | ||
@@ -154,5 +239,11 @@ return new StringBuilder(entityName) | ||
}, | ||
/** | ||
* Converts an entity name to factory file name | ||
*/ | ||
factoryFileName(entityName) { | ||
return new StringBuilder(this.factoryName(entityName)).snakeCase().ext('.ts').toString(); | ||
}, | ||
/** | ||
* Converts an entity name to service name | ||
*/ | ||
serviceName(entityName) { | ||
@@ -168,5 +259,11 @@ return new StringBuilder(entityName) | ||
}, | ||
/** | ||
* Converts an entity name to service file name | ||
*/ | ||
serviceFileName(entityName) { | ||
return new StringBuilder(this.serviceName(entityName)).snakeCase().ext('.ts').toString(); | ||
}, | ||
/** | ||
* Converts an entity name to seeder name | ||
*/ | ||
seederName(entityName) { | ||
@@ -182,5 +279,11 @@ return new StringBuilder(entityName) | ||
}, | ||
/** | ||
* Converts an entity name to seeder file name | ||
*/ | ||
seederFileName(entityName) { | ||
return new StringBuilder(this.seederName(entityName)).snakeCase().ext('.ts').toString(); | ||
}, | ||
/** | ||
* Converts an entity name to command terminal name | ||
*/ | ||
commandTerminalName(entityName) { | ||
@@ -194,2 +297,5 @@ const snakeCaseName = new StringBuilder(this.commandName(entityName)).snakeCase().toString(); | ||
}, | ||
/** | ||
* Converts an entity name to command name | ||
*/ | ||
commandName(entityName) { | ||
@@ -202,5 +308,11 @@ return new StringBuilder(entityName) | ||
}, | ||
/** | ||
* Converts an entity name to command file name | ||
*/ | ||
commandFileName(entityName) { | ||
return new StringBuilder(this.commandName(entityName)).snakeCase().ext('.ts').toString(); | ||
}, | ||
/** | ||
* Converts an entity name to validator name | ||
*/ | ||
validatorName(entityName) { | ||
@@ -215,5 +327,11 @@ return new StringBuilder(entityName) | ||
}, | ||
/** | ||
* Converts an entity name to validator file name | ||
*/ | ||
validatorFileName(entityName) { | ||
return new StringBuilder(this.validatorName(entityName)).snakeCase().ext('.ts').toString(); | ||
}, | ||
/** | ||
* Converts an entity name to exception name | ||
*/ | ||
exceptionName(entityName) { | ||
@@ -227,5 +345,11 @@ return new StringBuilder(entityName) | ||
}, | ||
/** | ||
* Converts an entity name to exception file name | ||
*/ | ||
exceptionFileName(entityName) { | ||
return new StringBuilder(this.exceptionName(entityName)).snakeCase().ext('.ts').toString(); | ||
}, | ||
/** | ||
* Converts an entity name to mailer name | ||
*/ | ||
mailerName(entityName, type = 'notification') { | ||
@@ -241,5 +365,11 @@ return new StringBuilder(entityName) | ||
}, | ||
/** | ||
* Converts an entity name to mailer file name | ||
*/ | ||
mailerFileName(entityName, type = 'notification') { | ||
return new StringBuilder(this.mailerName(entityName, type)).snakeCase().ext('.ts').toString(); | ||
}, | ||
/** | ||
* Converts an entity to test group name | ||
*/ | ||
testGroupName(entity) { | ||
@@ -252,2 +382,5 @@ return new StringBuilder(`${entity.path}/${entity.name}`) | ||
}, | ||
/** | ||
* Converts an entity name to test file name | ||
*/ | ||
testFileName(entityName) { | ||
@@ -254,0 +387,0 @@ return new StringBuilder(entityName) |
@@ -1,4 +0,9 @@ | ||
/// <reference types="node" resolution-mode="require"/> | ||
/// <reference types="node" resolution-mode="require"/> | ||
/// <reference types="@types/node" resolution-mode="require"/> | ||
/// <reference types="@types/node" resolution-mode="require"/> | ||
import type { PathLike } from 'node:fs'; | ||
/** | ||
* Attempts to read a file from multiple sources and returns the contents | ||
* of the first matching one. `null` is returned when file does not | ||
* exist in any of the sources. | ||
*/ | ||
export declare function readFileFromSources(fileName: string, sources: string[]): Promise<{ | ||
@@ -10,4 +15,9 @@ contents: string; | ||
} | null>; | ||
/** | ||
* Optionally read the contents of a file | ||
*/ | ||
export declare function readFileOptional(filePath: URL | string): Promise<string | null>; | ||
/** | ||
* Check if a file for the given path exists | ||
*/ | ||
export declare function pathExists(path: PathLike): Promise<boolean>; | ||
//# sourceMappingURL=helpers.d.ts.map |
@@ -0,3 +1,16 @@ | ||
/* | ||
* @adonisjs/application | ||
* | ||
* (c) AdonisJS | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
import { join } from 'node:path'; | ||
import { access, readFile } from 'node:fs/promises'; | ||
/** | ||
* Attempts to read a file from multiple sources and returns the contents | ||
* of the first matching one. `null` is returned when file does not | ||
* exist in any of the sources. | ||
*/ | ||
export async function readFileFromSources(fileName, sources) { | ||
@@ -18,2 +31,5 @@ for (let source of sources) { | ||
} | ||
/** | ||
* Optionally read the contents of a file | ||
*/ | ||
export async function readFileOptional(filePath) { | ||
@@ -24,2 +40,3 @@ try { | ||
catch (error) { | ||
/* c8 ignore next 3 */ | ||
if (error.code !== 'ENOENT') { | ||
@@ -31,2 +48,5 @@ throw error; | ||
} | ||
/** | ||
* Check if a file for the given path exists | ||
*/ | ||
export async function pathExists(path) { | ||
@@ -33,0 +53,0 @@ try { |
@@ -1,10 +0,25 @@ | ||
/// <reference types="node" resolution-mode="require"/> | ||
/// <reference types="@types/node" resolution-mode="require"/> | ||
import { Config } from '@adonisjs/config'; | ||
/** | ||
* Env manager is used to load, parse, validate and set environment | ||
* variables. | ||
*/ | ||
export declare class ConfigManager { | ||
#private; | ||
/** | ||
* Reference to the config class. The value is defined | ||
* after the "init" method call | ||
*/ | ||
config: Config; | ||
constructor(appRoot: URL); | ||
/** | ||
* Define the config values to use when booting the | ||
* config provider. Calling this method disables | ||
* reading files from the config directory. | ||
*/ | ||
useConfig(values: Record<any, any>): this; | ||
/** | ||
* Process config values. | ||
*/ | ||
process(configDirectory: string): Promise<void>; | ||
} | ||
//# sourceMappingURL=config.d.ts.map |
@@ -0,6 +1,25 @@ | ||
/* | ||
* @adonisjs/application | ||
* | ||
* (c) AdonisJS | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
import { Config, ConfigLoader } from '@adonisjs/config'; | ||
import debug from '../debug.js'; | ||
/** | ||
* Env manager is used to load, parse, validate and set environment | ||
* variables. | ||
*/ | ||
export class ConfigManager { | ||
#appRoot; | ||
/** | ||
* Config tree set explicitly | ||
*/ | ||
#configValues; | ||
/** | ||
* Reference to the config class. The value is defined | ||
* after the "init" method call | ||
*/ | ||
config; | ||
@@ -10,2 +29,7 @@ constructor(appRoot) { | ||
} | ||
/** | ||
* Define the config values to use when booting the | ||
* config provider. Calling this method disables | ||
* reading files from the config directory. | ||
*/ | ||
useConfig(values) { | ||
@@ -15,2 +39,5 @@ this.#configValues = values; | ||
} | ||
/** | ||
* Process config values. | ||
*/ | ||
async process(configDirectory) { | ||
@@ -17,0 +44,0 @@ if (this.#configValues) { |
@@ -0,6 +1,16 @@ | ||
/** | ||
* NodeEnvManager is used to extract a normalized node environment by | ||
* inspect the "process.env.NODE_ENV". | ||
* | ||
* - The "test" and "testing" envs are normalized to "test" | ||
* - The "prod" and "production" envs are normalized to "production" | ||
* - The "dev", "develop", and "development" envs are normalized to "development" | ||
*/ | ||
export declare class NodeEnvManager { | ||
#private; | ||
nodeEnvironment: 'unknown' | 'development' | 'production' | 'test' | string; | ||
/** | ||
* Capture the current node env | ||
*/ | ||
process(): void; | ||
} | ||
//# sourceMappingURL=node_env.d.ts.map |
@@ -0,6 +1,28 @@ | ||
/* | ||
* @adonisjs/application | ||
* | ||
* (c) AdonisJS | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
/** | ||
* Aliases for different environments | ||
*/ | ||
const TEST_ENVS = ['test', 'testing']; | ||
const PROD_ENVS = ['prod', 'production']; | ||
const DEV_ENVS = ['dev', 'develop', 'development']; | ||
/** | ||
* NodeEnvManager is used to extract a normalized node environment by | ||
* inspect the "process.env.NODE_ENV". | ||
* | ||
* - The "test" and "testing" envs are normalized to "test" | ||
* - The "prod" and "production" envs are normalized to "production" | ||
* - The "dev", "develop", and "development" envs are normalized to "development" | ||
*/ | ||
export class NodeEnvManager { | ||
nodeEnvironment = 'unknown'; | ||
/** | ||
* Normalizes node env | ||
*/ | ||
#normalizeNodeEnv(env) { | ||
@@ -22,2 +44,5 @@ if (!env || typeof env !== 'string') { | ||
} | ||
/** | ||
* Capture the current node env | ||
*/ | ||
process() { | ||
@@ -24,0 +49,0 @@ this.nodeEnvironment = this.#normalizeNodeEnv(process.env.NODE_ENV); |
import type { AppEnvironments, Importer, PreloadNode } from '../types.js'; | ||
/** | ||
* The PreloadsManager class is used to resolve and import preload modules. | ||
* | ||
* The class relies on "import.meta.resolve" to resolve the provider modules from | ||
* the root of the application. | ||
*/ | ||
export declare class PreloadsManager { | ||
@@ -7,5 +13,10 @@ #private; | ||
}); | ||
/** | ||
* Pass an array of preload modules to import | ||
*/ | ||
use(list: PreloadNode[]): this; | ||
/** | ||
* Import preload files | ||
*/ | ||
import(): Promise<void>; | ||
} | ||
//# sourceMappingURL=preloads.d.ts.map |
@@ -0,5 +1,28 @@ | ||
/* | ||
* @adonisjs/application | ||
* | ||
* (c) AdonisJS | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
import debug from '../debug.js'; | ||
/** | ||
* The PreloadsManager class is used to resolve and import preload modules. | ||
* | ||
* The class relies on "import.meta.resolve" to resolve the provider modules from | ||
* the root of the application. | ||
*/ | ||
export class PreloadsManager { | ||
/** | ||
* List of registered preloads | ||
*/ | ||
#list = []; | ||
/** | ||
* The application root path | ||
*/ | ||
#importer; | ||
/** | ||
* The options accepted by the manager. | ||
*/ | ||
#options; | ||
@@ -10,2 +33,5 @@ constructor(importer, options) { | ||
} | ||
/** | ||
* Filters the preload modules by the current environment. | ||
*/ | ||
#filterByEnvironment(provider) { | ||
@@ -17,5 +43,13 @@ if (this.#options.environment === 'unknown') { | ||
} | ||
/** | ||
* Imports a preload module from the registered path. The method relies | ||
* on "--experimental-import-meta-resolve" flag to resolve paths from | ||
* the app root. | ||
*/ | ||
#importPreloadModule(preload) { | ||
return this.#importer(preload.file); | ||
} | ||
/** | ||
* Pass an array of preload modules to import | ||
*/ | ||
use(list) { | ||
@@ -25,2 +59,5 @@ this.#list = list; | ||
} | ||
/** | ||
* Import preload files | ||
*/ | ||
async import() { | ||
@@ -27,0 +64,0 @@ const preloads = this.#list.filter((preload) => this.#filterByEnvironment(preload)); |
import type { Importer, ProviderNode, AppEnvironments } from '../types.js'; | ||
/** | ||
* The ProvidersManager class is used to resolve, import and execute lifecycle | ||
* methods on registered providers. | ||
* | ||
* The class relies on "import.meta.resolve" to resolve the provider modules from | ||
* the root of the application. | ||
* | ||
* Also, a single instance of the provider is used to executed all the hooks. | ||
*/ | ||
export declare class ProvidersManager { | ||
@@ -8,9 +17,27 @@ #private; | ||
}); | ||
/** | ||
* Pass an array of providers to use | ||
*/ | ||
use(list: ProviderNode[]): this; | ||
/** | ||
* Invoke register method on the providers. | ||
*/ | ||
register(): Promise<void>; | ||
/** | ||
* Invoke boot method on the providers. The existing providers | ||
* instances are used. | ||
*/ | ||
boot(): Promise<void>; | ||
/** | ||
* Invoke start method on all the providers | ||
*/ | ||
start(): Promise<void>; | ||
/** | ||
* Invoke ready method on all the providers | ||
*/ | ||
ready(): Promise<void>; | ||
/** | ||
* Invoke shutdown method on all the providers | ||
*/ | ||
shutdown(): Promise<void>; | ||
} | ||
//# sourceMappingURL=providers.d.ts.map |
@@ -0,8 +1,42 @@ | ||
/* | ||
* @adonisjs/application | ||
* | ||
* (c) AdonisJS | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
import { importDefault, RuntimeException } from '@poppinss/utils'; | ||
import debug from '../debug.js'; | ||
/** | ||
* The ProvidersManager class is used to resolve, import and execute lifecycle | ||
* methods on registered providers. | ||
* | ||
* The class relies on "import.meta.resolve" to resolve the provider modules from | ||
* the root of the application. | ||
* | ||
* Also, a single instance of the provider is used to executed all the hooks. | ||
*/ | ||
export class ProvidersManager { | ||
/** | ||
* An array of collected providers | ||
*/ | ||
#providers = []; | ||
/** | ||
* An array of providers with the `shutdown` method. We release the | ||
* values from the providers array and only keep the once with | ||
* shutdown method | ||
*/ | ||
#providersWithShutdownListeners = []; | ||
/** | ||
* An array of providers modules | ||
*/ | ||
#list = []; | ||
/** | ||
* The application root path | ||
*/ | ||
#importer; | ||
/** | ||
* The options accepted by the manager | ||
*/ | ||
#options; | ||
@@ -13,2 +47,5 @@ constructor(importer, options) { | ||
} | ||
/** | ||
* Filters the providers by the current environment. | ||
*/ | ||
#filterByEnvironment(provider) { | ||
@@ -20,2 +57,5 @@ if (this.#options.environment === 'unknown') { | ||
} | ||
/** | ||
* Ensure the value is a valid ES class | ||
*/ | ||
#ensureIsClass(providerPath, providerClass) { | ||
@@ -26,5 +66,13 @@ if (typeof providerClass !== 'function' || !providerClass.toString().startsWith('class ')) { | ||
} | ||
/** | ||
* Resolves a provider module path and imports it | ||
*/ | ||
async #importProvider(providerPath) { | ||
return importDefault(() => this.#importer(providerPath), providerPath); | ||
} | ||
/** | ||
* Imports all providers from the registered module path. The method relies | ||
* on --experimental-import-meta-resolve flag to resolve paths from | ||
* the app root. | ||
*/ | ||
async #resolveProvider(provider) { | ||
@@ -35,2 +83,5 @@ const providerClass = await this.#importProvider(provider.file); | ||
} | ||
/** | ||
* Resolves all providers from the supplied list of module paths. | ||
*/ | ||
#resolve() { | ||
@@ -41,2 +92,5 @@ const providers = this.#list.filter((provider) => this.#filterByEnvironment(provider)); | ||
} | ||
/** | ||
* Pass an array of providers to use | ||
*/ | ||
use(list) { | ||
@@ -46,2 +100,5 @@ this.#list = list; | ||
} | ||
/** | ||
* Invoke register method on the providers. | ||
*/ | ||
async register() { | ||
@@ -61,2 +118,6 @@ const providers = await this.#resolve(); | ||
} | ||
/** | ||
* Invoke boot method on the providers. The existing providers | ||
* instances are used. | ||
*/ | ||
async boot() { | ||
@@ -69,2 +130,5 @@ for (let provider of this.#providers) { | ||
} | ||
/** | ||
* Invoke start method on all the providers | ||
*/ | ||
async start() { | ||
@@ -77,2 +141,5 @@ for (let provider of this.#providers) { | ||
} | ||
/** | ||
* Invoke ready method on all the providers | ||
*/ | ||
async ready() { | ||
@@ -86,2 +153,5 @@ for (let provider of this.#providers) { | ||
} | ||
/** | ||
* Invoke shutdown method on all the providers | ||
*/ | ||
async shutdown() { | ||
@@ -88,0 +158,0 @@ for (let provider of this.#providersWithShutdownListeners) { |
@@ -1,12 +0,31 @@ | ||
/// <reference types="node" resolution-mode="require"/> | ||
/// <reference types="@types/node" resolution-mode="require"/> | ||
import type { RcFile } from '../types.js'; | ||
import { RcFileEditor } from '../rc_file/editor.js'; | ||
/** | ||
* RcFileManager is used to process the raw contents or the contents | ||
* of ".adonisrc.json" file. | ||
*/ | ||
export declare class RcFileManager { | ||
#private; | ||
/** | ||
* Reference to the parsed rc file. The value is defined | ||
* after the "init" method call | ||
*/ | ||
rcFile: RcFile; | ||
/** | ||
* Reference to the RC file editor. The value is defined | ||
* after the "init" method call | ||
*/ | ||
rcFileEditor: RcFileEditor; | ||
constructor(appRoot: URL); | ||
/** | ||
* Specify the contents of the ".adonisrc.json" file as | ||
* an object. Calling this method will disable loading | ||
* the ".adonisrc.json" file from the disk. | ||
*/ | ||
rcContents(value: Record<string, any>): this; | ||
/** | ||
* Process the contents for the rcFile | ||
*/ | ||
process(): Promise<void>; | ||
} | ||
//# sourceMappingURL=rc_file.d.ts.map |
@@ -0,1 +1,9 @@ | ||
/* | ||
* @adonisjs/application | ||
* | ||
* (c) AdonisJS | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
import debug from '../debug.js'; | ||
@@ -5,6 +13,21 @@ import { readFileOptional } from '../helpers.js'; | ||
import { RcFileEditor } from '../rc_file/editor.js'; | ||
/** | ||
* RcFileManager is used to process the raw contents or the contents | ||
* of ".adonisrc.json" file. | ||
*/ | ||
export class RcFileManager { | ||
#appRoot; | ||
/** | ||
* RcFile contents set explicitly | ||
*/ | ||
#rcContents; | ||
/** | ||
* Reference to the parsed rc file. The value is defined | ||
* after the "init" method call | ||
*/ | ||
rcFile; | ||
/** | ||
* Reference to the RC file editor. The value is defined | ||
* after the "init" method call | ||
*/ | ||
rcFileEditor; | ||
@@ -14,2 +37,7 @@ constructor(appRoot) { | ||
} | ||
/** | ||
* Specify the contents of the ".adonisrc.json" file as | ||
* an object. Calling this method will disable loading | ||
* the ".adonisrc.json" file from the disk. | ||
*/ | ||
rcContents(value) { | ||
@@ -19,2 +47,5 @@ this.#rcContents = value; | ||
} | ||
/** | ||
* Process the contents for the rcFile | ||
*/ | ||
async process() { | ||
@@ -21,0 +52,0 @@ const rcFilePath = new URL('.adonisrc.json', this.#appRoot); |
@@ -1,16 +0,43 @@ | ||
/// <reference types="node" resolution-mode="require"/> | ||
/// <reference types="@types/node" resolution-mode="require"/> | ||
import type { PreloadNode, ProviderNode, RcFile } from '../types.js'; | ||
/** | ||
* The RcFile editor class exposes the API to edit and save the ".adonisrc.json" | ||
* file. The formatting and whitespaces are not retained during the edit. | ||
*/ | ||
export declare class RcFileEditor { | ||
#private; | ||
constructor(filePath: URL, rcFile: Record<string, any>); | ||
/** | ||
* Add command to rcFile | ||
*/ | ||
addCommand(commandPath: string): this; | ||
/** | ||
* Add provider to rcFile | ||
*/ | ||
addProvider(providerPath: string, environments?: ProviderNode['environment']): this; | ||
/** | ||
* Add preload file to rcFile | ||
*/ | ||
addPreloadFile(modulePath: string, environments?: PreloadNode['environment']): this; | ||
/** | ||
* Add meta file to rcFile | ||
*/ | ||
addMetaFile(globPattern: string, reloadServer?: boolean): this; | ||
/** | ||
* Set directory name and path | ||
*/ | ||
setDirectory(key: string, value: string): this; | ||
/** | ||
* Set command alias | ||
*/ | ||
setCommandAlias(alias: string, command: string): this; | ||
/** | ||
* Add a new tests suite to the rcFile | ||
*/ | ||
addSuite(suiteName: string, files: string | string[], timeout?: number): this; | ||
toJSON(): Partial<RcFile>; | ||
/** | ||
* Writes updated rcFile to the disk | ||
*/ | ||
save(): Promise<void>; | ||
} | ||
//# sourceMappingURL=editor.d.ts.map |
@@ -0,1 +1,9 @@ | ||
/* | ||
* @adonisjs/application | ||
* | ||
* (c) AdonisJS | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
import { dirname } from 'node:path'; | ||
@@ -5,2 +13,6 @@ import { fileURLToPath } from 'node:url'; | ||
import { mkdir, writeFile } from 'node:fs/promises'; | ||
/** | ||
* The RcFile editor class exposes the API to edit and save the ".adonisrc.json" | ||
* file. The formatting and whitespaces are not retained during the edit. | ||
*/ | ||
export class RcFileEditor { | ||
@@ -13,2 +25,5 @@ #rcFile; | ||
} | ||
/** | ||
* Check if environments array has a subset of available environments | ||
*/ | ||
#isInSpecificEnvironment(environments) { | ||
@@ -20,2 +35,5 @@ if (!environments) { | ||
} | ||
/** | ||
* Add command to rcFile | ||
*/ | ||
addCommand(commandPath) { | ||
@@ -30,2 +48,5 @@ this.#rcFile.commands = this.#rcFile.commands || []; | ||
} | ||
/** | ||
* Add provider to rcFile | ||
*/ | ||
addProvider(providerPath, environments) { | ||
@@ -50,2 +71,5 @@ this.#rcFile.providers = this.#rcFile.providers || []; | ||
} | ||
/** | ||
* Add preload file to rcFile | ||
*/ | ||
addPreloadFile(modulePath, environments) { | ||
@@ -70,2 +94,5 @@ this.#rcFile.preloads = this.#rcFile.preloads || []; | ||
} | ||
/** | ||
* Add meta file to rcFile | ||
*/ | ||
addMetaFile(globPattern, reloadServer = false) { | ||
@@ -83,2 +110,5 @@ this.#rcFile.metaFiles = this.#rcFile.metaFiles || []; | ||
} | ||
/** | ||
* Set directory name and path | ||
*/ | ||
setDirectory(key, value) { | ||
@@ -88,2 +118,5 @@ lodash.set(this.#rcFile, `directories.${key}`, value); | ||
} | ||
/** | ||
* Set command alias | ||
*/ | ||
setCommandAlias(alias, command) { | ||
@@ -93,2 +126,5 @@ lodash.set(this.#rcFile, `commandAliases.${alias}`, command); | ||
} | ||
/** | ||
* Add a new tests suite to the rcFile | ||
*/ | ||
addSuite(suiteName, files, timeout) { | ||
@@ -110,2 +146,5 @@ this.#rcFile.tests = this.#rcFile.tests || { suites: [], forceExit: true, timeout: 2000 }; | ||
} | ||
/** | ||
* Writes updated rcFile to the disk | ||
*/ | ||
async save() { | ||
@@ -112,0 +151,0 @@ const filePath = fileURLToPath(this.#filePath); |
import type { RcFile } from '../types.js'; | ||
/** | ||
* Rc file parser is used to parse and validate the `.adonisrc.json` file contents. | ||
*/ | ||
export declare class RcFileParser { | ||
#private; | ||
constructor(rcFile: Record<string, any>); | ||
/** | ||
* Parse and validate file contents and merge them with defaults | ||
*/ | ||
parse(): RcFile; | ||
} | ||
//# sourceMappingURL=parser.d.ts.map |
@@ -0,1 +1,9 @@ | ||
/* | ||
* @adonisjs/application | ||
* | ||
* (c) AdonisJS | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
import { inspect } from 'node:util'; | ||
@@ -5,3 +13,10 @@ import globParent from 'glob-parent'; | ||
import { directories } from '../directories.js'; | ||
/** | ||
* Rc file parser is used to parse and validate the `.adonisrc.json` file contents. | ||
*/ | ||
export class RcFileParser { | ||
/** | ||
* Defaults for the RcFile. This object initiates all | ||
* the known properties | ||
*/ | ||
#defaults = { | ||
@@ -22,2 +37,5 @@ typescript: true, | ||
}; | ||
/** | ||
* RcFile merged with defaults | ||
*/ | ||
#rcFile; | ||
@@ -28,5 +46,11 @@ constructor(rcFile) { | ||
} | ||
/** | ||
* An array of known environments | ||
*/ | ||
#knownEnvironments() { | ||
return ['web', 'console', 'test', 'repl']; | ||
} | ||
/** | ||
* Returns the assets bundler object | ||
*/ | ||
#getAssetsBundler() { | ||
@@ -39,6 +63,6 @@ if (!this.#rcFile.assetsBundler) { | ||
} | ||
if (!this.#rcFile.assetsBundler.devServerCommand) { | ||
if (!this.#rcFile.assetsBundler.devServer) { | ||
throw new errors.E_MISSING_BUNDLER_DEV_COMMAND(); | ||
} | ||
if (!this.#rcFile.assetsBundler.buildCommand) { | ||
if (!this.#rcFile.assetsBundler.build) { | ||
throw new errors.E_MISSING_BUNDLER_BUILD_COMMAND(); | ||
@@ -48,6 +72,9 @@ } | ||
name: this.#rcFile.assetsBundler.name, | ||
devServerCommand: this.#rcFile.assetsBundler.devServerCommand, | ||
buildCommand: this.#rcFile.assetsBundler.buildCommand, | ||
devServer: this.#rcFile.assetsBundler.devServer, | ||
build: this.#rcFile.assetsBundler.build, | ||
}; | ||
} | ||
/** | ||
* Returns a normalized array of preload files | ||
*/ | ||
#getPreloads() { | ||
@@ -71,2 +98,5 @@ return this.#rcFile.preloads.map((preload) => { | ||
} | ||
/** | ||
* Returns a normalized array of providers | ||
*/ | ||
#getProviders() { | ||
@@ -89,2 +119,5 @@ return this.#rcFile.providers.map((provider) => { | ||
} | ||
/** | ||
* Returns a nornalized array of meta files | ||
*/ | ||
#getMetaFiles() { | ||
@@ -107,2 +140,5 @@ return this.#rcFile.metaFiles.map((pattern) => { | ||
} | ||
/** | ||
* Returns a normalized array of test suites | ||
*/ | ||
#getSuites() { | ||
@@ -126,2 +162,5 @@ const suites = this.#rcFile.tests.suites || []; | ||
} | ||
/** | ||
* Parse and validate file contents and merge them with defaults | ||
*/ | ||
parse() { | ||
@@ -128,0 +167,0 @@ const assetsBundler = this.#getAssetsBundler(); |
import { Stub } from './stub.js'; | ||
import { Application } from '../application.js'; | ||
/** | ||
* Stub Manager is used to read and copy stubs from different sources. Also | ||
* allows creating resources from pre-existing stubs | ||
*/ | ||
export declare class StubsManager { | ||
#private; | ||
constructor(app: Application<any>, publishTarget: string); | ||
/** | ||
* Creates an instance of stub by its name. The lookup is performed inside | ||
* the publishTarget and the optional source or pkg destination. | ||
*/ | ||
build(stubName: string, options?: { | ||
@@ -10,2 +18,6 @@ source?: string; | ||
}): Promise<Stub>; | ||
/** | ||
* Copy one or more stub files from a custom location to publish | ||
* target. | ||
*/ | ||
copy(stubPath: string, options: { | ||
@@ -19,2 +31,1 @@ overwrite?: boolean; | ||
} | ||
//# sourceMappingURL=manager.d.ts.map |
@@ -0,1 +1,9 @@ | ||
/* | ||
* @adonisjs/application | ||
* | ||
* (c) AdonisJS | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
import { join } from 'node:path'; | ||
@@ -7,4 +15,12 @@ import { cp } from 'node:fs/promises'; | ||
import { readFileFromSources } from '../helpers.js'; | ||
/** | ||
* Stub Manager is used to read and copy stubs from different sources. Also | ||
* allows creating resources from pre-existing stubs | ||
*/ | ||
export class StubsManager { | ||
#app; | ||
/** | ||
* Absolute path to the directory where stubs should | ||
* be published or read from with priority | ||
*/ | ||
#publishTarget; | ||
@@ -15,2 +31,5 @@ constructor(app, publishTarget) { | ||
} | ||
/** | ||
* Returns the path to the stubs source directory of a package | ||
*/ | ||
async #getPackageSource(packageName) { | ||
@@ -23,7 +42,17 @@ const pkgMainExports = await this.#app.import(packageName); | ||
} | ||
/** | ||
* Creates an instance of stub by its name. The lookup is performed inside | ||
* the publishTarget and the optional source or pkg destination. | ||
*/ | ||
async build(stubName, options) { | ||
const sources = [this.#publishTarget]; | ||
/** | ||
* Push custom source (if defined) | ||
*/ | ||
if (options?.source) { | ||
sources.push(options.source); | ||
} | ||
/** | ||
* Push pkg source (if defined) | ||
*/ | ||
if (options?.pkg) { | ||
@@ -33,2 +62,5 @@ sources.push(await this.#getPackageSource(options.pkg)); | ||
debug('finding stub "%s" in sources "%O"', stubName, sources); | ||
/** | ||
* Attempt to read file from one of the available sources | ||
*/ | ||
const file = await readFileFromSources(stubName, sources); | ||
@@ -43,2 +75,6 @@ if (!file) { | ||
} | ||
/** | ||
* Copy one or more stub files from a custom location to publish | ||
* target. | ||
*/ | ||
async copy(stubPath, options) { | ||
@@ -50,2 +86,5 @@ const filesCopied = []; | ||
}; | ||
/** | ||
* Getting the source absolute path | ||
*/ | ||
const source = 'source' in options | ||
@@ -59,2 +98,5 @@ ? join(options.source, stubPath) | ||
debug('preparing to copy stubs "%s"', files); | ||
/** | ||
* Copy all files one by one and maintain the files structure | ||
*/ | ||
for (let filePath of files) { | ||
@@ -61,0 +103,0 @@ const sourcePath = join(source, filePath); |
import type { Application } from '../application.js'; | ||
/** | ||
* The stub class uses tempura template engine to process | ||
* a stub template and generate a resource file. | ||
* | ||
* Finding the correct stub to use is outside of the scope | ||
* of this class. | ||
*/ | ||
export declare class Stub { | ||
#private; | ||
constructor(app: Application<any>, stubContents: string, stubPath: string); | ||
/** | ||
* Prepare stub to be written to the disk | ||
*/ | ||
prepare(stubData: Record<string, any>): Promise<{ | ||
@@ -11,2 +21,5 @@ contents: any; | ||
}>; | ||
/** | ||
* Generate resource for the stub. Writes file to the disk | ||
*/ | ||
generate(stubData: Record<string, any>): Promise<{ | ||
@@ -32,2 +45,1 @@ contents: any; | ||
} | ||
//# sourceMappingURL=stub.d.ts.map |
@@ -0,1 +1,10 @@ | ||
/* | ||
* @adonisjs/application | ||
* | ||
* (c) AdonisJS | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
// @ts-expect-error | ||
import * as tempura from 'tempura'; | ||
@@ -10,5 +19,22 @@ import string from '@poppinss/utils/string'; | ||
import { pathExists } from '../helpers.js'; | ||
/** | ||
* The stub class uses tempura template engine to process | ||
* a stub template and generate a resource file. | ||
* | ||
* Finding the correct stub to use is outside of the scope | ||
* of this class. | ||
*/ | ||
export class Stub { | ||
/** | ||
* The absolute path to the stub file. Need it for reporting | ||
* errors | ||
*/ | ||
#stubPath; | ||
/** | ||
* The contents of the stub to process | ||
*/ | ||
#stubContents; | ||
/** | ||
* Application class reference | ||
*/ | ||
#app; | ||
@@ -20,2 +46,5 @@ constructor(app, stubContents, stubPath) { | ||
} | ||
/** | ||
* Patch error stack and point it to the stub file | ||
*/ | ||
#patchErrorStack(error) { | ||
@@ -26,4 +55,11 @@ const stack = error.stack.split('\n'); | ||
} | ||
/** | ||
* Patch tempura error stack and point it to the stub file | ||
*/ | ||
#patchTempuraStack(error) { | ||
const stack = error.stack.split('\n'); | ||
/** | ||
* Check if there is an error in the template processing, then | ||
* pick the exact line number from the reported error | ||
*/ | ||
const templateErrorLine = stack[1].match(/<anonymous>:(\d+):\d+\)$/); | ||
@@ -38,2 +74,5 @@ if (!templateErrorLine) { | ||
} | ||
/** | ||
* Validates the "to" attribute | ||
*/ | ||
#validateToAttribute(attributes) { | ||
@@ -51,2 +90,5 @@ if (!attributes.to) { | ||
} | ||
/** | ||
* Returns the default state for the stub | ||
*/ | ||
#getStubDefaults() { | ||
@@ -60,2 +102,5 @@ return { | ||
} | ||
/** | ||
* Renders stub using tempura templating syntax. | ||
*/ | ||
async #renderStub(data) { | ||
@@ -73,3 +118,7 @@ try { | ||
} | ||
/** | ||
* Parsers the front-matter stub | ||
*/ | ||
#parseFrontMatter(stubOutput) { | ||
// @ts-expect-error (the typings of the package are messedup) | ||
const { attributes, body } = fm(stubOutput); | ||
@@ -79,2 +128,5 @@ this.#validateToAttribute(attributes); | ||
} | ||
/** | ||
* Prepare stub to be written to the disk | ||
*/ | ||
async prepare(stubData) { | ||
@@ -95,2 +147,5 @@ const data = { | ||
} | ||
/** | ||
* Generate resource for the stub. Writes file to the disk | ||
*/ | ||
async generate(stubData) { | ||
@@ -110,2 +165,5 @@ const { force, ...stub } = await this.prepare(stubData); | ||
} | ||
/** | ||
* Overwrite file because force flag is enabled | ||
*/ | ||
if (hasFile && force) { | ||
@@ -112,0 +170,0 @@ debug('overwriting file to %s', stub.destination); |
import type { Application } from './application.js'; | ||
/** | ||
* Known application environments. The list is strictly limited to | ||
* AdonisJS known environments and custom environments are not | ||
* supported as of now | ||
*/ | ||
export type AppEnvironments = 'web' | 'console' | 'test' | 'repl' | 'unknown'; | ||
/** | ||
* Known application states. | ||
* | ||
* - 'created' Creating an application class instance sets the state to 'created'. | ||
* | ||
* - 'initiated' Calling `app.init()` method sets the state to 'initiated'. | ||
* The rc file contents and environment variables are parsed during | ||
* init phase. | ||
* | ||
* - 'booted' Calling `app.boot()` method sets the state to `booted`. The service | ||
* providers are registered and booted in this state. | ||
* | ||
* - 'ready' Calling `app.start()` method sets the state to `ready`. A set of | ||
* pre and post start operations inside this method. | ||
* | ||
* The service providers start methods are called during pre-start phase. | ||
* The service providers shutdown and application terminating hooks are | ||
* called during post-start phase. | ||
* | ||
* - 'terminated' Calling `app.terminate' method sets the state to `terminated`. The service | ||
* providers shutdown methods are called in this state. | ||
*/ | ||
export type ApplicationStates = 'created' | 'initiated' | 'booted' | 'ready' | 'terminated'; | ||
/** | ||
* State shared with hooks | ||
*/ | ||
export type HooksState<ContainerBindings extends Record<any, any>> = [ | ||
@@ -12,2 +42,6 @@ [ | ||
]; | ||
/** | ||
* Shape of directories object with known and unknown | ||
* directories | ||
*/ | ||
export interface DirectoriesNode { | ||
@@ -39,2 +73,5 @@ [key: string]: string; | ||
} | ||
/** | ||
* Shape of preload files | ||
*/ | ||
export type PreloadNode = { | ||
@@ -44,2 +81,5 @@ file: string; | ||
}; | ||
/** | ||
* Shape of provider modules | ||
*/ | ||
export type ProviderNode = { | ||
@@ -49,2 +89,5 @@ file: string; | ||
}; | ||
/** | ||
* Shape of semver node | ||
*/ | ||
export type SemverNode = { | ||
@@ -58,2 +101,6 @@ major: number; | ||
}; | ||
/** | ||
* Shape of the meta file inside the `metaFiles` array inside | ||
* `.adonisrc.json` file. | ||
*/ | ||
export type MetaFileNode = { | ||
@@ -63,19 +110,64 @@ pattern: string; | ||
}; | ||
/** | ||
* Shape of the .adonisrc.json file | ||
*/ | ||
export type RcFile = { | ||
/** | ||
* Configure a custom assets bundler to bundle and serve | ||
* assets. | ||
* | ||
* This config can be used to configure assets bundler apart from | ||
* vite and encore (since both are auto-detected) | ||
*/ | ||
assetsBundler?: { | ||
name: string; | ||
devServerCommand: string; | ||
buildCommand: string; | ||
devServer: { | ||
command: string; | ||
args?: string[]; | ||
}; | ||
build: { | ||
command: string; | ||
args?: string[]; | ||
}; | ||
}; | ||
/** | ||
* Is it a TypeScript project | ||
*/ | ||
typescript: boolean; | ||
/** | ||
* List of configured directories | ||
*/ | ||
directories: DirectoriesNode & { | ||
[key: string]: string; | ||
}; | ||
/** | ||
* An array of files to load after the application | ||
* has been booted | ||
*/ | ||
preloads: PreloadNode[]; | ||
/** | ||
* An array of files to load after the application | ||
* has been booted | ||
*/ | ||
metaFiles: MetaFileNode[]; | ||
/** | ||
* Providers to register. | ||
* | ||
* - The "base" key is used to register providers in all the environments. | ||
* - The environment specific keys are used to register providers for a specific env. | ||
*/ | ||
providers: ProviderNode[]; | ||
/** | ||
* An array of commands to register | ||
*/ | ||
commands: string[]; | ||
/** | ||
* Custom command aliases | ||
*/ | ||
commandsAliases: { | ||
[key: string]: string; | ||
}; | ||
/** | ||
* Register test suites | ||
*/ | ||
tests: { | ||
@@ -91,12 +183,58 @@ suites: { | ||
}; | ||
/** | ||
* Reference to `.adonisrc.json` file raw contents | ||
*/ | ||
raw: Record<string, any>; | ||
}; | ||
/** | ||
* Shape of the container provider class instance. | ||
*/ | ||
export interface ContainerProviderContract { | ||
/** | ||
* The register method on the provider class is meant to | ||
* register bindings in the container | ||
*/ | ||
register?(): void; | ||
/** | ||
* The boot method on the provider class is meant to boot | ||
* any state that application might need. | ||
* | ||
* For example: Registering macros/getters, defining middleware, | ||
* or repl bindings. | ||
*/ | ||
boot?(): void | Promise<void>; | ||
/** | ||
* The start method on the provider class is called right the | ||
* boot method. | ||
* | ||
* This method is best place to use existing container bindings before | ||
* the application gets started. Also, at this stage you can be sure | ||
* that all providers have been booted. | ||
*/ | ||
start?(): void | Promise<void>; | ||
/** | ||
* The ready method is called after the preloaded files have been | ||
* imported and the app is considered ready. In case of an HTTP | ||
* server, the server will be ready to receive incoming HTTP requests | ||
* before this hook gets called. | ||
*/ | ||
ready?(): void | Promise<void>; | ||
/** | ||
* The shutdown method on the provider class is meant to perform | ||
* cleanup for graceful shutdown. You should avoid executing | ||
* long running tasks in this method. | ||
* | ||
* If the shutdown process takes time, the application might get | ||
* forcefully killed based upon the event that occurred shutdown | ||
* in first place. | ||
*/ | ||
shutdown?(): void | Promise<void>; | ||
} | ||
/** | ||
* The importer is used to import modules in context of the | ||
* an AdonisJS application. | ||
* | ||
* Anytime AdonisJS wants to import a module from a bare string, it | ||
* will call this function | ||
*/ | ||
export type Importer = (moduleIdentifier: string, options?: ImportCallOptions) => any; | ||
//# sourceMappingURL=types.d.ts.map |
@@ -0,1 +1,9 @@ | ||
/* | ||
* @adonisjs/application | ||
* | ||
* (c) AdonisJS | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
export {}; |
{ | ||
"name": "@adonisjs/application", | ||
"version": "7.1.2-5", | ||
"version": "7.1.2-6", | ||
"description": "AdonisJS application class to read app related data", | ||
@@ -8,9 +8,5 @@ "type": "module", | ||
"files": [ | ||
"src", | ||
"factories", | ||
"index.ts", | ||
"build/src", | ||
"build/factories", | ||
"build/index.d.ts", | ||
"build/index.d.ts.map", | ||
"build/index.js" | ||
@@ -24,6 +20,10 @@ ], | ||
}, | ||
"engines": { | ||
"node": ">=18.16.0" | ||
}, | ||
"scripts": { | ||
"pretest": "npm run lint", | ||
"test": "cross-env NODE_DEBUG=adonisjs:app c8 npm run vscode:test", | ||
"test": "cross-env NODE_DEBUG=adonisjs:app c8 npm run quick:test", | ||
"clean": "del-cli build", | ||
"typecheck": "tsc --noEmit", | ||
"compile": "npm run lint && npm run clean && tsc", | ||
@@ -37,3 +37,3 @@ "build": "npm run compile", | ||
"sync-labels": "github-label-sync --labels .github/labels.json adonisjs/application", | ||
"vscode:test": "node --loader=ts-node/esm bin/test.ts" | ||
"quick:test": "node --loader=ts-node/esm bin/test.ts" | ||
}, | ||
@@ -47,24 +47,22 @@ "keywords": [ | ||
"devDependencies": { | ||
"@adonisjs/config": "^4.2.1-1", | ||
"@adonisjs/fold": "^9.9.3-4", | ||
"@commitlint/cli": "^17.6.3", | ||
"@commitlint/config-conventional": "^17.6.3", | ||
"@japa/assert": "^1.4.1", | ||
"@japa/expect-type": "^1.0.3", | ||
"@japa/file-system": "^1.0.1", | ||
"@japa/run-failed-tests": "^1.1.1", | ||
"@japa/runner": "^2.5.1", | ||
"@japa/spec-reporter": "^1.3.3", | ||
"@swc/core": "^1.3.59", | ||
"@adonisjs/config": "^4.2.1-2", | ||
"@adonisjs/eslint-config": "^1.1.7", | ||
"@adonisjs/fold": "^9.9.3-5", | ||
"@adonisjs/prettier-config": "^1.1.7", | ||
"@adonisjs/tsconfig": "^1.1.7", | ||
"@commitlint/cli": "^17.6.6", | ||
"@commitlint/config-conventional": "^17.6.6", | ||
"@japa/assert": "^2.0.0-1", | ||
"@japa/expect-type": "^2.0.0-0", | ||
"@japa/file-system": "^2.0.0-1", | ||
"@japa/runner": "^3.0.0-3", | ||
"@swc/core": "^1.3.67", | ||
"@types/fs-extra": "^11.0.1", | ||
"@types/glob-parent": "^5.1.1", | ||
"@types/node": "^20.2.3", | ||
"@types/node": "^20.3.3", | ||
"@types/semver": "^7.5.0", | ||
"c8": "^7.13.0", | ||
"c8": "^8.0.0", | ||
"cross-env": "^7.0.3", | ||
"del-cli": "^5.0.0", | ||
"eslint": "^8.41.0", | ||
"eslint-config-prettier": "^8.8.0", | ||
"eslint-plugin-adonis": "^3.0.3", | ||
"eslint-plugin-prettier": "^4.2.1", | ||
"eslint": "^8.44.0", | ||
"fs-extra": "^11.1.1", | ||
@@ -74,12 +72,12 @@ "github-label-sync": "^2.3.1", | ||
"jsonschema": "^1.4.1", | ||
"np": "^7.7.0", | ||
"np": "^8.0.4", | ||
"prettier": "^2.8.8", | ||
"semver": "^7.5.1", | ||
"semver": "^7.5.3", | ||
"ts-dedent": "^2.2.0", | ||
"ts-node": "^10.9.1", | ||
"typescript": "^5.0.4" | ||
"typescript": "^5.1.6" | ||
}, | ||
"dependencies": { | ||
"@poppinss/hooks": "^7.1.1-2", | ||
"@poppinss/utils": "^6.5.0-2", | ||
"@poppinss/hooks": "^7.1.1-4", | ||
"@poppinss/utils": "^6.5.0-3", | ||
"front-matter": "^4.0.2", | ||
@@ -101,32 +99,2 @@ "glob-parent": "^6.0.2", | ||
"homepage": "https://github.com/adonisjs/application#readme", | ||
"eslintConfig": { | ||
"extends": [ | ||
"plugin:adonis/typescriptPackage", | ||
"prettier" | ||
], | ||
"plugins": [ | ||
"prettier" | ||
], | ||
"rules": { | ||
"prettier/prettier": [ | ||
"error", | ||
{ | ||
"endOfLine": "auto" | ||
} | ||
] | ||
} | ||
}, | ||
"eslintIgnore": [ | ||
"build" | ||
], | ||
"prettier": { | ||
"trailingComma": "es5", | ||
"semi": false, | ||
"singleQuote": true, | ||
"useTabs": false, | ||
"quoteProps": "consistent", | ||
"bracketSpacing": true, | ||
"arrowParens": "always", | ||
"printWidth": 100 | ||
}, | ||
"commitlint": { | ||
@@ -155,3 +123,7 @@ "extends": [ | ||
] | ||
} | ||
}, | ||
"eslintConfig": { | ||
"extends": "@adonisjs/eslint-config/package" | ||
}, | ||
"prettier": "@adonisjs/prettier-config" | ||
} |
@@ -5,3 +5,3 @@ # @adonisjs/application | ||
[![gh-workflow-image]][gh-workflow-url] [![npm-image]][npm-url] ![][typescript-image] [![license-image]][license-url] [![synk-image]][synk-url] | ||
[![gh-workflow-image]][gh-workflow-url] [![npm-image]][npm-url] ![][typescript-image] [![license-image]][license-url] | ||
@@ -25,4 +25,4 @@ ## Introduction | ||
[gh-workflow-image]: https://img.shields.io/github/actions/workflow/status/adonisjs/application/test.yml?style=for-the-badge | ||
[gh-workflow-url]: https://github.com/adonisjs/application/actions/workflows/test.yml "Github action" | ||
[gh-workflow-image]: https://img.shields.io/github/actions/workflow/status/adonisjs/application/checks.yml?style=for-the-badge | ||
[gh-workflow-url]: https://github.com/adonisjs/application/actions/workflows/checks.yml "Github action" | ||
@@ -37,4 +37,1 @@ [typescript-image]: https://img.shields.io/badge/Typescript-294E80.svg?style=for-the-badge&logo=typescript | ||
[license-url]: LICENSE.md "license" | ||
[synk-image]: https://img.shields.io/snyk/vulnerabilities/github/adonisjs/application?label=Synk%20Vulnerabilities&style=for-the-badge | ||
[synk-url]: https://snyk.io/test/github/adonisjs/application?targetFile=package.json "synk" |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
30
108986
41
3387
35
1
Updated@poppinss/hooks@^7.1.1-4
Updated@poppinss/utils@^6.5.0-3