38 lines
2.9 KiB
JavaScript
38 lines
2.9 KiB
JavaScript
import fs from 'node:fs'
|
|
import path from 'node:path'
|
|
import vm from 'node:vm'
|
|
import assert from 'node:assert/strict'
|
|
import { fileURLToPath } from 'node:url'
|
|
|
|
const projectRoot = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..')
|
|
const output = path.resolve(projectRoot, process.argv[2] || 'dist/build/mp-weixin')
|
|
const config = JSON.parse(fs.readFileSync(path.join(output, 'app.json'), 'utf8'))
|
|
const sourcePages = JSON.parse(fs.readFileSync(path.join(projectRoot, 'pages.json'), 'utf8'))
|
|
const allPages = new Set([...config.pages, ...(config.subPackages || config.subpackages || []).flatMap(pkg => pkg.pages.map(page => `${pkg.root}/${page}`))])
|
|
assert.equal(config.pages[0], 'tongji/pages/weekly', 'The standalone Tongji home must remain the startup page')
|
|
for (const page of sourcePages.pages) assert(allPages.has(page.path), `Missing existing host route: ${page.path}`)
|
|
for (const pkg of sourcePages.subPackages || []) {
|
|
for (const page of pkg.pages) assert(allPages.has(`${pkg.root}/${page.path}`), `Missing host subpackage route: ${pkg.root}/${page.path}`)
|
|
}
|
|
assert(allPages.has('tongji/tang-detective/index'))
|
|
assert(allPages.has('tang-detective/pages/home/home'))
|
|
assert(allPages.has('tongji/endless-game/index'))
|
|
const apiText = fs.readFileSync(path.join(projectRoot, 'config/api.js'), 'utf8')
|
|
const sourceApi = apiText.match(/export\s+const\s+API_BASE_URL\s*=\s*['"]([^'"]+)['"]/)
|
|
assert(sourceApi, 'Public API config must export API_BASE_URL')
|
|
const platform = { module: { exports: {} } }
|
|
vm.runInNewContext(fs.readFileSync(path.join(output, 'tang-detective/utils/platformConfig.js'), 'utf8'), platform, { timeout: 1000 })
|
|
assert.deepEqual(Object.keys(platform.module.exports), ['apiBaseUrl'], 'Only the public API base belongs in native platformConfig')
|
|
assert.equal(platform.module.exports.apiBaseUrl, sourceApi[1], 'Native progress calls must use this host API, not the previous project API')
|
|
const weekly = fs.readFileSync(path.join(output, 'tongji/pages/weekly.wxml'), 'utf8')
|
|
assert(weekly.includes('唐侦探'), 'The standalone weekly page must contain the game entry')
|
|
assert(weekly.includes('识糖小课堂'), 'Existing match-three entry must remain visible')
|
|
assert(!fs.existsSync(path.join(output, 'TUICallKit')), 'Do not import the unrelated call SDK into TongjiUniApp')
|
|
const home = fs.readFileSync(path.join(output, 'tang-detective/pages/home/home.js'), 'utf8')
|
|
assert(home.includes("wx.reLaunch({ url: '/tongji/pages/weekly' })"), 'Return must target the standalone host home')
|
|
console.log(JSON.stringify({ passed: true, project: 'TongjiUniApp', startupPage: config.pages[0],
|
|
sourceHostRoutes: sourcePages.pages.length + (sourcePages.subPackages || []).reduce((sum, pkg) => sum + pkg.pages.length, 0),
|
|
nativePages: [...allPages].filter(page => page.startsWith('tang-detective/')).length,
|
|
apiBaseUrl: sourceApi[1], unrelatedCallSdkImported: false,
|
|
boundary: 'Built output routing/configuration checks only; not a live backend or device test.' }, null, 2))
|