fix(core): update
This commit is contained in:
parent
311852efe8
commit
beb6680856
19
.gitignore
vendored
19
.gitignore
vendored
@ -1,5 +1,22 @@
|
||||
.nogit/
|
||||
node_modules/
|
||||
|
||||
# artifacts
|
||||
coverage/
|
||||
public/
|
||||
pages/
|
||||
|
||||
# installs
|
||||
node_modules/
|
||||
|
||||
# caches
|
||||
.yarn/
|
||||
.cache/
|
||||
.rpt2_cache
|
||||
|
||||
# builds
|
||||
dist/
|
||||
dist_web/
|
||||
dist_serve/
|
||||
dist_ts_web/
|
||||
|
||||
# custom
|
@ -1,5 +1,5 @@
|
||||
# gitzone standard
|
||||
image: hosttoday/ht-docker-node:npmci
|
||||
# gitzone ci_default
|
||||
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||
|
||||
cache:
|
||||
paths:
|
||||
@ -38,19 +38,7 @@ snyk:
|
||||
# test stage
|
||||
# ====================
|
||||
|
||||
testLTS:
|
||||
stage: test
|
||||
script:
|
||||
- npmci npm prepare
|
||||
- npmci node install lts
|
||||
- npmci npm install
|
||||
- npmci npm test
|
||||
coverage: /\d+.?\d+?\%\s*coverage/
|
||||
tags:
|
||||
- docker
|
||||
- notpriv
|
||||
|
||||
testSTABLE:
|
||||
testStable:
|
||||
stage: test
|
||||
script:
|
||||
- npmci npm prepare
|
||||
@ -60,12 +48,24 @@ testSTABLE:
|
||||
coverage: /\d+.?\d+?\%\s*coverage/
|
||||
tags:
|
||||
- docker
|
||||
- priv
|
||||
|
||||
testBuild:
|
||||
stage: test
|
||||
script:
|
||||
- npmci npm prepare
|
||||
- npmci node install lts
|
||||
- npmci npm install
|
||||
- npmci command npm run build
|
||||
coverage: /\d+.?\d+?\%\s*coverage/
|
||||
tags:
|
||||
- docker
|
||||
- notpriv
|
||||
|
||||
release:
|
||||
stage: release
|
||||
script:
|
||||
- npmci node install stable
|
||||
- npmci node install lts
|
||||
- npmci npm publish
|
||||
only:
|
||||
- tags
|
||||
@ -78,19 +78,11 @@ release:
|
||||
# ====================
|
||||
codequality:
|
||||
stage: metadata
|
||||
image: docker:stable
|
||||
allow_failure: true
|
||||
services:
|
||||
- docker:stable-dind
|
||||
script:
|
||||
- export SP_VERSION=$(echo "$CI_SERVER_VERSION" | sed 's/^\([0-9]*\)\.\([0-9]*\).*/\1-\2-stable/')
|
||||
- docker run
|
||||
--env SOURCE_CODE="$PWD"
|
||||
--volume "$PWD":/code
|
||||
--volume /var/run/docker.sock:/var/run/docker.sock
|
||||
"registry.gitlab.com/gitlab-org/security-products/codequality:$SP_VERSION" /code
|
||||
artifacts:
|
||||
paths: [codeclimate.json]
|
||||
- npmci command npm install -g tslint typescript
|
||||
- npmci npm install
|
||||
- npmci command "tslint -c tslint.json ./ts/**/*.ts"
|
||||
tags:
|
||||
- docker
|
||||
- priv
|
||||
@ -106,13 +98,15 @@ trigger:
|
||||
- notpriv
|
||||
|
||||
pages:
|
||||
image: hosttoday/ht-docker-node:npmci
|
||||
image: hosttoday/ht-docker-dbase:npmci
|
||||
services:
|
||||
- docker:stable-dind
|
||||
stage: metadata
|
||||
script:
|
||||
- npmci command npm install -g typedoc typescript
|
||||
- npmci command npm install -g @gitzone/tsdoc
|
||||
- npmci npm prepare
|
||||
- npmci npm install
|
||||
- npmci command typedoc --module "commonjs" --target "ES2016" --out public/ ts/
|
||||
- npmci command tsdoc
|
||||
tags:
|
||||
- docker
|
||||
- notpriv
|
||||
|
717
package-lock.json
generated
717
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
23
package.json
23
package.json
@ -12,17 +12,30 @@
|
||||
"build": "(tsbuild)"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@gitzone/tsbuild": "^2.1.8",
|
||||
"@gitzone/tstest": "^1.0.20",
|
||||
"@pushrocks/tapbundle": "^3.0.9",
|
||||
"tslint": "^5.16.0",
|
||||
"@gitzone/tsbuild": "^2.1.17",
|
||||
"@gitzone/tstest": "^1.0.24",
|
||||
"@pushrocks/tapbundle": "^3.0.13",
|
||||
"tslint": "^5.19.0",
|
||||
"tslint-config-prettier": "^1.18.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"@pushrocks/smartpromise": "^3.0.2",
|
||||
"@pushrocks/smartstring": "^3.0.10",
|
||||
"@types/default-gateway": "^3.0.0",
|
||||
"@types/portscanner": "^2.1.0",
|
||||
"default-gateway": "^5.0.3",
|
||||
"portscanner": "^2.2.0",
|
||||
"speedtest-net": "^1.5.1"
|
||||
}
|
||||
},
|
||||
"files": [
|
||||
"ts/*",
|
||||
"ts_web/*",
|
||||
"dist/*",
|
||||
"dist_web/*",
|
||||
"dist_ts_web/*",
|
||||
"assets/*",
|
||||
"cli.js",
|
||||
"npmextra.json",
|
||||
"readme.md"
|
||||
]
|
||||
}
|
||||
|
18
readme.md
18
readme.md
@ -22,21 +22,25 @@ network diagnostics
|
||||
import * as smartnetwork from 'smartnetwork';
|
||||
const testSmartNetwork = new smartnetwork.SmartNetwork();
|
||||
const run = async () => {
|
||||
|
||||
// measure average speed over a period of 5 seconds
|
||||
// the structure of speedResult is self explanatory using TypeScript (or the linked TypeDoc above)
|
||||
const speedResult = testSmartNetwork.getSpeed(5000)
|
||||
const speedResult = testSmartNetwork.getSpeed(5000);
|
||||
|
||||
//
|
||||
const isLocalPortAvailable: boolean = await testSmartNetwork.isLocalPortAvailable(1234);
|
||||
const isRemotePortAvailable: boolean = await testSmartNetwork.isRemotePortAvailable('google.com:80');
|
||||
const isRemotePortAvailable: boolean = await testSmartNetwork.isRemotePortAvailable('google.com', 80);
|
||||
}
|
||||
const isRemotePortAvailable: boolean = await testSmartNetwork.isRemotePortAvailable(
|
||||
'google.com:80'
|
||||
);
|
||||
const isRemotePortAvailable: boolean = await testSmartNetwork.isRemotePortAvailable(
|
||||
'google.com',
|
||||
80
|
||||
);
|
||||
};
|
||||
```
|
||||
|
||||
For further information read the linked docs at the top of this readme.
|
||||
|
||||
> MIT licensed | **©** [Lossless GmbH](https://lossless.gmbh)
|
||||
| By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy.html)
|
||||
| By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy)
|
||||
|
||||
[![repo-footer](https://pushrocks.gitlab.io/assets/repo-footer.svg)](https://maintainedby.lossless.com)
|
||||
[![repo-footer](https://lossless.gitlab.io/publicrelations/repofooter.svg)](https://maintainedby.lossless.com)
|
||||
|
11
test/test.ts
11
test/test.ts
@ -19,9 +19,14 @@ tap.test('should determine wether a port is free', async () => {
|
||||
});
|
||||
|
||||
tap.test('should scan a port', async () => {
|
||||
await expect(testSmartNetwork.isRemotePortAvailable('google.com:80')).to.eventually.be.true;
|
||||
await expect(testSmartNetwork.isRemotePortAvailable('google.com', 80)).to.be.eventually.true;
|
||||
await expect(testSmartNetwork.isRemotePortAvailable('67.207.79.63:12346')).to.eventually.be.false;
|
||||
await expect(testSmartNetwork.isRemotePortAvailable('lossless.com:443')).to.eventually.be.true;
|
||||
await expect(testSmartNetwork.isRemotePortAvailable('lossless.com', 443)).to.be.eventually.true;
|
||||
// await expect(testSmartNetwork.isRemotePortAvailable('lossless.com:444')).to.eventually.be.false;
|
||||
});
|
||||
|
||||
tap.test('should get the default gateways', async () => {
|
||||
const gatewayResult = await testSmartNetwork.getDefaultGateway();
|
||||
console.log(gatewayResult);
|
||||
})
|
||||
|
||||
tap.start();
|
||||
|
@ -36,8 +36,12 @@ export interface ISpeedtestData {
|
||||
* SmartNetwork simplifies actions within the network
|
||||
*/
|
||||
export class SmartNetwork {
|
||||
async getSpeed(measurementTime = 5000): Promise<ISpeedtestData> {
|
||||
let done = plugins.smartpromise.defer<ISpeedtestData>();
|
||||
/**
|
||||
* get network speed
|
||||
* @param measurementTime
|
||||
*/
|
||||
public async getSpeed(measurementTime = 5000): Promise<ISpeedtestData> {
|
||||
const done = plugins.smartpromise.defer<ISpeedtestData>();
|
||||
const test = plugins.speedtestNet({ maxTime: measurementTime });
|
||||
test.on('data', data => {
|
||||
done.resolve(data);
|
||||
@ -53,21 +57,21 @@ export class SmartNetwork {
|
||||
* note: false also resolves with false as argument
|
||||
* @param port
|
||||
*/
|
||||
async isLocalPortAvailable(port: number): Promise<boolean> {
|
||||
public async isLocalPortAvailable(port: number): Promise<boolean> {
|
||||
const doneIpV4 = plugins.smartpromise.defer<boolean>();
|
||||
const doneIpV6 = plugins.smartpromise.defer<boolean>();
|
||||
const net = await import('net'); // creates only one instance of net ;) even on multiple calls
|
||||
|
||||
// test IPv4 space
|
||||
const ipv4Test = net.createServer();
|
||||
ipv4Test.once('error', function(err: any) {
|
||||
ipv4Test.once('error', (err: any) => {
|
||||
if (err.code !== 'EADDRINUSE') {
|
||||
doneIpV4.resolve(false);
|
||||
return;
|
||||
}
|
||||
doneIpV4.resolve(false);
|
||||
});
|
||||
ipv4Test.once('listening', function() {
|
||||
ipv4Test.once('listening', () => {
|
||||
ipv4Test.once('close', () => {
|
||||
doneIpV4.resolve(true);
|
||||
});
|
||||
@ -78,21 +82,21 @@ export class SmartNetwork {
|
||||
await doneIpV4.promise;
|
||||
|
||||
// test IPv6 space
|
||||
const test_ipv6 = net.createServer();
|
||||
test_ipv6.once('error', function(err: any) {
|
||||
const ipv6Test = net.createServer();
|
||||
ipv6Test.once('error', function(err: any) {
|
||||
if (err.code !== 'EADDRINUSE') {
|
||||
doneIpV6.resolve(false);
|
||||
return;
|
||||
}
|
||||
doneIpV6.resolve(false);
|
||||
});
|
||||
test_ipv6.once('listening', function() {
|
||||
test_ipv6.once('close', () => {
|
||||
ipv6Test.once('listening', () => {
|
||||
ipv6Test.once('close', () => {
|
||||
doneIpV6.resolve(true);
|
||||
});
|
||||
test_ipv6.close();
|
||||
ipv6Test.close();
|
||||
});
|
||||
test_ipv6.listen(port, '::');
|
||||
ipv6Test.listen(port, '::');
|
||||
|
||||
// lets wait for the result
|
||||
const resultIpV4 = await doneIpV4.promise;
|
||||
@ -120,8 +124,16 @@ export class SmartNetwork {
|
||||
} else {
|
||||
done.resolve(false);
|
||||
}
|
||||
})
|
||||
});
|
||||
const result = await done.promise;
|
||||
return result;
|
||||
}
|
||||
|
||||
public async getDefaultGateway() {
|
||||
const result = {
|
||||
v4: await plugins.defaultGateway.v4(),
|
||||
v6: await plugins.defaultGateway.v6()
|
||||
};
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
@ -7,7 +7,8 @@ import * as smartstring from '@pushrocks/smartstring';
|
||||
export { smartpromise, smartstring };
|
||||
|
||||
// @third party scope
|
||||
let speedtestNet = require('speedtest-net');
|
||||
import defaultGateway from 'default-gateway';
|
||||
const speedtestNet = require('speedtest-net');
|
||||
import * as portscanner from 'portscanner';
|
||||
|
||||
export { speedtestNet, portscanner };
|
||||
export { defaultGateway, speedtestNet, portscanner };
|
||||
|
Loading…
Reference in New Issue
Block a user