read readme changes

This commit is contained in:
2022-06-08 09:13:04 -05:00
parent ffe6969889
commit 69d8ee884e
3 changed files with 33 additions and 15 deletions

View File

@@ -46,16 +46,26 @@ function getReadmeFileName(): string | null {
function readReadmeFile(readmeFile: string): [string, string] {
let content = readFileSync(readmeFile).toString()
const regex =
/<!-- START INSTALL LINKS -->(?:.|\n)*?<!-- END INSTALL LINKS -->/
/\n{0,1}<!-- START INSTALL LINKS -->(?:.|\n)*?<!-- END INSTALL LINKS -->\n{0,1}/
const index = regex.exec(content)?.index
let contentPre = '',
contentPost = ''
if (index === undefined) {
if (!content.endsWith('\n')) {
content += '\n'
}
return [content, '']
contentPre = content
} else {
content = content.replace(regex, '')
contentPre = content.slice(0, index)
contentPost = content.slice(index)
}
content = content.replace(regex, '')
return [content.slice(0, index), content.slice(index)]
if (!contentPre.endsWith('\n')) {
contentPre += '\n'
}
if (!contentPost.endsWith('\n')) {
contentPost += '\n'
}
return [contentPre, contentPost]
}