task-181(静态资源部署与 Nginx History 托管): 确认后台 dist 发布目录约定
补充 deploy/release-structure.md 与 verify-dist.mjs,契约测试锁 conf。 TDD: task-181.test.ts 8 用例 RED→GREEN。
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
#!/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}`)
|
||||
Reference in New Issue
Block a user