Setup eslint and enforce rules
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
@@ -1,12 +1,12 @@
|
||||
/**
|
||||
* Base type for a canonical definition.
|
||||
*/
|
||||
import {Canon} from "./Canon";
|
||||
import {universalPath, UniversalPath, ErrorWithContext} from "../util";
|
||||
import {Logging} from "./Logging";
|
||||
import {Inject} from "../di";
|
||||
import {Canon} from './Canon'
|
||||
import {universalPath, UniversalPath, ErrorWithContext} from '../util'
|
||||
import {Logging} from './Logging'
|
||||
import {Inject} from '../di'
|
||||
import * as nodePath from 'path'
|
||||
import {Unit} from "../lifecycle/Unit";
|
||||
import {Unit} from '../lifecycle/Unit'
|
||||
|
||||
/**
|
||||
* Interface describing a definition of a single canonical item loaded from the app.
|
||||
@@ -61,14 +61,14 @@ export abstract class Canonical<T> extends Unit {
|
||||
* The file suffix of files in the base path that should be loaded.
|
||||
* @type string
|
||||
*/
|
||||
protected suffix: string = '.js'
|
||||
protected suffix = '.js'
|
||||
|
||||
/**
|
||||
* The singular, programmatic name of one of these canonical items.
|
||||
* @example middleware
|
||||
* @type string
|
||||
*/
|
||||
protected canonicalItem: string = ''
|
||||
protected canonicalItem = ''
|
||||
|
||||
/**
|
||||
* Object mapping canonical names to loaded file references.
|
||||
@@ -90,13 +90,15 @@ export abstract class Canonical<T> extends Unit {
|
||||
public static resolve(reference: string): CanonicalReference {
|
||||
const rscParts = reference.split('::')
|
||||
const resource = rscParts.length > 1 ? rscParts[0] + 's' : undefined
|
||||
const rsc_less = rscParts.length > 1 ? rscParts[1] : rscParts[0]
|
||||
const prtParts = rsc_less.split('.')
|
||||
const rscLess = rscParts.length > 1 ? rscParts[1] : rscParts[0]
|
||||
const prtParts = rscLess.split('.')
|
||||
const item = prtParts[0]
|
||||
const particular = prtParts.length > 1 ? prtParts.slice(1).join('.') : undefined
|
||||
|
||||
return {
|
||||
resource, item, particular
|
||||
resource,
|
||||
item,
|
||||
particular,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -115,7 +117,7 @@ export abstract class Canonical<T> extends Unit {
|
||||
}
|
||||
|
||||
/** Get the plural name of the canonical items provided by this unit. */
|
||||
public get canonicalItems() {
|
||||
public get canonicalItems(): string {
|
||||
return `${this.canonicalItem}s`
|
||||
}
|
||||
|
||||
@@ -167,7 +169,7 @@ export abstract class Canonical<T> extends Unit {
|
||||
* @param name
|
||||
* @param resolver
|
||||
*/
|
||||
public registerNamespace(name: string, resolver: CanonicalResolver<T>) {
|
||||
public registerNamespace(name: string, resolver: CanonicalResolver<T>): void {
|
||||
if ( !name.startsWith('@') ) {
|
||||
throw new ErrorWithContext(`Canonical namespaces must start with @.`, { name })
|
||||
}
|
||||
@@ -179,7 +181,7 @@ export abstract class Canonical<T> extends Unit {
|
||||
this.loadedNamespaces[name] = resolver
|
||||
}
|
||||
|
||||
public async up() {
|
||||
public async up(): Promise<void> {
|
||||
for await ( const entry of this.path.walk() ) {
|
||||
if ( !entry.endsWith(this.suffix) ) {
|
||||
this.logging.debug(`Skipping file with invalid suffix: ${entry}`)
|
||||
@@ -212,14 +214,20 @@ export abstract class Canonical<T> extends Unit {
|
||||
const originalName = filePath.replace(this.path.toLocal, '').substr(1)
|
||||
const pathRegex = new RegExp(nodePath.sep, 'g')
|
||||
const canonicalName = originalName.replace(pathRegex, ':')
|
||||
.split('').reverse().join('')
|
||||
.split('')
|
||||
.reverse()
|
||||
.join('')
|
||||
.substr(this.suffix.length)
|
||||
.split('').reverse().join('')
|
||||
.split('')
|
||||
.reverse()
|
||||
.join('')
|
||||
|
||||
const fullUniversalPath = universalPath(filePath)
|
||||
this.logging.verbose(`Importing from: ${fullUniversalPath}`)
|
||||
|
||||
const imported = await import(fullUniversalPath.toLocal)
|
||||
return { canonicalName, originalName, imported }
|
||||
return { canonicalName,
|
||||
originalName,
|
||||
imported }
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user