Skip to content

feat(progress-bar): setup basic #98

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 59 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
4f650bd
feat(progress-bar): setup basic
AugustinMauroy Sep 11, 2024
a3e7623
test: progress-bar
AugustinMauroy Sep 11, 2024
b96cfd0
fix: code style
AugustinMauroy Sep 12, 2024
9180963
fix: code style
AugustinMauroy Sep 12, 2024
3d1760f
fix: code style
AugustinMauroy Sep 12, 2024
5e879ff
fix + update
AugustinMauroy Oct 14, 2024
6297b0d
fix: codespell
AugustinMauroy Oct 14, 2024
9e75a18
wip
AugustinMauroy Oct 22, 2024
2cfc4e1
Merge branch 'main' into feat(progress-bar)
AugustinMauroy Oct 22, 2024
4701dcb
remove
AugustinMauroy Oct 22, 2024
2dbc286
add withe-spaces
AugustinMauroy Nov 18, 2024
aa799c5
remove useless await
AugustinMauroy Nov 18, 2024
62f3486
WIP(spinner)
AugustinMauroy Dec 22, 2024
076815d
use clack
AugustinMauroy Dec 22, 2024
c64aa3e
Merge branch 'main' into feat(progress-bar)
AugustinMauroy Jan 19, 2025
5c5884c
hotfix: type and build fixes (#177)
ovflowd Jan 20, 2025
8ec63c9
refactor(addon-verify): some improvements (#175)
araujogui Jan 20, 2025
cfee887
hotfix: correctly use dedent
ovflowd Jan 20, 2025
1da598d
doc: improve accessibility of expandable lists
aduh95 Jan 26, 2025
a4ea425
doc: add "Skip to content" button
aduh95 Jan 26, 2025
cb66e80
doc: fix styles of the expandable TOC
aduh95 Jan 26, 2025
6c234f6
meta: bump actions/upload-artifact from 4.5.0 to 4.6.0 (#189)
dependabot[bot] Feb 2, 2025
bf1fe58
meta: bump actions/setup-node from 4.1.0 to 4.2.0 (#188)
dependabot[bot] Feb 2, 2025
ef6f16f
meta: bump step-security/harden-runner from 2.10.2 to 2.10.4 (#187)
dependabot[bot] Feb 2, 2025
4019ac0
meta: bump github/codeql-action from 3.28.0 to 3.28.8 (#186)
dependabot[bot] Feb 2, 2025
9091505
meta: bump lint-staged from 15.3.0 to 15.4.3 (#185)
dependabot[bot] Feb 2, 2025
5321cb9
meta: bump glob from 11.0.0 to 11.0.1 (#184)
dependabot[bot] Feb 2, 2025
5751332
meta: bump semver from 7.6.3 to 7.7.0 (#183)
dependabot[bot] Feb 2, 2025
92b7f03
meta: bump commander from 13.0.0 to 13.1.0 (#182)
dependabot[bot] Feb 2, 2025
8e3d276
meta: bump @types/node from 22.10.3 to 22.13.0 (#180)
dependabot[bot] Feb 2, 2025
653672e
meta: bump shiki from 1.24.4 to 2.2.0 (#181)
dependabot[bot] Feb 2, 2025
1c86005
meta: bump the lint group with 4 updates (#179)
dependabot[bot] Feb 2, 2025
3452cf2
doc: make MDN links to global classes more consistent (#190)
aduh95 Feb 7, 2025
11a7953
feat apilinks.json generator (#153)
flakey5 Feb 11, 2025
20d1cac
meta: bump ossf/scorecard-action from 2.4.0 to 2.4.1 (#202)
dependabot[bot] Mar 1, 2025
9a3c811
meta: bump step-security/harden-runner from 2.10.4 to 2.11.0 (#201)
dependabot[bot] Mar 1, 2025
546f284
meta: bump actions/upload-artifact from 4.6.0 to 4.6.1 (#200)
dependabot[bot] Mar 1, 2025
1206535
meta: bump github/codeql-action from 3.28.8 to 3.28.10 (#199)
dependabot[bot] Mar 1, 2025
c6c1408
meta: bump hastscript from 9.0.0 to 9.0.1 (#198)
dependabot[bot] Mar 1, 2025
0a05afb
meta: bump semver from 7.7.0 to 7.7.1 (#197)
dependabot[bot] Mar 1, 2025
d162314
meta: bump remark-gfm from 4.0.0 to 4.0.1 (#195)
dependabot[bot] Mar 1, 2025
d896c77
meta: bump @types/node from 22.13.0 to 22.13.8 (#194)
dependabot[bot] Mar 1, 2025
588d8f2
meta: bump the lint group with 4 updates (#193)
dependabot[bot] Mar 1, 2025
c26adb4
meta: bump prettier from 3.4.2 to 3.5.2 in the fromat group (#192)
dependabot[bot] Mar 1, 2025
adefb11
workflow(pr): improve (#203)
AugustinMauroy Mar 2, 2025
4eb8286
feat(progress-bar): setup basic
AugustinMauroy Sep 11, 2024
984022e
test: progress-bar
AugustinMauroy Sep 11, 2024
766bae6
fix: code style
AugustinMauroy Sep 12, 2024
5479cab
fix: code style
AugustinMauroy Sep 12, 2024
2769920
fix: code style
AugustinMauroy Sep 12, 2024
6b1308d
fix + update
AugustinMauroy Oct 14, 2024
47c2765
fix: codespell
AugustinMauroy Oct 14, 2024
3a00ed5
wip
AugustinMauroy Oct 22, 2024
0c22339
remove
AugustinMauroy Oct 22, 2024
89228fd
add withe-spaces
AugustinMauroy Nov 18, 2024
f311669
remove useless await
AugustinMauroy Nov 18, 2024
9124051
WIP(spinner)
AugustinMauroy Dec 22, 2024
89e377e
use clack
AugustinMauroy Dec 22, 2024
b45d230
Merge branch 'feat(progress-bar)' of https://github.com/nodejs/api-do…
AugustinMauroy Mar 4, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions package-lock.json

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

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"prettier": "3.3.3"
},
"dependencies": {
"cli-progress": "^3.12.0",
"commander": "^12.1.0",
"github-slugger": "^2.0.0",
"glob": "^11.0.0",
Expand Down
13 changes: 13 additions & 0 deletions src/generators/legacy-html/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ import tableOfContents from './utils/tableOfContents.mjs';

import { groupNodesByModule } from '../../utils/generators.mjs';
import { getRemarkRehype } from '../../utils/remark.mjs';
import {
createProgressBar,
startProgressBar,
updateProgressBar,
stopProgressBar,
} from '../../utils/progressBar.mjs';

/**
* @typedef {{
Expand Down Expand Up @@ -147,6 +153,10 @@ export default {
return replaceTemplateValues(generatedTemplate);
};

// Creates a progress bar to show the progress of the generation process
const progressBar = createProgressBar('Generating HTML files');
startProgressBar(progressBar, headNodes.length);

for (const node of headNodes) {
const result = processModuleNodes(node);

Expand All @@ -157,7 +167,10 @@ export default {
});

await writeFile(join(output, `${node.api}.html`), minified);
updateProgressBar(progressBar);
}
// Stops the progress bar and clears the line
stopProgressBar(progressBar);

// Define the output folder for API docs assets
const assetsFolder = join(output, 'assets');
Expand Down
14 changes: 14 additions & 0 deletions src/loader.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@ import { extname } from 'node:path';
import { globSync } from 'glob';
import { VFile } from 'vfile';

import {
createProgressBar,
startProgressBar,
updateProgressBar,
stopProgressBar,
} from './utils/progressBar.mjs';

/**
* This method creates a simple abstract "Loader", which technically
* could be used for different things, but here we want to use it to load
Expand All @@ -26,8 +33,15 @@ const createLoader = () => {
filePath => extname(filePath) === '.md'
);

const progressBar = createProgressBar('Loading files');
startProgressBar(progressBar, resolvedFiles.length);

return resolvedFiles.map(async filePath => {
const fileContents = await readFile(filePath, 'utf-8');
updateProgressBar(progressBar);
// normally we stop the progress bar when the loop is done
// but here we return the loop so we need to stop it when the last file is loaded
if (progressBar.value === progressBar.total) stopProgressBar(progressBar);

return new VFile({ path: filePath, value: fileContents });
});
Expand Down
43 changes: 43 additions & 0 deletions src/utils/progressBar.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { styleText } from 'node:util';

import cliProgress from 'cli-progress';

/**
*
* @param {string} label
* @returns {import('cli-progress').SingleBar}
*/
export function createProgressBar(label = '') {
const format = ` ${styleText(['bold', 'green'], '{bar}')} | ${label} {percentage}% | {value}/{total}`;

return new cliProgress.SingleBar({
format,
barCompleteChar: '\u2588',
barIncompleteChar: '\u2591',
hideCursor: true,
});
}

/**
*
* @param {import('cli-progress').SingleBar} bar
* @param {number} total
*/
export function startProgressBar(bar, total) {
bar.start(total, 0);
}

/**
* @param {import('cli-progress').SingleBar} bar
* @param {number} value
*/
export function updateProgressBar(bar, value = 1) {
bar.update(value);
}

/**
* @param {import('cli-progress').SingleBar} bar
*/
export function stopProgressBar(bar) {
bar.stop();
}
30 changes: 30 additions & 0 deletions src/utils/tests/progressBar.test.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import assert from 'node:assert';
import { describe, it } from 'node:test';

import cliProgress from 'cli-progress';

import {
createProgressBar,
startProgressBar,
stopProgressBar,
} from '../progressBar.mjs';

describe('progressBar', () => {
it('createProgressBar returns an instance of SingleBar', () => {
const bar = createProgressBar();
assert.ok(bar instanceof cliProgress.SingleBar);
});

it('startProgressBar sets the correct total value', () => {
const bar = createProgressBar();
startProgressBar(bar, 100);
assert.strictEqual(bar.getTotal(), 100);
});

it('stopProgressBar stops the progress bar', () => {
const bar = createProgressBar();
startProgressBar(bar, 100);
stopProgressBar(bar);
assert.strictEqual(bar.isActive, false);
});
});
Loading