|
|
|
@ -8,6 +8,7 @@ import {Inject} from '../di'
|
|
|
|
|
import * as nodePath from 'path'
|
|
|
|
|
import {Unit} from '../lifecycle/Unit'
|
|
|
|
|
import {isCanonicalReceiver} from '../support/CanonicalReceiver'
|
|
|
|
|
import {env} from '../lifecycle/Application'
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Interface describing a definition of a single canonical item loaded from the app.
|
|
|
|
@ -70,9 +71,13 @@ export abstract class Canonical<T> extends Unit {
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The file suffix of files in the base path that should be loaded.
|
|
|
|
|
* This should EXCLUDE `.js` or `.ts`. These file extensions are determined
|
|
|
|
|
* by the framework depending on the Node runtime.
|
|
|
|
|
* @example `.service`
|
|
|
|
|
* @example `.middleware`
|
|
|
|
|
* @type string
|
|
|
|
|
*/
|
|
|
|
|
protected suffix = '.js'
|
|
|
|
|
protected suffix = ''
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The singular, programmatic name of one of these canonical items.
|
|
|
|
@ -113,6 +118,14 @@ export abstract class Canonical<T> extends Unit {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get the suffix that files must have to be loaded by this service.
|
|
|
|
|
* Determines the runtime file extension based on the Node runtime.
|
|
|
|
|
*/
|
|
|
|
|
public getScriptSuffix(): string {
|
|
|
|
|
return `${this.suffix}${env('NODE_SCRIPT_SUFFIX', '.js')}`
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Return an array of all loaded canonical names.
|
|
|
|
|
*/
|
|
|
|
@ -247,7 +260,7 @@ export abstract class Canonical<T> extends Unit {
|
|
|
|
|
public async up(): Promise<void> {
|
|
|
|
|
if ( await this.path.exists() ) {
|
|
|
|
|
for await ( const entry of this.path.walk() ) {
|
|
|
|
|
if ( !entry.endsWith(this.suffix) ) {
|
|
|
|
|
if ( !entry.endsWith(this.getScriptSuffix()) ) {
|
|
|
|
|
this.logging.debug(`Skipping file with invalid suffix: ${entry}`)
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
@ -292,7 +305,7 @@ export abstract class Canonical<T> extends Unit {
|
|
|
|
|
.split('')
|
|
|
|
|
.reverse()
|
|
|
|
|
.join('')
|
|
|
|
|
.substr(this.suffix.length)
|
|
|
|
|
.substr(this.getScriptSuffix().length)
|
|
|
|
|
.split('')
|
|
|
|
|
.reverse()
|
|
|
|
|
.join('')
|
|
|
|
|