Compare commits
52 Commits
Author | SHA1 | Date | |
---|---|---|---|
29b7d266b6 | |||
71422beea3 | |||
71f44f64fb | |||
3eac579317 | |||
f87fa3bf2b | |||
8b101369b8 | |||
89d9692701 | |||
69b22df534 | |||
0b2e88f430 | |||
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 |
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
|
@@ -1,53 +0,0 @@
|
||||
image: hosttoday/ht-docker-node:npmts
|
||||
stages:
|
||||
- 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:
|
||||
stage: test
|
||||
script:
|
||||
- npmci test stable
|
||||
tags:
|
||||
- docker
|
||||
release:
|
||||
stage: release
|
||||
script:
|
||||
- npmci publish
|
||||
only:
|
||||
- tags
|
||||
tags:
|
||||
- docker
|
||||
trigger:
|
||||
stage: trigger
|
||||
script:
|
||||
- npmci trigger
|
||||
only:
|
||||
- tags
|
||||
tags:
|
||||
- docker
|
||||
pages:
|
||||
image: hosttoday/ht-docker-node:npmpage
|
||||
stage: page
|
||||
script:
|
||||
- npmci command npmpage --host gitlab
|
||||
only:
|
||||
- tags
|
||||
artifacts:
|
||||
expire_in: 1 week
|
||||
paths:
|
||||
- public
|
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"]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
48
README.md
48
README.md
@@ -1,48 +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
|
||||
|
||||
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 */
|
||||
})
|
||||
```
|
56
changelog.md
Normal file
56
changelog.md
Normal file
@@ -0,0 +1,56 @@
|
||||
# Changelog
|
||||
|
||||
## 2025-08-29 - 3.0.3 - fix(readme)
|
||||
Update README: expand documentation, add installation, usage examples, API overview, and advanced guides
|
||||
|
||||
- Completely revamped README with a clearer project description and features list
|
||||
- Added Installation section with npm / pnpm / yarn examples
|
||||
- Added Quick Start, API overview, and multiple usage examples (env, CPU, network, systeminformation)
|
||||
- Added Real-World Use Cases (health check, network monitoring, resource scaling) and Advanced Features (cross-platform, Docker detection)
|
||||
- Clarified TypeScript support and added links to full API documentation
|
||||
- Documentation-only changes; no code or API behaviour modified
|
||||
|
||||
## 2025-08-29 - 3.0.2 - fix(smartsystem)
|
||||
Normalize package scopes, update dev dependencies and tooling, add pnpm workspace and packageManager, remove GitLab CI, and update imports/docs/tests
|
||||
|
||||
- Normalize package scope names from @pushrocks/* to @push.rocks/* across source, commit info and README
|
||||
- Update dependency versions: bump @push.rocks/smartpromise to ^4.0.2 and ensure other @push.rocks packages use caret ranges
|
||||
- Switch dev tooling namespaces to @git.zone (tsbuild/tsrun/tstest) and add @git.zone/tsrun
|
||||
- Enhance npm scripts: make test run with verbose, logfile and increased timeout
|
||||
- Add packageManager field (pnpm@10.14.0+sha512...) to package.json and add pnpm-workspace.yaml with onlyBuiltDependencies: [esbuild]
|
||||
- Remove legacy .gitlab-ci.yml CI configuration
|
||||
- Update imports in ts and test files to match new package namespaces
|
||||
|
||||
## 2024-05-29 - 3.0.1 - chore
|
||||
Update of package metadata and TypeScript configuration.
|
||||
|
||||
- update description
|
||||
- update tsconfig (adjustments to TypeScript config)
|
||||
- update npmextra.json: githost (fixes to githost entries)
|
||||
|
||||
## 2022-07-28 - 3.0.0 - fix(core)
|
||||
Minor core fixes and release of 3.0.0.
|
||||
|
||||
- fix(core): update
|
||||
|
||||
## 2022-07-28 - 2.0.10 - BREAKING (core)
|
||||
Breaking change: module format switched to ESM.
|
||||
|
||||
- BREAKING CHANGE(core): switch to esm
|
||||
- misc maintenance and fixes leading up to this release
|
||||
|
||||
## 2017-07-31 - 2.0.1..2.0.9 - maintenance
|
||||
Series of patch releases with small fixes and upkeep across the 2.0.x line.
|
||||
|
||||
- Multiple patch releases (2.0.1 → 2.0.9) containing repeated core fixes
|
||||
- Updates to README and repository metadata
|
||||
- update yarn lock (notably in 2.0.1)
|
||||
|
||||
## 2017-07-31 - 1.0.0..1.0.18 - initial development & improvements
|
||||
Initial development, feature additions and documentation improvements across 1.0.x.
|
||||
|
||||
- initial releases and basic module structure; first working version
|
||||
- add npm as default module loader (1.0.6)
|
||||
- improve path resolution and add keywords (1.0.4–1.0.5)
|
||||
- add docs, improve README and tests across multiple 1.0.x releases
|
||||
- CI updates and general streamlining of the project
|
25
dist/index.d.ts
vendored
25
dist/index.d.ts
vendored
@@ -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;
|
||||
}
|
68
dist/index.js
vendored
68
dist/index.js
vendored
@@ -1,68 +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) {
|
||||
this.loader = 'npm';
|
||||
if (!cwdArg) {
|
||||
throw new Error('You must specify a directory to resolve from!');
|
||||
}
|
||||
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,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQUEsMEJBQXVCO0FBR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MsR0FBRyxDQUFDLENBQUEsQ0FBQyxDQUFDLENBQUMsQ0FBQTtRQUN6QyxDQUFDO1FBQUMsSUFBSSxDQUFDLENBQUM7WUFDSixNQUFNLEtBQUssQ0FBQyxzQkFBc0IsQ0FBQyxDQUFBO1FBQ3ZDLENBQUM7UUFDRCxNQUFNLENBQUMsSUFBSSxDQUFDLE9BQU8sQ0FBQTtJQUN2QixDQUFDO0lBRUQ7O09BRUc7SUFDSCxRQUFRLENBQUMsR0FBRyxJQUF1QjtJQUVuQyxDQUFDO0NBQ0o7QUF0REQsZ0NBc0RDIn0=
|
31
npmextra.json
Normal file
31
npmextra.json
Normal file
@@ -0,0 +1,31 @@
|
||||
{
|
||||
"npmci": {
|
||||
"npmGlobalTools": [],
|
||||
"npmAccessLevel": "public"
|
||||
},
|
||||
"gitzone": {
|
||||
"projectType": "npm",
|
||||
"module": {
|
||||
"githost": "code.foss.global",
|
||||
"gitscope": "push.rocks",
|
||||
"gitrepo": "smartsystem",
|
||||
"description": "A TypeScript library for interacting with the system it's running on, including environment, network, and hardware information.",
|
||||
"npmPackagename": "@push.rocks/smartsystem",
|
||||
"license": "MIT",
|
||||
"keywords": [
|
||||
"TypeScript",
|
||||
"system information",
|
||||
"environment variables",
|
||||
"network",
|
||||
"hardware info",
|
||||
"OS interaction",
|
||||
"module loading",
|
||||
"async",
|
||||
"cross-platform"
|
||||
]
|
||||
}
|
||||
},
|
||||
"tsdoc": {
|
||||
"legal": "\n## License and Legal Information\n\nThis repository contains open-source code that is licensed under the MIT License. A copy of the MIT License can be found in the [license](license) file within this repository. \n\n**Please note:** The MIT License does not grant permission to use the trade names, trademarks, service marks, or product names of the project, except as required for reasonable and customary use in describing the origin of the work and reproducing the content of the NOTICE file.\n\n### Trademarks\n\nThis project is owned and maintained by Task Venture Capital GmbH. The names and logos associated with Task Venture Capital GmbH and any related products or services are trademarks of Task Venture Capital GmbH and are not included within the scope of the MIT license granted herein. Use of these trademarks must comply with Task Venture Capital GmbH's Trademark Guidelines, and any usage must be approved in writing by Task Venture Capital GmbH.\n\n### Company Information\n\nTask Venture Capital GmbH \nRegistered at District court Bremen HRB 35230 HB, Germany\n\nFor any legal inquiries or if you require further information, please contact us via email at hello@task.vc.\n\nBy using this repository, you acknowledge that you have read this section, agree to comply with its terms, and understand that the licensing of the code does not imply endorsement by Task Venture Capital GmbH of any derivative works.\n"
|
||||
}
|
||||
}
|
14753
package-lock.json
generated
Normal file
14753
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
66
package.json
66
package.json
@@ -1,37 +1,65 @@
|
||||
{
|
||||
"name": "smartsystem",
|
||||
"version": "1.0.10",
|
||||
"description": "simplifies lazy loading with TypeScript",
|
||||
"main": "dist/index.js",
|
||||
"typings": "dist/index.d.ts",
|
||||
"name": "@push.rocks/smartsystem",
|
||||
"version": "3.0.3",
|
||||
"description": "A TypeScript library for interacting with the system it's running on, including environment, network, and hardware information.",
|
||||
"main": "dist_ts/index.js",
|
||||
"typings": "dist_ts/index.d.ts",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"test": "(npmts)"
|
||||
"test": "(tstest test/ --verbose --logfile --timeout 60)",
|
||||
"build": "(tsbuild --web --allowimplicitany)",
|
||||
"buildDocs": "tsdoc"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+ssh://git@gitlab.com/pushrocks/smartsystem.git"
|
||||
"url": "https://code.foss.global/push.rocks/smartsystem.git"
|
||||
},
|
||||
"keywords": [
|
||||
"TypeScript",
|
||||
"lazy",
|
||||
"module loader"
|
||||
"system information",
|
||||
"environment variables",
|
||||
"network",
|
||||
"hardware info",
|
||||
"OS interaction",
|
||||
"module loading",
|
||||
"async",
|
||||
"cross-platform"
|
||||
],
|
||||
"author": "Lossless GmbH",
|
||||
"license": "MIT",
|
||||
"bugs": {
|
||||
"url": "https://gitlab.com/pushrocks/smartsystem/issues"
|
||||
},
|
||||
"homepage": "https://gitlab.com/pushrocks/smartsystem#README",
|
||||
"homepage": "https://code.foss.global/push.rocks/smartsystem",
|
||||
"dependencies": {
|
||||
"@types/q": "0.0.32",
|
||||
"lik": "^1.0.27",
|
||||
"q": "^1.4.1",
|
||||
"systemjs": "^0.19.41",
|
||||
"typings-global": "^1.0.14"
|
||||
"@push.rocks/lik": "^6.0.0",
|
||||
"@push.rocks/smartenv": "^5.0.2",
|
||||
"@push.rocks/smartnetwork": "^3.0.0",
|
||||
"@push.rocks/smartpromise": "^4.0.2",
|
||||
"systeminformation": "^5.12.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/should": "^8.1.30",
|
||||
"should": "^11.1.2",
|
||||
"typings-test": "^1.0.3"
|
||||
}
|
||||
"@git.zone/tsbuild": "^2.1.63",
|
||||
"@git.zone/tsrun": "^1.3.3",
|
||||
"@git.zone/tstest": "^1.0.72",
|
||||
"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"
|
||||
],
|
||||
"packageManager": "pnpm@10.14.0+sha512.ad27a79641b49c3e481a16a805baa71817a04bbe06a38d17e60e2eaee83f6a146c6a688125f5792e48dd5ba30e7da52a5cda4c3992b9ccf333f9ce223af84748"
|
||||
}
|
||||
|
8474
pnpm-lock.yaml
generated
Normal file
8474
pnpm-lock.yaml
generated
Normal file
File diff suppressed because it is too large
Load Diff
2
pnpm-workspace.yaml
Normal file
2
pnpm-workspace.yaml
Normal file
@@ -0,0 +1,2 @@
|
||||
onlyBuiltDependencies:
|
||||
- esbuild
|
1
readme.hints.md
Normal file
1
readme.hints.md
Normal file
@@ -0,0 +1 @@
|
||||
|
253
readme.md
Normal file
253
readme.md
Normal file
@@ -0,0 +1,253 @@
|
||||
# @push.rocks/smartsystem 🚀
|
||||
**Smart System Interaction for Node.js**
|
||||
|
||||
> Zero-hassle system information and environment management for modern Node.js applications.
|
||||
|
||||
## 🌟 Features
|
||||
|
||||
`@push.rocks/smartsystem` consolidates system interaction into a single, elegant TypeScript-first API:
|
||||
|
||||
- 🔧 **Unified System Interface** - One `Smartsystem` instance to rule them all
|
||||
- 🌍 **Environment Management** - Smart env variable handling via [@push.rocks/smartenv](https://www.npmjs.com/package/@push.rocks/smartenv)
|
||||
- 💻 **CPU Information** - Direct access to CPU specs without the boilerplate
|
||||
- 🌐 **Network Intelligence** - Advanced networking utilities from [@push.rocks/smartnetwork](https://www.npmjs.com/package/@push.rocks/smartnetwork)
|
||||
- 📊 **Deep System Insights** - Comprehensive hardware and OS data via [systeminformation](https://www.npmjs.com/package/systeminformation)
|
||||
- ⚡ **TypeScript Native** - Built with TypeScript, for TypeScript (but works great with JS too!)
|
||||
|
||||
## 📦 Installation
|
||||
|
||||
Get started with your package manager of choice:
|
||||
|
||||
```bash
|
||||
# Using npm
|
||||
npm install @push.rocks/smartsystem
|
||||
|
||||
# Using pnpm (recommended)
|
||||
pnpm add @push.rocks/smartsystem
|
||||
|
||||
# Using yarn
|
||||
yarn add @push.rocks/smartsystem
|
||||
```
|
||||
|
||||
## 🚀 Quick Start
|
||||
|
||||
```typescript
|
||||
import { Smartsystem } from '@push.rocks/smartsystem';
|
||||
|
||||
// Create your system interface
|
||||
const mySystem = new Smartsystem();
|
||||
|
||||
// You're ready to rock! 🎸
|
||||
```
|
||||
|
||||
## 📖 API Overview
|
||||
|
||||
The `Smartsystem` class provides these powerful properties:
|
||||
|
||||
| Property | Type | Description |
|
||||
|----------|------|-------------|
|
||||
| `env` | `Smartenv` | Environment variable management with validation and type safety |
|
||||
| `cpus` | `os.CpuInfo[]` | Direct access to CPU core information |
|
||||
| `network` | `SmartNetwork` | Network interface inspection and utilities |
|
||||
| `information` | `systeminformation` | Full access to the systeminformation library |
|
||||
|
||||
## 💡 Usage Examples
|
||||
|
||||
### Environment Variables Made Easy
|
||||
|
||||
```typescript
|
||||
const mySystem = new Smartsystem();
|
||||
|
||||
// Get all environment variables
|
||||
const envVars = mySystem.env.getEnvVars();
|
||||
|
||||
// Access specific variables with type safety
|
||||
const apiKey = mySystem.env.getEnvVarOnDemand('API_KEY');
|
||||
```
|
||||
|
||||
### CPU Information at Your Fingertips
|
||||
|
||||
```typescript
|
||||
const mySystem = new Smartsystem();
|
||||
|
||||
// Get CPU details
|
||||
console.log(`Running on ${mySystem.cpus.length} CPU cores`);
|
||||
console.log(`Primary CPU: ${mySystem.cpus[0].model}`);
|
||||
```
|
||||
|
||||
### Network Intelligence
|
||||
|
||||
```typescript
|
||||
const mySystem = new Smartsystem();
|
||||
|
||||
// Get comprehensive network information
|
||||
const networkInfo = await mySystem.network.getNetworkInfo();
|
||||
console.log('Network interfaces:', networkInfo);
|
||||
```
|
||||
|
||||
### Deep System Insights
|
||||
|
||||
Access detailed system information for advanced use cases:
|
||||
|
||||
```typescript
|
||||
const mySystem = new Smartsystem();
|
||||
|
||||
// Hardware information
|
||||
const systemInfo = await mySystem.information.system();
|
||||
console.log(`System: ${systemInfo.manufacturer} ${systemInfo.model}`);
|
||||
|
||||
// Operating system details
|
||||
const osInfo = await mySystem.information.osInfo();
|
||||
console.log(`OS: ${osInfo.distro} ${osInfo.release}`);
|
||||
|
||||
// Real-time system metrics
|
||||
const load = await mySystem.information.currentLoad();
|
||||
console.log(`CPU Load: ${load.currentLoad.toFixed(2)}%`);
|
||||
|
||||
// Memory usage
|
||||
const mem = await mySystem.information.mem();
|
||||
console.log(`Memory: ${(mem.used / mem.total * 100).toFixed(2)}% used`);
|
||||
```
|
||||
|
||||
## 🎯 Real-World Use Cases
|
||||
|
||||
### System Health Monitoring
|
||||
|
||||
Create a simple health check for your application:
|
||||
|
||||
```typescript
|
||||
const mySystem = new Smartsystem();
|
||||
|
||||
async function healthCheck() {
|
||||
const load = await mySystem.information.currentLoad();
|
||||
const mem = await mySystem.information.mem();
|
||||
const disk = await mySystem.information.fsSize();
|
||||
|
||||
return {
|
||||
status: 'healthy',
|
||||
metrics: {
|
||||
cpuLoad: `${load.currentLoad.toFixed(2)}%`,
|
||||
memoryUsage: `${(mem.used / mem.total * 100).toFixed(2)}%`,
|
||||
diskUsage: disk.map(fs => ({
|
||||
mount: fs.mount,
|
||||
usage: `${fs.use.toFixed(2)}%`
|
||||
}))
|
||||
}
|
||||
};
|
||||
}
|
||||
```
|
||||
|
||||
### Network Traffic Analysis
|
||||
|
||||
Monitor network activity for debugging or performance optimization:
|
||||
|
||||
```typescript
|
||||
const mySystem = new Smartsystem();
|
||||
|
||||
async function monitorNetwork() {
|
||||
const defaultInterface = await mySystem.information.networkInterfaceDefault();
|
||||
const baseline = await mySystem.information.networkStats(defaultInterface);
|
||||
|
||||
// Check again after 1 second
|
||||
await new Promise(resolve => setTimeout(resolve, 1000));
|
||||
|
||||
const current = await mySystem.information.networkStats(defaultInterface);
|
||||
const rxSpeed = (current[0].rx_sec / 1024 / 1024).toFixed(2);
|
||||
const txSpeed = (current[0].tx_sec / 1024 / 1024).toFixed(2);
|
||||
|
||||
console.log(`📥 Download: ${rxSpeed} MB/s | 📤 Upload: ${txSpeed} MB/s`);
|
||||
}
|
||||
```
|
||||
|
||||
### Smart Resource Scaling
|
||||
|
||||
Make intelligent decisions based on system resources:
|
||||
|
||||
```typescript
|
||||
const mySystem = new Smartsystem();
|
||||
|
||||
async function getOptimalWorkerCount() {
|
||||
const cpuCount = mySystem.cpus.length;
|
||||
const load = await mySystem.information.currentLoad();
|
||||
const mem = await mySystem.information.mem();
|
||||
|
||||
// Scale workers based on available resources
|
||||
const memoryConstraint = Math.floor(mem.available / (512 * 1024 * 1024)); // 512MB per worker
|
||||
const cpuConstraint = Math.max(1, Math.floor(cpuCount * (1 - load.currentLoad / 100)));
|
||||
|
||||
return Math.min(memoryConstraint, cpuConstraint, cpuCount);
|
||||
}
|
||||
```
|
||||
|
||||
## 🔧 Advanced Features
|
||||
|
||||
### Cross-Platform Compatibility
|
||||
|
||||
`@push.rocks/smartsystem` works seamlessly across different operating systems:
|
||||
|
||||
```typescript
|
||||
const mySystem = new Smartsystem();
|
||||
|
||||
const osInfo = await mySystem.information.osInfo();
|
||||
const platform = osInfo.platform; // 'linux', 'darwin', 'win32', etc.
|
||||
|
||||
// Platform-specific logic
|
||||
if (platform === 'linux') {
|
||||
// Linux-specific operations
|
||||
} else if (platform === 'darwin') {
|
||||
// macOS-specific operations
|
||||
} else if (platform === 'win32') {
|
||||
// Windows-specific operations
|
||||
}
|
||||
```
|
||||
|
||||
### Docker & Container Detection
|
||||
|
||||
Detect if your application is running in a containerized environment:
|
||||
|
||||
```typescript
|
||||
const mySystem = new Smartsystem();
|
||||
|
||||
const virt = await mySystem.information.dockerInfo();
|
||||
if (virt.dockerContainers && virt.dockerContainers.length > 0) {
|
||||
console.log('🐳 Running in Docker');
|
||||
}
|
||||
```
|
||||
|
||||
## 🛠️ TypeScript Support
|
||||
|
||||
Full TypeScript support with comprehensive type definitions:
|
||||
|
||||
```typescript
|
||||
import { Smartsystem } from '@push.rocks/smartsystem';
|
||||
import type { Systeminformation } from 'systeminformation';
|
||||
|
||||
const mySystem = new Smartsystem();
|
||||
|
||||
// All methods are fully typed
|
||||
const cpuInfo: Systeminformation.CpuData = await mySystem.information.cpu();
|
||||
const memInfo: Systeminformation.MemData = await mySystem.information.mem();
|
||||
```
|
||||
|
||||
## 📚 API Documentation
|
||||
|
||||
For complete API documentation, visit: [https://code.foss.global/push.rocks/smartsystem](https://code.foss.global/push.rocks/smartsystem)
|
||||
|
||||
## License and Legal Information
|
||||
|
||||
This repository contains open-source code that is licensed under the MIT License. A copy of the MIT License can be found in the [license](license) file within this repository.
|
||||
|
||||
**Please note:** The MIT License does not grant permission to use the trade names, trademarks, service marks, or product names of the project, except as required for reasonable and customary use in describing the origin of the work and reproducing the content of the NOTICE file.
|
||||
|
||||
### Trademarks
|
||||
|
||||
This project is owned and maintained by Task Venture Capital GmbH. The names and logos associated with Task Venture Capital GmbH and any related products or services are trademarks of Task Venture Capital GmbH and are not included within the scope of the MIT license granted herein. Use of these trademarks must comply with Task Venture Capital GmbH's Trademark Guidelines, and any usage must be approved in writing by Task Venture Capital GmbH.
|
||||
|
||||
### Company Information
|
||||
|
||||
Task Venture Capital GmbH
|
||||
Registered at District court Bremen HRB 35230 HB, Germany
|
||||
|
||||
For any legal inquiries or if you require further information, please contact us via email at hello@task.vc.
|
||||
|
||||
By using this repository, you acknowledge that you have read this section, agree to comply with its terms, and understand that the licensing of the code does not imply endorsement by Task Venture Capital GmbH of any derivative works.
|
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,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibW9kdWxlRXhhbXBsZS5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIm1vZHVsZUV4YW1wbGUudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFXLFFBQUEsbUJBQW1CLEdBQUcsSUFBSSxDQUFBO0FBRXJDLE9BQU8sQ0FBQyxHQUFHLENBQUMsbUNBQW1DLENBQUMsQ0FBQSJ9
|
@@ -1,3 +0,0 @@
|
||||
export let exportedTestBoolean = true
|
||||
import * as q from 'q'
|
||||
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', __dirname);
|
||||
lazyModuleExample.load().then(m => {
|
||||
console.log(m.exportedTestBoolean);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidGVzdC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbInRlc3QudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLHdCQUFxQjtBQUVyQiw2Q0FBNEM7QUFJNUMsUUFBUSxDQUFDLGFBQWEsRUFBRTtJQUNwQixFQUFFLENBQUMsNkJBQTZCLEVBQUUsVUFBVSxJQUFJO1FBQzVDLElBQUksaUJBQWlCLEdBQUcsSUFBSSxXQUFXLENBQUMsVUFBVSxDQUF3QiwwQkFBMEIsRUFBQyxTQUFTLENBQUMsQ0FBQTtRQUUvRyxpQkFBaUIsQ0FBQyxJQUFJLEVBQUUsQ0FBQyxJQUFJLENBQUMsQ0FBQztZQUMzQixPQUFPLENBQUMsR0FBRyxDQUFDLENBQUMsQ0FBQyxtQkFBbUIsQ0FBQyxDQUFBO1lBQ2xDLElBQUksRUFBRSxDQUFBO1FBQ1YsQ0FBQyxDQUFDLENBQUE7SUFDTixDQUFDLENBQUMsQ0FBQTtBQUNOLENBQUMsQ0FBQyxDQUFBIn0=
|
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 '@git.zone/tstest/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',__dirname)
|
||||
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 @push.rocks/commitinfo
|
||||
*/
|
||||
export const commitinfo = {
|
||||
name: '@push.rocks/smartsystem',
|
||||
version: '3.0.3',
|
||||
description: 'A TypeScript library for interacting with the system it's running on, including environment, network, and hardware information.'
|
||||
}
|
87
ts/index.ts
87
ts/index.ts
@@ -1,81 +1,10 @@
|
||||
import 'typings-global'
|
||||
import * as plugins from './smartsystem.plugins.js';
|
||||
|
||||
import * as path from 'path'
|
||||
import * as q from 'q'
|
||||
import { Objectmap } from 'lik'
|
||||
|
||||
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) {
|
||||
if (!cwdArg) {
|
||||
throw new Error('You must specify a directory to resolve from!')
|
||||
}
|
||||
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>[]) {
|
||||
|
||||
}
|
||||
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 '@push.rocks/lik';
|
||||
import * as smartenv from '@push.rocks/smartenv';
|
||||
import * as smartnetwork from '@push.rocks/smartnetwork';
|
||||
import * as smartpromise from '@push.rocks/smartpromise';
|
||||
|
||||
export { lik, smartenv, smartnetwork, smartpromise };
|
||||
|
||||
// third party
|
||||
import * as systeminformation from 'systeminformation';
|
||||
|
||||
export { systeminformation };
|
14
tsconfig.json
Normal file
14
tsconfig.json
Normal file
@@ -0,0 +1,14 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"experimentalDecorators": true,
|
||||
"useDefineForClassFields": false,
|
||||
"target": "ES2022",
|
||||
"module": "NodeNext",
|
||||
"moduleResolution": "NodeNext",
|
||||
"esModuleInterop": true,
|
||||
"verbatimModuleSyntax": true
|
||||
},
|
||||
"exclude": [
|
||||
"dist_*/**/*.d.ts"
|
||||
]
|
||||
}
|
@@ -1,3 +0,0 @@
|
||||
{
|
||||
"extends": "tslint-config-standard"
|
||||
}
|
Reference in New Issue
Block a user