Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
AugustinMauroy committed Oct 22, 2024
1 parent 6297b0d commit 9e75a18
Show file tree
Hide file tree
Showing 10 changed files with 4,891 additions and 22 deletions.
1,387 changes: 1,387 additions & 0 deletions fixtures/addons.md

Large diffs are not rendered by default.

2,587 changes: 2,587 additions & 0 deletions fixtures/assert.md

Large diffs are not rendered by default.

888 changes: 888 additions & 0 deletions fixtures/async_context.md

Large diffs are not rendered by default.

9 changes: 0 additions & 9 deletions src/generators/json-simple/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import { remove } from 'unist-util-remove';

import createQueries from '../../queries.mjs';
import { getRemark } from '../../utils/remark.mjs';
import { createProgressBar } from '../../utils/progressBar.mjs';

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

// Creates a progress bar for the JSON generation
const progressBar = createProgressBar('Generating JSON');
progressBar.start(input.length, 0);

// Iterates the input (ApiDocMetadataEntry) and performs a few changes
const mappedInput = input.map(node => {
// Deep clones the content nodes to avoid affecting upstream nodes
Expand All @@ -53,13 +48,9 @@ export default {
// For the JSON generate we want to transform the whole content into JSON
content.toJSON = () => remarkProcessor.stringify(content);

progressBar.increment();

return { ...node, content };
});

progressBar.stop();

// This simply grabs all the different files and stringifies them
const stringifiedContent = JSON.stringify(mappedInput);

Expand Down
9 changes: 0 additions & 9 deletions src/generators/legacy-html/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import tableOfContents from './utils/tableOfContents.mjs';

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

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

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

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

Expand All @@ -162,12 +157,8 @@ export default {
});

await writeFile(join(output, `${node.api}.html`), minified);
progressBar.increment();
}

// Stops the progress bar and clears the line
progressBar.stop();

// Define the output folder for API docs assets
const assetsFolder = join(output, 'assets');

Expand Down
2 changes: 1 addition & 1 deletion src/loader.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { extname } from 'node:path';
import { globSync } from 'glob';
import { VFile } from 'vfile';

import { createProgressBar } from './utils/progressBar.mjs';
import createProgressBar from './utils/progressBar.mjs';

/**
* This method creates a simple abstract "Loader", which technically
Expand Down
14 changes: 13 additions & 1 deletion src/parser.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import createQueries from './queries.mjs';

import { getRemark } from './utils/remark.mjs';
import { createNodeSlugger } from './utils/slugger.mjs';
import createProgressBar from './utils/progressBar.mjs';

/**
* Creates an API doc parser for a given Markdown API doc file
Expand Down Expand Up @@ -177,7 +178,18 @@ const createParser = () => {
const parseApiDocs = async apiDocs => {
// We do a Promise.all, to ensure that each API doc is resolved asynchronously
// but all need to be resolved first before we return the result to the caller
const resolvedApiDocEntries = await Promise.all(apiDocs.map(parseApiDoc));

const progressBar = createProgressBar('Parsing API Docs');
progressBar.start(apiDocs.length, 0);

const resolvedApiDocEntries = await Promise.all(
apiDocs.map(async apiDoc => {
progressBar.increment();
return await parseApiDoc(apiDoc);
})
);

progressBar.stop();

return resolvedApiDocEntries.flat();
};
Expand Down
8 changes: 8 additions & 0 deletions src/utils/generators.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import { coerce } from 'semver';

import createProgressBar from './progressBar.mjs';

/**
* Groups all the API metadata nodes by module (`api` property) so that we can process each different file
* based on the module it belongs to.
Expand All @@ -12,14 +14,20 @@ export const groupNodesByModule = nodes => {
/** @type {Map<string, Array<ApiDocMetadataEntry>>} */
const groupedNodes = new Map();

const progressBar = createProgressBar(groupNodesByModule.name);
progressBar.start(nodes.length, 0);

for (const node of nodes) {
if (!groupedNodes.has(node.api)) {
groupedNodes.set(node.api, []);
}

groupedNodes.get(node.api).push(node);
progressBar.increment();
}

progressBar.stop();

return groupedNodes;
};

Expand Down
7 changes: 6 additions & 1 deletion src/utils/progressBar.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@ import { styleText } from 'node:util';
import cliProgress from 'cli-progress';

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

return new cliProgress.SingleBar({
Expand All @@ -17,3 +20,5 @@ export function createProgressBar(label = '') {
hideCursor: true,
});
}

export default createProgressBar;
2 changes: 1 addition & 1 deletion src/utils/tests/progressBar.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { test } from 'node:test';

import cliProgress from 'cli-progress';

import { createProgressBar } from '../progressBar.mjs';
import createProgressBar from '../progressBar.mjs';

/**
* Simple test to unsure that the progress bar is created
Expand Down

0 comments on commit 9e75a18

Please sign in to comment.