Compare commits
134 Commits
Author | SHA1 | Date | |
---|---|---|---|
b3431a6679 | |||
eb65b8fedf | |||
57948890a1 | |||
00191bbeb5 | |||
ed1470365c | |||
c81c8b3ffb | |||
8f676bead7 | |||
b0a6875efb | |||
b25fc0a6e4 | |||
f251a7d0fa | |||
cfdf0267e9 | |||
0c5a88a08f | |||
261f86d664 | |||
b0116a7967 | |||
6dfdfd41b9 | |||
2e9bc0db42 | |||
af837f5303 | |||
9145cc890c | |||
e3fa407c1c | |||
865e58b190 | |||
66d00d938c | |||
5c3e165625 | |||
82e282a19f | |||
16ca87923d | |||
62676cf816 | |||
c88bb03e6c | |||
98f9c51613 | |||
a0b237ca8c | |||
4a7139b6f8 | |||
48f9249313 | |||
278eda4869 | |||
ce99e04b45 | |||
c0a1e0a14f | |||
83392d18f6 | |||
270cb2533e | |||
fad367ca0b | |||
836f8d18b0 | |||
ce269ae337 | |||
727d26fae4 | |||
0f2b71ebc3 | |||
638c1a8c8c | |||
c54644949e | |||
53c26d4634 | |||
e3b1ec0633 | |||
1892bd6df1 | |||
20bdf70686 | |||
7787330d63 | |||
67c3efdd59 | |||
7655ba749a | |||
0a089b6f10 | |||
29bf694db6 | |||
019d8deadd | |||
bfef45cab3 | |||
eddc64b891 | |||
e47df19015 | |||
af96ab531b | |||
b96206e8f7 | |||
f96bfc0875 | |||
62f3dbabda | |||
5486e268ed | |||
6d61043379 | |||
ac92f355d4 | |||
140bfb4f5e | |||
4ed87cac7e | |||
d2182a6d0f | |||
b7e48313e1 | |||
9f8e30526f | |||
8dd5c97f3b | |||
58b6a9a328 | |||
1c4020824d | |||
521e5740e5 | |||
ce76702d53 | |||
4590c8f64e | |||
ab7155f198 | |||
feba451f90 | |||
1ba1b0447b | |||
e4db3ba7ee | |||
da209ecc06 | |||
e010b01c42 | |||
225c46a788 | |||
7883f1cb7d | |||
394dd88a1d | |||
1d8fee1506 | |||
88d5409c40 | |||
b8c9508d21 | |||
59f97c3254 | |||
0491493b2e | |||
aca45165f8 | |||
569c597f8b | |||
5f17ea48ed | |||
6a9cdd297a | |||
0a363b441c | |||
3af6edd5e6 | |||
9a26f1367d | |||
15dd17e7a7 | |||
3b704dbde5 | |||
48aeb16dfd | |||
b40d8452ec | |||
d8281f098a | |||
3ffee9d0d6 | |||
03dfdda812 | |||
24cce5d9b2 | |||
295e568097 | |||
846bcf66db | |||
fc7d7fd27f | |||
9829c7bb1e | |||
6827999cf8 | |||
b318fa2076 | |||
0c751e1bca | |||
cb489552f2 | |||
addd66091f | |||
c2f8199f0b | |||
5e5696cce1 | |||
44d9782487 | |||
41592a4d2f | |||
23367249ec | |||
b415bf4ee7 | |||
86b6a6c3c4 | |||
ffbfc29628 | |||
9c6e452801 | |||
96c421e96e | |||
84af99ba80 | |||
6bb20dbc7b | |||
66a7fc2afe | |||
a42faf36d2 | |||
6db7cc0e14 | |||
102d384de5 | |||
1ceae01a49 | |||
7f4adbfe9f | |||
eb72e2dccc | |||
839c80f5dd | |||
e7e96972ad | |||
799c2a58ca | |||
1955dadba3 |
66
.gitea/workflows/default_nottags.yaml
Normal file
66
.gitea/workflows/default_nottags.yaml
Normal file
@ -0,0 +1,66 @@
|
||||
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
|
124
.gitea/workflows/default_tags.yaml
Normal file
124
.gitea/workflows/default_tags.yaml
Normal file
@ -0,0 +1,124 @@
|
||||
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,4 +1,20 @@
|
||||
node_modules/
|
||||
docs/
|
||||
.nogit/
|
||||
|
||||
# artifacts
|
||||
coverage/
|
||||
ts/typings/
|
||||
public/
|
||||
pages/
|
||||
|
||||
# installs
|
||||
node_modules/
|
||||
|
||||
# caches
|
||||
.yarn/
|
||||
.cache/
|
||||
.rpt2_cache
|
||||
|
||||
# builds
|
||||
dist/
|
||||
dist_*/
|
||||
|
||||
# custom
|
140
.gitlab-ci.yml
Normal file
140
.gitlab-ci.yml
Normal file
@ -0,0 +1,140 @@
|
||||
# gitzone ci_default
|
||||
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||
|
||||
cache:
|
||||
paths:
|
||||
- .npmci_cache/
|
||||
key: '$CI_BUILD_STAGE'
|
||||
|
||||
stages:
|
||||
- security
|
||||
- test
|
||||
- release
|
||||
- metadata
|
||||
|
||||
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:
|
||||
stage: test
|
||||
script:
|
||||
- npmci npm prepare
|
||||
- npmci node install stable
|
||||
- npmci npm install
|
||||
- npmci npm test
|
||||
coverage: /\d+.?\d+?\%\s*coverage/
|
||||
tags:
|
||||
- docker
|
||||
|
||||
testBuild:
|
||||
stage: test
|
||||
script:
|
||||
- npmci npm prepare
|
||||
- npmci node install stable
|
||||
- npmci npm install
|
||||
- npmci command npm run build
|
||||
coverage: /\d+.?\d+?\%\s*coverage/
|
||||
tags:
|
||||
- docker
|
||||
|
||||
release:
|
||||
stage: release
|
||||
script:
|
||||
- npmci node install stable
|
||||
- npmci npm 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
|
@ -1,4 +0,0 @@
|
||||
docs/
|
||||
coverage/
|
||||
ts/typings/
|
||||
.travis.yml
|
12
.travis.yml
12
.travis.yml
@ -1,12 +0,0 @@
|
||||
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
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"]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
2
LICENSE
2
LICENSE
@ -1,6 +1,6 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2016 Push.Rocks
|
||||
Copyright (c) 2016 Lossless GmbH
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
|
15
README.md
15
README.md
@ -1,15 +0,0 @@
|
||||
# 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
|
||||
```
|
||||
|
2
dist/index.d.ts
vendored
2
dist/index.d.ts
vendored
@ -1,2 +0,0 @@
|
||||
export declare let start: (moduleNameArg?: string, loaderLengthArg?: number) => void;
|
||||
export declare let stop: () => void;
|
64
dist/index.js
vendored
64
dist/index.js
vendored
@ -1,64 +0,0 @@
|
||||
"use strict";
|
||||
/// <reference path="./typings/index.d.ts" />
|
||||
var colors = require("colors");
|
||||
var readline = require("readline");
|
||||
var rl;
|
||||
var initReadline = function () {
|
||||
rl = readline.createInterface({
|
||||
input: process.stdin,
|
||||
output: process.stdout
|
||||
});
|
||||
};
|
||||
var moduleName;
|
||||
var loaderLength;
|
||||
var frameCounter = 0;
|
||||
var makeFrame = function () {
|
||||
var resultString = "["
|
||||
+ "/".green.repeat(frameCounter)
|
||||
+ " ".repeat(loaderLength - frameCounter)
|
||||
+ "]"
|
||||
+ " starting "
|
||||
+ moduleName.cyan;
|
||||
if (frameCounter == loaderLength) {
|
||||
frameCounter = 0;
|
||||
}
|
||||
else {
|
||||
frameCounter++;
|
||||
}
|
||||
return resultString;
|
||||
};
|
||||
var abort = true;
|
||||
var logEarly = function () {
|
||||
rl.write(null, { ctrl: true, name: 'u' });
|
||||
rl.write(makeFrame());
|
||||
setTimeout(function () {
|
||||
if (!abort) {
|
||||
logEarly();
|
||||
}
|
||||
}, 200);
|
||||
};
|
||||
// exports
|
||||
exports.start = function (moduleNameArg, loaderLengthArg) {
|
||||
if (moduleNameArg === void 0) { moduleNameArg = ""; }
|
||||
if (loaderLengthArg === void 0) { loaderLengthArg = 10; }
|
||||
abort = false;
|
||||
moduleName = moduleNameArg;
|
||||
loaderLength = loaderLengthArg;
|
||||
if (!process.env.CI) {
|
||||
initReadline();
|
||||
logEarly();
|
||||
}
|
||||
else {
|
||||
console.log("**** starting " + moduleName + " ****");
|
||||
}
|
||||
;
|
||||
};
|
||||
exports.stop = function () {
|
||||
abort = true;
|
||||
if (!process.env.CI) {
|
||||
rl.write(null, { ctrl: true, name: 'u' });
|
||||
rl.close();
|
||||
}
|
||||
};
|
||||
|
||||
//# sourceMappingURL=data:application/json;charset=utf8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbImluZGV4LnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7QUFBQSw2Q0FBNkM7QUFDN0MsSUFBSSxNQUFNLEdBQUcsT0FBTyxDQUFDLFFBQVEsQ0FBQyxDQUFDO0FBQy9CLElBQUksUUFBUSxHQUFHLE9BQU8sQ0FBQyxVQUFVLENBQUMsQ0FBQztBQUVuQyxJQUFJLEVBQUUsQ0FBQztBQUNQLElBQUksWUFBWSxHQUFHO0lBQ2YsRUFBRSxHQUFHLFFBQVEsQ0FBQyxlQUFlLENBQUM7UUFDOUIsS0FBSyxFQUFFLE9BQU8sQ0FBQyxLQUFLO1FBQ3BCLE1BQU0sRUFBRSxPQUFPLENBQUMsTUFBTTtLQUNyQixDQUFDLENBQUM7QUFDUCxDQUFDLENBQUM7QUFFRixJQUFJLFVBQWlCLENBQUM7QUFDdEIsSUFBSSxZQUFtQixDQUFDO0FBQ3hCLElBQUksWUFBWSxHQUFVLENBQUMsQ0FBQztBQUU1QixJQUFJLFNBQVMsR0FBRztJQUNaLElBQUksWUFBWSxHQUFVLEdBQUc7VUFDdkIsR0FBRyxDQUFDLEtBQUssQ0FBQyxNQUFNLENBQUMsWUFBWSxDQUFDO1VBQzlCLEdBQUcsQ0FBQyxNQUFNLENBQUMsWUFBWSxHQUFHLFlBQVksQ0FBQztVQUN2QyxHQUFHO1VBQ0gsWUFBWTtVQUNaLFVBQVUsQ0FBQyxJQUFJLENBQUM7SUFFdEIsRUFBRSxDQUFBLENBQUMsWUFBWSxJQUFJLFlBQVksQ0FBQyxDQUFB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gKCFwcm9jZXNzLmVudi5DSSl7XHJcbiAgICAgICAgaW5pdFJlYWRsaW5lKCk7XHJcbiAgICAgICAgbG9nRWFybHkoKTtcclxuICAgIH0gZWxzZSB7XHJcbiAgICAgICAgY29uc29sZS5sb2coXCIqKioqIHN0YXJ0aW5nIFwiICsgbW9kdWxlTmFtZSArIFwiICoqKipcIik7XHJcbiAgICB9O1xyXG59O1xyXG5cclxuZXhwb3J0IGxldCBzdG9wID0gZnVuY3Rpb24oKXtcclxuICAgIGFib3J0ID0gdHJ1ZTtcclxuICAgIGlmICghcHJvY2Vzcy5lbnYuQ0kpe1xyXG4gICAgICAgIHJsLndyaXRlKG51bGwsIHtjdHJsOiB0cnVlLCBuYW1lOiAndSd9KTtcclxuICAgICAgICBybC5jbG9zZSgpO1xyXG4gICAgfVxyXG59O1xyXG5cclxuIl19
|
28
npmextra.json
Normal file
28
npmextra.json
Normal file
@ -0,0 +1,28 @@
|
||||
{
|
||||
"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"
|
||||
]
|
||||
}
|
||||
},
|
||||
"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"
|
||||
}
|
||||
}
|
57
package.json
57
package.json
@ -1,28 +1,59 @@
|
||||
{
|
||||
"name": "early",
|
||||
"version": "1.0.4",
|
||||
"description": "nice module loading animation for modules that need a little starting time.",
|
||||
"main": "dist/index.js",
|
||||
"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",
|
||||
"scripts": {
|
||||
"test": "(npmts)"
|
||||
"test": "(tstest test/)",
|
||||
"build": "(tsbuild --web)",
|
||||
"buildDocs": "tsdoc"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/pushrocks/early.git"
|
||||
"url": "https://code.foss.global/push.rocks/early.git"
|
||||
},
|
||||
"keywords": [
|
||||
"preloader"
|
||||
"performance measurement",
|
||||
"startup time",
|
||||
"high resolution timer",
|
||||
"plugin",
|
||||
"typescript",
|
||||
"nodejs"
|
||||
],
|
||||
"author": "Lossless GmbH",
|
||||
"license": "MIT",
|
||||
"bugs": {
|
||||
"url": "https://github.com/pushrocks/early/issues"
|
||||
"url": "https://gitlab.com/pushrocks/early/issues"
|
||||
},
|
||||
"homepage": "https://github.com/pushrocks/early#readme",
|
||||
"homepage": "https://code.foss.global/push.rocks/early",
|
||||
"devDependencies": {
|
||||
"npmts": "^5.1.9"
|
||||
"@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"
|
||||
},
|
||||
"dependencies": {
|
||||
"colors": "^1.1.2"
|
||||
}
|
||||
}
|
||||
"@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"
|
||||
]
|
||||
}
|
5789
pnpm-lock.yaml
generated
Normal file
5789
pnpm-lock.yaml
generated
Normal file
File diff suppressed because it is too large
Load Diff
1
readme.hints.md
Normal file
1
readme.hints.md
Normal file
@ -0,0 +1 @@
|
||||
|
114
readme.md
Normal file
114
readme.md
Normal file
@ -0,0 +1,114 @@
|
||||
# @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.
|
0
test/test.d.ts
vendored
0
test/test.d.ts
vendored
15
test/test.js
15
test/test.js
@ -1,15 +0,0 @@
|
||||
"use strict";
|
||||
/// <reference path="../ts/typings/index.d.ts" />
|
||||
var early = require("../dist/index.js");
|
||||
describe("early", function () {
|
||||
it(".start()", function (done) {
|
||||
this.timeout(10000);
|
||||
early.start("early");
|
||||
setTimeout(done, 5000);
|
||||
});
|
||||
it(".stop()", function () {
|
||||
early.stop();
|
||||
});
|
||||
});
|
||||
|
||||
//# sourceMappingURL=data:application/json;charset=utf8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInRlc3QudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLGlEQUFpRDtBQUNqRCxJQUFPLEtBQUssV0FBVyxrQkFBa0IsQ0FBQyxDQUFDO0FBRTNDLFFBQVEsQ0FBQyxPQUFPLEVBQUM7SUFDYixFQUFFLENBQUMsVUFBVSxFQUFDLFVBQVMsSUFBSTtRQUN2QixJQUFJLENBQUMsT0FBTyxDQUFDLEtBQUssQ0FBQyxDQUFDO1FBQ3BCLEtBQUssQ0FBQyxLQUFLLENBQUMsT0FBTyxDQUFDLENBQUM7UUFDckIsVUFBVSxDQUFDLElBQUksRUFBQyxJQUFJLENBQUMsQ0FBQztJQUMxQixDQUFDLENBQUMsQ0FBQztJQUNILEVBQUUsQ0FBQyxTQUFTLEVBQUM7UUFDVCxLQUFLLENBQUMsSUFBSSxFQUFFLENBQUM7SUFDakIsQ0FBQyxDQUFDLENBQUE7QUFDTixDQUFDLENBQUMsQ0FBQSIsImZpbGUiOiJ0ZXN0LmpzIiwic291cmNlc0NvbnRlbnQiOlsiLy8vIDxyZWZlcmVuY2UgcGF0aD1cIi4uL3RzL3R5cGluZ3MvaW5kZXguZC50c1wiIC8+XHJcbmltcG9ydCBlYXJseSA9IHJlcXVpcmUoXCIuLi9kaXN0L2luZGV4LmpzXCIpO1xyXG5cclxuZGVzY3JpYmUoXCJlYXJseVwiLGZ1bmN0aW9uKCl7XHJcbiAgICBpdChcIi5zdGFydCgpXCIsZnVuY3Rpb24oZG9uZSl7XHJcbiAgICAgICAgdGhpcy50aW1lb3V0KDEwMDAwKTtcclxuICAgICAgICBlYXJseS5zdGFydChcImVhcmx5XCIpO1xyXG4gICAgICAgIHNldFRpbWVvdXQoZG9uZSw1MDAwKTtcclxuICAgIH0pO1xyXG4gICAgaXQoXCIuc3RvcCgpXCIsZnVuY3Rpb24oKXtcclxuICAgICAgICBlYXJseS5zdG9wKCk7XHJcbiAgICB9KVxyXG59KSJdfQ==
|
36
test/test.ts
36
test/test.ts
@ -1,13 +1,25 @@
|
||||
/// <reference path="../ts/typings/index.d.ts" />
|
||||
import early = require("../dist/index.js");
|
||||
import { expect, expectAsync, tap } from '@push.rocks/tapbundle';
|
||||
import * as smartdelay from '@push.rocks/smartdelay';
|
||||
|
||||
describe("early",function(){
|
||||
it(".start()",function(done){
|
||||
this.timeout(10000);
|
||||
early.start("early");
|
||||
setTimeout(done,5000);
|
||||
});
|
||||
it(".stop()",function(){
|
||||
early.stop();
|
||||
})
|
||||
})
|
||||
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();
|
||||
|
8
ts/00_commitinfo_data.ts
Normal file
8
ts/00_commitinfo_data.ts
Normal file
@ -0,0 +1,8 @@
|
||||
/**
|
||||
* 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'
|
||||
}
|
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: [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;
|
||||
}
|
||||
}
|
97
ts/index.ts
97
ts/index.ts
@ -1,65 +1,42 @@
|
||||
/// <reference path="./typings/index.d.ts" />
|
||||
let colors = require("colors");
|
||||
let readline = require("readline");
|
||||
import * as consolecolor from '@push.rocks/consolecolor';
|
||||
import * as smartpromise from '@push.rocks/smartpromise';
|
||||
import { HrtMeasurement } from './early.hrtMeasurement.js';
|
||||
|
||||
let rl;
|
||||
let initReadline = () => {
|
||||
rl = readline.createInterface({
|
||||
input: process.stdin,
|
||||
output: process.stdout
|
||||
});
|
||||
export { HrtMeasurement };
|
||||
|
||||
let doText: boolean = false;
|
||||
let moduleName: string = 'undefined module name';
|
||||
let startHrt: HrtMeasurement;
|
||||
|
||||
if (process.argv.indexOf('-v') === -1) {
|
||||
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')} ****`);
|
||||
}
|
||||
};
|
||||
|
||||
let moduleName:string;
|
||||
let loaderLength:number;
|
||||
let frameCounter:number = 0;
|
||||
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'
|
||||
)}`
|
||||
);
|
||||
}
|
||||
|
||||
let makeFrame = ():string => {
|
||||
let resultString:string = "["
|
||||
+ "/".green.repeat(frameCounter)
|
||||
+ " ".repeat(loaderLength - frameCounter)
|
||||
+ "]"
|
||||
+ " starting "
|
||||
+ moduleName.cyan;
|
||||
|
||||
if(frameCounter == loaderLength){
|
||||
frameCounter = 0;
|
||||
} else {
|
||||
frameCounter++;
|
||||
}
|
||||
return resultString;
|
||||
done.resolve(earlyExecutionTime);
|
||||
return done.promise;
|
||||
};
|
||||
|
||||
let abort:boolean = true;
|
||||
let logEarly = () => {
|
||||
rl.write(null, {ctrl: true, name: 'u'});
|
||||
rl.write(makeFrame());
|
||||
setTimeout(function(){
|
||||
if(!abort){
|
||||
logEarly();
|
||||
}
|
||||
},200);
|
||||
};
|
||||
|
||||
|
||||
// exports
|
||||
export let start = function(moduleNameArg:string = "",loaderLengthArg:number = 10){
|
||||
abort = false;
|
||||
moduleName = moduleNameArg;
|
||||
loaderLength = loaderLengthArg;
|
||||
if (!process.env.CI){
|
||||
initReadline();
|
||||
logEarly();
|
||||
} else {
|
||||
console.log("**** starting " + moduleName + " ****");
|
||||
};
|
||||
};
|
||||
|
||||
export let stop = function(){
|
||||
abort = true;
|
||||
if (!process.env.CI){
|
||||
rl.write(null, {ctrl: true, name: 'u'});
|
||||
rl.close();
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -1,6 +0,0 @@
|
||||
{
|
||||
"globalDependencies": {
|
||||
"colors": "registry:dt/colors#0.6.0-1+20160501135139",
|
||||
"node": "registry:dt/node#6.0.0+20160514165920"
|
||||
}
|
||||
}
|
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"
|
||||
]
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user