Skip to content

Commit 49a3681

Browse files
authored
chore(web): change apple-app-site-association by region (#2050)
1 parent 1ade003 commit 49a3681

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import type { Plugin, ResolvedConfig } from "vite";
2+
import { existsSync, promises } from "fs";
3+
import { resolve } from "path";
4+
5+
export function appleAppSiteAssociation(): Plugin {
6+
const AppleAppID = {
7+
CN: "48TB6ZZL5S.io.agora.flat",
8+
SG: "48TB6ZZL5S.io.agora.flint",
9+
};
10+
11+
const { readFile, writeFile } = promises;
12+
13+
let config: ResolvedConfig;
14+
15+
return {
16+
name: "flat:apple-app-site-association",
17+
apply: "build",
18+
configResolved(config_) {
19+
config = config_;
20+
},
21+
async closeBundle() {
22+
const region = (process.env.FLAT_REGION as "CN" | "SG") || "CN";
23+
const file = resolve(config.build.outDir, "apple-app-site-association.json");
24+
25+
if (!existsSync(file)) {
26+
console.warn("Not found apple-app-site-association.json.");
27+
return;
28+
}
29+
30+
const content = await readFile(file, "utf8");
31+
const json = JSON.parse(content) as { applinks: { details: { appID: string }[] } };
32+
33+
json.applinks.details.forEach(detail => {
34+
detail.appID = AppleAppID[region];
35+
console.log("Updated apple-app-site-association.json:", detail.appID);
36+
});
37+
38+
await writeFile(file, JSON.stringify(json, null, 2), "utf8");
39+
},
40+
};
41+
}

web/flat-web/vite.config.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { inlineAssets } from "./scripts/vite-plugin-inline-assets";
77
import { injectGtag } from "./scripts/vite-plugin-html-gtag";
88
import { generateFavicon } from "./scripts/vite-plugin-favicon";
99
import { autoChooseConfig } from "../../scripts/utils/auto-choose-config";
10+
import { appleAppSiteAssociation } from "./scripts/vite-plugin-apple-app-site-association";
1011
import viteCompression from "vite-plugin-compression";
1112

1213
// HACK: disable dedupe in the react plugin
@@ -34,6 +35,7 @@ export default defineConfig({
3435
generateFavicon(),
3536
reactVirtualized(),
3637
viteCompression({ filter: /\.(js)$/i }),
38+
appleAppSiteAssociation(),
3739
],
3840
resolve: {
3941
alias: [

0 commit comments

Comments
 (0)