Skip to content
This repository was archived by the owner on Jan 20, 2025. It is now read-only.

Commit 8f37303

Browse files
committed
feat: add support to update implementations and keep manual additions
1 parent 09d66e1 commit 8f37303

File tree

1 file changed

+28
-6
lines changed

1 file changed

+28
-6
lines changed

scripts/populate-implementations.js

+28-6
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,21 @@
1-
const { writeFileSync } = require('fs')
1+
const { writeFileSync, existsSync, readFileSync } = require('fs')
2+
const { updateOrCreateSegment } = require('@ulisesgascon/text-tags-manager')
23
const path = require('path')
34

45
const checks = require('../data/checks.json')
6+
const listStartTag = '<!-- LIST:START -->'
7+
const listEndTag = '<!-- LIST:END -->'
58

69
const projectStatus = ['incubating', 'active', 'retiring']
710
const implementationPriority = ['expected', 'deferrable', 'recommended']
811
const data = {}
912
const files = {}
13+
// @TODO: Move this function to a shared file
1014
const capitalizeWords = str => str.split(' ').map(w => w[0].toUpperCase() + w.slice(1).toLowerCase()).join(' ')
15+
// @TODO: Move this function to a shared file
16+
const replaceMetadata = (fileContent, metadata) => {
17+
return fileContent.replace(/---[^]*?---/, metadata)
18+
}
1119

1220
// Basic structure of the data object
1321
projectStatus.forEach(status => {
@@ -52,17 +60,31 @@ slug: /implementations/${status}
5260
## ${priority.charAt(0).toUpperCase() + priority.slice(1)}
5361
${addHeader()}
5462
${data[status][priority].map(addRow).join('\n')}
55-
`
63+
`
5664
}).join('\n')
5765

58-
const fileContent = `${metadata}
59-
<!-- LIST:START -->
66+
let fileContent = `${metadata}
6067
61-
<!-- LIST:END -->
68+
${listStartTag}
6269
${listContent}
63-
<!-- LIST:END -->
70+
${listEndTag}
6471
`
72+
const updateContent = (currentContent) => {
73+
fileContent = currentContent
74+
replaceMetadata(fileContent, metadata)
75+
fileContent = updateOrCreateSegment({
76+
original: fileContent,
77+
replacementSegment: listContent,
78+
startTag: listStartTag,
79+
endTag: listEndTag
80+
})
81+
}
6582

6683
const destination = path.join(process.cwd(), `docs/implementation/${status}.mdx`)
84+
const fileExists = existsSync(destination)
85+
if (fileExists) {
86+
const currentFileContent = readFileSync(destination, 'utf8')
87+
updateContent(currentFileContent)
88+
}
6789
writeFileSync(destination, fileContent)
6890
})

0 commit comments

Comments
 (0)