forked from wangziqi/gongxue-base
fix: align Taro H5 with legacy question bank UI
This commit is contained in:
@@ -7,6 +7,7 @@ const taroSrc = path.join(repoRoot, 'apps', 'taro', 'src');
|
||||
const pagesRoot = path.join(taroSrc, 'pages');
|
||||
const appConfigPath = path.join(taroSrc, 'app.config.ts');
|
||||
const bootstrapPath = path.join(pagesRoot, 'bootstrap', 'index.tsx');
|
||||
const routeGuardPath = path.join(taroSrc, 'services', 'routeGuard.ts');
|
||||
const h5StaticSmokePath = path.join(repoRoot, 'scripts', 'taro-h5-static-smoke.js');
|
||||
const frontendHandoffPath = path.join(repoRoot, 'docs', 'refactor', 'frontend-handoff-index.md');
|
||||
|
||||
@@ -34,13 +35,23 @@ function walkIndexPages(dir) {
|
||||
|
||||
function parseAppRoutes() {
|
||||
const text = readText(appConfigPath);
|
||||
const match = text.match(/pages\s*:\s*\[([\s\S]*?)\]/m);
|
||||
assert.ok(match, 'apps/taro/src/app.config.ts must define pages: [...]');
|
||||
const match = text.match(/const\s+allPageRoutes\s*=\s*\[([\s\S]*?)\]/m);
|
||||
assert.ok(match, 'apps/taro/src/app.config.ts must define const allPageRoutes = [...]');
|
||||
return [...match[1].matchAll(/['"`]([^'"`]+)['"`]/g)]
|
||||
.map(item => item[1].trim())
|
||||
.filter(route => route.startsWith('pages/'));
|
||||
}
|
||||
|
||||
function parsePortalLandingRoutes() {
|
||||
const text = readText(appConfigPath);
|
||||
const match = text.match(/const\s+portalLandingRoutes\s*:\s*Record<string,\s*string>\s*=\s*\{([\s\S]*?)\}/m);
|
||||
assert.ok(match, 'apps/taro/src/app.config.ts must define portalLandingRoutes');
|
||||
return Object.fromEntries(
|
||||
[...match[1].matchAll(/['"`]?([\w-]+)['"`]?\s*:\s*['"`]([^'"`]+)['"`]/g)]
|
||||
.map(item => [item[1], item[2]]),
|
||||
);
|
||||
}
|
||||
|
||||
function routeFromIndexFile(filePath) {
|
||||
return normalizeSlashes(path.relative(taroSrc, filePath)).replace(/\/index\.tsx$/, '/index');
|
||||
}
|
||||
@@ -59,9 +70,9 @@ const appRoutes = parseAppRoutes();
|
||||
const appRouteSet = new Set(appRoutes);
|
||||
const actualRoutes = walkIndexPages(pagesRoot).map(routeFromIndexFile);
|
||||
const actualRouteSet = new Set(actualRoutes);
|
||||
const portalLandingRouteMap = parsePortalLandingRoutes();
|
||||
|
||||
assert.equal(appRoutes.length, appRouteSet.size, 'app.config.ts must not contain duplicate page routes');
|
||||
assert.equal(appRoutes[0], 'pages/bootstrap/index', 'The first Taro page must be the bootstrap page for tenant/runtime config resolution');
|
||||
|
||||
const missingFiles = appRoutes.filter(route => !actualRouteSet.has(route));
|
||||
const unregisteredPages = actualRoutes.filter(route => !appRouteSet.has(route));
|
||||
@@ -73,22 +84,37 @@ const expectedPortalLandingRoutes = [
|
||||
'pages/student/home/index',
|
||||
'pages/tenant-admin/workbench/index',
|
||||
];
|
||||
const bootstrapPageRoutes = parseLiteralPagePaths(readText(bootstrapPath));
|
||||
const bootstrapLandingRoutes = bootstrapPageRoutes.filter(route => route !== 'pages/bootstrap/index');
|
||||
assert.deepEqual(
|
||||
uniqueSorted(bootstrapLandingRoutes),
|
||||
uniqueSorted(Object.values(portalLandingRouteMap)),
|
||||
expectedPortalLandingRoutes,
|
||||
'Bootstrap landing routes must stay explicit for the three H5 portals',
|
||||
'Portal-specific H5 builds must put each portal landing route first',
|
||||
);
|
||||
for (const route of bootstrapPageRoutes) {
|
||||
assert.ok(appRouteSet.has(route), `Bootstrap route is not registered in app.config.ts: ${route}`);
|
||||
for (const route of Object.values(portalLandingRouteMap)) {
|
||||
assert.ok(appRouteSet.has(route), `Portal landing route is not registered in app.config.ts: ${route}`);
|
||||
}
|
||||
|
||||
const bootstrapPageRoutes = parseLiteralPagePaths(readText(bootstrapPath));
|
||||
const routeGuardPageRoutes = parseLiteralPagePaths(readText(routeGuardPath));
|
||||
const publicRoutes = new Set([
|
||||
'pages/bootstrap/index',
|
||||
'pages/student/login/index',
|
||||
'pages/student/region/index',
|
||||
]);
|
||||
const routeGuardLandingRoutes = routeGuardPageRoutes.filter(route => !publicRoutes.has(route));
|
||||
assert.deepEqual(
|
||||
uniqueSorted(routeGuardLandingRoutes),
|
||||
expectedPortalLandingRoutes,
|
||||
'Route guard landing routes must stay explicit for the three H5 portals',
|
||||
);
|
||||
for (const route of [...bootstrapPageRoutes, ...routeGuardPageRoutes]) {
|
||||
assert.ok(appRouteSet.has(route), `Referenced route is not registered in app.config.ts: ${route}`);
|
||||
}
|
||||
|
||||
const staticSmokeLandingRoutes = parseLiteralPagePaths(readText(h5StaticSmokePath));
|
||||
assert.deepEqual(
|
||||
uniqueSorted(staticSmokeLandingRoutes),
|
||||
uniqueSorted(bootstrapLandingRoutes),
|
||||
'H5 static smoke landing routes must match bootstrap landing routes',
|
||||
uniqueSorted(routeGuardLandingRoutes),
|
||||
'H5 static smoke landing routes must match route guard landing routes',
|
||||
);
|
||||
for (const route of staticSmokeLandingRoutes) {
|
||||
assert.ok(appRouteSet.has(route), `H5 static smoke landing route is not registered in app.config.ts: ${route}`);
|
||||
|
||||
Reference in New Issue
Block a user