26 lines
1.8 KiB
JavaScript
26 lines
1.8 KiB
JavaScript
// Uses the installed WeChat compiler binaries only. No DevTools UI, server,
|
|
// account, network, upload, media playback or files outside the build are used.
|
|
const fs = require('node:fs')
|
|
const path = require('node:path')
|
|
const { spawnSync } = require('node:child_process')
|
|
const root = path.resolve(__dirname, '../dist/build/mp-weixin')
|
|
const bin = process.env.TANG_WECHAT_COMPILER_DIR || '/Applications/wechatwebdevtools.app/Contents/Resources/app.asar.unpacked/node_modules/wcc-exec'
|
|
const app = JSON.parse(fs.readFileSync(path.join(root, 'app.json'), 'utf8'))
|
|
const pages = [...app.pages, ...(app.subPackages || []).flatMap(pkg => pkg.pages.map(page => `${pkg.root}/${page}`))]
|
|
.filter(page => page.startsWith('tang-detective/'))
|
|
if (pages.length !== 24) throw new Error(`Expected 24 native pages, found ${pages.length}`)
|
|
const results = []
|
|
for (const [tool, args] of [
|
|
['wcc', pages.map(page => './' + page + '.wxml')],
|
|
['wcsc', ['-pc', String(pages.length), ...pages.map(page => './' + page + '.wxss'), './tang-detective/shared.wxss']],
|
|
]) {
|
|
if (!fs.existsSync(path.join(bin, tool))) throw new Error(`${tool} not available; set TANG_WECHAT_COMPILER_DIR`)
|
|
const run = spawnSync(path.join(bin, tool), args, { cwd: root, encoding: 'utf8', timeout: 30000, maxBuffer: 64 * 1024 * 1024 })
|
|
results.push({ tool, exitCode: run.status, passed: run.status === 0 && !run.error,
|
|
generatedOutputBytes: Buffer.byteLength(run.stdout || ''),
|
|
diagnostics: (run.stderr || '').slice(0, 3000), error: run.error ? run.error.message : null })
|
|
}
|
|
console.log(JSON.stringify({ nativePages: pages.length, results,
|
|
boundary: 'Installed compiler syntax check only, not simulator/device, networking or upload acceptance.' }, null, 2))
|
|
if (results.some(result => !result.passed)) process.exitCode = 1
|