Compare commits
55 Commits
Author | SHA1 | Date | |
---|---|---|---|
b584978287 | |||
44bfff2a6b | |||
af07a53053 | |||
2ace413435 | |||
16dfec29f4 | |||
10ab005343 | |||
9dded0eab5 | |||
c54ae3fdb4 | |||
3ae2f9a6b2 | |||
48959be97e | |||
658e60475a | |||
f6c64c6583 | |||
e3929a17ed | |||
a4734d9c10 | |||
a1139c5da4 | |||
a401fd2e8f | |||
8157371a1d | |||
719a9b32d7 | |||
a732d2a403 | |||
11fe4618ba | |||
f4290ca8fa | |||
04518f28cf | |||
0d6ea31bd2 | |||
60bd95093d | |||
05d4e0ff6d | |||
e05f7d32fd | |||
5f0ddc6600 | |||
d312d6ae5a | |||
8ca254595d | |||
7661ae506d | |||
4e8dd83839 | |||
7ab1a4eec7 | |||
3098fbec89 | |||
1caa8a7c31 | |||
c689a3c349 | |||
a8a0778708 | |||
82ebb181a0 | |||
adabcb3c4a | |||
32db51c49a | |||
62b91adf0e | |||
2f6a56c857 | |||
988cf907a4 | |||
18d79cb403 | |||
1d2c073206 | |||
fa85e689df | |||
e5d18a75f8 | |||
87c9556064 | |||
f4b8766dae | |||
ecaaaee54a | |||
46693c4bef | |||
cd7361bb96 | |||
d3b4a252e9 | |||
abc9e7888e | |||
193bf8f891 | |||
3932177fb0 |
22
.gitignore
vendored
22
.gitignore
vendored
@ -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
|
114
.gitlab-ci.yml
114
.gitlab-ci.yml
@ -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:
|
# ====================
|
||||||
stage: test
|
# security stage
|
||||||
|
# ====================
|
||||||
|
mirror:
|
||||||
|
stage: security
|
||||||
script:
|
script:
|
||||||
- npmci test stable
|
- npmci git mirror
|
||||||
tags:
|
tags:
|
||||||
- docker
|
- 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
|
||||||
|
script:
|
||||||
|
- npmci npm prepare
|
||||||
|
- npmci node install stable
|
||||||
|
- npmci npm install
|
||||||
|
- npmci npm test
|
||||||
|
coverage: /\d+.?\d+?\%\s*coverage/
|
||||||
|
tags:
|
||||||
|
- 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:
|
tags:
|
||||||
- docker
|
- docker
|
||||||
|
- notpriv
|
||||||
|
|
||||||
pages:
|
pages:
|
||||||
image: hosttoday/ht-docker-node:npmpage
|
image: hosttoday/ht-docker-dbase:npmci
|
||||||
stage: page
|
services:
|
||||||
|
- docker:stable-dind
|
||||||
|
stage: metadata
|
||||||
script:
|
script:
|
||||||
- npmci command npmpage --host gitlab
|
- npmci command npm install -g @gitzone/tsdoc
|
||||||
|
- npmci npm prepare
|
||||||
|
- npmci npm install
|
||||||
|
- npmci command tsdoc
|
||||||
|
tags:
|
||||||
|
- docker
|
||||||
|
- notpriv
|
||||||
only:
|
only:
|
||||||
- tags
|
- tags
|
||||||
artifacts:
|
artifacts:
|
||||||
expire_in: 1 week
|
expire_in: 1 week
|
||||||
paths:
|
paths:
|
||||||
- public
|
- public
|
||||||
|
allow_failure: true
|
||||||
|
44
README.md
44
README.md
@ -1,44 +0,0 @@
|
|||||||
# smartsystem
|
|
||||||
simplifies lazy loading with TypeScript
|
|
||||||
|
|
||||||
## Availabililty
|
|
||||||
[](https://www.npmjs.com/package/smartsystem)
|
|
||||||
[](https://gitlab.com/pushrocks/smartsystem)
|
|
||||||
[](https://github.com/pushrocks/smartsystem)
|
|
||||||
[](https://pushrocks.gitlab.io/smartsystem/)
|
|
||||||
|
|
||||||
## Status for master
|
|
||||||
[](https://gitlab.com/pushrocks/smartsystem/commits/master)
|
|
||||||
[](https://gitlab.com/pushrocks/smartsystem/commits/master)
|
|
||||||
[](https://david-dm.org/pushrocks/smartsystem)
|
|
||||||
[](https://www.bithound.io/github/pushrocks/smartsystem/master/dependencies/npm)
|
|
||||||
[](https://www.bithound.io/github/pushrocks/smartsystem)
|
|
||||||
[](https://nodejs.org/dist/latest-v6.x/docs/api/)
|
|
||||||
[](https://nodejs.org/dist/latest-v6.x/docs/api/)
|
|
||||||
[](http://standardjs.com/)
|
|
||||||
|
|
||||||
## Usage
|
|
||||||
We recommend the use of TypeScript for best Intellisense
|
|
||||||
|
|
||||||
```typescript
|
|
||||||
import { LazyModule } from 'smartsystem'
|
|
||||||
|
|
||||||
import * as myPluginType from 'myPlugin' // plugin does not get loaded here at runtime
|
|
||||||
let myPluginLazy = new LazyModule<typeof myPlugin>('myPlugin')
|
|
||||||
|
|
||||||
import * as anotherPluginType from 'anotherPlugin' // plugin does not get loaded here at runtime
|
|
||||||
let anotherPluginPromised = LazyModule<typeof anotherPlugin>('anotherPlugin')
|
|
||||||
|
|
||||||
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 */
|
|
||||||
})
|
|
||||||
```
|
|
21
dist/index.d.ts
vendored
21
dist/index.d.ts
vendored
@ -1,21 +0,0 @@
|
|||||||
/// <reference types="q" />
|
|
||||||
import * as q from 'q';
|
|
||||||
/**
|
|
||||||
* defines a LazyModule
|
|
||||||
*/
|
|
||||||
export declare class LazyModule<T> {
|
|
||||||
name: string;
|
|
||||||
nameIsPath: boolean;
|
|
||||||
cwd: string;
|
|
||||||
whenLoaded: q.Promise<T>;
|
|
||||||
private whenLoadedDeferred;
|
|
||||||
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;
|
|
||||||
}
|
|
50
dist/index.js
vendored
50
dist/index.js
vendored
@ -1,50 +0,0 @@
|
|||||||
"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); // add module to smartsystem instance
|
|
||||||
this.nameIsPath = /\.\//.test(this.name); // figure out if name is path
|
|
||||||
this.whenLoadedDeferred = q.defer();
|
|
||||||
this.whenLoaded = this.whenLoadedDeferred.promise;
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* loads the module
|
|
||||||
*/
|
|
||||||
load() {
|
|
||||||
let done = q.defer();
|
|
||||||
let loadedModule;
|
|
||||||
systemjs.import(this.name).then((m) => {
|
|
||||||
loadedModule = m;
|
|
||||||
this.whenLoadedDeferred.resolve(loadedModule);
|
|
||||||
done.resolve(loadedModule);
|
|
||||||
}).catch(err => { console.log(err); });
|
|
||||||
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,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBRUEsdUJBQXNCO0FBQ3RCLDZCQUErQjtBQUMvQixJQUFJLFFBQVEsR0FBRyxPQUFPLENBQUMsVUFBVSxDQUFDLENBQUE7QUFFbEM7SUFBQTtRQUNJLGdCQUFXLEdBQUcsSUFBSSxlQUFTLEVBQW1CLENBQUE7SUFRbEQsQ0FBQztJQU5HOztPQUVHO0lBQ0gsYUFBYSxDQUFDLGFBQThCO1FBQ3hDLElBQUksQ0FBQyxXQUFXLENBQUMsR0FBRyxDQUFDLGFBQWEsQ0FBQyxDQUFBO0lBQ3ZDLENBQUM7Q0FDSjtBQUVELGtDQUFrQztBQUNsQyxJQUFJLFdBQVcsR0FBRyxJQUFJLFdBQVcsRUFBRSxDQUFBO0FBRW5DOztHQUVHO0FBQ0g7SUFNSSxZQUFZLE9BQWUsRUFBRSxNQUFNLEdBQVcsT0FBTyxDQUFDLEdBQUcsRUFBRTtRQUN2RCxJQUFJLENBQUMsSUFBSSxHQUFHLE9BQU8sQ0FBQTtRQUNuQixJQUFJLENBQUMsR0FBRyxHQUFHLE1BQU0sQ0FBQTtRQUNqQixXQUFXLENBQUMsYUFBYSxDQUFDLElBQUksQ0FBQyxDQUFBLENBQUMscUNBQXFDO1FBQ3JFLElBQUksQ0FBQyxVQUFVLEdBQUcsTUFBTSxDQUFDLElBQUksQ0FBQyxJQUFJLENBQUMsSUFBSSxDQUFDLENBQUEsQ0FBQyw2QkFBNkI7UUFDdEUsSUFBSSxDQUFDLGtCQUFrQixHQUFHLENBQUMsQ0FBQyxLQUFLLEVBQUssQ0FBQTtRQUN0QyxJQUFJLENBQUMsVUFBVSxHQUFHLElBQUksQ0FBQyxrQkFBa0IsQ0FBQyxPQUFPLENBQUE7SUFDckQsQ0FBQztJQUVEOztPQUVHO0lBQ0gsSUFBSTtRQUNBLElBQUksSUFBSSxHQUFHLENBQUMsQ0FBQyxLQUFLLEVBQUssQ0FBQTtRQUN2QixJQUFJLFlBQWUsQ0FBQTtRQUNuQixRQUFRLENBQUMsTUFBTSxDQUFDLElBQUksQ0FBQyxJQUFJLENBQUMsQ0FBQyxJQUFJLENBQUMsQ0FBQyxDQUFDO1lBQzlCLFlBQVksR0FBRyxDQUFDLENBQUE7WUFDaEIsSUFBSSxDQUFDLGtCQUFrQixDQUFDLE9BQU8sQ0FBQyxZQUFZLENBQUMsQ0FBQTtZQUM3QyxJQUFJLENBQUMsT0FBTyxDQUFDLFlBQVksQ0FBQyxDQUFBO1FBQzlCLENBQUMsQ0FBQyxDQUFDLEtBQUssQ0FBQyxHQUFHLE1BQU0sT0FBTyxDQUFDLEdBQUcsQ0FBQyxHQUFHLENBQUMsQ0FBQSxDQUFDLENBQUMsQ0FBQyxDQUFBO1FBQ3JDLE1BQU0sQ0FBQyxJQUFJLENBQUMsT0FBTyxDQUFBO0lBQ3ZCLENBQUM7SUFFRDs7T0FFRztJQUNILFFBQVEsQ0FBQyxHQUFHLElBQXVCO0lBRW5DLENBQUM7Q0FDSjtBQW5DRCxnQ0FtQ0MifQ==
|
|
69
docs/index.md
Normal file
69
docs/index.md
Normal file
@ -0,0 +1,69 @@
|
|||||||
|
---
|
||||||
|
name: smartsystem
|
||||||
|
description: simplifies lazy loading with TypeScript
|
||||||
|
---
|
||||||
|
|
||||||
|
# smartsystem
|
||||||
|
|
||||||
|
simplifies lazy loading with TypeScript
|
||||||
|
|
||||||
|
## Availabililty
|
||||||
|
|
||||||
|
[](https://www.npmjs.com/package/smartsystem)
|
||||||
|
[](https://GitLab.com/pushrocks/smartsystem)
|
||||||
|
[](https://github.com/pushrocks/smartsystem)
|
||||||
|
[](https://pushrocks.gitlab.io/smartsystem/)
|
||||||
|
|
||||||
|
## Status for master
|
||||||
|
|
||||||
|
[](https://GitLab.com/pushrocks/smartsystem/commits/master)
|
||||||
|
[](https://GitLab.com/pushrocks/smartsystem/commits/master)
|
||||||
|
[](https://www.npmjs.com/package/smartsystem)
|
||||||
|
[](https://david-dm.org/pushrocks/smartsystem)
|
||||||
|
[](https://www.bithound.io/github/pushrocks/smartsystem/master/dependencies/npm)
|
||||||
|
[](https://www.bithound.io/github/pushrocks/smartsystem)
|
||||||
|
[](https://nodejs.org/dist/latest-v6.x/docs/api/)
|
||||||
|
[](https://nodejs.org/dist/latest-v6.x/docs/api/)
|
||||||
|
[](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 | **©** [Lossless GmbH](https://lossless.gmbh)
|
||||||
|
> | By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy.html)
|
||||||
|
|
||||||
|
[](https://push.rocks)
|
16
npmextra.json
Normal file
16
npmextra.json
Normal 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
2157
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
45
package.json
45
package.json
@ -1,16 +1,22 @@
|
|||||||
{
|
{
|
||||||
"name": "smartsystem",
|
"name": "@pushrocks/smartsystem",
|
||||||
"version": "1.0.1",
|
"version": "2.0.9",
|
||||||
"description": "wraps systemjs for smarter workflows",
|
"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",
|
||||||
"url": "git+ssh://git@gitlab.com/pushrocks/smartsystem.git"
|
"url": "git+ssh://git@gitlab.com/pushrocks/smartsystem.git"
|
||||||
},
|
},
|
||||||
|
"keywords": [
|
||||||
|
"TypeScript",
|
||||||
|
"lazy",
|
||||||
|
"module loader"
|
||||||
|
],
|
||||||
"author": "Lossless GmbH",
|
"author": "Lossless GmbH",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"bugs": {
|
"bugs": {
|
||||||
@ -18,14 +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",
|
||||||
|
"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
28
readme.md
Normal 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
|
||||||
|
[](https://gitlab.com/pushrocks/smartsystem/commits/master)
|
||||||
|
[](https://gitlab.com/pushrocks/smartsystem/commits/master)
|
||||||
|
[](https://www.npmjs.com/package/@pushrocks/smartsystem)
|
||||||
|
[](https://snyk.io/test/npm/@pushrocks/smartsystem)
|
||||||
|
[](https://nodejs.org/dist/latest-v10.x/docs/api/)
|
||||||
|
[](https://nodejs.org/dist/latest-v10.x/docs/api/)
|
||||||
|
[](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 | **©** [Lossless GmbH](https://lossless.gmbh)
|
||||||
|
| By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy)
|
||||||
|
|
||||||
|
[](https://maintainedby.lossless.com)
|
1
test/moduleExample.d.ts
vendored
1
test/moduleExample.d.ts
vendored
@ -1 +0,0 @@
|
|||||||
export declare let exportedTestBoolean: boolean;
|
|
@ -1,4 +0,0 @@
|
|||||||
"use strict";
|
|
||||||
exports.exportedTestBoolean = true;
|
|
||||||
console.log('moduleExample loaded successfully');
|
|
||||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibW9kdWxlRXhhbXBsZS5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIm1vZHVsZUV4YW1wbGUudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFXLFFBQUEsbUJBQW1CLEdBQUcsSUFBSSxDQUFBO0FBQ3JDLE9BQU8sQ0FBQyxHQUFHLENBQUMsbUNBQW1DLENBQUMsQ0FBQSJ9
|
|
@ -1,2 +0,0 @@
|
|||||||
export let exportedTestBoolean = true
|
|
||||||
console.log('moduleExample loaded successfully')
|
|
1
test/test.d.ts
vendored
1
test/test.d.ts
vendored
@ -1 +0,0 @@
|
|||||||
import 'typings-test';
|
|
13
test/test.js
13
test/test.js
@ -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==
|
|
29
test/test.ts
29
test/test.ts
@ -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();
|
||||||
|
63
ts/index.ts
63
ts/index.ts
@ -1,59 +1,10 @@
|
|||||||
import * as plugins from './smartsystem.plugins'
|
import * as plugins from './smartsystem.plugins';
|
||||||
|
|
||||||
import * as q from 'q'
|
|
||||||
import { Objectmap } from 'lik'
|
|
||||||
let systemjs = require('systemjs')
|
|
||||||
|
|
||||||
class Smartsystem {
|
|
||||||
lazyModules = new Objectmap<LazyModule<any>>()
|
|
||||||
|
|
||||||
/**
|
|
||||||
* add lazyModule to Smartsystem
|
|
||||||
*/
|
|
||||||
addLazyModule(lazyModuleArg: LazyModule<any>) {
|
|
||||||
this.lazyModules.add(lazyModuleArg)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// create the internal smartsystem
|
|
||||||
let smartsystem = new Smartsystem()
|
|
||||||
|
|
||||||
/**
|
|
||||||
* defines a LazyModule
|
|
||||||
*/
|
|
||||||
export class LazyModule<T> {
|
|
||||||
name: string
|
|
||||||
nameIsPath: boolean
|
|
||||||
cwd: string
|
|
||||||
whenLoaded: q.Promise<T>
|
|
||||||
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
|
|
||||||
this.whenLoadedDeferred = q.defer<T>()
|
|
||||||
this.whenLoaded = this.whenLoadedDeferred.promise
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* loads the module
|
|
||||||
*/
|
|
||||||
load(): q.Promise<T> {
|
|
||||||
let done = q.defer<T>()
|
|
||||||
let loadedModule: T
|
|
||||||
systemjs.import(this.name).then((m) => {
|
|
||||||
loadedModule = m
|
|
||||||
this.whenLoadedDeferred.resolve(loadedModule)
|
|
||||||
done.resolve(loadedModule)
|
|
||||||
}).catch(err => { console.log(err) })
|
|
||||||
return done.promise
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* loads additional lazy modules specified as arguments and returns them in the promise for easy use
|
|
||||||
*/
|
|
||||||
loadAlso(...args: LazyModule<any>[]) {
|
|
||||||
|
|
||||||
|
export class Smartsystem {
|
||||||
|
public env = new plugins.smartenv.Smartenv();
|
||||||
|
public cpus = plugins.os.cpus();
|
||||||
|
public network = new plugins.smartnetwork.SmartNetwork();
|
||||||
|
public get information() {
|
||||||
|
return plugins.systeminformation;
|
||||||
}
|
}
|
||||||
}
|
}
|
16
ts/smartsystem.plugins.ts
Normal file
16
ts/smartsystem.plugins.ts
Normal 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 };
|
16
tslint.json
16
tslint.json
@ -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"
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user