Compare commits
No commits in common. "master" and "v2.0.24" have entirely different histories.
@ -1,66 +0,0 @@
|
||||
name: Default (not tags)
|
||||
|
||||
on:
|
||||
push:
|
||||
tags-ignore:
|
||||
- '**'
|
||||
|
||||
env:
|
||||
IMAGE: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||
NPMCI_COMPUTED_REPOURL: https://${{gitea.repository_owner}}:${{secrets.GITEA_TOKEN}}@gitea.lossless.digital/${{gitea.repository}}.git
|
||||
NPMCI_TOKEN_NPM: ${{secrets.NPMCI_TOKEN_NPM}}
|
||||
NPMCI_TOKEN_NPM2: ${{secrets.NPMCI_TOKEN_NPM2}}
|
||||
NPMCI_GIT_GITHUBTOKEN: ${{secrets.NPMCI_GIT_GITHUBTOKEN}}
|
||||
NPMCI_URL_CLOUDLY: ${{secrets.NPMCI_URL_CLOUDLY}}
|
||||
|
||||
jobs:
|
||||
security:
|
||||
runs-on: ubuntu-latest
|
||||
continue-on-error: true
|
||||
container:
|
||||
image: ${{ env.IMAGE }}
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
- name: Install pnpm and npmci
|
||||
run: |
|
||||
pnpm install -g pnpm
|
||||
pnpm install -g @shipzone/npmci
|
||||
|
||||
- name: Run npm prepare
|
||||
run: npmci npm prepare
|
||||
|
||||
- name: Audit production dependencies
|
||||
run: |
|
||||
npmci command npm config set registry https://registry.npmjs.org
|
||||
npmci command pnpm audit --audit-level=high --prod
|
||||
continue-on-error: true
|
||||
|
||||
- name: Audit development dependencies
|
||||
run: |
|
||||
npmci command npm config set registry https://registry.npmjs.org
|
||||
npmci command pnpm audit --audit-level=high --dev
|
||||
continue-on-error: true
|
||||
|
||||
test:
|
||||
if: ${{ always() }}
|
||||
needs: security
|
||||
runs-on: ubuntu-latest
|
||||
container:
|
||||
image: ${{ env.IMAGE }}
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
- name: Test stable
|
||||
run: |
|
||||
npmci node install stable
|
||||
npmci npm install
|
||||
npmci npm test
|
||||
|
||||
- name: Test build
|
||||
run: |
|
||||
npmci node install stable
|
||||
npmci npm install
|
||||
npmci npm build
|
@ -1,124 +0,0 @@
|
||||
name: Default (tags)
|
||||
|
||||
on:
|
||||
push:
|
||||
tags:
|
||||
- '*'
|
||||
|
||||
env:
|
||||
IMAGE: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||
NPMCI_COMPUTED_REPOURL: https://${{gitea.repository_owner}}:${{secrets.GITEA_TOKEN}}@gitea.lossless.digital/${{gitea.repository}}.git
|
||||
NPMCI_TOKEN_NPM: ${{secrets.NPMCI_TOKEN_NPM}}
|
||||
NPMCI_TOKEN_NPM2: ${{secrets.NPMCI_TOKEN_NPM2}}
|
||||
NPMCI_GIT_GITHUBTOKEN: ${{secrets.NPMCI_GIT_GITHUBTOKEN}}
|
||||
NPMCI_URL_CLOUDLY: ${{secrets.NPMCI_URL_CLOUDLY}}
|
||||
|
||||
jobs:
|
||||
security:
|
||||
runs-on: ubuntu-latest
|
||||
continue-on-error: true
|
||||
container:
|
||||
image: ${{ env.IMAGE }}
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
- name: Prepare
|
||||
run: |
|
||||
pnpm install -g pnpm
|
||||
pnpm install -g @shipzone/npmci
|
||||
npmci npm prepare
|
||||
|
||||
- name: Audit production dependencies
|
||||
run: |
|
||||
npmci command npm config set registry https://registry.npmjs.org
|
||||
npmci command pnpm audit --audit-level=high --prod
|
||||
continue-on-error: true
|
||||
|
||||
- name: Audit development dependencies
|
||||
run: |
|
||||
npmci command npm config set registry https://registry.npmjs.org
|
||||
npmci command pnpm audit --audit-level=high --dev
|
||||
continue-on-error: true
|
||||
|
||||
test:
|
||||
if: ${{ always() }}
|
||||
needs: security
|
||||
runs-on: ubuntu-latest
|
||||
container:
|
||||
image: ${{ env.IMAGE }}
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
- name: Prepare
|
||||
run: |
|
||||
pnpm install -g pnpm
|
||||
pnpm install -g @shipzone/npmci
|
||||
npmci npm prepare
|
||||
|
||||
- name: Test stable
|
||||
run: |
|
||||
npmci node install stable
|
||||
npmci npm install
|
||||
npmci npm test
|
||||
|
||||
- name: Test build
|
||||
run: |
|
||||
npmci node install stable
|
||||
npmci npm install
|
||||
npmci npm build
|
||||
|
||||
release:
|
||||
needs: test
|
||||
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')
|
||||
runs-on: ubuntu-latest
|
||||
container:
|
||||
image: ${{ env.IMAGE }}
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
- name: Prepare
|
||||
run: |
|
||||
pnpm install -g pnpm
|
||||
pnpm install -g @shipzone/npmci
|
||||
npmci npm prepare
|
||||
|
||||
- name: Release
|
||||
run: |
|
||||
npmci node install stable
|
||||
npmci npm publish
|
||||
|
||||
metadata:
|
||||
needs: test
|
||||
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')
|
||||
runs-on: ubuntu-latest
|
||||
container:
|
||||
image: ${{ env.IMAGE }}
|
||||
continue-on-error: true
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
- name: Prepare
|
||||
run: |
|
||||
pnpm install -g pnpm
|
||||
pnpm install -g @shipzone/npmci
|
||||
npmci npm prepare
|
||||
|
||||
- name: Code quality
|
||||
run: |
|
||||
npmci command npm install -g typescript
|
||||
npmci npm install
|
||||
|
||||
- name: Trigger
|
||||
run: npmci trigger
|
||||
|
||||
- name: Build docs and upload artifacts
|
||||
run: |
|
||||
npmci node install stable
|
||||
npmci npm install
|
||||
pnpm install -g @gitzone/tsdoc
|
||||
npmci command tsdoc
|
||||
continue-on-error: true
|
22
.gitignore
vendored
22
.gitignore
vendored
@ -1,20 +1,4 @@
|
||||
.nogit/
|
||||
|
||||
# artifacts
|
||||
coverage/
|
||||
public/
|
||||
pages/
|
||||
|
||||
# installs
|
||||
node_modules/
|
||||
|
||||
# caches
|
||||
.yarn/
|
||||
.cache/
|
||||
.rpt2_cache
|
||||
|
||||
# builds
|
||||
dist/
|
||||
dist_*/
|
||||
|
||||
# custom
|
||||
docs/
|
||||
coverage/
|
||||
ts/typings/
|
137
.gitlab-ci.yml
137
.gitlab-ci.yml
@ -1,140 +1,35 @@
|
||||
# gitzone ci_default
|
||||
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||
|
||||
cache:
|
||||
paths:
|
||||
- .npmci_cache/
|
||||
key: '$CI_BUILD_STAGE'
|
||||
image: hosttoday/ht-docker-node:npmts
|
||||
|
||||
stages:
|
||||
- security
|
||||
- test
|
||||
- release
|
||||
- metadata
|
||||
- test
|
||||
- release
|
||||
|
||||
before_script:
|
||||
- npm install -g @shipzone/npmci
|
||||
|
||||
# ====================
|
||||
# security stage
|
||||
# ====================
|
||||
mirror:
|
||||
stage: security
|
||||
script:
|
||||
- npmci git mirror
|
||||
only:
|
||||
- tags
|
||||
tags:
|
||||
- lossless
|
||||
- docker
|
||||
- notpriv
|
||||
|
||||
auditProductionDependencies:
|
||||
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||
stage: security
|
||||
script:
|
||||
- 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
|
||||
|
||||
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:
|
||||
testLEGACY:
|
||||
stage: test
|
||||
script:
|
||||
- npmci npm prepare
|
||||
- npmci node install stable
|
||||
- npmci npm install
|
||||
- npmci npm test
|
||||
coverage: /\d+.?\d+?\%\s*coverage/
|
||||
- npmci test legacy
|
||||
tags:
|
||||
- docker
|
||||
|
||||
testBuild:
|
||||
testLTS:
|
||||
stage: test
|
||||
script:
|
||||
- npmci npm prepare
|
||||
- npmci node install stable
|
||||
- npmci npm install
|
||||
- npmci command npm run build
|
||||
coverage: /\d+.?\d+?\%\s*coverage/
|
||||
- npmci test lts
|
||||
tags:
|
||||
- docker
|
||||
|
||||
testSTABLE:
|
||||
stage: test
|
||||
script:
|
||||
- npmci test stable
|
||||
tags:
|
||||
- docker
|
||||
|
||||
release:
|
||||
stage: release
|
||||
script:
|
||||
- npmci node install stable
|
||||
- npmci npm publish
|
||||
- npmci 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: metadata
|
||||
script:
|
||||
- npmci trigger
|
||||
only:
|
||||
- tags
|
||||
tags:
|
||||
- lossless
|
||||
- docker
|
||||
- notpriv
|
||||
|
||||
pages:
|
||||
stage: metadata
|
||||
script:
|
||||
- npmci node install lts
|
||||
- npmci command npm install -g @gitzone/tsdoc
|
||||
- npmci npm prepare
|
||||
- npmci npm install
|
||||
- npmci command tsdoc
|
||||
tags:
|
||||
- lossless
|
||||
- docker
|
||||
- notpriv
|
||||
only:
|
||||
- tags
|
||||
artifacts:
|
||||
expire_in: 1 week
|
||||
paths:
|
||||
- public
|
||||
allow_failure: true
|
||||
- docker
|
2
.npmignore
Normal file
2
.npmignore
Normal file
@ -0,0 +1,2 @@
|
||||
docs/
|
||||
coverage/
|
12
.travis.yml
Normal file
12
.travis.yml
Normal file
@ -0,0 +1,12 @@
|
||||
language: node_js
|
||||
node_js:
|
||||
- '4'
|
||||
- stable
|
||||
deploy:
|
||||
provider: npm
|
||||
email: npm@lossless.digital
|
||||
api_key:
|
||||
secure: WmJJw1aJ1kbTOtArdBvgtYEcEk2899hiPc/XnCoUrHz45DAgnAES4eVUbhI5AC78tjnKc+iqbB9e5+vziSW4G5P4KAuP0CYLd5v4G5ZC4IYigFPxroIib7wFtGoOlhe8AItLDMdYO2KcPYXVpZzaITj2FlfNjoqg5UiKnSVShKwUALQk6JdZ345d0iwyr2nmNA6m0FJhcO2weY3BEDRyPWuody/FEoVZ3I2Q1f3R50v3Kb7Nzfn0uob5ABjux4YZ4xJ6tNeJkU021tSgJhjqfwbVMoIVJohwa5jlaqXdMQvWWKvhOAFyDj6zOJ1BnIuVYltDoWczuPi3+YVtFoc2+rYdSXYUcK1aCfVQZ8DDYYzlZ9Sp1vxiy8D3RZuNkLzUImranCDl6r6EYTxEw2L2bAowo9wLZtnht/mlRvOOLM9ZYVi0yr7Cd9FhVfiLZO97OGybfTFvih+nbMZGk5/RVeQzYzsycgeNT96ii5+de0yerbD690Qf+Kap5IlS5Fyvo2Y/SVQ3nxgQt7Pa4bTLbMwzSmXoBgUO6j6d8Qv7fPGQvbOQJEGJaZDaqpgxxS7WIc2YtwLXXob757BxKNW6Y6xPCcTqX7lMqfyQa194EjPTNTK+O0YnGAFFnXps/uCc8ccH3z3x6IrAAQpPx68gPERiWMf2WiPsMoh+kH4UzLc=
|
||||
on:
|
||||
tags: true
|
||||
repo: pushrocks/early
|
11
.vscode/launch.json
vendored
11
.vscode/launch.json
vendored
@ -1,11 +0,0 @@
|
||||
{
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"command": "npm test",
|
||||
"name": "Run npm test",
|
||||
"request": "launch",
|
||||
"type": "node-terminal"
|
||||
}
|
||||
]
|
||||
}
|
26
.vscode/settings.json
vendored
26
.vscode/settings.json
vendored
@ -1,26 +0,0 @@
|
||||
{
|
||||
"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"]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
2
LICENSE
2
LICENSE
@ -1,6 +1,6 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2016 Lossless GmbH
|
||||
Copyright (c) 2016 Push.Rocks
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
|
16
README.md
Normal file
16
README.md
Normal file
@ -0,0 +1,16 @@
|
||||
# early
|
||||
minimal and fast loading animation for modules that need a little starting time.
|
||||
|
||||
## Usage
|
||||
|
||||
```typescript
|
||||
// Put the following at the start of your module
|
||||
import * as early from "early";
|
||||
early.start("myModuleName");
|
||||
/*
|
||||
do your loading stuff
|
||||
*/
|
||||
early.stop(); // stop "early" when your module is ready
|
||||
```
|
||||
|
||||
early runs in its own process: The loader animation runs smoothly even when your event queue of your currently loading module is working heavily.
|
1
dist/early.child.d.ts
vendored
Normal file
1
dist/early.child.d.ts
vendored
Normal file
@ -0,0 +1 @@
|
||||
import "typings-global";
|
46
dist/early.child.js
vendored
Normal file
46
dist/early.child.js
vendored
Normal file
@ -0,0 +1,46 @@
|
||||
"use strict";
|
||||
require("typings-global");
|
||||
const chalk = require("chalk");
|
||||
const readline = require("readline");
|
||||
let rl = readline.createInterface({
|
||||
input: process.stdin,
|
||||
output: process.stdout
|
||||
});
|
||||
let moduleName;
|
||||
let loaderLength;
|
||||
let frameCounter = 0;
|
||||
let makeFrame = () => {
|
||||
let resultString = `[${chalk.green("/".repeat(frameCounter))}${" ".repeat(loaderLength - frameCounter)}] starting ${moduleName}`;
|
||||
if (frameCounter == loaderLength) {
|
||||
frameCounter = 0;
|
||||
}
|
||||
else {
|
||||
frameCounter++;
|
||||
}
|
||||
return resultString;
|
||||
};
|
||||
let logEarlyAbort = false;
|
||||
let logEarly = () => {
|
||||
if (!logEarlyAbort) {
|
||||
rl.write(null, { ctrl: true, name: 'u' });
|
||||
rl.write(makeFrame());
|
||||
setTimeout(function () {
|
||||
logEarly();
|
||||
}, 80);
|
||||
}
|
||||
};
|
||||
let start = function (moduleNameArg = "", loaderLengthArg = "10") {
|
||||
moduleName = moduleNameArg;
|
||||
loaderLength = parseInt(loaderLengthArg);
|
||||
logEarly();
|
||||
};
|
||||
start(process.env.moduleNameArg, process.env.loaderLengthArg);
|
||||
process.on('SIGINT', () => {
|
||||
logEarlyAbort = true;
|
||||
rl.write(null, { ctrl: true, name: 'u' });
|
||||
rl.write(`loaded ${chalk.green(moduleName)}`);
|
||||
rl.close();
|
||||
rl.on("close", () => {
|
||||
});
|
||||
});
|
||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZWFybHkuY2hpbGQuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9lYXJseS5jaGlsZC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQUEsUUFBTyxnQkFBZ0IsQ0FBQyxDQUFBO0FBQ3hCLE1BQU8sS0FBSyxXQUFXLE9BQU8sQ0FBQyxDQUFDO0FBQ2hDLE1BQU8sUUFBUSxXQUFXLFVBQVUsQ0FBQyxDQUFDO0FBQ3RDLElBQUksRUFBRSxHQUFHLFFBQVEsQ0FBQyxlQUFlLENBQUM7SUFDOUIsS0FBSyxFQUFFLE9BQU8sQ0FBQyxLQUFLO0l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JQUFJLEtBQUssR0FBRyxVQUFVLGFBQWEsR0FBVyxFQUFFLEVBQUUsZUFBZSxHQUFXLElBQUk7SUFDNUUsVUFBVSxHQUFHLGFBQWEsQ0FBQztJQUMzQixZQUFZLEdBQUcsUUFBUSxDQUFDLGVBQWUsQ0FBQyxDQUFDO0lBQ3pDLFFBQVEsRUFBRSxDQUFDO0FBQ2YsQ0FBQyxDQUFDO0FBRUYsS0FBSyxDQUFDLE9BQU8sQ0FBQyxHQUFHLENBQUMsYUFBYSxFQUFFLE9BQU8sQ0FBQyxHQUFHLENBQUMsZUFBZSxDQUFDLENBQUM7QUFFOUQsT0FBTyxDQUFDLEVBQUUsQ0FBQyxRQUFRLEVBQUU7SUFDakIsYUFBYSxHQUFHLElBQUksQ0FBQztJQUNyQixFQUFFLENBQUMsS0FBSyxDQUFDLElBQUksRUFBRSxFQUFFLElBQUksRUFBRSxJQUFJLEVBQUUsSUFBSSxFQUFFLEdBQUcsRUFBRSxDQUFDLENBQUM7SUFDMUMsRUFBRSxDQUFDLEtBQUssQ0FBQyxVQUFVLEtBQUssQ0FBQyxLQUFLLENBQUMsVUFBVSxDQUFDLEVBQUUsQ0FBQyxDQUFDO0lBQzlDLEVBQUUsQ0FBQyxLQUFLLEVBQUUsQ0FBQztJQUNYLEVBQUUsQ0FBQyxFQUFFLENBQUMsT0FBTyxFQUFDO0lBRWQsQ0FBQyxDQUFDLENBQUE7QUFDTixDQUFDLENBQUMsQ0FBQyJ9
|
3
dist/index.d.ts
vendored
Normal file
3
dist/index.d.ts
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
import "typings-global";
|
||||
export declare let start: (moduleNameArg?: string, loaderLengthArg?: string) => void;
|
||||
export declare let stop: () => any;
|
52
dist/index.js
vendored
Normal file
52
dist/index.js
vendored
Normal file
@ -0,0 +1,52 @@
|
||||
"use strict";
|
||||
require("typings-global");
|
||||
const path = require("path");
|
||||
const chalk = require("chalk");
|
||||
let q = require("q");
|
||||
const childProcess = require("child_process");
|
||||
let earlyChild;
|
||||
let doAnimation = true;
|
||||
let doText = false;
|
||||
let moduleName = "undefined module name";
|
||||
let startTime;
|
||||
if (process.argv.indexOf("-v") != -1 || process.env.CI) {
|
||||
doAnimation = false;
|
||||
}
|
||||
if (process.argv.indexOf("-v") == -1 && process.env.CI) {
|
||||
doText = true;
|
||||
}
|
||||
// exports
|
||||
exports.start = function (moduleNameArg = "", loaderLengthArg = "10") {
|
||||
startTime = Date.now();
|
||||
moduleName = moduleNameArg;
|
||||
if (doAnimation) {
|
||||
earlyChild = childProcess.fork(path.join(__dirname, "early.child.js"), [], {
|
||||
env: {
|
||||
moduleNameArg: moduleNameArg,
|
||||
loaderLengthArg: loaderLengthArg,
|
||||
CI: process.env.CI
|
||||
}
|
||||
});
|
||||
}
|
||||
else if (doText) {
|
||||
console.log(`**** starting ${chalk.green(moduleNameArg)} ****`);
|
||||
}
|
||||
};
|
||||
exports.stop = function () {
|
||||
let done = q.defer();
|
||||
let endTime = Date.now();
|
||||
let executionTime = ((endTime - startTime) / 1000).toString();
|
||||
if (doAnimation) {
|
||||
earlyChild.kill("SIGINT");
|
||||
earlyChild.on("close", function () {
|
||||
console.log(` in ${executionTime} seconds!`);
|
||||
done.resolve();
|
||||
});
|
||||
}
|
||||
else {
|
||||
console.log(`... finished loading ${moduleName} in ${executionTime}`);
|
||||
done.resolve();
|
||||
}
|
||||
return done.promise;
|
||||
};
|
||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQUEsUUFBTyxnQkFDUCxDQUFDLENBRHNCO0FBQ3ZCLE1BQU8sSUFBSSxXQUFXLE1BQU0sQ0FBQyxDQUFDO0FBQzlCLE1BQU8sS0FBSyxXQUFXLE9BQU8sQ0FBQyxDQUFDO0FBQ2hDLElBQUksQ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0FBQyxDQUFDO1FBQ3RFLElBQUksQ0FBQyxPQUFPLEVBQUUsQ0FBQztJQUNuQixDQUFDO0lBQ0QsTUFBTSxDQUFDLElBQUksQ0FBQyxPQUFPLENBQUM7QUFDeEIsQ0FBQyxDQUFDIn0=
|
@ -1,28 +1,5 @@
|
||||
{
|
||||
"npmci": {
|
||||
"npmGlobalTools": [],
|
||||
"npmAccessLevel": "public"
|
||||
},
|
||||
"gitzone": {
|
||||
"projectType": "npm",
|
||||
"module": {
|
||||
"githost": "code.foss.global",
|
||||
"gitscope": "push.rocks",
|
||||
"gitrepo": "early",
|
||||
"description": "A plugin for measuring startup time with minimal performance impact.",
|
||||
"npmPackagename": "@push.rocks/early",
|
||||
"license": "MIT",
|
||||
"keywords": [
|
||||
"performance measurement",
|
||||
"startup time",
|
||||
"high resolution timer",
|
||||
"plugin",
|
||||
"typescript",
|
||||
"nodejs"
|
||||
]
|
||||
"npmts":{
|
||||
"coverageTreshold":50
|
||||
}
|
||||
},
|
||||
"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"
|
||||
}
|
||||
}
|
4
npmts.json
Normal file
4
npmts.json
Normal file
@ -0,0 +1,4 @@
|
||||
{
|
||||
"mode":"default",
|
||||
"coverageTreshold":30
|
||||
}
|
60
package.json
60
package.json
@ -1,59 +1,33 @@
|
||||
{
|
||||
"name": "@push.rocks/early",
|
||||
"version": "4.0.4",
|
||||
"private": false,
|
||||
"description": "A plugin for measuring startup time with minimal performance impact.",
|
||||
"main": "dist_ts/index.js",
|
||||
"typings": "dist_ts/index.d.ts",
|
||||
"type": "module",
|
||||
"name": "early",
|
||||
"version": "2.0.24",
|
||||
"description": "nice module loading animation for modules that need a little starting time.",
|
||||
"main": "dist/index.js",
|
||||
"typings": "dist/index.d.ts",
|
||||
"scripts": {
|
||||
"test": "(tstest test/)",
|
||||
"build": "(tsbuild --web)",
|
||||
"buildDocs": "tsdoc"
|
||||
"test": "(npmts)"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://code.foss.global/push.rocks/early.git"
|
||||
"url": "git+https://gitlab.com/pushrocks/early.git"
|
||||
},
|
||||
"keywords": [
|
||||
"performance measurement",
|
||||
"startup time",
|
||||
"high resolution timer",
|
||||
"plugin",
|
||||
"typescript",
|
||||
"nodejs"
|
||||
"preloader"
|
||||
],
|
||||
"author": "Lossless GmbH",
|
||||
"license": "MIT",
|
||||
"bugs": {
|
||||
"url": "https://gitlab.com/pushrocks/early/issues"
|
||||
},
|
||||
"homepage": "https://code.foss.global/push.rocks/early",
|
||||
"homepage": "https://gitlab.com/pushrocks/early#readme",
|
||||
"devDependencies": {
|
||||
"@gitzone/tsbuild": "^2.1.66",
|
||||
"@gitzone/tsrun": "^1.2.44",
|
||||
"@gitzone/tstest": "^1.0.77",
|
||||
"@push.rocks/smartdelay": "^3.0.1",
|
||||
"@push.rocks/tapbundle": "^5.0.8",
|
||||
"@types/node": "^20.5.3"
|
||||
"npmts-g": "^5.2.8",
|
||||
"typings-test": "^1.0.1"
|
||||
},
|
||||
"dependencies": {
|
||||
"@push.rocks/consolecolor": "^2.0.1",
|
||||
"@push.rocks/smartpromise": "^4.0.2"
|
||||
},
|
||||
"files": [
|
||||
"ts/**/*",
|
||||
"ts_web/**/*",
|
||||
"dist/**/*",
|
||||
"dist_*/**/*",
|
||||
"dist_ts/**/*",
|
||||
"dist_ts_web/**/*",
|
||||
"assets/**/*",
|
||||
"cli.js",
|
||||
"npmextra.json",
|
||||
"readme.md"
|
||||
],
|
||||
"browserslist": [
|
||||
"last 1 chrome versions"
|
||||
]
|
||||
}
|
||||
"@types/chalk": "^0.4.28",
|
||||
"chalk": "^1.1.3",
|
||||
"q": "^1.4.1",
|
||||
"typings-global": "^1.0.6"
|
||||
}
|
||||
}
|
||||
|
5789
pnpm-lock.yaml
generated
5789
pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load Diff
@ -1 +0,0 @@
|
||||
|
114
readme.md
114
readme.md
@ -1,114 +0,0 @@
|
||||
# @push.rocks/early
|
||||
minimal and fast loading plugin for startup time measuring
|
||||
|
||||
## Install
|
||||
|
||||
To install `@push.rocks/early`, run the following command in your terminal:
|
||||
|
||||
```bash
|
||||
npm install @push.rocks/early --save
|
||||
```
|
||||
This will add `@push.rocks/early` to your project's dependencies and prepare it for use.
|
||||
|
||||
## Usage
|
||||
|
||||
In this guide, we'll explore how to use `@push.rocks/early` to measure startup times in your application. This tool is designed to be minimal and fast, providing accurate measurements of how long it takes for parts of your application to load.
|
||||
|
||||
### Getting Started with `@push.rocks/early`
|
||||
|
||||
First, ensure that your project is set up with TypeScript and that you are familiar with working with ES modules. `@push.rocks/early` is built with TypeScript in mind, offering excellent IntelliSense support in compatible editors.
|
||||
|
||||
#### Importing `@push.rocks/early`
|
||||
|
||||
To begin, import the library into your module:
|
||||
|
||||
```typescript
|
||||
import * as early from '@push.rocks/early';
|
||||
```
|
||||
|
||||
#### Starting Measurement
|
||||
|
||||
The first step in using `@push.rocks/early` is to start the measurement. This should be done as early as possible in your application's startup sequence:
|
||||
|
||||
```typescript
|
||||
early.start('myModuleName');
|
||||
```
|
||||
Replace `'myModuleName'` with a string identifier for the module or application part you are measuring. This is purely for identification purposes and aids in debugging or logging.
|
||||
|
||||
#### Performing Your Loading Operations
|
||||
|
||||
After starting the measurement, proceed with the operations or loading tasks you wish to measure. This could involve loading modules, reading files, or any setup tasks required for your application to start:
|
||||
|
||||
```typescript
|
||||
// Example loading operations
|
||||
await myModule.initialize();
|
||||
await myOtherModule.loadConfig();
|
||||
```
|
||||
|
||||
#### Stopping Measurement and Retrieving Results
|
||||
|
||||
Once your loading operations are complete, stop the measurement to retrieve the loading time:
|
||||
|
||||
```typescript
|
||||
early.stop().then((loadingTime: number) => {
|
||||
console.log(`Loading time: ${loadingTime} milliseconds`);
|
||||
});
|
||||
```
|
||||
|
||||
This will output the total loading time in milliseconds, giving you a precise measure of the startup performance.
|
||||
|
||||
### Advanced Features
|
||||
|
||||
`@push.rocks/early` allows for more advanced use cases, such as measuring multiple segments individually or in parallel. Each `start` can be matched with a corresponding `stop` to measure different parts of your application independently:
|
||||
|
||||
```typescript
|
||||
early.start('partOne');
|
||||
// Load operations for part one...
|
||||
early.stop().then((time: number) => console.log(`Part one loading time: ${time}`));
|
||||
|
||||
early.start('partTwo');
|
||||
// Load operations for part two...
|
||||
early.stop().then((time: number) => console.log(`Part two loading time: ${time}`));
|
||||
```
|
||||
|
||||
### High Resolution Time Measurement Class
|
||||
|
||||
For more granular control or to measure very short operations, `@push.rocks/early` offers a `HrtMeasurement` class for high-resolution time measurements:
|
||||
|
||||
```typescript
|
||||
import { HrtMeasurement } from '@push.rocks/early';
|
||||
|
||||
const hrtMeasurement = new HrtMeasurement();
|
||||
hrtMeasurement.start();
|
||||
// perform short duration tasks
|
||||
hrtMeasurement.stop();
|
||||
|
||||
console.log(`Operation took ${hrtMeasurement.milliSeconds} milliseconds`);
|
||||
```
|
||||
|
||||
This can be particularly useful for micro-benchmarks or when measuring the performance impact of optimization efforts.
|
||||
|
||||
### Conclusion
|
||||
|
||||
`@push.rocks/early` is a powerful yet minimalistic tool for measuring startup times and performance in Node.js applications. Its straightforward API, coupled with TypeScript support, makes it an excellent choice for developers looking to optimize their applications or simply understand their loading characteristics better.
|
||||
|
||||
By integrating `@push.rocks/early` into your development process, you can gain valuable insights into your application's performance, helping you make informed decisions about optimizations and improvements.
|
||||
|
||||
## 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/test.d.ts
vendored
Normal file
1
test/test.d.ts
vendored
Normal file
@ -0,0 +1 @@
|
||||
import "typings-test";
|
15
test/test.js
Normal file
15
test/test.js
Normal file
@ -0,0 +1,15 @@
|
||||
"use strict";
|
||||
require("typings-test");
|
||||
const early = require("../dist/index");
|
||||
describe("early", function () {
|
||||
it(".start()", function (done) {
|
||||
this.timeout(10000);
|
||||
early.start("early");
|
||||
setTimeout(done, 5000);
|
||||
});
|
||||
it(".stop()", function (done) {
|
||||
early.stop()
|
||||
.then(done);
|
||||
});
|
||||
});
|
||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidGVzdC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbInRlc3QudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLFFBQU8sY0FBYyxDQUFDLENBQUE7QUFDdEIsTUFBTyxLQUFLLFdBQVcsZUFBZSxDQUFDLENBQUM7QUFFeEMsUUFBUSxDQUFDLE9BQU8sRUFBQztJQUNiLEVBQUUsQ0FBQyxVQUFVLEVBQUMsVUFBUyxJQUFJO1FBQ3ZCLElBQUksQ0FBQyxPQUFPLENBQUMsS0FBSyxDQUFDLENBQUM7UUFDcEIsS0FBSyxDQUFDLEtBQUssQ0FBQyxPQUFPLENBQUMsQ0FBQztRQUNyQixVQUFVLENBQUMsSUFBSSxFQUFDLElBQUksQ0FBQyxDQUFDO0lBQzFCLENBQUMsQ0FBQyxDQUFDO0lBQ0gsRUFBRSxDQUFDLFNBQVMsRUFBQyxVQUFTLElBQUk7UUFDdEIsS0FBSyxDQUFDLElBQUksRUFBRTthQUNQLElBQUksQ0FBQyxJQUFJLENBQUMsQ0FBQztJQUNwQixDQUFDLENBQUMsQ0FBQTtBQUNOLENBQUMsQ0FBQyxDQUFBIn0=
|
37
test/test.ts
37
test/test.ts
@ -1,25 +1,14 @@
|
||||
import { expect, expectAsync, tap } from '@push.rocks/tapbundle';
|
||||
import * as smartdelay from '@push.rocks/smartdelay';
|
||||
import "typings-test";
|
||||
import early = require("../dist/index");
|
||||
|
||||
import * as early from '../ts/index.js';
|
||||
|
||||
tap.test('.start()', async () => {
|
||||
process.env.CLI_CALL_MODULENAME = 'early';
|
||||
early.start('early');
|
||||
await smartdelay.delayFor(2000);
|
||||
});
|
||||
|
||||
tap.test('.stop()', async () => {
|
||||
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();
|
||||
describe("early",function(){
|
||||
it(".start()",function(done){
|
||||
this.timeout(10000);
|
||||
early.start("early");
|
||||
setTimeout(done,5000);
|
||||
});
|
||||
it(".stop()",function(done){
|
||||
early.stop()
|
||||
.then(done);
|
||||
})
|
||||
})
|
@ -1,8 +0,0 @@
|
||||
/**
|
||||
* autocreated commitinfo by @pushrocks/commitinfo
|
||||
*/
|
||||
export const commitinfo = {
|
||||
name: '@push.rocks/early',
|
||||
version: '4.0.4',
|
||||
description: 'minimal and fast loading plugin for startup time measuring'
|
||||
}
|
50
ts/early.child.ts
Normal file
50
ts/early.child.ts
Normal file
@ -0,0 +1,50 @@
|
||||
import "typings-global";
|
||||
import chalk = require("chalk");
|
||||
import readline = require("readline");
|
||||
let rl = readline.createInterface({
|
||||
input: process.stdin,
|
||||
output: process.stdout
|
||||
});
|
||||
|
||||
let moduleName: string;
|
||||
let loaderLength: number;
|
||||
let frameCounter: number = 0;
|
||||
|
||||
let makeFrame = (): string => {
|
||||
let resultString: string = `[${chalk.green("/".repeat(frameCounter))}${" ".repeat(loaderLength - frameCounter)}] starting ${moduleName}`;
|
||||
if (frameCounter == loaderLength) {
|
||||
frameCounter = 0;
|
||||
} else {
|
||||
frameCounter++;
|
||||
}
|
||||
return resultString;
|
||||
};
|
||||
|
||||
let logEarlyAbort = false;
|
||||
let logEarly = () => {
|
||||
if (!logEarlyAbort) {
|
||||
rl.write(null, { ctrl: true, name: 'u' });
|
||||
rl.write(makeFrame());
|
||||
setTimeout(function () {
|
||||
logEarly();
|
||||
}, 80);
|
||||
}
|
||||
};
|
||||
|
||||
let start = function (moduleNameArg: string = "", loaderLengthArg: string = "10") {
|
||||
moduleName = moduleNameArg;
|
||||
loaderLength = parseInt(loaderLengthArg);
|
||||
logEarly();
|
||||
};
|
||||
|
||||
start(process.env.moduleNameArg, process.env.loaderLengthArg);
|
||||
|
||||
process.on('SIGINT', () => {
|
||||
logEarlyAbort = true;
|
||||
rl.write(null, { ctrl: true, name: 'u' });
|
||||
rl.write(`loaded ${chalk.green(moduleName)}`);
|
||||
rl.close();
|
||||
rl.on("close",() => {
|
||||
|
||||
})
|
||||
});
|
@ -1,45 +0,0 @@
|
||||
import * as process from 'process';
|
||||
|
||||
/**
|
||||
* easy high resolution time measurement
|
||||
*/
|
||||
export class HrtMeasurement {
|
||||
nanoSeconds: number = null;
|
||||
milliSeconds: number = null;
|
||||
private _hrTimeStart: [number, number] = null;
|
||||
private _hrTimeStopDiff: [number, number] = 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;
|
||||
}
|
||||
}
|
82
ts/index.ts
82
ts/index.ts
@ -1,42 +1,56 @@
|
||||
import * as consolecolor from '@push.rocks/consolecolor';
|
||||
import * as smartpromise from '@push.rocks/smartpromise';
|
||||
import { HrtMeasurement } from './early.hrtMeasurement.js';
|
||||
|
||||
export { HrtMeasurement };
|
||||
import "typings-global"
|
||||
import path = require("path");
|
||||
import chalk = require("chalk");
|
||||
let q = require("q");
|
||||
import readline = require("readline");
|
||||
import childProcess = require("child_process");
|
||||
let earlyChild;
|
||||
|
||||
let doAnimation: boolean = true;
|
||||
let doText: boolean = false;
|
||||
let moduleName: string = 'undefined module name';
|
||||
let startHrt: HrtMeasurement;
|
||||
let moduleName: string = "undefined module name";
|
||||
let startTime;
|
||||
|
||||
if (process.argv.indexOf('-v') === -1) {
|
||||
doText = true;
|
||||
if (process.argv.indexOf("-v") != -1 || process.env.CI) {
|
||||
doAnimation = false;
|
||||
}
|
||||
if (process.argv.indexOf("-v") == -1 && process.env.CI) {
|
||||
doText = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* start the loading
|
||||
*/
|
||||
export let start = function (moduleNameArg: string = '', loaderLengthArg: string = '10') {
|
||||
moduleName = moduleNameArg;
|
||||
startHrt = new HrtMeasurement();
|
||||
startHrt.start();
|
||||
if (doText && process.env.CLI_CALL_MODULENAME === moduleName) {
|
||||
console.log(`**** starting ${consolecolor.coloredString(moduleNameArg, 'green')} ****`);
|
||||
}
|
||||
// exports
|
||||
export let start = function (moduleNameArg: string = "", loaderLengthArg: string = "10") {
|
||||
|
||||
startTime = Date.now();
|
||||
|
||||
moduleName = moduleNameArg;
|
||||
if (doAnimation) {
|
||||
earlyChild = childProcess.fork(path.join(__dirname, "early.child.js"), [], {
|
||||
env: {
|
||||
moduleNameArg: moduleNameArg,
|
||||
loaderLengthArg: loaderLengthArg,
|
||||
CI: process.env.CI
|
||||
}
|
||||
});
|
||||
} else if (doText) {
|
||||
console.log(`**** starting ${chalk.green(moduleNameArg)} ****`);
|
||||
}
|
||||
};
|
||||
|
||||
export let stop = (): Promise<number> => {
|
||||
let done = smartpromise.defer<number>();
|
||||
let earlyExecutionTime = startHrt.stop().milliSeconds;
|
||||
let earlyExecutionTimeString: string = (earlyExecutionTime / 1000).toString();
|
||||
if (doText && process.env.CLI_CALL_MODULENAME === moduleName) {
|
||||
console.log(
|
||||
`OK! -> finished loading within ${consolecolor.coloredString(
|
||||
earlyExecutionTimeString,
|
||||
'blue'
|
||||
)}`
|
||||
);
|
||||
}
|
||||
|
||||
done.resolve(earlyExecutionTime);
|
||||
return done.promise;
|
||||
export let stop = function () {
|
||||
let done = q.defer();
|
||||
let endTime = Date.now();
|
||||
let executionTime:string = ((endTime - startTime) / 1000).toString();
|
||||
if (doAnimation) {
|
||||
earlyChild.kill("SIGINT");
|
||||
earlyChild.on("close", function () {
|
||||
console.log(` in ${executionTime} seconds!`);
|
||||
done.resolve();
|
||||
})
|
||||
} else {
|
||||
console.log(`... finished loading ${moduleName} in ${executionTime}`);
|
||||
done.resolve();
|
||||
}
|
||||
return done.promise;
|
||||
};
|
||||
|
||||
|
@ -1,14 +0,0 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"experimentalDecorators": true,
|
||||
"useDefineForClassFields": false,
|
||||
"target": "ES2022",
|
||||
"module": "NodeNext",
|
||||
"moduleResolution": "NodeNext",
|
||||
"esModuleInterop": true,
|
||||
"verbatimModuleSyntax": true
|
||||
},
|
||||
"exclude": [
|
||||
"dist_*/**/*.d.ts"
|
||||
]
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user