| 197 | } |
| 198 | |
| 199 | export async function updateFunctionREADME(indexes: PackageIndexes) { |
| 200 | const hasTypes = existsSync(DIR_TYPES) |
| 201 | |
| 202 | if (!hasTypes) |
| 203 | console.warn('No types dist found, run `npm run build:types` first.') |
| 204 | |
| 205 | for (const fn of indexes.functions) { |
| 206 | const mdPath = `packages/${fn.package}/${fn.name}/index.md` |
| 207 | if (!existsSync(mdPath)) |
| 208 | continue |
| 209 | |
| 210 | let readme = await fs.readFile(mdPath, 'utf-8') |
| 211 | |
| 212 | const { content, data = {} } = matter(readme) |
| 213 | const yamlData = yaml.stringify(data, { |
| 214 | singleQuote: true, |
| 215 | }) |
| 216 | |
| 217 | data.category = fn.category || 'Unknown' |
| 218 | |
| 219 | readme = `---\n${yamlData}---\n\n${content.trim()}`.trim().replace(/\r\n/g, '\n') |
| 220 | |
| 221 | await fs.writeFile(mdPath, `${readme}\n`, 'utf-8') |
| 222 | } |
| 223 | } |
| 224 | |
| 225 | export async function updateCountBadge(indexes: PackageIndexes) { |
| 226 | const functionsCount = indexes.functions.filter(i => !i.internal).length |