Skip to content

Commit 4043275

Browse files
richardlautargos
authored andcommitted
doc,tools: allow stability table to be updated
Keep markers for the stability table so that it can be updated on subsequent runs of the doc tooling. Only overwrite the files if they have been changed. PR-URL: #38048 Fixes: #37886 Reviewed-By: Antoine du Hamel <[email protected]> Reviewed-By: Rich Trott <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Juan José Arboleda <[email protected]>
1 parent 8615fa1 commit 4043275

File tree

2 files changed

+18
-14
lines changed

2 files changed

+18
-14
lines changed

doc/api/documentation.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ modifications occur. To avoid surprises, use of an Experimental feature may need
5050
a command-line flag. Experimental features may also emit a [warning][].
5151

5252
## Stability overview
53-
<!-- STABILITY_OVERVIEW_SLOT -->
53+
<!-- STABILITY_OVERVIEW_SLOT_BEGIN -->
54+
<!-- STABILITY_OVERVIEW_SLOT_END -->
5455

5556
## JSON output
5657
<!-- YAML

tools/doc/stability.js

+16-13
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ const visit = require('unist-util-visit');
1414

1515
const source = `${__dirname}/../../out/doc/api`;
1616
const data = require(path.join(source, 'all.json'));
17-
const mark = '<!-- STABILITY_OVERVIEW_SLOT -->';
17+
const markBegin = '<!-- STABILITY_OVERVIEW_SLOT_BEGIN -->';
18+
const markEnd = '<!-- STABILITY_OVERVIEW_SLOT_END -->';
19+
const mark = `${markBegin}(.*)${markEnd}`;
1820

1921
const output = {
2022
json: path.join(source, 'stability.json'),
@@ -84,28 +86,29 @@ function processStability() {
8486

8587
function updateStabilityMark(file, value, mark) {
8688
const fd = fs.openSync(file, 'r+');
87-
const content = fs.readFileSync(fd);
89+
const content = fs.readFileSync(fd, { encoding: 'utf8' });
8890

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);
91+
const replaced = content.replace(mark, value);
92+
if (replaced !== content) {
93+
fs.writeSync(fd, replaced, 0, 'utf8');
94+
}
9795
fs.closeSync(fd);
9896
}
9997

10098
const stability = collectStability(data);
10199

102100
// add markdown
103101
const markdownTable = createMarkdownTable(stability);
104-
updateStabilityMark(output.docMarkdown, markdownTable, mark);
102+
updateStabilityMark(output.docMarkdown,
103+
`${markBegin}\n${markdownTable}\n${markEnd}`,
104+
new RegExp(mark, 's'));
105105

106106
// add html table
107107
const html = createHTML(markdownTable);
108-
updateStabilityMark(output.docHTML, html, mark);
108+
updateStabilityMark(output.docHTML, `${markBegin}${html}${markEnd}`,
109+
new RegExp(mark, 's'));
109110

110111
// add json output
111-
updateStabilityMark(output.docJSON, JSON.stringify(html), JSON.stringify(mark));
112+
updateStabilityMark(output.docJSON,
113+
JSON.stringify(`${markBegin}${html}${markEnd}`),
114+
new RegExp(JSON.stringify(mark), 's'));

0 commit comments

Comments
 (0)