smartsystem/dist/index.js

55 lines
3.5 KiB
JavaScript
Raw Normal View History

2016-10-11 23:41:30 +00:00
"use strict";
2017-07-31 13:16:10 +00:00
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
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");
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) {
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
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
}
/**
* loads the module
*/
load() {
2017-07-31 13:16:10 +00:00
return __awaiter(this, void 0, void 0, function* () {
let loadedModule = require(this.name);
this.whenLoadedDeferred.resolve(loadedModule);
return loadedModule;
});
2016-10-11 23:41:30 +00:00
}
}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