fix(core): update
This commit is contained in:
57
ts/index.ts
57
ts/index.ts
@ -1,56 +1,7 @@
|
||||
import 'typings-global'
|
||||
import * as plugins from './smartsystem.plugins';
|
||||
|
||||
import * as path from 'path'
|
||||
import * as smartq from 'smartq'
|
||||
import { Objectmap } from 'lik'
|
||||
export class Smartsystem {
|
||||
public env = new plugins.smartenv.Smartenv()
|
||||
|
||||
class Smartsystem {
|
||||
lazyModules = new Objectmap<LazyModule<any>>()
|
||||
|
||||
/**
|
||||
* add lazyModule to Smartsystem
|
||||
*/
|
||||
addLazyModule (lazyModuleArg: LazyModule<any>) {
|
||||
this.lazyModules.add(lazyModuleArg)
|
||||
}
|
||||
}
|
||||
|
||||
// create the internal smartsystem
|
||||
let smartsystem = new Smartsystem()
|
||||
|
||||
/**
|
||||
* defines a LazyModule
|
||||
*/
|
||||
|
||||
export type TLoader = 'npm' | 'systemjs'
|
||||
|
||||
export class LazyModule<T> {
|
||||
name: string
|
||||
cwd: string
|
||||
whenLoaded: Promise<T>
|
||||
private nameIsPath: boolean
|
||||
private whenLoadedDeferred: smartq.Deferred<T>
|
||||
constructor (nameArg: string, cwdArg: string) {
|
||||
if (!cwdArg) {
|
||||
throw new Error('You must specify a directory to resolve from!')
|
||||
}
|
||||
this.name = nameArg
|
||||
this.cwd = cwdArg
|
||||
smartsystem.addLazyModule(this) // add module to smartsystem instance
|
||||
this.nameIsPath = /\.\//.test(this.name) // figure out if name is path
|
||||
if (this.nameIsPath) {
|
||||
this.name = path.join(this.cwd, this.name)
|
||||
}
|
||||
this.whenLoadedDeferred = smartq.defer<T>()
|
||||
this.whenLoaded = this.whenLoadedDeferred.promise
|
||||
}
|
||||
|
||||
/**
|
||||
* loads the module
|
||||
*/
|
||||
async load (): Promise<T> {
|
||||
let loadedModule: T = require(this.name)
|
||||
this.whenLoadedDeferred.resolve(loadedModule)
|
||||
return loadedModule
|
||||
}
|
||||
public cpuCount = plugins.os.cpus().length;
|
||||
}
|
||||
|
16
ts/smartsystem.plugins.ts
Normal file
16
ts/smartsystem.plugins.ts
Normal file
@ -0,0 +1,16 @@
|
||||
// node native
|
||||
import os from 'os'
|
||||
|
||||
export {
|
||||
os
|
||||
}
|
||||
|
||||
import * as lik from '@pushrocks/lik';
|
||||
import * as smartenv from '@pushrocks/smartenv';
|
||||
import * as smartpromise from '@pushrocks/smartpromise';
|
||||
|
||||
export {
|
||||
lik,
|
||||
smartenv,
|
||||
smartpromise
|
||||
}
|
Reference in New Issue
Block a user