Files
crawler-plugin/admin-frontend-vue/deploy/verify-dist.mjs
T
huangzd1997 a36a60f151 task-181(静态资源部署与 Nginx History 托管): 确认后台 dist 发布目录约定
补充 deploy/release-structure.md 与 verify-dist.mjs,契约测试锁 conf。

TDD: task-181.test.ts 8 用例 RED→GREEN。
2026-09-05 18:09:04 +08:00

28 lines
1.0 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/usr/bin/env node
// Admin Vue 构建产物清单校验(module 10):base=/admin-vue/ 且 index.html 引用的资源均存在。
import { existsSync, readdirSync, readFileSync } from 'node:fs'
import { join, resolve } from 'node:path'
const root = resolve(process.cwd())
const dist = join(root, 'dist')
const index = join(dist, 'index.html')
function fail(message) {
console.error(`[verify-dist] ${message}`)
process.exit(1)
}
if (!existsSync(index)) fail('缺少 dist/index.html(请先 npm run build')
const html = readFileSync(index, 'utf8')
if (!html.includes('/admin-vue/')) fail('index.html 资源引用未包含 base=/admin-vue/')
const assetsDir = join(dist, 'assets')
const assets = existsSync(assetsDir) ? readdirSync(assetsDir) : []
const refs = [...html.matchAll(/(?:src|href)="\/admin-vue\/assets\/([^"]+)"/g)].map((m) => m[1])
for (const ref of refs) {
if (!assets.includes(ref)) fail(`index.html 引用的资源缺失: assets/${ref}`)
}
console.log(`[verify-dist] ok: base=/admin-vue/, assets=${assets.length}, refs=${refs.length}`)