mirror of
https://github.com/XiaoDaiGua-Ray/ray-template.git
synced 2026-11-17 16:13:36 +08:00
Add user CRUD, account-scoped navigation history and favorites. Unify HTTP mocks, backend contracts and route configuration. Reuse existing scrolling components and add Harness reuse guidance.
45 lines
1.2 KiB
JavaScript
45 lines
1.2 KiB
JavaScript
import { mkdirSync, readFileSync, writeFileSync } from 'node:fs'
|
|
import { getAdminOpenApi } from '../apps/admin/src/api/admin/openapi.ts'
|
|
|
|
const file = new URL(
|
|
'../apps/admin/public/contracts/admin-api.json',
|
|
import.meta.url,
|
|
)
|
|
const content = `${JSON.stringify(getAdminOpenApi(), null, 2)}\n`
|
|
const files = [
|
|
file,
|
|
new URL('../apps/docs/public/contracts/admin-api.json', import.meta.url),
|
|
]
|
|
|
|
if (process.argv.includes('--check')) {
|
|
const worker = new URL(
|
|
'../apps/admin/public/mockServiceWorker.js',
|
|
import.meta.url,
|
|
)
|
|
|
|
if (
|
|
readFileSync(worker, 'utf8') !==
|
|
readFileSync(
|
|
new URL(import.meta.resolve('msw/mockServiceWorker.js')),
|
|
'utf8',
|
|
)
|
|
) {
|
|
throw new Error(
|
|
'Mock worker is stale. Run pnpm exec msw init apps/admin/public --save.',
|
|
)
|
|
}
|
|
|
|
if (files.some((target) => readFileSync(target, 'utf8') !== content)) {
|
|
throw new Error('Admin API contract is stale. Run pnpm api:generate.')
|
|
}
|
|
|
|
console.log('Admin API contract matches the runtime schemas.')
|
|
} else {
|
|
for (const target of files) {
|
|
mkdirSync(new URL('.', target), { recursive: true })
|
|
writeFileSync(target, content)
|
|
}
|
|
|
|
console.log('Generated Admin API contracts for the app and docs.')
|
|
}
|