| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent f260f4a commit 15d66fb
5 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -695,7 +695,7 @@ doc-only: tools/doc/node_modules \ | |||
| 695 | 695 | @if [ "$(shell $(node_use_openssl))" != "true" ]; then \ | |
| 696 | 696 | echo "Skipping doc-only (no crypto)"; \ | |
| 697 | 697 | else \ | |
| 698 | - $(MAKE) out/doc/api/all.html out/doc/api/all.json; \ | ||
| 698 | + $(MAKE) out/doc/api/all.html out/doc/api/all.json out/doc/api/stability; \ | ||
| 699 | 699 | fi | |
| 700 | 700 | ||
| 701 | 701 | .PHONY: doc | |
@@ -748,6 +748,10 @@ out/doc/api/all.html: $(apidocs_html) tools/doc/allhtml.js \ | |||
| 748 | 748 | out/doc/api/all.json: $(apidocs_json) tools/doc/alljson.js | out/doc/api | |
| 749 | 749 | $(call available-node, tools/doc/alljson.js) | |
| 750 | 750 | ||
| 751 | + .PHONY: out/doc/api/stability | ||
| 752 | + out/doc/api/stability: out/doc/api/all.json tools/doc/stability.js | out/doc/api | ||
| 753 | + $(call available-node, tools/doc/stability.js) | ||
| 754 | + | ||
| 751 | 755 | .PHONY: docopen | |
| 752 | 756 | docopen: out/doc/api/all.html | |
| 753 | 757 | @$(PYTHON) -mwebbrowser file://$(abspath $<) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -43,6 +43,9 @@ Bugs or behavior changes may surprise users when Experimental API | |||
| 43 | 43 | modifications occur. To avoid surprises, use of an Experimental feature may need | |
| 44 | 44 | a command-line flag. Experimental features may also emit a [warning][]. | |
| 45 | 45 | ||
| 46 | + ## Stability overview | ||
| 47 | + <!-- STABILITY_OVERVIEW_SLOT --> | ||
| 48 | + | ||
| 46 | 49 | ## JSON output | |
| 47 | 50 | <!-- YAML | |
| 48 | 51 | added: v0.6.12 | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -263,6 +263,10 @@ ol.version-picker li:last-child a { | |||
| 263 | 263 | background-color: var(--green2); | |
| 264 | 264 | } | |
| 265 | 265 | ||
| 266 | + .module_stability { | ||
| 267 | + vertical-align: middle; | ||
| 268 | + } | ||
| 269 | + | ||
| 266 | 270 | .api_metadata { | |
| 267 | 271 | font-size: .85rem; | |
| 268 | 272 | margin-bottom: 1rem; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -43,6 +43,9 @@ for (const link of toc.match(/<a.*?>/g)) { | |||
| 43 | 43 | ||
| 44 | 44 | for (const property in data) { | |
| 45 | 45 | if (results.hasOwnProperty(property)) { | |
| 46 | + data[property].forEach((mod) => { | ||
| 47 | + mod.source = data.source; | ||
| 48 | + }); | ||
| 46 | 49 | results[property].push(...data[property]); | |
| 47 | 50 | } | |
| 48 | 51 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,111 @@ | |||
| 1 | + 'use strict'; | ||
| 2 | + | ||
| 3 | + // Build stability table to documentation.html/json/md by generated all.json | ||
| 4 | + | ||
| 5 | + const fs = require('fs'); | ||
| 6 | + const path = require('path'); | ||
| 7 | + const unified = require('unified'); | ||
| 8 | + const raw = require('rehype-raw'); | ||
| 9 | + const markdown = require('remark-parse'); | ||
| 10 | + const htmlStringify = require('rehype-stringify'); | ||
| 11 | + const gfm = require('remark-gfm'); | ||
| 12 | + const remark2rehype = require('remark-rehype'); | ||
| 13 | + const visit = require('unist-util-visit'); | ||
| 14 | + | ||
| 15 | + const source = `${__dirname}/../../out/doc/api`; | ||
| 16 | + const data = require(path.join(source, 'all.json')); | ||
| 17 | + const mark = '<!-- STABILITY_OVERVIEW_SLOT -->'; | ||
| 18 | + | ||
| 19 | + const output = { | ||
| 20 | + json: path.join(source, 'stability.json'), | ||
| 21 | + docHTML: path.join(source, 'documentation.html'), | ||
| 22 | + docJSON: path.join(source, 'documentation.json'), | ||
| 23 | + docMarkdown: path.join(source, 'documentation.md'), | ||
| 24 | + }; | ||
| 25 | + | ||
| 26 | + function collectStability(data) { | ||
| 27 | + const stability = []; | ||
| 28 | + | ||
| 29 | + for (const mod of data.modules) { | ||
| 30 | + if (mod.displayName && mod.stability >= 0) { | ||
| 31 | + const link = mod.source.replace('doc/api/', '').replace('.md', '.html'); | ||
| 32 | + // const link = re.exec(toc)[1] | ||
| 33 | + stability.push({ | ||
| 34 | + api: mod.name, | ||
| 35 | + link: link, | ||
| 36 | + stability: mod.stability, | ||
| 37 | + stabilityText: `(${mod.stability}) ${mod.stabilityText}`, | ||
| 38 | + }); | ||
| 39 | + } | ||
| 40 | + } | ||
| 41 | + | ||
| 42 | + stability.sort((a, b) => a.api.localeCompare(b.api)); | ||
| 43 | + return stability; | ||
| 44 | + } | ||
| 45 | + | ||
| 46 | + function createMarkdownTable(data) { | ||
| 47 | + const md = ['| API | Stability |', '| --- | --------- |']; | ||
| 48 | + | ||
| 49 | + for (const mod of data) { | ||
| 50 | + md.push(`| [${mod.api}](${mod.link}) | ${mod.stabilityText} |`); | ||
| 51 | + } | ||
| 52 | + | ||
| 53 | + return md.join('\n'); | ||
| 54 | + } | ||
| 55 | + | ||
| 56 | + function createHTML(md) { | ||
| 57 | + const file = unified() | ||
| 58 | + .use(markdown) | ||
| 59 | + .use(gfm) | ||
| 60 | + .use(remark2rehype, { allowDangerousHtml: true }) | ||
| 61 | + .use(raw) | ||
| 62 | + .use(htmlStringify) | ||
| 63 | + .use(processStability) | ||
| 64 | + .processSync(md); | ||
| 65 | + | ||
| 66 | + return file.contents.trim(); | ||
| 67 | + } | ||
| 68 | + | ||
| 69 | + function processStability() { | ||
| 70 | + return (tree) => { | ||
| 71 | + visit(tree, { type: 'element', tagName: 'tr' }, (node) => { | ||
| 72 | + const [api, stability] = node.children; | ||
| 73 | + if (api.tagName !== 'td') { | ||
| 74 | + return; | ||
| 75 | + } | ||
| 76 | + | ||
| 77 | + api.properties.class = 'module_stability'; | ||
| 78 | + | ||
| 79 | + const level = stability.children[0].value[1]; | ||
| 80 | + stability.properties.class = `api_stability api_stability_${level}`; | ||
| 81 | + }); | ||
| 82 | + }; | ||
| 83 | + } | ||
| 84 | + | ||
| 85 | + function updateStabilityMark(file, value, mark) { | ||
| 86 | + const fd = fs.openSync(file, 'r+'); | ||
| 87 | + const content = fs.readFileSync(fd); | ||
| 88 | + | ||
| 89 | + // Find the position of the `mark`. | ||
| 90 | + const index = content.indexOf(mark); | ||
| 91 | + | ||
| 92 | + // Overwrite the mark with `value` parameter. | ||
| 93 | + const offset = fs.writeSync(fd, value, index, 'utf-8'); | ||
| 94 | + | ||
| 95 | + // Re-write the end of the file after `value`. | ||
| 96 | + fs.writeSync(fd, content, index + mark.length, undefined, index + offset); | ||
| 97 | + fs.closeSync(fd); | ||
| 98 | + } | ||
| 99 | + | ||
| 100 | + const stability = collectStability(data); | ||
| 101 | + | ||
| 102 | + // add markdown | ||
| 103 | + const markdownTable = createMarkdownTable(stability); | ||
| 104 | + updateStabilityMark(output.docMarkdown, markdownTable, mark); | ||
| 105 | + | ||
| 106 | + // add html table | ||
| 107 | + const html = createHTML(markdownTable); | ||
| 108 | + updateStabilityMark(output.docHTML, html, mark); | ||
| 109 | + | ||
| 110 | + // add json output | ||
| 111 | + updateStabilityMark(output.docJSON, JSON.stringify(html), JSON.stringify(mark)); | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments