Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(web): change apple-app-site-association by region #2050

Merged
merged 1 commit into from
Oct 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions web/flat-web/scripts/vite-plugin-apple-app-site-association.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import type { Plugin, ResolvedConfig } from "vite";
import { existsSync, promises } from "fs";
import { resolve } from "path";

export function appleAppSiteAssociation(): Plugin {
const AppleAppID = {
CN: "48TB6ZZL5S.io.agora.flat",
SG: "48TB6ZZL5S.io.agora.flint",
};

const { readFile, writeFile } = promises;

let config: ResolvedConfig;

return {
name: "flat:apple-app-site-association",
apply: "build",
configResolved(config_) {
config = config_;
},
async closeBundle() {
const region = (process.env.FLAT_REGION as "CN" | "SG") || "CN";
const file = resolve(config.build.outDir, "apple-app-site-association.json");

if (!existsSync(file)) {
console.warn("Not found apple-app-site-association.json.");
return;
}

const content = await readFile(file, "utf8");
const json = JSON.parse(content) as { applinks: { details: { appID: string }[] } };

json.applinks.details.forEach(detail => {
detail.appID = AppleAppID[region];
console.log("Updated apple-app-site-association.json:", detail.appID);
});

await writeFile(file, JSON.stringify(json, null, 2), "utf8");
},
};
}
2 changes: 2 additions & 0 deletions web/flat-web/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { inlineAssets } from "./scripts/vite-plugin-inline-assets";
import { injectGtag } from "./scripts/vite-plugin-html-gtag";
import { generateFavicon } from "./scripts/vite-plugin-favicon";
import { autoChooseConfig } from "../../scripts/utils/auto-choose-config";
import { appleAppSiteAssociation } from "./scripts/vite-plugin-apple-app-site-association";
import viteCompression from "vite-plugin-compression";

// HACK: disable dedupe in the react plugin
Expand Down Expand Up @@ -34,6 +35,7 @@ export default defineConfig({
generateFavicon(),
reactVirtualized(),
viteCompression({ filter: /\.(js)$/i }),
appleAppSiteAssociation(),
],
resolve: {
alias: [
Expand Down