Skip to content

Commit 9e75a18

Browse files
wip
1 parent 6297b0d commit 9e75a18

File tree

10 files changed

+4891
-22
lines changed

10 files changed

+4891
-22
lines changed

fixtures/addons.md

Lines changed: 1387 additions & 0 deletions
Large diffs are not rendered by default.

fixtures/assert.md

Lines changed: 2587 additions & 0 deletions
Large diffs are not rendered by default.

fixtures/async_context.md

Lines changed: 888 additions & 0 deletions
Large diffs are not rendered by default.

src/generators/json-simple/index.mjs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import { remove } from 'unist-util-remove';
77

88
import createQueries from '../../queries.mjs';
99
import { getRemark } from '../../utils/remark.mjs';
10-
import { createProgressBar } from '../../utils/progressBar.mjs';
1110

1211
/**
1312
* This generator generates a simplified JSON version of the API docs and returns it as a string
@@ -34,10 +33,6 @@ export default {
3433
// Gets a remark processor for stringifying the AST tree into JSON
3534
const remarkProcessor = getRemark();
3635

37-
// Creates a progress bar for the JSON generation
38-
const progressBar = createProgressBar('Generating JSON');
39-
progressBar.start(input.length, 0);
40-
4136
// Iterates the input (ApiDocMetadataEntry) and performs a few changes
4237
const mappedInput = input.map(node => {
4338
// Deep clones the content nodes to avoid affecting upstream nodes
@@ -53,13 +48,9 @@ export default {
5348
// For the JSON generate we want to transform the whole content into JSON
5449
content.toJSON = () => remarkProcessor.stringify(content);
5550

56-
progressBar.increment();
57-
5851
return { ...node, content };
5952
});
6053

61-
progressBar.stop();
62-
6354
// This simply grabs all the different files and stringifies them
6455
const stringifiedContent = JSON.stringify(mappedInput);
6556

src/generators/legacy-html/index.mjs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import tableOfContents from './utils/tableOfContents.mjs';
1111

1212
import { groupNodesByModule } from '../../utils/generators.mjs';
1313
import { getRemarkRehype } from '../../utils/remark.mjs';
14-
import { createProgressBar } from '../../utils/progressBar.mjs';
1514

1615
/**
1716
* @typedef {{
@@ -148,10 +147,6 @@ export default {
148147
return replaceTemplateValues(generatedTemplate);
149148
};
150149

151-
// Creates a progress bar to show the progress of the generation process
152-
const progressBar = createProgressBar('Generating HTML files');
153-
progressBar.start(headNodes.length, 0);
154-
155150
for (const node of headNodes) {
156151
const result = processModuleNodes(node);
157152

@@ -162,12 +157,8 @@ export default {
162157
});
163158

164159
await writeFile(join(output, `${node.api}.html`), minified);
165-
progressBar.increment();
166160
}
167161

168-
// Stops the progress bar and clears the line
169-
progressBar.stop();
170-
171162
// Define the output folder for API docs assets
172163
const assetsFolder = join(output, 'assets');
173164

src/loader.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { extname } from 'node:path';
66
import { globSync } from 'glob';
77
import { VFile } from 'vfile';
88

9-
import { createProgressBar } from './utils/progressBar.mjs';
9+
import createProgressBar from './utils/progressBar.mjs';
1010

1111
/**
1212
* This method creates a simple abstract "Loader", which technically

src/parser.mjs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import createQueries from './queries.mjs';
1111

1212
import { getRemark } from './utils/remark.mjs';
1313
import { createNodeSlugger } from './utils/slugger.mjs';
14+
import createProgressBar from './utils/progressBar.mjs';
1415

1516
/**
1617
* Creates an API doc parser for a given Markdown API doc file
@@ -177,7 +178,18 @@ const createParser = () => {
177178
const parseApiDocs = async apiDocs => {
178179
// We do a Promise.all, to ensure that each API doc is resolved asynchronously
179180
// but all need to be resolved first before we return the result to the caller
180-
const resolvedApiDocEntries = await Promise.all(apiDocs.map(parseApiDoc));
181+
182+
const progressBar = createProgressBar('Parsing API Docs');
183+
progressBar.start(apiDocs.length, 0);
184+
185+
const resolvedApiDocEntries = await Promise.all(
186+
apiDocs.map(async apiDoc => {
187+
progressBar.increment();
188+
return await parseApiDoc(apiDoc);
189+
})
190+
);
191+
192+
progressBar.stop();
181193

182194
return resolvedApiDocEntries.flat();
183195
};

src/utils/generators.mjs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
import { coerce } from 'semver';
44

5+
import createProgressBar from './progressBar.mjs';
6+
57
/**
68
* Groups all the API metadata nodes by module (`api` property) so that we can process each different file
79
* based on the module it belongs to.
@@ -12,14 +14,20 @@ export const groupNodesByModule = nodes => {
1214
/** @type {Map<string, Array<ApiDocMetadataEntry>>} */
1315
const groupedNodes = new Map();
1416

17+
const progressBar = createProgressBar(groupNodesByModule.name);
18+
progressBar.start(nodes.length, 0);
19+
1520
for (const node of nodes) {
1621
if (!groupedNodes.has(node.api)) {
1722
groupedNodes.set(node.api, []);
1823
}
1924

2025
groupedNodes.get(node.api).push(node);
26+
progressBar.increment();
2127
}
2228

29+
progressBar.stop();
30+
2331
return groupedNodes;
2432
};
2533

src/utils/progressBar.mjs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,14 @@ import { styleText } from 'node:util';
33
import cliProgress from 'cli-progress';
44

55
/**
6+
*
7+
* Create a progress bar instance
8+
* with our custom format
69
*
710
* @param {string} label
811
* @returns {import('cli-progress').SingleBar}
912
*/
10-
export function createProgressBar(label = '') {
13+
function createProgressBar(label = '') {
1114
const format = ` ${styleText(['bold', 'green'], '{bar}')} | ${label} {percentage}% | {value}/{total}`;
1215

1316
return new cliProgress.SingleBar({
@@ -17,3 +20,5 @@ export function createProgressBar(label = '') {
1720
hideCursor: true,
1821
});
1922
}
23+
24+
export default createProgressBar;

src/utils/tests/progressBar.test.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { test } from 'node:test';
33

44
import cliProgress from 'cli-progress';
55

6-
import { createProgressBar } from '../progressBar.mjs';
6+
import createProgressBar from '../progressBar.mjs';
77

88
/**
99
* Simple test to unsure that the progress bar is created

0 commit comments

Comments
 (0)