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", "name": "@extollo/lib",
"version": "0.10.2", "version": "0.10.3",
"description": "The framework library that lifts up your code.", "description": "The framework library that lifts up your code.",
"main": "lib/index.js", "main": "lib/index.js",
"types": "lib/index.d.ts", "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. * Returns true if the given file path has the correct suffix to be loaded by this unit.
* Determines the runtime file extension based on the Node runtime.
*/ */
public getScriptSuffix(): string { public isValidSuffix(path: string): boolean {
return `${this.suffix}${env('NODE_SCRIPT_SUFFIX', '.js')}` 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> { public async up(): Promise<void> {
if ( await this.path.exists() ) { if ( await this.path.exists() ) {
for await ( const entry of this.path.walk() ) { 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}`) this.logging.debug(`Skipping file with invalid suffix: ${entry}`)
continue continue
} }
@ -305,7 +306,7 @@ export abstract class Canonical<T> extends Unit {
.split('') .split('')
.reverse() .reverse()
.join('') .join('')
.substr(this.getScriptSuffix().length) .substr(this.suffix.length + 3) // +3 to account for `.js` or `.ts` ending
.split('') .split('')
.reverse() .reverse()
.join('') .join('')

@ -39,9 +39,10 @@ export class Routing extends Unit {
this.logging.verbose('Registering @extollo view engine namespace.') this.logging.verbose('Registering @extollo view engine namespace.')
engine.registerNamespace('extollo', lib().concat('resources', 'views')) 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() ) { 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}`) this.logging.debug(`Skipping routes file with invalid suffix: ${entry}`)
continue continue
} }

Loading…
Cancel
Save