readme file now shows the script's url matches

This commit is contained in:
zomo
2025-12-10 13:36:15 -06:00
parent ad5f5a3c15
commit 11cea55569
5 changed files with 54 additions and 6 deletions

View File

@@ -1,5 +1,6 @@
import { readdirSync, readFileSync, writeFileSync } from 'fs'
import { runBuildResult } from './build'
import { UserScriptMetaFull, UserScriptMetaMultiple } from './types'
export function updateReadmeFile(fileList: runBuildResult[]) {
let readmeFile = getReadmeFileName()
@@ -28,13 +29,40 @@ function readmeDataErrorString(error: string | null): string {
return `\n\n${error}`
}
function arrayify(val: UserScriptMetaMultiple): string[] {
let newval = Array.isArray(val) ? val : [val]
return newval.map(v => v.trim()).filter(v => v)
}
function readmeDataMatches(meta: UserScriptMetaFull): string {
const matches = arrayify(meta.match).map(v => '`' + v + '`')
const matchesStr = `
- ${matches.join(',')}`
if (matches.length === 0) {
return ''
}
const excludes = arrayify(meta.excludematch).map(v => '`' + v + '`')
const excludesStr = `
- excluding: ${excludes.join(',')}`
if (excludes.length === 0) {
return matchesStr
}
return matchesStr + excludesStr
}
function readmeDataToString(results: runBuildResult): string {
let { meta, error } = results
let errStr = error !== null ? '~~' : ''
let errMsg = readmeDataErrorString(error)
const matchesStr = readmeDataMatches(meta)
return `
- ${errStr}[${meta.name}](${meta.downloadURL})${errStr}${errMsg}
- ${meta.namespace} ${meta.version}
- **${meta.namespace}** v${meta.version}${matchesStr}
- ${meta.description}
`.trim()
}