Skip to content

Commit

Permalink
feat: add support to update implementations and keep manual additions
Browse files Browse the repository at this point in the history
  • Loading branch information
UlisesGascon committed Dec 8, 2024
1 parent 09d66e1 commit 8f37303
Showing 1 changed file with 28 additions and 6 deletions.
34 changes: 28 additions & 6 deletions scripts/populate-implementations.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
const { writeFileSync } = require('fs')
const { writeFileSync, existsSync, readFileSync } = require('fs')
const { updateOrCreateSegment } = require('@ulisesgascon/text-tags-manager')
const path = require('path')

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

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

// Basic structure of the data object
projectStatus.forEach(status => {
Expand Down Expand Up @@ -52,17 +60,31 @@ slug: /implementations/${status}
## ${priority.charAt(0).toUpperCase() + priority.slice(1)}
${addHeader()}
${data[status][priority].map(addRow).join('\n')}
`
`
}).join('\n')

const fileContent = `${metadata}
<!-- LIST:START -->
let fileContent = `${metadata}
<!-- LIST:END -->
${listStartTag}
${listContent}
<!-- LIST:END -->
${listEndTag}
`
const updateContent = (currentContent) => {
fileContent = currentContent
replaceMetadata(fileContent, metadata)
fileContent = updateOrCreateSegment({
original: fileContent,
replacementSegment: listContent,
startTag: listStartTag,
endTag: listEndTag
})
}

const destination = path.join(process.cwd(), `docs/implementation/${status}.mdx`)
const fileExists = existsSync(destination)
if (fileExists) {
const currentFileContent = readFileSync(destination, 'utf8')
updateContent(currentFileContent)
}
writeFileSync(destination, fileContent)
})

0 comments on commit 8f37303

Please sign in to comment.