mirror of
https://github.com/cocos/cocos4.git
synced 2026-12-02 00:22:43 +08:00
1c737b91fd
* publish build-engine 4.3.5 * update build-engine deps * remove default-constants.ts ds remove de * delete consts.d.ts * support build-const workflow * remove EXPORT_TO_GLOBAL * update comment * fix interface-check * update comment
57 lines
1.9 KiB
TypeScript
57 lines
1.9 KiB
TypeScript
|
|
export type IBuildTimeConstantValue = string | number | boolean;
|
|
|
|
/**
|
|
* @deprecated since 4.3.5, use `BuildTimeConstants` instead.
|
|
*/
|
|
export type IBuildTimeConstants = Record<string, IBuildTimeConstantValue>;
|
|
|
|
/**
|
|
* @deprecated since v4.3.0, use `StatsQuery.prototype.constantManager` instead.
|
|
*/
|
|
export function setupBuildTimeConstants ({
|
|
mode,
|
|
platform,
|
|
flags,
|
|
}: {
|
|
mode?: string;
|
|
platform: string;
|
|
flags: Record<string, IBuildTimeConstantValue>;
|
|
}) {
|
|
const buildModeConstantNames = getBuildModeConstantNames();
|
|
const platformConstantNames = getPlatformConstantNames();
|
|
|
|
const result: Record<string, string | number | boolean> = {};
|
|
platformConstantNames.forEach(name => result[name] = false);
|
|
buildModeConstantNames.forEach(name => result[name] = false);
|
|
|
|
if (mode) {
|
|
if (!buildModeConstantNames.includes(mode)) {
|
|
console.warn(`Unknown build mode constant: ${mode}`);
|
|
}
|
|
result[mode] = true;
|
|
}
|
|
|
|
if (!platformConstantNames.includes(platform)) {
|
|
console.warn(`Unknown platform constant: ${platform}`);
|
|
}
|
|
result[platform] = true;
|
|
|
|
Object.assign(result, flags);
|
|
|
|
result.DEV = result.EDITOR || result.PREVIEW || result.TEST;
|
|
result.DEBUG = result.DEBUG || result.DEV;
|
|
result.RUNTIME_BASED = result.OPPO || result.VIVO || result.HUAWEI || result.COCOSPLAY || result.LINKSURE || result.QTT;
|
|
result.MINIGAME = result.WECHAT || result.ALIPAY || result.XIAOMI || result.BYTEDANCE || result.BAIDU;
|
|
result.JSB = result.NATIVE;
|
|
result.SUPPORT_JIT = !(result.MINIGAME || result.RUNTIME_BASED);
|
|
return result;
|
|
}
|
|
|
|
export function getPlatformConstantNames () {
|
|
return ['HTML5', 'WECHAT', 'ALIPAY', 'BAIDU', 'XIAOMI', 'BYTEDANCE', 'OPPO', 'VIVO', 'HUAWEI', 'NATIVE', 'COCOSPLAY', 'LINKSURE', 'QTT'];
|
|
}
|
|
|
|
export function getBuildModeConstantNames () {
|
|
return ['EDITOR', 'PREVIEW', 'BUILD', 'TEST'];
|
|
} |