Skip to content

Commit 4cd471e

Browse files
Lxxyxruyadorno
authored andcommitted
tools,doc: list the stability status of each API
Fixes: #23723 PR-URL: #36223 Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Myles Borins <myles.borins@gmail.com> Reviewed-By: Franziska Hinkelmann <franziska.hinkelmann@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
1 parent 0c9e2d0 commit 4cd471e

5 files changed

Lines changed: 126 additions & 1 deletion

File tree

‎Makefile‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -696,7 +696,7 @@ doc-only: tools/doc/node_modules \
696696
@if [ "$(shell $(node_use_openssl))"!="true" ];then\
697697
echo"Skipping doc-only (no crypto)";\
698698
else\
699-
$(MAKE) out/doc/api/all.html out/doc/api/all.json;\
699+
$(MAKE) out/doc/api/all.html out/doc/api/all.json out/doc/api/stability;\
700700
fi
701701

702702
.PHONY: doc
@@ -749,6 +749,10 @@ out/doc/api/all.html: $(apidocs_html) tools/doc/allhtml.js \
749749
out/doc/api/all.json: $(apidocs_json) tools/doc/alljson.js | out/doc/api
750750
$(call available-node, tools/doc/alljson.js)
751751

752+
.PHONY: out/doc/api/stability
753+
out/doc/api/stability: out/doc/api/all.json tools/doc/stability.js | out/doc/api
754+
$(call available-node, tools/doc/stability.js)
755+
752756
.PHONY: docopen
753757
docopen: out/doc/api/all.html
754758
@$(PYTHON) -mwebbrowser file://$(abspath$<)

‎doc/api/documentation.md‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ Bugs or behavior changes may surprise users when Experimental API
4343
modifications occur. To avoid surprises, use of an Experimental feature may need
4444
a command-line flag. Experimental features may also emit a [warning][].
4545

46+
## Stability overview
47+
<!-- STABILITY_OVERVIEW_SLOT -->
48+
4649
## JSON output
4750
<!-- YAML
4851
added: v0.6.12

‎doc/api_assets/style.css‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,10 @@ ol.version-picker li:last-child a {
263263
background-color:var(--green2);
264264
}
265265

266+
.module_stability {
267+
vertical-align: middle;
268+
}
269+
266270
.api_metadata {
267271
font-size:.85rem;
268272
margin-bottom:1rem;

‎tools/doc/alljson.js‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ for (const link of toc.match(/<a.*?>/g)) {
4343

4444
for(constpropertyindata){
4545
if(results.hasOwnProperty(property)){
46+
data[property].forEach((mod)=>{
47+
mod.source=data.source;
48+
});
4649
results[property].push(...data[property]);
4750
}
4851
}

‎tools/doc/stability.js‎

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff 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+
constfs=require('fs');
6+
constpath=require('path');
7+
constunified=require('unified');
8+
constraw=require('rehype-raw');
9+
constmarkdown=require('remark-parse');
10+
consthtmlStringify=require('rehype-stringify');
11+
constgfm=require('remark-gfm');
12+
constremark2rehype=require('remark-rehype');
13+
constvisit=require('unist-util-visit');
14+
15+
constsource=`${__dirname}/../../out/doc/api`;
16+
constdata=require(path.join(source,'all.json'));
17+
constmark='<!-- STABILITY_OVERVIEW_SLOT -->';
18+
19+
constoutput={
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+
functioncollectStability(data){
27+
conststability=[];
28+
29+
for(constmodofdata.modules){
30+
if(mod.displayName&&mod.stability>=0){
31+
constlink=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+
returnstability;
44+
}
45+
46+
functioncreateMarkdownTable(data){
47+
constmd=['| API | Stability |','| --- | --------- |'];
48+
49+
for(constmodofdata){
50+
md.push(`| [${mod.api}](${mod.link}) | ${mod.stabilityText} |`);
51+
}
52+
53+
returnmd.join('\n');
54+
}
55+
56+
functioncreateHTML(md){
57+
constfile=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+
returnfile.contents.trim();
67+
}
68+
69+
functionprocessStability(){
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+
constlevel=stability.children[0].value[1];
80+
stability.properties.class=`api_stability api_stability_${level}`;
81+
});
82+
};
83+
}
84+
85+
functionupdateStabilityMark(file,value,mark){
86+
constfd=fs.openSync(file,'r+');
87+
constcontent=fs.readFileSync(fd);
88+
89+
// Find the position of the `mark`.
90+
constindex=content.indexOf(mark);
91+
92+
// Overwrite the mark with `value` parameter.
93+
constoffset=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+
conststability=collectStability(data);
101+
102+
// add markdown
103+
constmarkdownTable=createMarkdownTable(stability);
104+
updateStabilityMark(output.docMarkdown,markdownTable,mark);
105+
106+
// add html table
107+
consthtml=createHTML(markdownTable);
108+
updateStabilityMark(output.docHTML,html,mark);
109+
110+
// add json output
111+
updateStabilityMark(output.docJSON,JSON.stringify(html),JSON.stringify(mark));

0 commit comments

Comments
 (0)