|
|
|
@ -2,6 +2,7 @@ import LifecycleUnit from '../lifecycle/Unit.ts'
|
|
|
|
|
import {fs, path} from '../external/std.ts'
|
|
|
|
|
import {Canon} from './Canon.ts'
|
|
|
|
|
import {Logging} from '../service/logging/Logging.ts'
|
|
|
|
|
import {universal_path, UniversalPath} from '../support/UniversalPath.ts'
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Base type for a canonical definition.
|
|
|
|
@ -82,8 +83,8 @@ export class Canonical<T> extends LifecycleUnit {
|
|
|
|
|
* Get the fully-qualified path to the base directory for this unit.
|
|
|
|
|
* @type string
|
|
|
|
|
*/
|
|
|
|
|
public get path(): string {
|
|
|
|
|
return path.resolve(this.base_path)
|
|
|
|
|
public get path(): UniversalPath {
|
|
|
|
|
return universal_path(this.base_path)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@ -96,7 +97,7 @@ export class Canonical<T> extends LifecycleUnit {
|
|
|
|
|
|
|
|
|
|
public async up() {
|
|
|
|
|
const logger = this.make(Logging)
|
|
|
|
|
for await ( const entry of fs.walk(this.path) ) {
|
|
|
|
|
for await ( const entry of fs.walk(this.path.to_local) ) {
|
|
|
|
|
if ( !entry.isFile || !entry.path.endsWith(this.suffix) ) {
|
|
|
|
|
if ( entry.isFile ) logger.debug(`Skipping file in canonical path with invalid suffix: ${entry.path}`)
|
|
|
|
|
continue
|
|
|
|
@ -125,19 +126,16 @@ export class Canonical<T> extends LifecycleUnit {
|
|
|
|
|
* @return Promise<CanonicalDefinition>
|
|
|
|
|
*/
|
|
|
|
|
private async _get_canonical_definition(file_path: string): Promise<CanonicalDefinition> {
|
|
|
|
|
const original_name = file_path.replace(this.path, '').substr(1)
|
|
|
|
|
const original_name = file_path.replace(this.path.to_local, '').substr(1)
|
|
|
|
|
const path_regex = new RegExp(path.SEP, 'g')
|
|
|
|
|
const canonical_name = original_name.replace(path_regex, ':')
|
|
|
|
|
.split('').reverse().join('')
|
|
|
|
|
.substr(this.suffix.length)
|
|
|
|
|
.split('').reverse().join('')
|
|
|
|
|
|
|
|
|
|
if ( file_path.startsWith('/') ) {
|
|
|
|
|
file_path = `file://${file_path}`
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this.make(Logging).debug(`Importing from: ${file_path}`)
|
|
|
|
|
const imported = await import(file_path)
|
|
|
|
|
const file_universal_path = universal_path(file_path)
|
|
|
|
|
this.make(Logging).debug(`Importing from: ${file_universal_path}`)
|
|
|
|
|
const imported = await import(file_universal_path.to_remote)
|
|
|
|
|
return { canonical_name, original_name, imported }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|