2026-03-09 21:29:03 +08:00
|
|
|
|
const appJson = require('./app.json');
|
2026-04-23 22:29:58 +08:00
|
|
|
|
const { execSync } = require('child_process');
|
2026-03-09 21:29:03 +08:00
|
|
|
|
|
|
|
|
|
|
const isDevVariant = process.env.APP_VARIANT === 'dev';
|
2026-04-22 16:54:51 +08:00
|
|
|
|
const releaseApiBaseUrl = 'https://withyou.littlelan.cn/api/v1';
|
2026-03-09 21:29:03 +08:00
|
|
|
|
const releaseUpdatesBaseUrl = 'https://updates.littlelan.cn';
|
|
|
|
|
|
const devApiBaseUrl = process.env.EXPO_PUBLIC_API_BASE_URL || 'http://192.168.31.238:8080/api/v1';
|
|
|
|
|
|
|
2026-06-18 00:03:37 +08:00
|
|
|
|
function getCommitCount() {
|
2026-04-23 22:29:58 +08:00
|
|
|
|
try {
|
2026-06-18 00:03:37 +08:00
|
|
|
|
return execSync('git rev-list --count HEAD', { encoding: 'utf-8' }).trim();
|
2026-04-23 22:29:58 +08:00
|
|
|
|
} catch {
|
2026-06-18 00:03:37 +08:00
|
|
|
|
return '1';
|
2026-04-23 22:29:58 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-06-18 00:03:37 +08:00
|
|
|
|
// 在 commit count 上加偏移,保证 versionCode / buildNumber / runtimeVersion
|
|
|
|
|
|
// 始终大于历史最大值(之前的最后一个版本是 5547),避免被系统/Play Store
|
|
|
|
|
|
// 误判为降级。后续即使 commit count 重置或换仓库,偏移也能保证单调递增。
|
2026-06-18 02:29:54 +08:00
|
|
|
|
const BUILD_NUMBER_OFFSET = 100000;
|
2026-06-18 00:03:37 +08:00
|
|
|
|
|
|
|
|
|
|
const commitCount = getCommitCount();
|
|
|
|
|
|
const buildNumber = String(parseInt(commitCount, 10) + BUILD_NUMBER_OFFSET);
|
2026-04-23 22:29:58 +08:00
|
|
|
|
|
2026-03-09 21:29:03 +08:00
|
|
|
|
function toManifestUrl(baseUrl, portOverride) {
|
|
|
|
|
|
const parsed = new URL(baseUrl);
|
|
|
|
|
|
if (portOverride != null) {
|
|
|
|
|
|
parsed.port = String(portOverride);
|
|
|
|
|
|
}
|
|
|
|
|
|
parsed.pathname = '/api/manifest';
|
|
|
|
|
|
parsed.search = '';
|
|
|
|
|
|
parsed.hash = '';
|
|
|
|
|
|
return parsed.toString();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const releaseUpdatesUrl =
|
|
|
|
|
|
process.env.EXPO_PUBLIC_UPDATES_URL || toManifestUrl(releaseUpdatesBaseUrl);
|
|
|
|
|
|
const devUpdatesUrl =
|
|
|
|
|
|
process.env.EXPO_PUBLIC_DEV_UPDATES_URL || toManifestUrl(devApiBaseUrl, 3001);
|
|
|
|
|
|
|
|
|
|
|
|
const expo = appJson.expo;
|
|
|
|
|
|
|
2026-03-29 02:34:13 +08:00
|
|
|
|
// 检测是否为 Web 平台
|
|
|
|
|
|
const isWeb = process.env.EXPO_TARGET === 'web' || process.env.PLATFORM === 'web';
|
|
|
|
|
|
|
|
|
|
|
|
// 原生平台特有的插件(在 Web 端会报错)
|
|
|
|
|
|
const nativeOnlyPlugins = [
|
|
|
|
|
|
'expo-camera',
|
|
|
|
|
|
'expo-notifications',
|
|
|
|
|
|
'expo-background-fetch',
|
|
|
|
|
|
'expo-media-library',
|
|
|
|
|
|
'expo-image-picker',
|
|
|
|
|
|
'expo-video',
|
|
|
|
|
|
'expo-sqlite',
|
|
|
|
|
|
'./plugins/withMainActivityConfigChange',
|
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
|
|
// 过滤插件:Web 端排除原生插件
|
|
|
|
|
|
const filteredPlugins = isWeb
|
|
|
|
|
|
? expo.plugins.filter((plugin) => {
|
|
|
|
|
|
const pluginName = Array.isArray(plugin) ? plugin[0] : plugin;
|
|
|
|
|
|
return !nativeOnlyPlugins.includes(pluginName);
|
|
|
|
|
|
})
|
|
|
|
|
|
: expo.plugins;
|
|
|
|
|
|
|
2026-03-09 21:29:03 +08:00
|
|
|
|
module.exports = {
|
|
|
|
|
|
...expo,
|
|
|
|
|
|
name: isDevVariant ? `${expo.name} Dev` : expo.name,
|
2026-06-18 00:03:37 +08:00
|
|
|
|
// runtimeVersion 用 build number(commit count + 偏移):单调递增、纯数字、与 version (语义版本) 解耦
|
|
|
|
|
|
// 字符串形式,等价于 policy: 'custom'
|
|
|
|
|
|
runtimeVersion: buildNumber,
|
2026-03-09 21:29:03 +08:00
|
|
|
|
updates: {
|
|
|
|
|
|
...(expo.updates || {}),
|
|
|
|
|
|
url: isDevVariant ? devUpdatesUrl : releaseUpdatesUrl,
|
|
|
|
|
|
checkAutomatically: 'ON_LOAD',
|
|
|
|
|
|
fallbackToCacheTimeout: 0,
|
|
|
|
|
|
},
|
2026-04-23 22:29:58 +08:00
|
|
|
|
ios: {
|
|
|
|
|
|
...expo.ios,
|
2026-06-18 00:03:37 +08:00
|
|
|
|
buildNumber: buildNumber,
|
2026-04-23 22:29:58 +08:00
|
|
|
|
},
|
2026-03-09 21:29:03 +08:00
|
|
|
|
android: {
|
|
|
|
|
|
...expo.android,
|
2026-04-23 22:29:58 +08:00
|
|
|
|
package: 'cn.qczlit.withyou',
|
2026-06-18 00:03:37 +08:00
|
|
|
|
versionCode: parseInt(buildNumber, 10),
|
2026-03-09 21:29:03 +08:00
|
|
|
|
},
|
2026-03-29 02:34:13 +08:00
|
|
|
|
// Web 端使用过滤后的插件
|
|
|
|
|
|
plugins: filteredPlugins,
|
2026-03-09 21:29:03 +08:00
|
|
|
|
extra: {
|
|
|
|
|
|
...(expo.extra || {}),
|
|
|
|
|
|
appVariant: isDevVariant ? 'dev' : 'release',
|
|
|
|
|
|
apiBaseUrl: isDevVariant ? devApiBaseUrl : releaseApiBaseUrl,
|
|
|
|
|
|
updatesUrl: isDevVariant ? devUpdatesUrl : releaseUpdatesUrl,
|
|
|
|
|
|
},
|
2026-03-29 02:34:13 +08:00
|
|
|
|
// Web 端配置
|
|
|
|
|
|
...(isWeb && {
|
|
|
|
|
|
web: {
|
|
|
|
|
|
...expo.web,
|
|
|
|
|
|
build: {
|
|
|
|
|
|
...expo.web?.build,
|
|
|
|
|
|
// 配置 Web 端别名,避免加载原生模块
|
|
|
|
|
|
babel: {
|
|
|
|
|
|
dangerouslyAddModulePathsToTranspile: [
|
2026-06-01 13:45:45 +08:00
|
|
|
|
'livekit-client',
|
|
|
|
|
|
'@livekit',
|
2026-03-29 02:34:13 +08:00
|
|
|
|
],
|
|
|
|
|
|
},
|
|
|
|
|
|
},
|
|
|
|
|
|
},
|
|
|
|
|
|
}),
|
2026-03-09 21:29:03 +08:00
|
|
|
|
};
|