diff options
author | Richard Lau <rlau@redhat.com> | 2021-04-02 22:27:19 +0300 |
---|---|---|
committer | Daniel Bevenius <daniel.bevenius@gmail.com> | 2021-04-06 07:14:44 +0300 |
commit | cbe3b27166504c7339d2cf255769b18c5b7e63c1 (patch) | |
tree | 77b9e7b7bf2c6940e6a7f90b0ffd968b913dc574 /tools | |
parent | a9332e84bf41066d3f0b04a43f2780868a5ce5ff (diff) |
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: https://github.com/nodejs/node/pull/38048
Fixes: https://github.com/nodejs/node/issues/37886
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Juan José Arboleda <soyjuanarbol@gmail.com>
Diffstat (limited to 'tools')
-rw-r--r-- | tools/doc/stability.js | 29 |
1 files changed, 16 insertions, 13 deletions
diff --git a/tools/doc/stability.js b/tools/doc/stability.js index 2eb5816e4da..9ab6fac827e 100644 --- a/tools/doc/stability.js +++ b/tools/doc/stability.js @@ -14,7 +14,9 @@ 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 markBegin = '<!-- STABILITY_OVERVIEW_SLOT_BEGIN -->'; +const markEnd = '<!-- STABILITY_OVERVIEW_SLOT_END -->'; +const mark = `${markBegin}(.*)${markEnd}`; const output = { json: path.join(source, 'stability.json'), @@ -84,16 +86,12 @@ function processStability() { function updateStabilityMark(file, value, mark) { const fd = fs.openSync(file, 'r+'); - const content = fs.readFileSync(fd); + const content = fs.readFileSync(fd, { encoding: 'utf8' }); - // 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); + const replaced = content.replace(mark, value); + if (replaced !== content) { + fs.writeSync(fd, replaced, 0, 'utf8'); + } fs.closeSync(fd); } @@ -101,11 +99,16 @@ const stability = collectStability(data); // add markdown const markdownTable = createMarkdownTable(stability); -updateStabilityMark(output.docMarkdown, markdownTable, mark); +updateStabilityMark(output.docMarkdown, + `${markBegin}\n${markdownTable}\n${markEnd}`, + new RegExp(mark, 's')); // add html table const html = createHTML(markdownTable); -updateStabilityMark(output.docHTML, html, mark); +updateStabilityMark(output.docHTML, `${markBegin}${html}${markEnd}`, + new RegExp(mark, 's')); // add json output -updateStabilityMark(output.docJSON, JSON.stringify(html), JSON.stringify(mark)); +updateStabilityMark(output.docJSON, + JSON.stringify(`${markBegin}${html}${markEnd}`), + new RegExp(JSON.stringify(mark), 's')); |