Compare commits
21 Commits
Author | SHA1 | Date | |
---|---|---|---|
2e9bc0db42 | |||
af837f5303 | |||
9145cc890c | |||
e3fa407c1c | |||
865e58b190 | |||
66d00d938c | |||
5c3e165625 | |||
82e282a19f | |||
16ca87923d | |||
62676cf816 | |||
c88bb03e6c | |||
98f9c51613 | |||
a0b237ca8c | |||
4a7139b6f8 | |||
48f9249313 | |||
278eda4869 | |||
ce99e04b45 | |||
c0a1e0a14f | |||
83392d18f6 | |||
270cb2533e | |||
fad367ca0b |
22
.gitignore
vendored
22
.gitignore
vendored
@ -1,4 +1,20 @@
|
|||||||
node_modules/
|
.nogit/
|
||||||
pages/
|
|
||||||
public/
|
# artifacts
|
||||||
coverage/
|
coverage/
|
||||||
|
public/
|
||||||
|
pages/
|
||||||
|
|
||||||
|
# installs
|
||||||
|
node_modules/
|
||||||
|
|
||||||
|
# caches
|
||||||
|
.yarn/
|
||||||
|
.cache/
|
||||||
|
.rpt2_cache
|
||||||
|
|
||||||
|
# builds
|
||||||
|
dist/
|
||||||
|
dist_*/
|
||||||
|
|
||||||
|
# custom
|
110
.gitlab-ci.yml
110
.gitlab-ci.yml
@ -1,38 +1,64 @@
|
|||||||
# gitzone standard
|
# gitzone ci_default
|
||||||
image: hosttoday/ht-docker-node:npmci
|
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||||
|
|
||||||
cache:
|
cache:
|
||||||
paths:
|
paths:
|
||||||
- .yarn/
|
- .npmci_cache/
|
||||||
key: "$CI_BUILD_STAGE"
|
key: '$CI_BUILD_STAGE'
|
||||||
|
|
||||||
stages:
|
stages:
|
||||||
- test
|
- security
|
||||||
- release
|
- test
|
||||||
- trigger
|
- release
|
||||||
- pages
|
- metadata
|
||||||
|
|
||||||
testLEGACY:
|
# ====================
|
||||||
|
# security stage
|
||||||
|
# ====================
|
||||||
|
mirror:
|
||||||
|
stage: security
|
||||||
|
script:
|
||||||
|
- npmci git mirror
|
||||||
|
only:
|
||||||
|
- tags
|
||||||
|
tags:
|
||||||
|
- lossless
|
||||||
|
- docker
|
||||||
|
- notpriv
|
||||||
|
|
||||||
|
audit:
|
||||||
|
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
|
||||||
|
tags:
|
||||||
|
- docker
|
||||||
|
|
||||||
|
# ====================
|
||||||
|
# test stage
|
||||||
|
# ====================
|
||||||
|
|
||||||
|
testStable:
|
||||||
stage: test
|
stage: test
|
||||||
script:
|
script:
|
||||||
- npmci test legacy
|
- npmci npm prepare
|
||||||
|
- npmci node install stable
|
||||||
|
- npmci npm install
|
||||||
|
- npmci npm test
|
||||||
coverage: /\d+.?\d+?\%\s*coverage/
|
coverage: /\d+.?\d+?\%\s*coverage/
|
||||||
tags:
|
tags:
|
||||||
- docker
|
- docker
|
||||||
allow_failure: true
|
|
||||||
|
|
||||||
testLTS:
|
testBuild:
|
||||||
stage: test
|
stage: test
|
||||||
script:
|
script:
|
||||||
- npmci test lts
|
- npmci npm prepare
|
||||||
coverage: /\d+.?\d+?\%\s*coverage/
|
- npmci node install stable
|
||||||
tags:
|
- npmci npm install
|
||||||
- docker
|
- npmci command npm run build
|
||||||
|
|
||||||
testSTABLE:
|
|
||||||
stage: test
|
|
||||||
script:
|
|
||||||
- npmci test stable
|
|
||||||
coverage: /\d+.?\d+?\%\s*coverage/
|
coverage: /\d+.?\d+?\%\s*coverage/
|
||||||
tags:
|
tags:
|
||||||
- docker
|
- docker
|
||||||
@ -40,32 +66,60 @@ testSTABLE:
|
|||||||
release:
|
release:
|
||||||
stage: release
|
stage: release
|
||||||
script:
|
script:
|
||||||
- npmci publish
|
- npmci node install stable
|
||||||
|
- npmci npm publish
|
||||||
only:
|
only:
|
||||||
- tags
|
- tags
|
||||||
tags:
|
tags:
|
||||||
|
- lossless
|
||||||
- docker
|
- 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:npmci
|
stage: metadata
|
||||||
stage: pages
|
|
||||||
script:
|
script:
|
||||||
- npmci command yarn global add npmpage
|
- npmci node install lts
|
||||||
- npmci command npmpage --publish gitlab
|
- npmci command npm install -g @gitzone/tsdoc
|
||||||
|
- npmci npm prepare
|
||||||
|
- npmci npm install
|
||||||
|
- npmci command tsdoc
|
||||||
tags:
|
tags:
|
||||||
|
- lossless
|
||||||
- docker
|
- 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
29
.vscode/launch.json
vendored
Normal 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
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"]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
40
README.md
40
README.md
@ -1,40 +0,0 @@
|
|||||||
# early
|
|
||||||
minimal and fast loading plugin for startup time measuring
|
|
||||||
|
|
||||||
## Availabililty
|
|
||||||
[](https://www.npmjs.com/package/early)
|
|
||||||
[](https://GitLab.com/pushrocks/early)
|
|
||||||
[](https://github.com/pushrocks/early)
|
|
||||||
[](https://pushrocks.gitlab.io/early/)
|
|
||||||
|
|
||||||
## Status for master
|
|
||||||
[](https://GitLab.com/pushrocks/early/commits/master)
|
|
||||||
[](https://GitLab.com/pushrocks/early/commits/master)
|
|
||||||
[](https://www.npmjs.com/package/early)
|
|
||||||
[](https://david-dm.org/pushrocks/early)
|
|
||||||
[](https://www.bithound.io/github/pushrocks/early/master/dependencies/npm)
|
|
||||||
[](https://www.bithound.io/github/pushrocks/early)
|
|
||||||
[](https://nodejs.org/dist/latest-v6.x/docs/api/)
|
|
||||||
[](https://nodejs.org/dist/latest-v6.x/docs/api/)
|
|
||||||
[](http://standardjs.com/)
|
|
||||||
|
|
||||||
## Usage
|
|
||||||
Use TypeScript for best in class instellisense.
|
|
||||||
|
|
||||||
```javascript
|
|
||||||
// Put the following at the start of your module
|
|
||||||
import * as early from "early";
|
|
||||||
early.start("myModuleName");
|
|
||||||
/*
|
|
||||||
do your loading stuff
|
|
||||||
*/
|
|
||||||
early.stop().then((loadingTime:number) => { // loadingTime in milliseconds
|
|
||||||
|
|
||||||
}); // stop "early" when your module is ready
|
|
||||||
```
|
|
||||||
|
|
||||||
For further information read the linked docs at the top of this README.
|
|
||||||
|
|
||||||
> MIT licensed | **©** [Lossless GmbH](https://lossless.gmbh)
|
|
||||||
|
|
||||||
[](https://push.rocks)
|
|
6
dist/index.d.ts
vendored
6
dist/index.d.ts
vendored
@ -1,6 +0,0 @@
|
|||||||
import 'typings-global';
|
|
||||||
/**
|
|
||||||
* start the loading
|
|
||||||
*/
|
|
||||||
export declare let start: (moduleNameArg?: string, loaderLengthArg?: string) => void;
|
|
||||||
export declare let stop: () => Promise<number>;
|
|
30
dist/index.js
vendored
30
dist/index.js
vendored
@ -1,30 +0,0 @@
|
|||||||
"use strict";
|
|
||||||
Object.defineProperty(exports, "__esModule", { value: true });
|
|
||||||
require("typings-global");
|
|
||||||
const beautycolor = require("beautycolor");
|
|
||||||
const smartq = require("smartq");
|
|
||||||
let doText = false;
|
|
||||||
let moduleName = 'undefined module name';
|
|
||||||
let startTime = Date.now();
|
|
||||||
if (process.argv.indexOf('-v') === -1) {
|
|
||||||
doText = true;
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* start the loading
|
|
||||||
*/
|
|
||||||
exports.start = function (moduleNameArg = '', loaderLengthArg = '10') {
|
|
||||||
moduleName = moduleNameArg;
|
|
||||||
if (doText) {
|
|
||||||
console.log(`**** starting ${beautycolor.coloredString(moduleNameArg, 'green')} ****`);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
exports.stop = () => {
|
|
||||||
let done = smartq.defer();
|
|
||||||
let endTime = Date.now();
|
|
||||||
let earlyExecutionTime = (endTime - startTime);
|
|
||||||
let earlyExecutionTimeString = (earlyExecutionTime / 1000).toString();
|
|
||||||
console.log(`OK! -> finished loading within ${beautycolor.coloredString(earlyExecutionTimeString, 'blue')}`);
|
|
||||||
done.resolve(earlyExecutionTime);
|
|
||||||
return done.promise;
|
|
||||||
};
|
|
||||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOztBQUFBLDBCQUF1QjtBQUN2QiwyQ0FBMEM7QUFDMUMsaUNBQWdDO0FBRWhDLElBQUksTUFBTSxHQUFZLEtBQUssQ0FBQTtBQUMzQixJQUFJLFVBQVUsR0FBVyx1QkFBdUIsQ0FBQTtBQUNoRCxJQUFJLFNBQVMsR0FBRyxJQUFJLENBQUMsR0FBRyxFQUFFLENBQUE7QUFFMUIsRUFBRSxDQUFDLENBQUMsT0FBTyxDQUFDLElBQUksQ0FBQyxPQUFPLENBQUMsSUFBSSxDQUFDLEtBQUssQ0FBQyxDQUFDLENBQUMsQ0FBQyxDQUFDO0lBQ3RDLE1BQU0sR0FBRyxJQUFJLENBQUE7QUFDZixDQUFDO0FBRUQ7O0dBRUc7QUFDUSxRQUFBLEtBQUssR0FBRyxVQUFVLGdCQUF3QixFQUFFLEVBQUUsa0JBQTBCLElBQUk7SUFDckYsVUFBVSxHQUFHLGFBQWEsQ0FBQTtJQUMxQixFQUFFLENBQUMsQ0FBQyxNQUFNLENBQUMsQ0FBQyxDQUFDO1FBQ1gsT0FBTyxDQUFDLEdBQUcsQ0FBQyxpQkFBaUIsV0FBVyxDQUFDLGFBQWEsQ0FBQyxhQUFhLEVBQUUsT0FBTyxDQUFDLE9BQU8sQ0FBQyxDQUFBO0lBQ3hGLENBQUM7QUFDSCxDQUFDLENBQUE7QUFFVSxRQUFBLElBQUksR0FBRztJQUNoQixJQUFJLElBQUksR0FBRyxNQUFNLENBQUMsS0FBSyxFQUFVLENBQUE7SUFDakMsSUFBSSxPQUFPLEdBQUcsSUFBSSxDQUFDLEdBQUcsRUFBRSxDQUFBO0lBQ3hCLElBQUksa0JBQWtCLEdBQVcsQ0FBQyxPQUFPLEdBQUcsU0FBUyxDQUFDLENBQUE7SUFDdEQsSUFBSSx3QkFBd0IsR0FBVyxDQUFDLGtCQUFrQixHQUFHLElBQUksQ0FBQyxDQUFDLFFBQVEsRUFBRSxDQUFBO0lBQzdFLE9BQU8sQ0FBQyxHQUFHLENBQUMsa0NBQWtDLFdBQVcsQ0FBQyxhQUFhLENBQUMsd0JBQXdCLEVBQUUsTUFBTSxDQUFDLEVBQUUsQ0FBQyxDQUFBO0lBQzVHLElBQUksQ0FBQyxPQUFPLENBQUMsa0JBQWtCLENBQUMsQ0FBQTtJQUNoQyxNQUFNLENBQUMsSUFBSSxDQUFDLE9BQU8sQ0FBQTtBQUNyQixDQUFDLENBQUEifQ==
|
|
@ -1,10 +1,17 @@
|
|||||||
{
|
{
|
||||||
"npmts":{
|
"npmci": {
|
||||||
"coverageTreshold":50
|
"npmGlobalTools": [],
|
||||||
},
|
"npmAccessLevel": "public"
|
||||||
"npmci": {
|
},
|
||||||
"globalNpmTools": [
|
"gitzone": {
|
||||||
"npmts"
|
"projectType": "npm",
|
||||||
]
|
"module": {
|
||||||
|
"githost": "gitlab.com",
|
||||||
|
"gitscope": "pushrocks",
|
||||||
|
"gitrepo": "early",
|
||||||
|
"shortDescription": "minimal and fast loading plugin for startup time measuring",
|
||||||
|
"npmPackagename": "@pushrocks/early",
|
||||||
|
"license": "MIT"
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
18433
package-lock.json
generated
Normal file
18433
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
42
package.json
42
package.json
@ -1,11 +1,14 @@
|
|||||||
{
|
{
|
||||||
"name": "early",
|
"name": "@pushrocks/early",
|
||||||
"version": "2.0.38",
|
"version": "4.0.0",
|
||||||
|
"private": false,
|
||||||
"description": "minimal and fast loading plugin for startup time measuring",
|
"description": "minimal and fast loading plugin for startup time measuring",
|
||||||
"main": "dist/index.js",
|
"main": "dist_ts/index.js",
|
||||||
"typings": "dist/index.d.ts",
|
"typings": "dist_ts/index.d.ts",
|
||||||
|
"type": "module",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "(npmts)"
|
"test": "(tstest test/)",
|
||||||
|
"build": "(tsbuild --web)"
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
@ -21,12 +24,29 @@
|
|||||||
},
|
},
|
||||||
"homepage": "https://gitlab.com/pushrocks/early#readme",
|
"homepage": "https://gitlab.com/pushrocks/early#readme",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"smartdelay": "^1.0.1",
|
"@gitzone/tsrun": "^1.2.31",
|
||||||
"tapbundle": "^1.0.5"
|
"@gitzone/tstest": "^1.0.69",
|
||||||
|
"@pushrocks/smartdelay": "^2.0.13",
|
||||||
|
"@pushrocks/tapbundle": "^5.0.2"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"beautycolor": "^1.0.7",
|
"@gitzone/tsbuild": "^2.1.60",
|
||||||
"smartq": "^1.1.1",
|
"@pushrocks/consolecolor": "^2.0.1",
|
||||||
"typings-global": "^1.0.14"
|
"@pushrocks/smartpromise": "^3.1.7"
|
||||||
}
|
},
|
||||||
|
"files": [
|
||||||
|
"ts/**/*",
|
||||||
|
"ts_web/**/*",
|
||||||
|
"dist/**/*",
|
||||||
|
"dist_*/**/*",
|
||||||
|
"dist_ts/**/*",
|
||||||
|
"dist_ts_web/**/*",
|
||||||
|
"assets/**/*",
|
||||||
|
"cli.js",
|
||||||
|
"npmextra.json",
|
||||||
|
"readme.md"
|
||||||
|
],
|
||||||
|
"browserslist": [
|
||||||
|
"last 1 chrome versions"
|
||||||
|
]
|
||||||
}
|
}
|
||||||
|
51
readme.md
Normal file
51
readme.md
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
# @pushrocks/early
|
||||||
|
minimal and fast loading plugin for startup time measuring
|
||||||
|
|
||||||
|
## Availabililty and Links
|
||||||
|
* [npmjs.org (npm package)](https://www.npmjs.com/package/@pushrocks/early)
|
||||||
|
* [gitlab.com (source)](https://gitlab.com/pushrocks/early)
|
||||||
|
* [github.com (source mirror)](https://github.com/pushrocks/early)
|
||||||
|
* [docs (typedoc)](https://pushrocks.gitlab.io/early/)
|
||||||
|
|
||||||
|
## 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
|
||||||
|
|
||||||
|
Use TypeScript for best in class instellisense.
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
// Put the following at the start of your module
|
||||||
|
import * as early from 'early';
|
||||||
|
early.start('myModuleName');
|
||||||
|
/*
|
||||||
|
do your loading stuff
|
||||||
|
*/
|
||||||
|
early.stop().then((loadingTime: number) => {
|
||||||
|
// loadingTime in milliseconds
|
||||||
|
}); // stop "early" when your module is ready
|
||||||
|
```
|
||||||
|
|
||||||
|
## 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)
|
30
test/test.ts
30
test/test.ts
@ -1,11 +1,25 @@
|
|||||||
import { expect, tap } from 'tapbundle'
|
import { expect, expectAsync, tap } from '@pushrocks/tapbundle';
|
||||||
import * as smartdelay from 'smartdelay'
|
import * as smartdelay from '@pushrocks/smartdelay';
|
||||||
import early = require('../dist/index')
|
|
||||||
|
import * as early from '../ts/index.js'
|
||||||
|
|
||||||
tap.test('.start()', async () => {
|
tap.test('.start()', async () => {
|
||||||
early.start('early')
|
process.env.CLI_CALL_MODULENAME = 'early';
|
||||||
await smartdelay.delayFor(2000)
|
early.start('early');
|
||||||
})
|
await smartdelay.delayFor(2000);
|
||||||
|
});
|
||||||
|
|
||||||
tap.test('.stop()', async () => {
|
tap.test('.stop()', async () => {
|
||||||
await early.stop()
|
await early.stop();
|
||||||
})
|
});
|
||||||
|
|
||||||
|
tap.test('hrTime Measurement', async () => {
|
||||||
|
let earlyHr = new early.HrtMeasurement();
|
||||||
|
earlyHr.start();
|
||||||
|
await smartdelay.delayFor(1000);
|
||||||
|
let measuredTime = earlyHr.stop();
|
||||||
|
console.log(measuredTime);
|
||||||
|
return expect(measuredTime.milliSeconds).toBeGreaterThan(999);
|
||||||
|
});
|
||||||
|
|
||||||
|
tap.start();
|
||||||
|
45
ts/early.hrtMeasurement.ts
Normal file
45
ts/early.hrtMeasurement.ts
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
import * as process from 'process';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* easy high resolution time measurement
|
||||||
|
*/
|
||||||
|
export class HrtMeasurement {
|
||||||
|
nanoSeconds: number = null;
|
||||||
|
milliSeconds: number = null;
|
||||||
|
private _hrTimeStart = null;
|
||||||
|
private _hrTimeStopDiff = null;
|
||||||
|
private _started: boolean = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* start the measurement
|
||||||
|
*/
|
||||||
|
start() {
|
||||||
|
this._started = true;
|
||||||
|
this._hrTimeStart = process.hrtime();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* stop the measurement
|
||||||
|
*/
|
||||||
|
stop() {
|
||||||
|
if (this._started === false) {
|
||||||
|
console.log("Hasn't started yet");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this._hrTimeStopDiff = process.hrtime(this._hrTimeStart);
|
||||||
|
this.nanoSeconds = this._hrTimeStopDiff[0] * 1e9 + this._hrTimeStopDiff[1];
|
||||||
|
this.milliSeconds = this.nanoSeconds / 1000000;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* reset the measurement
|
||||||
|
*/
|
||||||
|
reset() {
|
||||||
|
this.nanoSeconds = null;
|
||||||
|
this.milliSeconds = null;
|
||||||
|
this._hrTimeStart = null;
|
||||||
|
this._hrTimeStopDiff = null;
|
||||||
|
this._started = false;
|
||||||
|
}
|
||||||
|
}
|
49
ts/index.ts
49
ts/index.ts
@ -1,31 +1,42 @@
|
|||||||
import 'typings-global'
|
import * as consolecolor from '@pushrocks/consolecolor';
|
||||||
import * as beautycolor from 'beautycolor'
|
import * as smartpromise from '@pushrocks/smartpromise';
|
||||||
import * as smartq from 'smartq'
|
import { HrtMeasurement } from './early.hrtMeasurement.js';
|
||||||
|
|
||||||
let doText: boolean = false
|
export { HrtMeasurement };
|
||||||
let moduleName: string = 'undefined module name'
|
|
||||||
let startTime = Date.now()
|
let doText: boolean = false;
|
||||||
|
let moduleName: string = 'undefined module name';
|
||||||
|
let startHrt: HrtMeasurement;
|
||||||
|
|
||||||
if (process.argv.indexOf('-v') === -1) {
|
if (process.argv.indexOf('-v') === -1) {
|
||||||
doText = true
|
doText = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* start the loading
|
* start the loading
|
||||||
*/
|
*/
|
||||||
export let start = function (moduleNameArg: string = '', loaderLengthArg: string = '10') {
|
export let start = function (moduleNameArg: string = '', loaderLengthArg: string = '10') {
|
||||||
moduleName = moduleNameArg
|
moduleName = moduleNameArg;
|
||||||
if (doText) {
|
startHrt = new HrtMeasurement();
|
||||||
console.log(`**** starting ${beautycolor.coloredString(moduleNameArg, 'green')} ****`)
|
startHrt.start();
|
||||||
|
if (doText && process.env.CLI_CALL_MODULENAME === moduleName) {
|
||||||
|
console.log(`**** starting ${consolecolor.coloredString(moduleNameArg, 'green')} ****`);
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
export let stop = (): Promise<number> => {
|
export let stop = (): Promise<number> => {
|
||||||
let done = smartq.defer<number>()
|
let done = smartpromise.defer<number>();
|
||||||
let endTime = Date.now()
|
let earlyExecutionTime = startHrt.stop().milliSeconds;
|
||||||
let earlyExecutionTime: number = (endTime - startTime)
|
let earlyExecutionTimeString: string = (earlyExecutionTime / 1000).toString();
|
||||||
let earlyExecutionTimeString: string = (earlyExecutionTime / 1000).toString()
|
if (doText && process.env.CLI_CALL_MODULENAME === moduleName) {
|
||||||
console.log(`OK! -> finished loading within ${beautycolor.coloredString(earlyExecutionTimeString, 'blue')}`)
|
console.log(
|
||||||
done.resolve(earlyExecutionTime)
|
`OK! -> finished loading within ${consolecolor.coloredString(
|
||||||
return done.promise
|
earlyExecutionTimeString,
|
||||||
}
|
'blue'
|
||||||
|
)}`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
done.resolve(earlyExecutionTime);
|
||||||
|
return done.promise;
|
||||||
|
};
|
||||||
|
7
tsconfig.json
Normal file
7
tsconfig.json
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
{
|
||||||
|
"compilerOptions": {
|
||||||
|
"target": "ES2022",
|
||||||
|
"module": "ES2022",
|
||||||
|
"moduleResolution": "nodenext"
|
||||||
|
}
|
||||||
|
}
|
@ -1,3 +0,0 @@
|
|||||||
{
|
|
||||||
"extends": "tslint-config-standard"
|
|
||||||
}
|
|
Reference in New Issue
Block a user