Compare commits

...

14 Commits

Author SHA1 Message Date
d5c2d167ec 5.0.0 2022-03-16 16:10:47 +01:00
2af6d5a974 4.0.18 2022-03-16 16:10:09 +01:00
fdba21d60d 4.0.17 2022-03-16 16:09:25 +01:00
c17ebca309 fix(core): update 2022-03-16 16:09:24 +01:00
a014dcf1ab 4.0.16 2020-10-13 20:09:15 +00:00
44bee7bf6f fix(core): update 2020-10-13 20:09:15 +00:00
7841917058 4.0.15 2020-09-29 19:29:51 +00:00
f5a674f98d fix(core): update 2020-09-29 19:29:50 +00:00
80ece7c093 4.0.14 2020-09-29 19:10:00 +00:00
39250b3d47 fix(core): update 2020-09-29 19:10:00 +00:00
ed78c0becf 4.0.13 2020-09-29 18:38:22 +00:00
63c103fde5 fix(core): update 2020-09-29 18:38:21 +00:00
88003bde0f 4.0.12 2020-09-29 17:49:34 +00:00
276a0641e8 fix(core): update 2020-09-29 17:49:33 +00:00
7 changed files with 15164 additions and 7660 deletions

View File

@ -9,7 +9,7 @@
"githost": "gitlab.com", "githost": "gitlab.com",
"gitscope": "pushrocks", "gitscope": "pushrocks",
"gitrepo": "smartenv", "gitrepo": "smartenv",
"shortDescription": "store things about your environment and let them travel across modules", "description": "store things about your environment and let them travel across modules",
"npmPackagename": "@pushrocks/smartenv", "npmPackagename": "@pushrocks/smartenv",
"license": "MIT" "license": "MIT"
} }

22705
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -1,12 +1,13 @@
{ {
"name": "@pushrocks/smartenv", "name": "@pushrocks/smartenv",
"version": "4.0.11", "version": "5.0.0",
"description": "store things about your environment and let them travel across modules", "description": "store things about your environment and let them travel across modules",
"main": "dist_ts/index.js", "main": "dist_ts/index.js",
"typings": "dist_ts/index.d.ts", "typings": "dist_ts/index.d.ts",
"type": "module",
"scripts": { "scripts": {
"test": "(tstest test/ --web)", "test": "(tstest test/ --web)",
"build": "(tsbuild --web && tsbundle npm)", "build": "(tsbuild --web --allowimplicitany && tsbundle npm)",
"testbrowser": "(npm test) && (node testbrowser.js)" "testbrowser": "(npm test) && (node testbrowser.js)"
}, },
"repository": { "repository": {
@ -23,17 +24,16 @@
}, },
"homepage": "https://gitlab.com/pushrocks/smartenv", "homepage": "https://gitlab.com/pushrocks/smartenv",
"dependencies": { "dependencies": {
"@pushrocks/smartparam": "^1.1.6", "@pushrocks/smartpromise": "^3.1.7",
"@pushrocks/smartpromise": "^3.0.6", "@types/node": "^17.0.21"
"@types/node": "^14.11.2"
}, },
"devDependencies": { "devDependencies": {
"@gitzone/tsbuild": "^2.1.25", "@gitzone/tsbuild": "^2.1.56",
"@gitzone/tsbundle": "^1.0.78", "@gitzone/tsbundle": "^1.0.98",
"@gitzone/tsrun": "^1.2.12", "@gitzone/tsrun": "^1.2.31",
"@gitzone/tstest": "^1.0.44", "@gitzone/tstest": "^1.0.68",
"@pushrocks/tapbundle": "^3.2.9", "@pushrocks/tapbundle": "^5.0.2",
"@types/npm": "^2.0.31", "@types/npm": "^7.19.0",
"tslint": "^6.1.3", "tslint": "^6.1.3",
"tslint-config-prettier": "^1.18.0" "tslint-config-prettier": "^1.18.0"
}, },

View File

@ -1,5 +1,5 @@
import { tap, expect } from '@pushrocks/tapbundle'; import { tap, expect } from '@pushrocks/tapbundle';
import * as smartenv from '../ts/index'; import * as smartenv from '../ts/index.js';
let testEnv: smartenv.Smartenv; let testEnv: smartenv.Smartenv;
@ -17,20 +17,20 @@ tap.test('should get os', async () => {
const resultWindows = await testEnv.isWindowsAsync(); const resultWindows = await testEnv.isWindowsAsync();
const osModule = await import('os'); const osModule = await import('os');
if (resultMac) { if (resultMac) {
expect(osModule.platform()).to.equal('darwin'); expect(osModule.platform()).toEqual('darwin');
console.log('platform is Mac!'); console.log('platform is Mac!');
} else if (resultLinux) { } else if (resultLinux) {
expect(osModule.platform()).to.equal('linux'); expect(osModule.platform()).toEqual('linux');
console.log('platform is Linux!'); console.log('platform is Linux!');
} else { } else {
expect(osModule.platform()).to.equal('win32'); expect(osModule.platform()).toEqual('win32');
console.log('platform is Windows!'); console.log('platform is Windows!');
} }
}); });
tap.test('should state wether we are in CI', async () => { tap.test('should state wether we are in CI', async () => {
if (process.env.CI) { if (process.env.CI) {
expect(testEnv.isCI).to.be.true; expect(testEnv.isCI).toBeTrue();
} }
}); });

View File

@ -1 +1 @@
export * from './smartenv.classes.smartenv'; export * from './smartenv.classes.smartenv.js';

View File

@ -1,5 +1,5 @@
import * as plugins from './smartenv.plugins'; import * as plugins from './smartenv.plugins.js';
import * as interfaces from './interfaces'; import * as interfaces from './interfaces/index.js';
// interfaces // interfaces
export interface IEnvObject { export interface IEnvObject {
@ -11,16 +11,57 @@ export interface IEnvObject {
* Smartenv class that makes it easy * Smartenv class that makes it easy
*/ */
export class Smartenv { export class Smartenv {
public getSafeNodeModule<T = any>(moduleNameArg: string): T { public async getEnvAwareModule(optionsArg: {
nodeModuleName: string;
webUrlArg: string;
getFunction: () => any;
}) {
if (this.isNode) {
const moduleResult = await this.getSafeNodeModule(optionsArg.nodeModuleName);
return moduleResult;
} else if (this.isBrowser) {
const moduleResult = await this.getSafeWebModule(optionsArg.webUrlArg, optionsArg.getFunction);
} else {
console.error('platform for loading not supported by smartenv');
}
}
public async getSafeNodeModule<T = any>(moduleNameArg: string): Promise<T> {
if (!this.isNode) {
console.error('You tried to load a node module in a wrong context');
return;
}
// tslint:disable-next-line: function-constructor // tslint:disable-next-line: function-constructor
return new Function( return (new Function(`return import('${moduleNameArg}')`))() as Promise<T>;
'exports', }
'require',
'module', public loadedScripts: string[] = [];
'__filename', public async getSafeWebModule(urlArg: string, getFunctionArg: () => any) {
'__dirname', if (!this.isBrowser) {
`return require('${moduleNameArg}')` console.error('You tried to load a web module in a wrong context');
)(exports, require, module, __filename, __dirname); return;
}
if (this.loadedScripts.includes(urlArg)) {
return getFunctionArg();
} else {
this.loadedScripts.push(urlArg);
}
const done = plugins.smartpromise.defer();
if (globalThis.importScripts) {
globalThis.importScripts(urlArg);
done.resolve();
} else {
const script = document.createElement('script');
script.onload = () => {
done.resolve();
};
script.src = urlArg;
document.head.appendChild(script);
}
await done.promise;
return getFunctionArg();
} }
public get runtimeEnv() { public get runtimeEnv() {
@ -66,7 +107,7 @@ export class Smartenv {
public async isMacAsync(): Promise<boolean> { public async isMacAsync(): Promise<boolean> {
if (this.isNode) { if (this.isNode) {
const os = this.getSafeNodeModule('os'); const os = await this.getSafeNodeModule('os');
return os.platform() === 'darwin'; return os.platform() === 'darwin';
} else { } else {
return false; return false;
@ -75,7 +116,7 @@ export class Smartenv {
public async isWindowsAsync(): Promise<boolean> { public async isWindowsAsync(): Promise<boolean> {
if (this.isNode) { if (this.isNode) {
const os = this.getSafeNodeModule('os'); const os = await this.getSafeNodeModule('os');
return os.platform() === 'win32'; return os.platform() === 'win32';
} else { } else {
return false; return false;
@ -84,30 +125,21 @@ export class Smartenv {
public async isLinuxAsync(): Promise<boolean> { public async isLinuxAsync(): Promise<boolean> {
if (this.isNode) { if (this.isNode) {
const os = this.getSafeNodeModule('os'); const os = await this.getSafeNodeModule('os');
return os.platform() === 'linux'; return os.platform() === 'linux';
} else { } else {
return false; return false;
} }
} }
/**
* get environment variables that fit the description
*/
// get envVars (regexArg: RegExp) {
// let EnvironmentArray = []
// // TODO: plugins.smartparam.forEachMinimatch()
// }
/** /**
* prints the environment to console * prints the environment to console
*/ */
public async printEnv() { public async printEnv() {
if (this.isNode) { if (this.isNode) {
console.log('running on NODE'); console.log('running on NODE');
const smartenvVersion = require('../package.json').version;
console.log( console.log(
'node version is ' + this.nodeVersion + ' and smartenv version is ' + smartenvVersion 'node version is ' + this.nodeVersion
); );
} else { } else {
console.log('running on BROWSER'); console.log('running on BROWSER');

View File

@ -1,4 +1,3 @@
import * as smartparam from '@pushrocks/smartparam';
import * as smartpromise from '@pushrocks/smartpromise'; import * as smartpromise from '@pushrocks/smartpromise';
export { smartparam, smartpromise }; export { smartpromise };