"use strict"; require("typings-global"); const path = require("path"); const q = require("q"); 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 { constructor(nameArg, cwdArg = process.cwd()) { this.loader = 'npm'; 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 = q.defer(); this.whenLoaded = this.whenLoadedDeferred.promise; } setLoader(loaderArg) { this.loader = loaderArg; } /** * loads the module */ load() { let done = q.defer(); let loadedModule; if (this.loader === 'npm') { 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); }); } else { throw Error('loader not supported'); } return done.promise; } /** * loads additional lazy modules specified as arguments and returns them in the promise for easy use */ loadAlso(...args) { } } exports.LazyModule = LazyModule; //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQUEsMEJBQXVCO0FBRXZCLDZCQUE0QjtBQUM1Qix1QkFBc0I7QUFDdEIsNkJBQStCO0FBRS9CO0lBQUE7UUFDSSxnQkFBVyxHQUFHLElBQUksZUFBUyxFQUFtQixDQUFBO0lBUWxELENBQUM7SUFORzs7T0FFRztJQUNILGFBQWEsQ0FBQyxhQUE4QjtRQUN4QyxJQUFJLENBQUMsV0FBVyxDQUFDLEdBQUcsQ0FBQyxhQUFhLENBQUMsQ0FBQTt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