| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent a9332e8 commit cbe3b27
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -50,7 +50,8 @@ modifications occur. To avoid surprises, use of an Experimental feature may need | |||
| 50 | 50 | a command-line flag. Experimental features may also emit a [warning][]. | |
| 51 | 51 | ||
| 52 | 52 | ## Stability overview | |
| 53 | - <!-- STABILITY_OVERVIEW_SLOT --> | ||
| 53 | + <!-- STABILITY_OVERVIEW_SLOT_BEGIN --> | ||
| 54 | + <!-- STABILITY_OVERVIEW_SLOT_END --> | ||
| 54 | 55 | ||
| 55 | 56 | ## JSON output | |
| 56 | 57 | <!-- YAML | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -14,7 +14,9 @@ const visit = require('unist-util-visit'); | |||
| 14 | 14 | ||
| 15 | 15 | const source = `${__dirname}/../../out/doc/api`; | |
| 16 | 16 | 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}`; | ||
| 18 | 20 | ||
| 19 | 21 | const output = { | |
| 20 | 22 | json: path.join(source, 'stability.json'), | |
@@ -84,28 +86,29 @@ function processStability() { | |||
| 84 | 86 | ||
| 85 | 87 | function updateStabilityMark(file, value, mark) { | |
| 86 | 88 | const fd = fs.openSync(file, 'r+'); | |
| 87 | - const content = fs.readFileSync(fd); | ||
| 89 | + const content = fs.readFileSync(fd, { encoding: 'utf8' }); | ||
| 88 | 90 | ||
| 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 | + } | ||
| 97 | 95 | fs.closeSync(fd); | |
| 98 | 96 | } | |
| 99 | 97 | ||
| 100 | 98 | const stability = collectStability(data); | |
| 101 | 99 | ||
| 102 | 100 | // add markdown | |
| 103 | 101 | 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')); | ||
| 105 | 105 | ||
| 106 | 106 | // add html table | |
| 107 | 107 | const html = createHTML(markdownTable); | |
| 108 | - updateStabilityMark(output.docHTML, html, mark); | ||
| 108 | + updateStabilityMark(output.docHTML, `${markBegin}${html}${markEnd}`, | ||
| 109 | + new RegExp(mark, 's')); | ||
| 109 | 110 | ||
| 110 | 111 | // 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')); | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments