Skip to content

Commit

Permalink
Package version & readme version (#25)
Browse files Browse the repository at this point in the history
  • Loading branch information
zefir-git authored Sep 7, 2023
2 parents 8a10d9f + a790a3e commit 3c68c3f
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 18 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
# Rate limiting utility
![version: 1.2.1](https://img.shields.io/badge/version-1.2.1-%233b82f6)
[![npm](https://img.shields.io/npm/v/cldn-ratelimit)](https://www.npmjs.com/package/cldn-ratelimit)
[![npm downloads](https://img.shields.io/npm/dt/cldn-ratelimit?label=downloads)](https://www.npmjs.com/package/cldn-ratelimit)
![test: passing](https://img.shields.io/badge/tests-passing-%2316a34a)
![coverage: 100%](https://img.shields.io/badge/coverage-100%25-%2316a34a)
![build: passing](https://img.shields.io/badge/build-passing-%2316a34a)
[![CodeQL](https://github.com/cloudnode-pro/ratelimit/actions/workflows/github-code-scanning/codeql/badge.svg)](https://github.com/cloudnode-pro/ratelimit/actions/workflows/github-code-scanning/codeql)

A relatively simple utility for abstract rate limiting. This library uses memory storage (i.e. does not rely on external database or writing data on your file system). Rate limits are reset if the process is restarted.

Expand Down
4 changes: 3 additions & 1 deletion README.template.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
# Rate limiting utility
{{shield:version}}
[![npm](https://img.shields.io/npm/v/cldn-ratelimit)](https://www.npmjs.com/package/cldn-ratelimit)
[![npm downloads](https://img.shields.io/npm/dt/cldn-ratelimit?label=downloads)](https://www.npmjs.com/package/cldn-ratelimit)
{{shield:tests}}
{{shield:coverage}}
{{shield:build}}
[![CodeQL](https://github.com/cloudnode-pro/ratelimit/actions/workflows/github-code-scanning/codeql/badge.svg)](https://github.com/cloudnode-pro/ratelimit/actions/workflows/github-code-scanning/codeql)

A relatively simple utility for abstract rate limiting. This library uses memory storage (i.e. does not rely on external database or writing data on your file system). Rate limits are reset if the process is restarted.

Expand Down
26 changes: 23 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cldn-ratelimit",
"version": "1.2.2",
"version": "0.0.0-dev",
"description": "Simple ratelimiter for Node.js",
"main": "lib/RateLimit.js",
"type": "module",
Expand Down Expand Up @@ -32,7 +32,7 @@
"homepage": "https://github.com/cloudnode-pro/ratelimit#readme",
"devDependencies": {
"c8": "^8.0.1",
"mocha": "^10.0.0"
},
"dependencies": {}
"mocha": "^10.0.0",
"typescript": "^5.2.2"
}
}
11 changes: 2 additions & 9 deletions scripts/generateReadme.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,6 @@ import * as child_process from "child_process";
const TEMPLATE_FILE = "README.template.md";
const OUTPUT_FILE = "README.md";

/**
* Determine version from package.json
*/
const packageJson = JSON.parse(await fs.readFile("package.json", "utf8"));
const version = packageJson.version;

/**
* Run test and get coverage
*
Expand All @@ -30,7 +24,7 @@ const version = packageJson.version;
*
* The coverage percentage is the average of all columns for "All files".
*/
const testsResult = await new Promise((resolve, reject) => {
const testsResult = await new Promise((resolve) => {
const child = child_process.spawn("npm", ["test"]);
const data = [];
child.stdout.on("data", (chunk) => data.push(chunk));
Expand All @@ -52,7 +46,7 @@ const coverageColors = ["16a34a", "ca8a04", "f97316", "ef4444", "b91c1c"];
/**
* Determine if the build passes by the exit code of `npm run build`
*/
const buildPass = await new Promise((resolve, reject) => {
const buildPass = await new Promise((resolve) => {
const child = child_process.spawn("npm", ["run", "build"]);
child.on("exit", (code) => resolve(code === 0));
});
Expand All @@ -63,7 +57,6 @@ const buildPass = await new Promise((resolve, reject) => {
* {{variable_name}}
*/
const variables = {
"shield:version": `![version: ${version}](https://img.shields.io/badge/version-${version}-%233b82f6)`,
"shield:tests": `![test: ${testsResult.testsPass ? "passing" : "failing"}](https://img.shields.io/badge/tests-${testsResult.testsPass ? "passing" : "failing"}-${testsResult.testsPass ? "%2316a34a" : "%23ef4444"})`,
"shield:coverage": `![coverage: ${testsResult.coverage}%](https://img.shields.io/badge/coverage-${testsResult.coverage}%25-%23${coverageColors.reverse()[Math.floor(testsResult.coverage * (coverageColors.length - 1) / 100)]})`,
"shield:build": `![build: ${buildPass ? "passing" : "failing"}](https://img.shields.io/badge/build-${buildPass ? "passing" : "failing"}-${buildPass ? "%2316a34a" : "%23ef4444"})`,
Expand Down

0 comments on commit 3c68c3f

Please sign in to comment.