Modify canonical loading to allow either suffix.js or suffix.ts endings

master
Garrett Mills 2 years ago
parent 111ce0bcf9
commit 7d3fde85eb

@ -1,6 +1,6 @@
{
"name": "@extollo/lib",
"version": "0.10.2",
"version": "0.10.3",
"description": "The framework library that lifts up your code.",
"main": "lib/index.js",
"types": "lib/index.d.ts",

@ -119,11 +119,12 @@ 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.
* Returns true if the given file path has the correct suffix to be loaded by this unit.
*/
public getScriptSuffix(): string {
return `${this.suffix}${env('NODE_SCRIPT_SUFFIX', '.js')}`
public isValidSuffix(path: string): boolean {
const jsSuffix = `${this.suffix}.js`
const tsSuffix = `${this.suffix}.ts`
return path.endsWith(jsSuffix) || path.endsWith(tsSuffix)
}
/**
@ -260,7 +261,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.getScriptSuffix()) ) {
if ( !this.isValidSuffix(entry) ) {
this.logging.debug(`Skipping file with invalid suffix: ${entry}`)
continue
}
@ -305,7 +306,7 @@ export abstract class Canonical<T> extends Unit {
.split('')
.reverse()
.join('')
.substr(this.getScriptSuffix().length)
.substr(this.suffix.length + 3) // +3 to account for `.js` or `.ts` ending
.split('')
.reverse()
.join('')

@ -39,9 +39,10 @@ export class Routing extends Unit {
this.logging.verbose('Registering @extollo view engine namespace.')
engine.registerNamespace('extollo', lib().concat('resources', 'views'))
const suffix = `.routes${env('NODE_SCRIPT_SUFFIX', '.js')}`
const jsSuffix = `.routes.js`
const tsSuffix = `.routes.ts`
for await ( const entry of this.path.walk() ) {
if ( !entry.endsWith(suffix) ) {
if ( !entry.endsWith(jsSuffix) && !entry.endsWith(tsSuffix) ) {
this.logging.debug(`Skipping routes file with invalid suffix: ${entry}`)
continue
}

Loading…
Cancel
Save