Files
longbridge__developers/scripts/normalize_md.ts
twosugar 8005765472 feat(migrate): build scripts + prebuild integrations for astro
- scripts/copy-routes.ts: rewritten to walk dist/**/*.index.html and
  copy each to the sibling flat path (foo/index.html → foo.html) for
  Nginx fallback contract §10; uses glob + fs-extra, no vitepress paths

- scripts/normalize_md.ts: rewritten as post-build dist cleanup; walks
  dist/**/*.md, trims trailing whitespace per line, ensures single
  trailing newline; resolves 5 pre-existing astro check errors caused by
  legacy imports from docs/.vitepress/... paths

- scripts/generate-llms.ts: rewritten as no-op; llms.txt / llms-full.txt
  are emitted at build time by T14 Astro endpoint pages

- src/integrations/prebuild-mcp-tools.ts: new integration; astro:build:start
  hook fetches https://mcp.longbridge.com/mcp/tools.json → .data/mcp-tools.json;
  stale-cache fallback on network error

- src/integrations/prebuild-skills.ts: new integration; astro:build:done
  hook clones github.com/longbridge/skills → .data/skills and zips to
  dist/skill/skills.zip; skips gracefully if git/zip not available

- astro.config.ts: import + wire prebuildMcpTools() and prebuildSkills()
  after regionHostnameRewrite() in integrations array

- .gitignore: add .data/ entry (7th file touched, necessary for the
  prebuild data cache directory)

astro check: 0 errors (5 pre-existing scripts/ errors resolved)

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-08-17 19:27:52 +08:00

42 lines
1.1 KiB
TypeScript

/**
* Post-build script: walks dist/**\/*.md files emitted by Astro endpoint
* pages (T14 llm-markdown endpoints) and normalises them:
* - trims trailing whitespace from each line
* - ensures a single trailing newline at end of file
*
* Source docs/.md files are NOT touched — only dist/ artifacts.
*/
import fs from 'fs'
import path from 'path'
import { globSync } from 'glob'
const distDir = path.resolve('dist')
if (!fs.existsSync(distDir)) {
console.warn('[normalize_md] dist/ not found — run astro build first')
process.exit(0)
}
const mdFiles = globSync('**/*.md', { cwd: distDir, absolute: true })
let processed = 0
for (const file of mdFiles) {
const raw = fs.readFileSync(file, 'utf-8')
const normalised =
raw
.split('\n')
.map((line) => line.trimEnd())
.join('\n')
.replace(/\n*$/, '\n') // single trailing newline
if (normalised !== raw) {
fs.writeFileSync(file, normalised, 'utf-8')
console.log(`[normalize_md] normalised: ${path.relative(distDir, file)}`)
processed++
}
}
console.log(`[normalize_md] done — ${processed} file(s) updated, ${mdFiles.length - processed} already clean`)