47 Commits

Author SHA1 Message Date
b02ee5e9f4 2.0.10 2021-08-12 23:35:40 +02:00
93153baa95 fix(core): update 2021-08-12 23:35:39 +02:00
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
62b91adf0e 1.0.9 2016-10-14 04:08:43 +02:00
2f6a56c857 improve README 2016-10-14 04:08:38 +02:00
988cf907a4 1.0.8 2016-10-14 03:28:18 +02:00
18d79cb403 improve README 2016-10-14 03:27:52 +02:00
1d2c073206 1.0.7 2016-10-14 03:24:32 +02:00
fa85e689df add npm as default module loader 2016-10-14 03:24:29 +02:00
21 changed files with 25981 additions and 293 deletions

20
.gitignore vendored
View File

@ -1,4 +1,20 @@
node_modules/ .nogit/
# artifacts
coverage/ coverage/
pages/
public/ public/
pages/
# installs
node_modules/
# caches
.yarn/
.cache/
.rpt2_cache
# builds
dist/
dist_*/
# custom

View File

@ -1,53 +1,137 @@
image: hosttoday/ht-docker-node:npmts # gitzone ci_default
stages: image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
- test
- release
- trigger
- page
testLEGACY:
stage: test
script:
- npmci test legacy
tags:
- docker
allow_failure: true
testLTS:
stage: test
script:
- npmci test lts
tags:
- docker
testSTABLE: cache:
stage: test paths:
- .npmci_cache/
key: '$CI_BUILD_STAGE'
stages:
- security
- test
- release
- metadata
# ====================
# security stage
# ====================
mirror:
stage: security
script: script:
- npmci test stable - npmci git mirror
tags:
- docker
release:
stage: release
script:
- npmci publish
only: only:
- tags - tags
tags: tags:
- lossless
- docker - docker
- notpriv
auditProductionDependencies:
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
stage: security
script:
- npmci npm prepare
- npmci command npm install --production --ignore-scripts
- npmci command npm config set registry https://registry.npmjs.org
- npmci command npm audit --audit-level=high --only=prod --production
tags:
- docker
auditDevDependencies:
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
stage: security
script:
- npmci npm prepare
- npmci command npm install --ignore-scripts
- npmci command npm config set registry https://registry.npmjs.org
- npmci command npm audit --audit-level=high --only=dev
tags:
- docker
allow_failure: true
# ====================
# 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
testBuild:
stage: test
script:
- npmci npm prepare
- npmci node install stable
- npmci npm install
- npmci command npm run build
coverage: /\d+.?\d+?\%\s*coverage/
tags:
- docker
release:
stage: release
script:
- npmci node install stable
- npmci npm publish
only:
- tags
tags:
- lossless
- docker
- notpriv
# ====================
# metadata stage
# ====================
codequality:
stage: metadata
allow_failure: true
only:
- tags
script:
- npmci command npm install -g tslint typescript
- npmci npm prepare
- npmci npm install
- npmci command "tslint -c tslint.json ./ts/**/*.ts"
tags:
- lossless
- docker
- priv
trigger: trigger:
stage: trigger stage: metadata
script: script:
- npmci trigger - npmci trigger
only: only:
- tags - tags
tags: tags:
- lossless
- docker - docker
- notpriv
pages: pages:
image: hosttoday/ht-docker-node:npmpage stage: metadata
stage: page
script: script:
- npmci command npmpage --host gitlab - npmci node install lts
- npmci command npm install -g @gitzone/tsdoc
- npmci npm prepare
- npmci npm install
- npmci command tsdoc
tags:
- lossless
- docker
- notpriv
only: only:
- tags - tags
artifacts: artifacts:
expire_in: 1 week expire_in: 1 week
paths: paths:
- public - public
allow_failure: true

29
.vscode/launch.json vendored Normal file
View File

@ -0,0 +1,29 @@
{
"version": "0.2.0",
"configurations": [
{
"name": "current file",
"type": "node",
"request": "launch",
"args": [
"${relativeFile}"
],
"runtimeArgs": ["-r", "@gitzone/tsrun"],
"cwd": "${workspaceRoot}",
"protocol": "inspector",
"internalConsoleOptions": "openOnSessionStart"
},
{
"name": "test.ts",
"type": "node",
"request": "launch",
"args": [
"test/test.ts"
],
"runtimeArgs": ["-r", "@gitzone/tsrun"],
"cwd": "${workspaceRoot}",
"protocol": "inspector",
"internalConsoleOptions": "openOnSessionStart"
}
]
}

26
.vscode/settings.json vendored Normal file
View File

@ -0,0 +1,26 @@
{
"json.schemas": [
{
"fileMatch": ["/npmextra.json"],
"schema": {
"type": "object",
"properties": {
"npmci": {
"type": "object",
"description": "settings for npmci"
},
"gitzone": {
"type": "object",
"description": "settings for gitzone",
"properties": {
"projectType": {
"type": "string",
"enum": ["website", "element", "service", "npm", "wcc"]
}
}
}
}
}
}
]
}

View File

@ -1,44 +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
```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')
import * as _anotherPlugin from 'anotherPlugin' // plugin does not get loaded here at runtime
let anotherPluginLazy = new 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 */
})
```

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;
}

63
dist/index.js vendored
View File

@ -1,63 +0,0 @@
"use strict";
require("typings-global");
const path = require("path");
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();
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;
let loadingPath;
if (this.loader === 'npm') {
loadingPath = require.resolve(this.name);
}
else {
loadingPath = this.name;
}
systemjs.import(loadingPath).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,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQUEsMEJBQXVCO0FBRXZCLDZCQUE0QjtBQUM1Qix1QkFBc0I7QUFDdEIsNkJBQStCO0FBQy9CLElBQUksUUFBUSxHQUFHLE9BQU8sQ0FBQyxVQUFVLENBQUMsQ0FBQTtBQUVsQztJQUFBO1FBQ0ksZ0JBQVcsR0FBRyxJQUFJLGVBQVMsRUFBbUIsQ0FBQTtJQVFsRCxDQUFDO0lBTkc7O09BRUc7SUFDSCxhQUFhLENBQUMsYUFBOEI7UUFDeEMsSUFBSSxDQUFDLFdBQVcsQ0FBQyxHQUFHLENBQUMsYUFBYSxDQUFDLENBQUE7SUFDdkMsQ0FBQztDQUNKO0FBRUQsa0NBQWtDO0FBQ2xDLElBQUksV0FBVyxHQUFHLElBQUksV0FBVyxFQUFFLENBQUE7QUFRbkM7SUFPSSxZQUFZLE9BQWUsRUFBRSxNQUFNLEdBQVcsT0FBTyxDQUFDLEdBQUcsRUFBRTtRQUYzRCxXQUFNLEdBQVksS0FBSyxDQUFBO1FBR25CLElBQUksQ0FBQyxJQUFJLEdBQUcsT0FBTyxDQUFBO1FBQ25CLElBQUksQ0FBQyxHQUFHLEdBQUcsTUFBTSxDQUFBO1FBQ2pCLFdBQVcsQ0FBQyxhQUFhLENBQUMsSUFBSSxDQUFDLENBQUEsQ0FBQyxxQ0FBcUM7UUFDckUsSUFBSSxDQUFDLFVBQVUsR0FBRyxNQUFNLENBQUMsSUFBSSxDQUFDLElBQUksQ0FBQyxJQUFJLENBQUMsQ0FBQSxDQUFDLDZCQUE2QjtRQUN0RSxFQUFFLENBQUMsQ0FBQyxJQUFJLENBQUMsVUFBVSxDQUFDLENBQUMsQ0FBQztZQUNsQixJQUFJLENBQUMsSUFBSSxHQUFHLElBQUksQ0FBQyxJQUFJLENBQUMsSUFBSSxDQUFDLEdBQUcsRUFBRSxJQUFJLENBQUMsSUFBSSxDQUFDLENBQUE7UUFDOUMsQ0FBQztRQUNELElBQUksQ0FBQyxrQkFBa0IsR0FBRyxDQUFDLENBQUMsS0FBSyxFQUFLLENBQUE7UUFDdEMsSUFBSSxDQUFDLFVBQVUsR0FBRyxJQUFJLENBQUMsa0JBQWtCLENBQUMsT0FBTyxDQUFBO0lBQ3JELENBQUM7SUFFRCxTQUFTLENBQUMsU0FBa0I7UUFDeEIsSUFBSSxDQUFDLE1BQU0sR0FBRyxTQUFTLENBQUE7SUFDM0IsQ0FBQztJQUVEOztPQUVHO0lBQ0gsSUFBSTtRQUNBLElBQUksSUFBSSxHQUFHLENBQUMsQ0FBQyxLQUFLLEVBQUssQ0FBQTtRQUN2QixJQUFJLFlBQWUsQ0FBQTtRQUNuQixJQUFJLFdBQW1CLENBQUE7UUFDdkIsRUFBRSxDQUFDLENBQUMsSUFBSSxDQUFDLE1BQU0sS0FBSyxLQUFLLENBQUMsQ0FBQyxDQUFDO1lBQ3hCLFdBQVcsR0FBRyxPQUFPLENBQUMsT0FBTyxDQUFDLElBQUksQ0FBQyxJQUFJLENBQUMsQ0FBQTtRQUM1QyxDQUFDO1FBQUMsSUFBSSxDQUFDLENBQUM7WUFDSixXQUFXLEdBQUcsSUFBSSxDQUFDLElBQUksQ0FBQTtRQUMzQixDQUFDO1FBQ0QsUUFBUSxDQUFDLE1BQU0sQ0FBQyxXQUFXLENBQUMsQ0FBQyxJQUFJLENBQUMsQ0FBQyxDQUFDO1lBQ2hDLFlBQVksR0FBRyxDQUFDLENBQUE7WUFDaEIsSUFBSSxDQUFDLGtCQUFrQixDQUFDLE9BQU8sQ0FBQyxZQUFZLENBQUMsQ0FBQTtZQUM3QyxJQUFJLENBQUMsT0FBTyxDQUFDLFlBQVksQ0FBQyxDQUFBO1FBQzlCLENBQUMsQ0FBQyxDQUFDLEtBQUssQ0FBQyxHQUFHLE1BQU0sT0FBTyxDQUFDLEdBQUcsQ0FBQyxHQUFHLENBQUMsQ0FBQSxDQUFDLENBQUMsQ0FBQyxDQUFBO1FBQ3JDLE1BQU0sQ0FBQyxJQUFJLENBQUMsT0FBTyxDQUFBO0lBQ3ZCLENBQUM7SUFFRDs7T0FFRztJQUNILFFBQVEsQ0FBQyxHQUFHLElBQXVCO0lBRW5DLENBQUM7Q0FDSjtBQWpERCxnQ0FpREMifQ==

69
docs/index.md Normal file
View File

@ -0,0 +1,69 @@
---
name: smartsystem
description: simplifies lazy loading with TypeScript
---
# smartsystem
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)

17
npmextra.json Normal file
View File

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

25575
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.6", "version": "2.0.10",
"description": "simplifies lazy loading with TypeScript", "description": "interact with the system you are running on",
"main": "dist/index.js", "main": "dist_ts/index.js",
"typings": "dist/index.d.ts", "typings": "dist_ts/index.d.ts",
"scripts": { "scripts": {
"test": "(npmts)" "test": "(tstest test/)",
"build": "(tsbuild)"
}, },
"repository": { "repository": {
"type": "git", "type": "git",
@ -23,15 +24,33 @@
}, },
"homepage": "https://gitlab.com/pushrocks/smartsystem#README", "homepage": "https://gitlab.com/pushrocks/smartsystem#README",
"dependencies": { "dependencies": {
"@types/q": "0.0.32", "@pushrocks/lik": "^4.0.20",
"lik": "^1.0.24", "@pushrocks/smartenv": "^4.0.16",
"q": "^1.4.1", "@pushrocks/smartnetwork": "^2.0.10",
"systemjs": "^0.19.39", "@pushrocks/smartpromise": "^3.1.6",
"typings-global": "^1.0.14" "systeminformation": "^5.8.0"
}, },
"devDependencies": { "devDependencies": {
"@types/should": "^8.1.30", "@gitzone/tsbuild": "^2.1.25",
"should": "^11.1.1", "@gitzone/tstest": "^1.0.54",
"typings-test": "^1.0.3" "@pushrocks/tapbundle": "^3.2.14",
} "tslint": "^6.1.3",
"tslint-config-prettier": "^1.18.0"
},
"private": false,
"files": [
"ts/**/*",
"ts_web/**/*",
"dist/**/*",
"dist_*/**/*",
"dist_ts/**/*",
"dist_ts_web/**/*",
"assets/**/*",
"cli.js",
"npmextra.json",
"readme.md"
],
"browserslist": [
"last 1 chrome versions"
]
} }

40
readme.md Normal file
View File

@ -0,0 +1,40 @@
# @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
Status Category | Status Badge
-- | --
GitLab Pipelines | [![pipeline status](https://gitlab.com/pushrocks/smartsystem/badges/master/pipeline.svg)](https://lossless.cloud)
GitLab Pipline Test Coverage | [![coverage report](https://gitlab.com/pushrocks/smartsystem/badges/master/coverage.svg)](https://lossless.cloud)
npm | [![npm downloads per month](https://badgen.net/npm/dy/@pushrocks/smartsystem)](https://lossless.cloud)
Snyk | [![Known Vulnerabilities](https://badgen.net/snyk/pushrocks/smartsystem)](https://lossless.cloud)
TypeScript Support | [![TypeScript](https://badgen.net/badge/TypeScript/>=%203.x/blue?icon=typescript)](https://lossless.cloud)
node Support | [![node](https://img.shields.io/badge/node->=%2010.x.x-blue.svg)](https://nodejs.org/dist/latest-v10.x/docs/api/)
Code Style | [![Code Style](https://badgen.net/badge/style/prettier/purple)](https://lossless.cloud)
PackagePhobia (total standalone install weight) | [![PackagePhobia](https://badgen.net/packagephobia/install/@pushrocks/smartsystem)](https://lossless.cloud)
PackagePhobia (package size on registry) | [![PackagePhobia](https://badgen.net/packagephobia/publish/@pushrocks/smartsystem)](https://lossless.cloud)
BundlePhobia (total size when bundled) | [![BundlePhobia](https://badgen.net/bundlephobia/minzip/@pushrocks/smartsystem)](https://lossless.cloud)
Platform support | [![Supports Windows 10](https://badgen.net/badge/supports%20Windows%2010/yes/green?icon=windows)](https://lossless.cloud) [![Supports Mac OS X](https://badgen.net/badge/supports%20Mac%20OS%20X/yes/green?icon=apple)](https://lossless.cloud)
## Usage
We recommend the use of TypeScript for best Intellisense
## Contribution
We are always happy for code contributions. If you are not the code contributing type that is ok. Still, maintaining Open Source repositories takes considerable time and thought. If you like the quality of what we do and our modules are useful to you we would appreciate a little monthly contribution: You can [contribute one time](https://lossless.link/contribute-onetime) or [contribute monthly](https://lossless.link/contribute). :)
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,20 @@
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 { systeminformation } from '../ts/smartsystem.plugins';
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,77 +1,10 @@
import 'typings-global' import * as plugins from './smartsystem.plugins';
import * as path from 'path'
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 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
let loadingPath: string
if (this.loader === 'npm') {
loadingPath = require.resolve(this.name)
} else {
loadingPath = this.name
}
systemjs.import(loadingPath).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
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"
} }