统一三端桥接层结构
Tauri入口main.rs收敛为应用装配 桌面HostBridge按协议分发文件分享WebView和托盘职责拆分模块 微信小程序桥接逻辑迁入host-bridge目录并保留页面装配 原生壳检查锁定微信移动桌面桥接层文件结构 宿主壳文档和共享决策记录三端桥接层结构约定
This commit is contained in:
@@ -7,6 +7,36 @@ import path from 'node:path';
|
||||
const npmCommand = process.platform === 'win32' ? 'npm.cmd' : 'npm';
|
||||
|
||||
const productionShellRoots = ['apps/mobile-shell', 'apps/desktop-shell'];
|
||||
const expectedWechatHostBridgeFiles = [
|
||||
'wechatHostBridgePayment.js',
|
||||
'wechatHostBridgePayment.test.js',
|
||||
'wechatHostBridgeShareGrid.js',
|
||||
'wechatHostBridgeShareGrid.test.js',
|
||||
'wechatHostBridgeSubscribeMessage.js',
|
||||
'wechatHostBridgeSubscribeMessage.test.js',
|
||||
'wechatHostBridgeWebView.js',
|
||||
'wechatHostBridgeWebView.test.js',
|
||||
];
|
||||
const expectedMobileShellFiles = [
|
||||
'mobileHostBridge.ts',
|
||||
'mobileShellDeepLink.ts',
|
||||
'mobileShellLifecycle.ts',
|
||||
'mobileShellNavigation.ts',
|
||||
'mobileShellNetwork.ts',
|
||||
'mobileShellRuntime.ts',
|
||||
'mobileShellSafeArea.ts',
|
||||
'mobileShellUrl.ts',
|
||||
'mobileShellWebViewPolicy.ts',
|
||||
];
|
||||
const expectedDesktopShellRustFiles = [
|
||||
'desktop_host_bridge.rs',
|
||||
'desktop_host_bridge_files.rs',
|
||||
'desktop_host_bridge_protocol.rs',
|
||||
'desktop_host_bridge_share.rs',
|
||||
'desktop_shell_tray.rs',
|
||||
'desktop_shell_webview.rs',
|
||||
'main.rs',
|
||||
];
|
||||
const productionShellExtensions = new Set([
|
||||
'.json',
|
||||
'.mjs',
|
||||
@@ -145,6 +175,65 @@ function assertNoProductionShellDevScaffoldTerms() {
|
||||
}
|
||||
}
|
||||
|
||||
function assertSameList(actual, expected, label) {
|
||||
if (
|
||||
actual.length !== expected.length ||
|
||||
actual.some((value, index) => value !== expected[index])
|
||||
) {
|
||||
throw new Error(
|
||||
`${label} drifted: expected ${expected.join(', ')} but got ${actual.join(', ')}`,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
function assertHostBridgeLayerLayout() {
|
||||
const wechatBridgeFiles = fs
|
||||
.readdirSync('miniprogram/host-bridge', { withFileTypes: true })
|
||||
.filter((entry) => entry.isFile())
|
||||
.map((entry) => entry.name)
|
||||
.sort();
|
||||
assertSameList(
|
||||
wechatBridgeFiles,
|
||||
expectedWechatHostBridgeFiles,
|
||||
'wechat host bridge files',
|
||||
);
|
||||
|
||||
for (const pagePath of [
|
||||
'miniprogram/pages/web-view/index.js',
|
||||
'miniprogram/pages/wechat-pay/index.js',
|
||||
'miniprogram/pages/share-grid/index.js',
|
||||
'miniprogram/pages/subscribe-message/index.js',
|
||||
]) {
|
||||
const source = fs.readFileSync(pagePath, 'utf8');
|
||||
if (source.includes("require('./index.shared')")) {
|
||||
throw new Error(`${pagePath} must import from miniprogram/host-bridge`);
|
||||
}
|
||||
}
|
||||
|
||||
const mobileShellFiles = fs
|
||||
.readdirSync('apps/mobile-shell/src', { withFileTypes: true })
|
||||
.filter((entry) => entry.isFile() && !entry.name.endsWith('.test.ts'))
|
||||
.map((entry) => entry.name)
|
||||
.filter((name) => name.startsWith('mobileHostBridge') || name.startsWith('mobileShell'))
|
||||
.sort();
|
||||
assertSameList(
|
||||
mobileShellFiles,
|
||||
expectedMobileShellFiles,
|
||||
'mobile shell bridge files',
|
||||
);
|
||||
|
||||
const desktopShellRustFiles = fs
|
||||
.readdirSync('apps/desktop-shell/src-tauri/src', { withFileTypes: true })
|
||||
.filter((entry) => entry.isFile() && entry.name.endsWith('.rs'))
|
||||
.map((entry) => entry.name)
|
||||
.sort();
|
||||
assertSameList(
|
||||
desktopShellRustFiles,
|
||||
expectedDesktopShellRustFiles,
|
||||
'desktop shell Rust bridge files',
|
||||
);
|
||||
}
|
||||
|
||||
for (const step of steps) {
|
||||
console.log(`[check:native-shells] ${step.label}`);
|
||||
const result = spawnSync(step.command, step.args, {
|
||||
@@ -171,6 +260,9 @@ for (const step of steps) {
|
||||
}
|
||||
}
|
||||
|
||||
console.log('[check:native-shells] host-bridge-layer-layout');
|
||||
assertHostBridgeLayerLayout();
|
||||
|
||||
console.log('[check:native-shells] production-shell-dev-scaffold-scan');
|
||||
assertNoProductionShellDevScaffoldTerms();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user