Compare commits
57 Commits
Author | SHA1 | Date | |
---|---|---|---|
dea8ca6021 | |||
c5d531fc09 | |||
66db546d67 | |||
8956f4be89 | |||
b02ee5e9f4 | |||
93153baa95 | |||
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 |
20
.gitignore
vendored
20
.gitignore
vendored
@ -1,4 +1,20 @@
|
||||
node_modules/
|
||||
.nogit/
|
||||
|
||||
# artifacts
|
||||
coverage/
|
||||
pages/
|
||||
public/
|
||||
pages/
|
||||
|
||||
# installs
|
||||
node_modules/
|
||||
|
||||
# caches
|
||||
.yarn/
|
||||
.cache/
|
||||
.rpt2_cache
|
||||
|
||||
# builds
|
||||
dist/
|
||||
dist_*/
|
||||
|
||||
# custom
|
111
.gitlab-ci.yml
111
.gitlab-ci.yml
@ -1,53 +1,128 @@
|
||||
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:
|
||||
- test
|
||||
- release
|
||||
- trigger
|
||||
- page
|
||||
testLEGACY:
|
||||
stage: test
|
||||
- security
|
||||
- test
|
||||
- release
|
||||
- metadata
|
||||
|
||||
before_script:
|
||||
- npm install -g @shipzone/npmci
|
||||
|
||||
# ====================
|
||||
# security stage
|
||||
# ====================
|
||||
auditProductionDependencies:
|
||||
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||
stage: security
|
||||
script:
|
||||
- npmci test legacy
|
||||
- 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
|
||||
allow_failure: true
|
||||
testLTS:
|
||||
|
||||
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 test lts
|
||||
- npmci npm prepare
|
||||
- npmci node install stable
|
||||
- npmci npm install
|
||||
- npmci npm test
|
||||
coverage: /\d+.?\d+?\%\s*coverage/
|
||||
tags:
|
||||
- docker
|
||||
|
||||
testSTABLE:
|
||||
testBuild:
|
||||
stage: test
|
||||
script:
|
||||
- npmci test stable
|
||||
- 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 publish
|
||||
- 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 typescript
|
||||
- npmci npm prepare
|
||||
- npmci npm install
|
||||
tags:
|
||||
- lossless
|
||||
- docker
|
||||
- priv
|
||||
|
||||
trigger:
|
||||
stage: trigger
|
||||
stage: metadata
|
||||
script:
|
||||
- npmci trigger
|
||||
only:
|
||||
- tags
|
||||
tags:
|
||||
- lossless
|
||||
- docker
|
||||
- notpriv
|
||||
|
||||
pages:
|
||||
image: hosttoday/ht-docker-node:npmpage
|
||||
stage: page
|
||||
stage: metadata
|
||||
script:
|
||||
- npmci command npmpage --host gitlab
|
||||
- npmci node install stable
|
||||
- npmci npm prepare
|
||||
- npmci npm install
|
||||
- npmci command npm run buildDocs
|
||||
tags:
|
||||
- lossless
|
||||
- docker
|
||||
- notpriv
|
||||
only:
|
||||
- tags
|
||||
artifacts:
|
||||
expire_in: 1 week
|
||||
paths:
|
||||
- public
|
||||
- public
|
||||
allow_failure: true
|
||||
|
11
.vscode/launch.json
vendored
Normal file
11
.vscode/launch.json
vendored
Normal file
@ -0,0 +1,11 @@
|
||||
{
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"command": "npm test",
|
||||
"name": "Run npm test",
|
||||
"request": "launch",
|
||||
"type": "node-terminal"
|
||||
}
|
||||
]
|
||||
}
|
26
.vscode/settings.json
vendored
Normal file
26
.vscode/settings.json
vendored
Normal 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"]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
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 _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 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 */
|
||||
})
|
||||
```
|
22
dist/index.d.ts
vendored
22
dist/index.d.ts
vendored
@ -1,22 +0,0 @@
|
||||
/// <reference types="q" />
|
||||
import 'typings-global';
|
||||
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;
|
||||
}
|
51
dist/index.js
vendored
51
dist/index.js
vendored
@ -1,51 +0,0 @@
|
||||
"use strict";
|
||||
require("typings-global");
|
||||
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,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQUEsMEJBQXVCO0FBRXZCLHVCQUFzQjtBQUN0Qiw2QkFBK0I7QUFDL0IsSUFBSSxRQUFRLEdBQUcsT0FBTyxDQUFDLFVBQVUsQ0FBQyxDQUFBO0FBRWxDO0lBQUE7UUFDSSxnQkFBVyxHQUFHLElBQUksZUFBUyxFQUFtQixDQUFBO0lBUWxELENBQUM7SUFORzs7T0FFRztJQUNILGFBQWEsQ0FBQyxhQUE4QjtRQUN4QyxJQUFJLENBQUMsV0FBVyxDQUFDLEdBQUcsQ0FBQyxhQUFhLENBQUMsQ0FBQTtJQUN2QyxDQUFDO0NBQ0o7QUFFRCxrQ0FBa0M7QUFDbEMsSUFBSSxXQUFXLEdBQUcsSUFBSSxXQUFXLEVBQUUsQ0FBQTtBQUVuQzs7R0FFRztBQUNIO0lBTUksWUFBWSxPQUFlLEVBQUUsTUFBTSxHQUFXLE9BQU8sQ0FBQyxHQUFHLEVBQUU7UUFDdkQsSUFBSSxDQUFDLElBQUksR0FBRyxPQUFPLENBQUE7UUFDbkIsSUFBSSxDQUFDLEdBQUcsR0FBRyxNQUFNLENBQUE7UUFDakIsV0FBVyxDQUFDLGFBQWEsQ0FBQyxJQUFJLENBQUMsQ0FBQSxDQUFDLHFDQUFxQztRQUNyRSxJQUFJLENBQUMsVUFBVSxHQUFHLE1BQU0sQ0FBQyxJQUFJLENBQUMsSUFBSSxDQUFDLElBQUksQ0FBQyxDQUFBLENBQUMsNkJBQTZCO1FBQ3RFLElBQUksQ0FBQyxrQkFBa0IsR0FBRyxDQUFDLENBQUMsS0FBSyxFQUFLLENBQUE7UUFDdEMsSUFBSSxDQUFDLFVBQVUsR0FBRyxJQUFJLENBQUMsa0JBQWtCLENBQUMsT0FBTyxDQUFBO0lBQ3JELENBQUM7SUFFRDs7T0FFRztJQUNILElBQUk7UUFDQSxJQUFJLElBQUksR0FBRyxDQUFDLENBQUMsS0FBSyxFQUFLLENBQUE7UUFDdkIsSUFBSSxZQUFlLENBQUE7UUFDbkIsUUFBUSxDQUFDLE1BQU0sQ0FBQyxJQUFJLENBQUMsSUFBSSxDQUFDLENBQUMsSUFBSSxDQUFDLENBQUMsQ0FBQztZQUM5QixZQUFZLEdBQUcsQ0FBQyxDQUFBO1lBQ2hCLElBQUksQ0FBQyxrQkFBa0IsQ0FBQyxPQUFPLENBQUMsWUFBWSxDQUFDLENBQUE7WUFDN0MsSUFBSSxDQUFDLE9BQU8sQ0FBQyxZQUFZLENBQUMsQ0FBQTtRQUM5QixDQUFDLENBQUMsQ0FBQyxLQUFLLENBQUMsR0FBRyxNQUFNLE9BQU8sQ0FBQyxHQUFHLENBQUMsR0FBRyxDQUFDLENBQUEsQ0FBQyxDQUFDLENBQUMsQ0FBQTtRQUNyQyxNQUFNLENBQUMsSUFBSSxDQUFDLE9BQU8sQ0FBQTtJQUN2QixDQUFDO0lBRUQ7O09BRUc7SUFDSCxRQUFRLENBQUMsR0FBRyxJQUF1QjtJQUVuQyxDQUFDO0NBQ0o7QUFuQ0QsZ0NBbUNDIn0=
|
17
npmextra.json
Normal file
17
npmextra.json
Normal file
@ -0,0 +1,17 @@
|
||||
{
|
||||
"npmci": {
|
||||
"npmGlobalTools": [],
|
||||
"npmAccessLevel": "public"
|
||||
},
|
||||
"gitzone": {
|
||||
"projectType": "npm",
|
||||
"module": {
|
||||
"githost": "gitlab.com",
|
||||
"gitscope": "pushrocks",
|
||||
"gitrepo": "smartsystem",
|
||||
"description": "interact with the system you are running on",
|
||||
"npmPackagename": "@pushrocks/smartsystem",
|
||||
"license": "MIT"
|
||||
}
|
||||
}
|
||||
}
|
14753
package-lock.json
generated
Normal file
14753
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
56
package.json
56
package.json
@ -1,16 +1,24 @@
|
||||
{
|
||||
"name": "smartsystem",
|
||||
"version": "1.0.3",
|
||||
"description": "wraps systemjs for smarter workflows",
|
||||
"main": "dist/index.js",
|
||||
"typings": "dist/index.d.ts",
|
||||
"name": "@pushrocks/smartsystem",
|
||||
"version": "3.0.1",
|
||||
"description": "interact with the system you are running on",
|
||||
"main": "dist_ts/index.js",
|
||||
"typings": "dist_ts/index.d.ts",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"test": "(npmts)"
|
||||
"test": "(tstest test/)",
|
||||
"build": "(tsbuild --web --allowimplicitany)",
|
||||
"buildDocs": "tsdoc"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+ssh://git@gitlab.com/pushrocks/smartsystem.git"
|
||||
},
|
||||
"keywords": [
|
||||
"TypeScript",
|
||||
"lazy",
|
||||
"module loader"
|
||||
],
|
||||
"author": "Lossless GmbH",
|
||||
"license": "MIT",
|
||||
"bugs": {
|
||||
@ -18,15 +26,33 @@
|
||||
},
|
||||
"homepage": "https://gitlab.com/pushrocks/smartsystem#README",
|
||||
"dependencies": {
|
||||
"@types/q": "0.0.32",
|
||||
"lik": "^1.0.24",
|
||||
"q": "^1.4.1",
|
||||
"systemjs": "^0.19.39",
|
||||
"typings-global": "^1.0.14"
|
||||
"@pushrocks/lik": "^6.0.0",
|
||||
"@pushrocks/smartenv": "^5.0.2",
|
||||
"@pushrocks/smartnetwork": "^3.0.0",
|
||||
"@pushrocks/smartpromise": "^3.1.7",
|
||||
"systeminformation": "^5.12.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/should": "^8.1.30",
|
||||
"should": "^11.1.1",
|
||||
"typings-test": "^1.0.3"
|
||||
}
|
||||
"@gitzone/tsbuild": "^2.1.63",
|
||||
"@gitzone/tstest": "^1.0.72",
|
||||
"@pushrocks/tapbundle": "^5.0.4",
|
||||
"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"
|
||||
]
|
||||
}
|
||||
|
39
readme.md
Normal file
39
readme.md
Normal file
@ -0,0 +1,39 @@
|
||||
# @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 | [](https://lossless.cloud)
|
||||
GitLab Pipline Test Coverage | [](https://lossless.cloud)
|
||||
npm | [](https://lossless.cloud)
|
||||
Snyk | [](https://lossless.cloud)
|
||||
TypeScript Support | [](https://lossless.cloud)
|
||||
node Support | [](https://nodejs.org/dist/latest-v10.x/docs/api/)
|
||||
Code Style | [](https://lossless.cloud)
|
||||
PackagePhobia (total standalone install weight) | [](https://lossless.cloud)
|
||||
PackagePhobia (package size on registry) | [](https://lossless.cloud)
|
||||
BundlePhobia (total size when bundled) | [](https://lossless.cloud)
|
||||
Platform support | [](https://lossless.cloud) [](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 | **©** [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==
|
30
test/test.ts
30
test/test.ts
@ -1,16 +1,20 @@
|
||||
import 'typings-test'
|
||||
import * as should from 'should'
|
||||
import * as smartsystem from '../dist/index'
|
||||
import { tap, expect } from '@pushrocks/tapbundle';
|
||||
import * as smartsystem from '../ts/index.js';
|
||||
import { systeminformation } from '../ts/smartsystem.plugins.js';
|
||||
|
||||
import * as _moduleExample from './moduleExample'
|
||||
let smartsystemInstance: smartsystem.Smartsystem;
|
||||
|
||||
describe('smartsystem', function () {
|
||||
it('should load a module lazily', function (done) {
|
||||
let lazyModuleExample = new smartsystem.LazyModule<typeof _moduleExample>('./test/moduleExample.js')
|
||||
tap.test('should create a smartsystem instance', async (tools) => {
|
||||
smartsystemInstance = new smartsystem.Smartsystem();
|
||||
expect(smartsystemInstance).toBeInstanceOf(smartsystem.Smartsystem);
|
||||
});
|
||||
|
||||
lazyModuleExample.load().then(m => {
|
||||
console.log(m.exportedTestBoolean)
|
||||
done()
|
||||
})
|
||||
})
|
||||
})
|
||||
tap.test('should state the operating system', async () => {
|
||||
expect(smartsystemInstance.cpus.length).toBeGreaterThan(0);
|
||||
});
|
||||
|
||||
tap.test('should get systeminformation', async () => {
|
||||
console.log(await smartsystemInstance.information.networkInterfaceDefault());
|
||||
});
|
||||
|
||||
tap.start();
|
||||
|
8
ts/00_commitinfo_data.ts
Normal file
8
ts/00_commitinfo_data.ts
Normal file
@ -0,0 +1,8 @@
|
||||
/**
|
||||
* autocreated commitinfo by @pushrocks/commitinfo
|
||||
*/
|
||||
export const commitinfo = {
|
||||
name: '@pushrocks/smartsystem',
|
||||
version: '3.0.1',
|
||||
description: 'interact with the system you are running on'
|
||||
}
|
65
ts/index.ts
65
ts/index.ts
@ -1,59 +1,10 @@
|
||||
import 'typings-global'
|
||||
import * as plugins from './smartsystem.plugins.js';
|
||||
|
||||
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 };
|
10
tsconfig.json
Normal file
10
tsconfig.json
Normal file
@ -0,0 +1,10 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"experimentalDecorators": true,
|
||||
"useDefineForClassFields": false,
|
||||
"target": "ES2022",
|
||||
"module": "ES2022",
|
||||
"moduleResolution": "nodenext",
|
||||
"esModuleInterop": true
|
||||
}
|
||||
}
|
@ -1,3 +0,0 @@
|
||||
{
|
||||
"extends": "tslint-config-standard"
|
||||
}
|
Reference in New Issue
Block a user