2016-10-11 23:41:30 +00:00
|
|
|
"use strict";
|
2017-05-13 09:03:24 +00:00
|
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
2016-10-12 12:07:54 +00:00
|
|
|
require("typings-global");
|
2016-10-12 13:41:09 +00:00
|
|
|
const path = require("path");
|
2017-06-30 16:51:41 +00:00
|
|
|
const smartq = require("smartq");
|
2016-10-11 23:41:30 +00:00
|
|
|
const lik_1 = require("lik");
|
|
|
|
class Smartsystem {
|
|
|
|
constructor() {
|
|
|
|
this.lazyModules = new lik_1.Objectmap();
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
* add lazyModule to Smartsystem
|
|
|
|
*/
|
|
|
|
addLazyModule(lazyModuleArg) {
|
|
|
|
this.lazyModules.add(lazyModuleArg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// create the internal smartsystem
|
|
|
|
let smartsystem = new Smartsystem();
|
|
|
|
class LazyModule {
|
2016-12-10 18:46:47 +00:00
|
|
|
constructor(nameArg, cwdArg) {
|
2016-10-14 01:07:37 +00:00
|
|
|
this.loader = 'npm';
|
2016-12-10 18:46:47 +00:00
|
|
|
if (!cwdArg) {
|
|
|
|
throw new Error('You must specify a directory to resolve from!');
|
|
|
|
}
|
2016-10-11 23:41:30 +00:00
|
|
|
this.name = nameArg;
|
|
|
|
this.cwd = cwdArg;
|
2016-10-12 12:01:15 +00:00
|
|
|
smartsystem.addLazyModule(this); // add module to smartsystem instance
|
|
|
|
this.nameIsPath = /\.\//.test(this.name); // figure out if name is path
|
2016-10-12 13:41:09 +00:00
|
|
|
if (this.nameIsPath) {
|
|
|
|
this.name = path.join(this.cwd, this.name);
|
|
|
|
}
|
2017-06-30 16:51:41 +00:00
|
|
|
this.whenLoadedDeferred = smartq.defer();
|
2016-10-12 12:01:15 +00:00
|
|
|
this.whenLoaded = this.whenLoadedDeferred.promise;
|
2016-10-11 23:41:30 +00:00
|
|
|
}
|
2016-10-14 01:07:37 +00:00
|
|
|
setLoader(loaderArg) {
|
|
|
|
this.loader = loaderArg;
|
|
|
|
}
|
2016-10-11 23:41:30 +00:00
|
|
|
/**
|
|
|
|
* loads the module
|
|
|
|
*/
|
|
|
|
load() {
|
2017-06-30 16:51:41 +00:00
|
|
|
let done = smartq.defer();
|
2016-10-11 23:41:30 +00:00
|
|
|
let loadedModule;
|
2016-10-14 01:07:37 +00:00
|
|
|
if (this.loader === 'npm') {
|
2016-10-14 01:24:29 +00:00
|
|
|
loadedModule = require(this.name);
|
|
|
|
done.resolve(loadedModule);
|
|
|
|
}
|
|
|
|
else if (this.loader === 'systemjs') {
|
|
|
|
let systemjs = require('systemjs');
|
|
|
|
systemjs.import(this.name).then((m) => {
|
|
|
|
loadedModule = m;
|
|
|
|
this.whenLoadedDeferred.resolve(loadedModule);
|
|
|
|
done.resolve(loadedModule);
|
|
|
|
}).catch(err => { console.log(err); });
|
2016-10-14 01:07:37 +00:00
|
|
|
}
|
|
|
|
else {
|
2016-10-14 01:24:29 +00:00
|
|
|
throw Error('loader not supported');
|
2016-10-14 01:07:37 +00:00
|
|
|
}
|
2016-10-11 23:41:30 +00:00
|
|
|
return done.promise;
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
* loads additional lazy modules specified as arguments and returns them in the promise for easy use
|
|
|
|
*/
|
|
|
|
loadAlso(...args) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
exports.LazyModule = LazyModule;
|
2017-06-30 16:51:41 +00:00
|
|
|
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOztBQUFBLDBCQUF1QjtBQUV2Qiw2QkFBNEI7QUFDNUIsaUNBQWdDO0FBQ2hDLDZCQUErQjtBQUUvQjtJQUFBO1FBQ0UsZ0JBQVcsR0FBRyxJQUFJLGVBQVMsRUFBbUIsQ0FBQTtJQVFoRCxD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