a6cc190751
P1b Task 9: apps/admin based on art-design-pro v3.0.2 (tag, commit d224dd4; source recorded in apps/admin/SOURCE.md), trimmed to layout/login/i18n/request/table-form core. Login wired to real POST /v1/auth/password (single-token session), Bearer header on all requests, 401 interceptor logout+redirect, request-driven sliding renewal (refresh at ~80% TTL, single-flight), best-effort POST /v1/auth/logout on user-menu logout. One protected stub page (相册管理). Dev port 5176 strictPort + /v1 proxy to 8080. Admin keeps its own eslint9 flat config; root eslint ignores apps/admin/**. vitest unit tests for renewal pacing + Playwright e2e (guard redirect, localized wrong-password error, login lands on stub, token persists across reload, logout clears session). Co-Authored-By: Claude Code <noreply@anthropic.com>
25 lines
943 B
TypeScript
25 lines
943 B
TypeScript
// e2e 全局夹具:幂等种子管理员账号(复用 services/api 官方路径)。
|
||
// `pnpm --filter @photo/api-cn seed` 读仓库根 .env 的 ADMIN_ACCOUNT/ADMIN_PASSWORD;
|
||
// 账号已存在则跳过且绝不改写密码(seed-admin.ts 语义),重复跑 e2e 安全。
|
||
import { execSync } from 'node:child_process'
|
||
import { existsSync } from 'node:fs'
|
||
import { dirname, join } from 'node:path'
|
||
import { fileURLToPath } from 'node:url'
|
||
|
||
const repoRoot = fileURLToPath(new URL('../../..', import.meta.url))
|
||
const envFile = join(repoRoot, '.env')
|
||
|
||
export default function globalSetup(): void {
|
||
if (!existsSync(envFile)) {
|
||
throw new Error(
|
||
`[admin e2e] 仓库根 .env 不存在(${envFile}):请参考 .env.example 配置开发环境`
|
||
)
|
||
}
|
||
// shell:true 兼容 Windows(pnpm 是 .cmd)
|
||
execSync('pnpm --filter @photo/api-cn seed', {
|
||
cwd: dirname(envFile),
|
||
stdio: 'inherit',
|
||
shell: true
|
||
})
|
||
}
|