fix(core): update

This commit is contained in:
2019-08-22 01:05:21 +02:00
parent a1139c5da4
commit a4734d9c10
17 changed files with 2088 additions and 638 deletions

View File

@ -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
View 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
}