39 Commits

Author SHA1 Message Date
b584978287 2.0.9 2019-09-08 15:56:50 +02:00
44bfff2a6b fix(core): update 2019-09-08 15:56:50 +02:00
af07a53053 2.0.8 2019-08-22 15:23:09 +02:00
2ace413435 fix(core): update 2019-08-22 15:23:09 +02:00
16dfec29f4 2.0.7 2019-08-22 13:01:44 +02:00
10ab005343 fix(core): update 2019-08-22 13:01:44 +02:00
9dded0eab5 2.0.6 2019-08-22 02:15:40 +02:00
c54ae3fdb4 fix(core): update 2019-08-22 02:15:40 +02:00
3ae2f9a6b2 2.0.5 2019-08-22 02:14:43 +02:00
48959be97e fix(core): update 2019-08-22 02:14:42 +02:00
658e60475a 2.0.4 2019-08-22 02:14:18 +02:00
f6c64c6583 fix(core): update 2019-08-22 02:14:17 +02:00
e3929a17ed 2.0.3 2019-08-22 01:05:21 +02:00
a4734d9c10 fix(core): update 2019-08-22 01:05:21 +02:00
a1139c5da4 2.0.2 2017-07-31 15:20:43 +02:00
a401fd2e8f update yarn lock 2017-07-31 15:20:38 +02:00
8157371a1d 2.0.1 2017-07-31 15:19:50 +02:00
719a9b32d7 update readme 2017-07-31 15:19:46 +02:00
a732d2a403 2.0.0 2017-07-31 15:17:34 +02:00
11fe4618ba update docs 2017-07-31 15:17:31 +02:00
f4290ca8fa streamline things 2017-07-31 15:16:10 +02:00
04518f28cf 1.0.18 2017-06-30 18:51:44 +02:00
0d6ea31bd2 update to smartq 2017-06-30 18:51:41 +02:00
60bd95093d 1.0.17 2017-05-13 11:16:43 +02:00
05d4e0ff6d add docs 2017-05-13 11:16:39 +02:00
e05f7d32fd 1.0.16 2017-05-13 11:03:40 +02:00
5f0ddc6600 update tests and README 2017-05-13 11:03:24 +02:00
d312d6ae5a 1.0.15 2017-05-13 10:34:38 +02:00
8ca254595d 1.0.14 2017-05-13 10:34:19 +02:00
7661ae506d update ci 2017-05-13 10:34:08 +02:00
4e8dd83839 1.0.13 2017-05-13 10:33:38 +02:00
7ab1a4eec7 update README 2017-05-13 10:33:34 +02:00
3098fbec89 1.0.12 2016-12-11 11:01:07 +01:00
1caa8a7c31 improve README 2016-12-11 11:00:58 +01:00
c689a3c349 update npmextra.json 2016-12-10 22:15:22 +01:00
a8a0778708 1.0.11 2016-12-10 22:12:38 +01:00
82ebb181a0 update README 2016-12-10 22:12:24 +01:00
adabcb3c4a 1.0.10 2016-12-10 19:46:52 +01:00
32db51c49a update to latest standards 2016-12-10 19:46:47 +01:00
19 changed files with 2467 additions and 293 deletions

22
.gitignore vendored
View File

@ -1,4 +1,22 @@
node_modules/ .nogit/
# artifacts
coverage/ coverage/
pages/
public/ public/
pages/
# installs
node_modules/
# caches
.yarn/
.cache/
.rpt2_cache
# builds
dist/
dist_web/
dist_serve/
dist_ts_web/
# custom

View File

@ -1,53 +1,119 @@
image: hosttoday/ht-docker-node:npmts # gitzone ci_default
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
cache:
paths:
- .npmci_cache/
key: "$CI_BUILD_STAGE"
stages: stages:
- security
- test - test
- release - release
- trigger - metadata
- page
testLEGACY:
stage: test
script:
- npmci test legacy
tags:
- docker
allow_failure: true
testLTS:
stage: test
script:
- npmci test lts
tags:
- docker
testSTABLE: # ====================
# security stage
# ====================
mirror:
stage: security
script:
- npmci git mirror
tags:
- docker
- notpriv
snyk:
stage: security
script:
- npmci npm prepare
- npmci command npm install -g snyk
- npmci command npm install --ignore-scripts
- npmci command snyk test
tags:
- docker
- notpriv
# ====================
# test stage
# ====================
testStable:
stage: test stage: test
script: script:
- npmci test stable - npmci npm prepare
- npmci node install stable
- npmci npm install
- npmci npm test
coverage: /\d+.?\d+?\%\s*coverage/
tags: tags:
- docker - docker
- priv
testBuild:
stage: test
script:
- npmci npm prepare
- npmci node install lts
- npmci npm install
- npmci command npm run build
coverage: /\d+.?\d+?\%\s*coverage/
tags:
- docker
- notpriv
release: release:
stage: release stage: release
script: script:
- npmci publish - npmci node install lts
- npmci npm publish
only: only:
- tags - tags
tags: tags:
- docker - docker
- notpriv
# ====================
# metadata stage
# ====================
codequality:
stage: metadata
allow_failure: true
script:
- npmci command npm install -g tslint typescript
- npmci npm install
- npmci command "tslint -c tslint.json ./ts/**/*.ts"
tags:
- docker
- priv
trigger: trigger:
stage: trigger stage: metadata
script: script:
- npmci trigger - npmci trigger
only: only:
- tags - tags
tags:
- docker
- notpriv
pages:
image: hosttoday/ht-docker-dbase:npmci
services:
- docker:stable-dind
stage: metadata
script:
- npmci command npm install -g @gitzone/tsdoc
- npmci npm prepare
- npmci npm install
- npmci command tsdoc
tags: tags:
- docker - docker
pages: - notpriv
image: hosttoday/ht-docker-node:npmpage
stage: page
script:
- npmci command npmpage --host gitlab
only: only:
- tags - tags
artifacts: artifacts:
expire_in: 1 week expire_in: 1 week
paths: paths:
- public - public
allow_failure: true

View File

@ -1,48 +0,0 @@
# smartsystem
simplifies lazy loading with TypeScript
## Availabililty
[![npm](https://push.rocks/assets/repo-button-npm.svg)](https://www.npmjs.com/package/smartsystem)
[![git](https://push.rocks/assets/repo-button-git.svg)](https://gitlab.com/pushrocks/smartsystem)
[![git](https://push.rocks/assets/repo-button-mirror.svg)](https://github.com/pushrocks/smartsystem)
[![docs](https://push.rocks/assets/repo-button-docs.svg)](https://pushrocks.gitlab.io/smartsystem/)
## Status for master
[![build status](https://gitlab.com/pushrocks/smartsystem/badges/master/build.svg)](https://gitlab.com/pushrocks/smartsystem/commits/master)
[![coverage report](https://gitlab.com/pushrocks/smartsystem/badges/master/coverage.svg)](https://gitlab.com/pushrocks/smartsystem/commits/master)
[![Dependency Status](https://david-dm.org/pushrocks/smartsystem.svg)](https://david-dm.org/pushrocks/smartsystem)
[![bitHound Dependencies](https://www.bithound.io/github/pushrocks/smartsystem/badges/dependencies.svg)](https://www.bithound.io/github/pushrocks/smartsystem/master/dependencies/npm)
[![bitHound Code](https://www.bithound.io/github/pushrocks/smartsystem/badges/code.svg)](https://www.bithound.io/github/pushrocks/smartsystem)
[![TypeScript](https://img.shields.io/badge/TypeScript-2.x-blue.svg)](https://nodejs.org/dist/latest-v6.x/docs/api/)
[![node](https://img.shields.io/badge/node->=%206.x.x-blue.svg)](https://nodejs.org/dist/latest-v6.x/docs/api/)
[![JavaScript Style Guide](https://img.shields.io/badge/code%20style-standard-brightgreen.svg)](http://standardjs.com/)
## Usage
We recommend the use of TypeScript for best Intellisense
smartsystem supports both npm and SystemJs as module loader.
```typescript
import { LazyModule } from 'smartsystem'
import * as _myPlugin from 'myPlugin' // plugin does not get loaded here at runtime
let myPluginLazy = new LazyModule<typeof _myPlugin>('myPlugin')
myPluginLazy.setLoader('npm') // sets the loader, defaults to npm anyway
import * as _anotherPlugin from 'anotherPlugin' // plugin does not get loaded here at runtime
let anotherPluginLazy = new LazyModule<typeof _anotherPlugin>('anotherPlugin')
anotherPluginLazy.setLoader('systemjs') // sets the loader to systemjs
myPluginLazy.whenLoaded.then(myPlugin => {
/* do something with myPlugin.
myPlugin receives the typings flow from LazyModule class
This does NOT load the module during runtime
The promise whenLoaded will be resolved whenever load() is called for the first time */
})
myPluginLazy.load().then(myPlugin => {
/* do something with myPlugin.
myPlugin receives the typings flow from LazyModule class
This DOES LOAD the module */
})
```

25
dist/index.d.ts vendored
View File

@ -1,25 +0,0 @@
/// <reference types="q" />
import 'typings-global';
import * as q from 'q';
/**
* defines a LazyModule
*/
export declare type TLoader = 'npm' | 'systemjs';
export declare class LazyModule<T> {
name: string;
nameIsPath: boolean;
cwd: string;
whenLoaded: q.Promise<T>;
loader: TLoader;
private whenLoadedDeferred;
constructor(nameArg: string, cwdArg?: string);
setLoader(loaderArg: TLoader): void;
/**
* 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;
}

65
dist/index.js vendored
View File

@ -1,65 +0,0 @@
"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,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQUEsMEJBQXVCO0FBRXZCLDZCQUE0QjtBQUM1Qix1QkFBc0I7QUFDdEIsNkJBQStCO0FBRS9CO0lBQUE7UUFDSSxnQkFBVyxHQUFHLElBQUksZUFBUyxFQUFtQixDQUFBO0lBUWxELENBQUM7SUFORzs7T0FFRztJQUNILGFBQWEsQ0FBQyxhQUE4QjtRQUN4QyxJQUFJLENBQUMsV0FBVyxDQUFDLEdBQUcsQ0FBQyxhQUFhLENBQUMsQ0FBQTtJQUN2QyxDQUFDO0NBQ0o7QUFFRCxrQ0FBa0M7QUFDbEMsSUFBSSx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
simplifies lazy loading with TypeScript
## Availabililty
[![npm](https://pushrocks.gitlab.io/assets/repo-button-npm.svg)](https://www.npmjs.com/package/smartsystem)
[![git](https://pushrocks.gitlab.io/assets/repo-button-git.svg)](https://GitLab.com/pushrocks/smartsystem)
[![git](https://pushrocks.gitlab.io/assets/repo-button-mirror.svg)](https://github.com/pushrocks/smartsystem)
[![docs](https://pushrocks.gitlab.io/assets/repo-button-docs.svg)](https://pushrocks.gitlab.io/smartsystem/)
## Status for master
[![build status](https://GitLab.com/pushrocks/smartsystem/badges/master/build.svg)](https://GitLab.com/pushrocks/smartsystem/commits/master)
[![coverage report](https://GitLab.com/pushrocks/smartsystem/badges/master/coverage.svg)](https://GitLab.com/pushrocks/smartsystem/commits/master)
[![npm downloads per month](https://img.shields.io/npm/dm/smartsystem.svg)](https://www.npmjs.com/package/smartsystem)
[![Dependency Status](https://david-dm.org/pushrocks/smartsystem.svg)](https://david-dm.org/pushrocks/smartsystem)
[![bitHound Dependencies](https://www.bithound.io/github/pushrocks/smartsystem/badges/dependencies.svg)](https://www.bithound.io/github/pushrocks/smartsystem/master/dependencies/npm)
[![bitHound Code](https://www.bithound.io/github/pushrocks/smartsystem/badges/code.svg)](https://www.bithound.io/github/pushrocks/smartsystem)
[![TypeScript](https://img.shields.io/badge/TypeScript-2.x-blue.svg)](https://nodejs.org/dist/latest-v6.x/docs/api/)
[![node](https://img.shields.io/badge/node->=%206.x.x-blue.svg)](https://nodejs.org/dist/latest-v6.x/docs/api/)
[![JavaScript Style Guide](https://img.shields.io/badge/code%20style-standard-brightgreen.svg)](http://standardjs.com/)
## Usage
We recommend the use of TypeScript for best Intellisense
smartsystem supports both npm and SystemJs as module loader.
```javascript
import { LazyModule } from 'smartsystem';
// plugin does not get loaded here at runtime
import * as _myPlugin from 'myPlugin';
// define the lazy module
let myLazyModule = new LazyModule() < typeof _myPlugin > ('myPlugin', __dirname);
// another plugin
import * as _anotherPlugin from 'anotherPlugin'; // plugin does not get loaded here at runtime
// define lazy module
let anotherLazyModule = new LazyModule() < typeof _anotherPlugin > ('anotherPlugin', __dirname);
myLazyModule.whenLoaded.then(myPlugin => {
/* do something with myPlugin.
myPlugin receives the typings flow from LazyModule class
This does NOT load the module during runtime
The promise whenLoaded will be resolved whenever load() is called for the first time */
});
myLazyModule.load().then(myPlugin => {
/* do something with myPlugin.
myPlugin receives the typings flow from LazyModule class
This DOES LOAD the module */
});
```
For further information read the linked docs at the top of this README.
> MIT licensed | **&copy;** [Lossless GmbH](https://lossless.gmbh)
> | By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy.html)
[![repo-footer](https://pushrocks.gitlab.io/assets/repo-footer.svg)](https://push.rocks)

16
npmextra.json Normal file
View File

@ -0,0 +1,16 @@
{
"npmci": {
"npmGlobalTools": [],
"npmAccessLevel": "public"
},
"gitzone": {
"module": {
"githost": "gitlab.com",
"gitscope": "pushrocks",
"gitrepo": "smartsystem",
"shortDescription": "interact with the system you are running on",
"npmPackagename": "@pushrocks/smartsystem",
"license": "MIT"
}
}
}

2157
package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

View File

@ -1,11 +1,12 @@
{ {
"name": "smartsystem", "name": "@pushrocks/smartsystem",
"version": "1.0.9", "version": "2.0.9",
"description": "simplifies lazy loading with TypeScript", "description": "interact with the system you are running on",
"main": "dist/index.js", "main": "dist/index.js",
"typings": "dist/index.d.ts", "typings": "dist/index.d.ts",
"scripts": { "scripts": {
"test": "(npmts)" "test": "(tstest test/)",
"build": "(tsbuild)"
}, },
"repository": { "repository": {
"type": "git", "type": "git",
@ -23,15 +24,29 @@
}, },
"homepage": "https://gitlab.com/pushrocks/smartsystem#README", "homepage": "https://gitlab.com/pushrocks/smartsystem#README",
"dependencies": { "dependencies": {
"@types/q": "0.0.32", "@pushrocks/lik": "^3.0.11",
"lik": "^1.0.24", "@pushrocks/smartenv": "^4.0.7",
"q": "^1.4.1", "@pushrocks/smartnetwork": "^1.1.11",
"systemjs": "^0.19.39", "@pushrocks/smartpromise": "^3.0.2",
"typings-global": "^1.0.14" "systeminformation": "^4.14.8"
}, },
"devDependencies": { "devDependencies": {
"@types/should": "^8.1.30", "@gitzone/tsbuild": "^2.1.17",
"should": "^11.1.1", "@gitzone/tstest": "^1.0.24",
"typings-test": "^1.0.3" "@pushrocks/tapbundle": "^3.0.13",
} "tslint": "^5.19.0",
"tslint-config-prettier": "^1.18.0"
},
"private": false,
"files": [
"ts/*",
"ts_web/*",
"dist/*",
"dist_web/*",
"dist_ts_web/*",
"assets/*",
"cli.js",
"npmextra.json",
"readme.md"
]
} }

28
readme.md Normal file
View File

@ -0,0 +1,28 @@
# @pushrocks/smartsystem
interact with the system you are running on
## Availabililty and Links
* [npmjs.org (npm package)](https://www.npmjs.com/package/@pushrocks/smartsystem)
* [gitlab.com (source)](https://gitlab.com/pushrocks/smartsystem)
* [github.com (source mirror)](https://github.com/pushrocks/smartsystem)
* [docs (typedoc)](https://pushrocks.gitlab.io/smartsystem/)
## Status for master
[![build status](https://gitlab.com/pushrocks/smartsystem/badges/master/build.svg)](https://gitlab.com/pushrocks/smartsystem/commits/master)
[![coverage report](https://gitlab.com/pushrocks/smartsystem/badges/master/coverage.svg)](https://gitlab.com/pushrocks/smartsystem/commits/master)
[![npm downloads per month](https://img.shields.io/npm/dm/@pushrocks/smartsystem.svg)](https://www.npmjs.com/package/@pushrocks/smartsystem)
[![Known Vulnerabilities](https://snyk.io/test/npm/@pushrocks/smartsystem/badge.svg)](https://snyk.io/test/npm/@pushrocks/smartsystem)
[![TypeScript](https://img.shields.io/badge/TypeScript->=%203.x-blue.svg)](https://nodejs.org/dist/latest-v10.x/docs/api/)
[![node](https://img.shields.io/badge/node->=%2010.x.x-blue.svg)](https://nodejs.org/dist/latest-v10.x/docs/api/)
[![JavaScript Style Guide](https://img.shields.io/badge/code%20style-prettier-ff69b4.svg)](https://prettier.io/)
## Usage
We recommend the use of TypeScript for best Intellisense
For further information read the linked docs at the top of this readme.
> MIT licensed | **&copy;** [Lossless GmbH](https://lossless.gmbh)
| By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy)
[![repo-footer](https://lossless.gitlab.io/publicrelations/repofooter.svg)](https://maintainedby.lossless.com)

View File

@ -1 +0,0 @@
export declare let exportedTestBoolean: boolean;

View File

@ -1,4 +0,0 @@
"use strict";
exports.exportedTestBoolean = true;
console.log('moduleExample loaded successfully');
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibW9kdWxlRXhhbXBsZS5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIm1vZHVsZUV4YW1wbGUudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFXLFFBQUEsbUJBQW1CLEdBQUcsSUFBSSxDQUFBO0FBRXJDLE9BQU8sQ0FBQyxHQUFHLENBQUMsbUNBQW1DLENBQUMsQ0FBQSJ9

View File

@ -1,3 +0,0 @@
export let exportedTestBoolean = true
import * as q from 'q'
console.log('moduleExample loaded successfully')

1
test/test.d.ts vendored
View File

@ -1 +0,0 @@
import 'typings-test';

View File

@ -1,13 +0,0 @@
"use strict";
require("typings-test");
const smartsystem = require("../dist/index");
describe('smartsystem', function () {
it('should load a module lazily', function (done) {
let lazyModuleExample = new smartsystem.LazyModule('./test/moduleExample.js');
lazyModuleExample.load().then(m => {
console.log(m.exportedTestBoolean);
done();
});
});
});
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidGVzdC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbInRlc3QudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLHdCQUFxQjtBQUVyQiw2Q0FBNEM7QUFJNUMsUUFBUSxDQUFDLGFBQWEsRUFBRTtJQUNwQixFQUFFLENBQUMsNkJBQTZCLEVBQUUsVUFBVSxJQUFJO1FBQzVDLElBQUksaUJBQWlCLEdBQUcsSUFBSSxXQUFXLENBQUMsVUFBVSxDQUF3Qix5QkFBeUIsQ0FBQyxDQUFBO1FBRXBHLGlCQUFpQixDQUFDLElBQUksRUFBRSxDQUFDLElBQUksQ0FBQyxDQUFDO1lBQzNCLE9BQU8sQ0FBQyxHQUFHLENBQUMsQ0FBQyxDQUFDLG1CQUFtQixDQUFDLENBQUE7WUFDbEMsSUFBSSxFQUFFLENBQUE7UUFDVixDQUFDLENBQUMsQ0FBQTtJQUNOLENBQUMsQ0FBQyxDQUFBO0FBQ04sQ0FBQyxDQUFDLENBQUEifQ==

View File

@ -1,16 +1,19 @@
import 'typings-test' import { tap, expect } from '@pushrocks/tapbundle';
import * as should from 'should' import * as smartsystem from '../ts/index';
import * as smartsystem from '../dist/index'
import * as _moduleExample from './moduleExample' let smartsystemInstance: smartsystem.Smartsystem;
describe('smartsystem', function () { tap.test('should create a smartsystem instance', async tools => {
it('should load a module lazily', function (done) { smartsystemInstance = new smartsystem.Smartsystem();
let lazyModuleExample = new smartsystem.LazyModule<typeof _moduleExample>('./test/moduleExample.js') expect(smartsystemInstance).to.be.instanceOf(smartsystem.Smartsystem);
});
lazyModuleExample.load().then(m => { tap.test('should state the operating system', async () => {
console.log(m.exportedTestBoolean) expect(smartsystemInstance.cpus.length).to.be.greaterThan(0);
done() });
})
}) tap.test('should get systeminformation', async () => {
}) console.log(await smartsystemInstance.information.networkInterfaceDefault());
});
tap.start();

View File

@ -1,78 +1,10 @@
import 'typings-global' import * as plugins from './smartsystem.plugins';
import * as path from 'path' export class Smartsystem {
import * as q from 'q' public env = new plugins.smartenv.Smartenv();
import { Objectmap } from 'lik' public cpus = plugins.os.cpus();
public network = new plugins.smartnetwork.SmartNetwork();
class Smartsystem { public get information() {
lazyModules = new Objectmap<LazyModule<any>>() return plugins.systeminformation;
}
/**
* 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
nameIsPath: boolean
cwd: string
whenLoaded: q.Promise<T>
loader: TLoader = 'npm'
private whenLoadedDeferred: q.Deferred<T>
constructor(nameArg: string, cwdArg: string = process.cwd()) {
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<T>()
this.whenLoaded = this.whenLoadedDeferred.promise
}
setLoader(loaderArg: TLoader) {
this.loader = loaderArg
}
/**
* loads the module
*/
load(): q.Promise<T> {
let done = q.defer<T>()
let loadedModule: T
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: LazyModule<any>[]) {
}
} }

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 smartnetwork from '@pushrocks/smartnetwork';
import * as smartpromise from '@pushrocks/smartpromise';
export { lik, smartenv, smartnetwork, smartpromise };
// third party
import * as systeminformation from 'systeminformation';
export { systeminformation };

View File

@ -1,3 +1,17 @@
{ {
"extends": "tslint-config-standard" "extends": ["tslint:latest", "tslint-config-prettier"],
"rules": {
"semicolon": [true, "always"],
"no-console": false,
"ordered-imports": false,
"object-literal-sort-keys": false,
"member-ordering": {
"options":{
"order": [
"static-method"
]
}
}
},
"defaultSeverity": "warning"
} }