add basic module structure
This commit is contained in:
parent
45e57b3a84
commit
7e65012621
18
dist/index.d.ts
vendored
Normal file
18
dist/index.d.ts
vendored
Normal file
@ -0,0 +1,18 @@
|
||||
/// <reference types="q" />
|
||||
import * as q from 'q';
|
||||
/**
|
||||
* defines a LazyModule
|
||||
*/
|
||||
export declare class LazyModule<T> {
|
||||
name: string;
|
||||
cwd: string;
|
||||
constructor(nameArg: string, cwdArg?: string);
|
||||
/**
|
||||
* loads the module
|
||||
*/
|
||||
load(): q.Promise<T>;
|
||||
/**
|
||||
* loads additional lazy modules specified as arguments and returns them in the promise for easy use
|
||||
*/
|
||||
loadAlso(...args: LazyModule<any>[]): void;
|
||||
}
|
46
dist/index.js
vendored
Normal file
46
dist/index.js
vendored
Normal file
@ -0,0 +1,46 @@
|
||||
"use strict";
|
||||
const q = require("q");
|
||||
const lik_1 = require("lik");
|
||||
let systemjs = require('systemjs');
|
||||
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();
|
||||
/**
|
||||
* defines a LazyModule
|
||||
*/
|
||||
class LazyModule {
|
||||
constructor(nameArg, cwdArg = process.cwd()) {
|
||||
this.name = nameArg;
|
||||
this.cwd = cwdArg;
|
||||
smartsystem.addLazyModule(this);
|
||||
}
|
||||
/**
|
||||
* loads the module
|
||||
*/
|
||||
load() {
|
||||
let done = q.defer();
|
||||
let loadedModule;
|
||||
systemjs.import(this.name).then((m) => {
|
||||
loadedModule = m;
|
||||
done.resolve(loadedModule);
|
||||
});
|
||||
return done.promise;
|
||||
}
|
||||
/**
|
||||
* loads additional lazy modules specified as arguments and returns them in the promise for easy use
|
||||
*/
|
||||
loadAlso(...args) {
|
||||
}
|
||||
}
|
||||
exports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IsSUFBSSxDQUFDLE9BQU8sQ0FBQyxZQUFZLENBQUMsQ0FBQTtRQUM5QixDQUFDLENBQUMsQ0FBQTtRQUNGLE1BQU0sQ0FBQyxJQUFJLENBQUMsT0FBTyxDQUFBO0lBQ3ZCLENBQUM7SUFFRDs7T0FFRztJQUNILFFBQVEsQ0FBQyxHQUFHLElBQXVCO0lBRW5DLENBQUM7Q0FDSjtBQTVCRCxnQ0E0QkMifQ==
|
@ -3,6 +3,7 @@
|
||||
"version": "1.0.0",
|
||||
"description": "wraps systemjs for smarter workflows",
|
||||
"main": "dist/index.js",
|
||||
"typings": "dist/index.d.ts",
|
||||
"scripts": {
|
||||
"test": "(npmts)"
|
||||
},
|
||||
@ -19,6 +20,11 @@
|
||||
"dependencies": {
|
||||
"@types/q": "0.0.32",
|
||||
"lik": "^1.0.24",
|
||||
"q": "^1.4.1"
|
||||
"q": "^1.4.1",
|
||||
"systemjs": "^0.19.39"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/should": "^8.1.30",
|
||||
"should": "^11.1.1"
|
||||
}
|
||||
}
|
||||
|
0
test/test.d.ts
vendored
Normal file
0
test/test.d.ts
vendored
Normal file
2
test/test.js
Normal file
2
test/test.js
Normal file
@ -0,0 +1,2 @@
|
||||
"use strict";
|
||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidGVzdC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbInRlc3QudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IiJ9
|
2
test/test.ts
Normal file
2
test/test.ts
Normal file
@ -0,0 +1,2 @@
|
||||
import * as should from 'should'
|
||||
import * as smartsystem from '../dist/index'
|
51
ts/index.ts
51
ts/index.ts
@ -1,5 +1,54 @@
|
||||
import * as plugins from './smartsystem.plugins'
|
||||
|
||||
export class Smartsystem {
|
||||
import * as q from 'q'
|
||||
import { Objectmap } from 'lik'
|
||||
let systemjs = require('systemjs')
|
||||
|
||||
class Smartsystem {
|
||||
lazyModules = new Objectmap<LazyModule>()
|
||||
|
||||
/**
|
||||
* add lazyModule to Smartsystem
|
||||
*/
|
||||
addLazyModule(lazyModuleArg: LazyModule) {
|
||||
this.lazyModules.add(lazyModuleArg)
|
||||
}
|
||||
|
||||
loadLazyModule(lazyModuleArg: LazyModule)
|
||||
}
|
||||
|
||||
// create the internal smartsystem
|
||||
let smartsystem = new Smartsystem()
|
||||
|
||||
/**
|
||||
* defines a LazyModule
|
||||
*/
|
||||
export class LazyModule<T> {
|
||||
name: string
|
||||
cwd: string
|
||||
constructor(nameArg: string, cwdArg: string = process.cwd()){
|
||||
this.name = nameArg
|
||||
this.cwd = cwdArg
|
||||
smartsystem.addLazyModule(this)
|
||||
}
|
||||
|
||||
/**
|
||||
* loads the module
|
||||
*/
|
||||
load(): q.Promise<T> {
|
||||
let done = q.defer<T>()
|
||||
let loadedModule: T
|
||||
systemjs.import(this.name).then((m) => {
|
||||
loadedModule = m
|
||||
done.resolve(loadedModule)
|
||||
})
|
||||
return done.promise
|
||||
}
|
||||
|
||||
/**
|
||||
* loads additional lazy modules specified as arguments and returns them in the promise for easy use
|
||||
*/
|
||||
loadAlso(...args: LazyModule<any>[]) {
|
||||
|
||||
}
|
||||
}
|
@ -1 +0,0 @@
|
||||
import * as lik from 'lik'
|
3
tslint.json
Normal file
3
tslint.json
Normal file
@ -0,0 +1,3 @@
|
||||
{
|
||||
"extends": "tslint-config-standard"
|
||||
}
|
Loading…
Reference in New Issue
Block a user