-
-
Notifications
You must be signed in to change notification settings - Fork 34.2k
doc: list the stability status of each module #36223
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
Closed
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
5313444
doc: list the stability status of each API
Lxxyx 70979d2
Update Makefile
Lxxyx 32d333c
Update tools/doc/stability.js
Lxxyx 579c21c
Update tools/doc/stability.js
Lxxyx 8c573d1
Update tools/doc/stability.js
Lxxyx f0103c6
Update tools/doc/stability.js
Lxxyx File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,111 @@ | ||
| 'use strict'; | ||
|
|
||
| // Build stability table to documentation.html/json/md by generated all.json | ||
|
|
||
| const fs = require('fs'); | ||
| const path = require('path'); | ||
| const unified = require('unified'); | ||
| const raw = require('rehype-raw'); | ||
| const markdown = require('remark-parse'); | ||
| const htmlStringify = require('rehype-stringify'); | ||
| const gfm = require('remark-gfm'); | ||
| const remark2rehype = require('remark-rehype'); | ||
| const visit = require('unist-util-visit'); | ||
|
|
||
| const source = `${__dirname}/../../out/doc/api`; | ||
| const data = require(path.join(source, 'all.json')); | ||
| const mark = '<!-- STABILITY_OVERVIEW_SLOT -->'; | ||
|
|
||
| const output = { | ||
| json: path.join(source, 'stability.json'), | ||
| docHTML: path.join(source, 'documentation.html'), | ||
| docJSON: path.join(source, 'documentation.json'), | ||
| docMarkdown: path.join(source, 'documentation.md'), | ||
| }; | ||
|
|
||
| function collectStability(data) { | ||
| const stability = []; | ||
|
|
||
| for (const mod of data.modules) { | ||
| if (mod.displayName && mod.stability >= 0) { | ||
| const link = mod.source.replace('doc/api/', '').replace('.md', '.html'); | ||
| // const link = re.exec(toc)[1] | ||
| stability.push({ | ||
| api: mod.name, | ||
| link: link, | ||
| stability: mod.stability, | ||
| stabilityText: `(${mod.stability}) ${mod.stabilityText}`, | ||
| }); | ||
| } | ||
| } | ||
|
|
||
| stability.sort((a, b) => a.api.localeCompare(b.api)); | ||
| return stability; | ||
| } | ||
|
|
||
| function createMarkdownTable(data) { | ||
| const md = ['| API | Stability |', '| --- | --------- |']; | ||
|
|
||
| for (const mod of data) { | ||
| md.push(`| [${mod.api}](${mod.link}) | ${mod.stabilityText} |`); | ||
| } | ||
|
|
||
| return md.join('\n'); | ||
| } | ||
|
|
||
| function createHTML(md) { | ||
| const file = unified() | ||
| .use(markdown) | ||
| .use(gfm) | ||
| .use(remark2rehype, { allowDangerousHtml: true }) | ||
| .use(raw) | ||
| .use(htmlStringify) | ||
| .use(processStability) | ||
| .processSync(md); | ||
|
|
||
| return file.contents.trim(); | ||
| } | ||
|
|
||
| function processStability() { | ||
| return (tree) => { | ||
| visit(tree, { type: 'element', tagName: 'tr' }, (node) => { | ||
| const [api, stability] = node.children; | ||
| if (api.tagName !== 'td') { | ||
| return; | ||
| } | ||
|
|
||
| api.properties.class = 'module_stability'; | ||
|
|
||
| const level = stability.children[0].value[1]; | ||
| stability.properties.class = `api_stability api_stability_${level}`; | ||
| }); | ||
| }; | ||
| } | ||
|
|
||
| function updateStabilityMark(file, value, mark) { | ||
| const fd = fs.openSync(file, 'r+'); | ||
| const content = fs.readFileSync(fd); | ||
|
|
||
| // Find the position of the `mark`. | ||
| const index = content.indexOf(mark); | ||
|
|
||
| // Overwrite the mark with `value` parameter. | ||
| const offset = fs.writeSync(fd, value, index, 'utf-8'); | ||
|
|
||
| // Re-write the end of the file after `value`. | ||
| fs.writeSync(fd, content, index + mark.length, undefined, index + offset); | ||
| fs.closeSync(fd); | ||
| } | ||
|
|
||
| const stability = collectStability(data); | ||
|
|
||
| // add markdown | ||
| const markdownTable = createMarkdownTable(stability); | ||
| updateStabilityMark(output.docMarkdown, markdownTable, mark); | ||
|
|
||
| // add html table | ||
| const html = createHTML(markdownTable); | ||
| updateStabilityMark(output.docHTML, html, mark); | ||
|
|
||
| // add json output | ||
| updateStabilityMark(output.docJSON, JSON.stringify(html), JSON.stringify(mark)); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.