Skip to content

Commit

Permalink
use cli-progress for the prgoress bar
Browse files Browse the repository at this point in the history
  • Loading branch information
a-hariti committed Jul 24, 2024
1 parent 814afb5 commit 14d7665
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 12 deletions.
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -104,12 +104,14 @@
"@spotlightjs/spotlight": "^2.0.0-alpha.1",
"@tailwindcss/forms": "^0.5.7",
"@tailwindcss/typography": "^0.5.10",
"@types/cli-progress": "^3.11.6",
"@types/node": "^20",
"@types/react": "^18",
"@types/react-dom": "^18",
"@types/ws": "^8.5.10",
"@untitaker/quicktype-core-with-markdown": "^6.0.71",
"autoprefixer": "^10.4.17",
"cli-progress": "^3.12.0",
"concurrently": "^8.2.2",
"dotenv-cli": "^7.4.1",
"eslint": "^8",
Expand Down
18 changes: 6 additions & 12 deletions scripts/lint-404s/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@

import {readFileSync} from 'fs';
import path, {dirname} from 'path';
import readline from 'readline';
import {fileURLToPath} from 'url';

import cliProgress from 'cli-progress';

const baseURL = 'http://localhost:3000/';
type Link = {href: string; innerText: string};

Expand All @@ -27,16 +28,6 @@ async function fetchWithFollow(url: URL | string): Promise<Response> {
return r;
}

function updateProgressBar(current: number, total: number) {
const barLength = 40;
const progress = current / total;
const filledLength = Math.round(barLength * progress);
const bar = '▆'.repeat(filledLength) + '-'.repeat(barLength - filledLength);
const percentage = Math.round(progress * 100);
readline.cursorTo(process.stdout, 0); // Move cursor to the beginning of the line to overwrite
process.stdout.write(`Progress: ${bar} ${percentage}% (${current}/${total})`);
}

async function main() {
const sitemap = await fetch(`${baseURL}sitemap.xml`).then(r => r.text());

Expand Down Expand Up @@ -97,6 +88,9 @@ async function main() {
return false;
}

const progressBar = new cliProgress.SingleBar({}, cliProgress.Presets.shades_classic);
progressBar.start(slugs.length, 0);

for (let i = 0; i < slugs.length; i++) {
const slug = slugs[i];
const pageUrl = new URL(slug, baseURL);
Expand All @@ -122,7 +116,7 @@ async function main() {
all404s.push({slug, page404s});
}

updateProgressBar(i + 1, slugs.length);
progressBar.increment();
}

if (all404s.length === 0) {
Expand Down
14 changes: 14 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2815,6 +2815,13 @@
resolved "https://registry.yarnpkg.com/@types/caseless/-/caseless-0.12.5.tgz#db9468cb1b1b5a925b8f34822f1669df0c5472f5"
integrity sha512-hWtVTC2q7hc7xZ/RLbxapMvDMgUnDvKvMOpKal4DrMyfGBUfB1oKaZlIRr6mJL+If3bAP6sV/QneGzF6tJjZDg==

"@types/cli-progress@^3.11.6":
version "3.11.6"
resolved "https://registry.yarnpkg.com/@types/cli-progress/-/cli-progress-3.11.6.tgz#94b334ebe4190f710e51c1bf9b4fedb681fa9e45"
integrity sha512-cE3+jb9WRlu+uOSAugewNpITJDt1VF8dHOopPO4IABFc3SXYL5WE/+PTz/FCdZRRfIujiWW3n3aMbv1eIGVRWA==
dependencies:
"@types/node" "*"

"@types/connect@*":
version "3.4.38"
resolved "https://registry.yarnpkg.com/@types/connect/-/connect-3.4.38.tgz#5ba7f3bc4fbbdeaff8dded952e5ff2cc53f8d858"
Expand Down Expand Up @@ -4091,6 +4098,13 @@ clean-css@^5.0.0:
dependencies:
source-map "~0.6.0"

cli-progress@^3.12.0:
version "3.12.0"
resolved "https://registry.yarnpkg.com/cli-progress/-/cli-progress-3.12.0.tgz#807ee14b66bcc086258e444ad0f19e7d42577942"
integrity sha512-tRkV3HJ1ASwm19THiiLIXLO7Im7wlTuKnvkYaTkyoAPefqjNg7W7DHKUlGRxy9vxDvbyCYQkQozvptuMkGCg8A==
dependencies:
string-width "^4.2.3"

client-only@0.0.1:
version "0.0.1"
resolved "https://registry.yarnpkg.com/client-only/-/client-only-0.0.1.tgz#38bba5d403c41ab150bff64a95c85013cf73bca1"
Expand Down

0 comments on commit 14d7665

Please sign in to comment.