Files
buzz/mobile/scripts/generate-emoji-data.mjs
T
cls 9dfa06ffee
Docker image / Build (linux/amd64) (push) Has been cancelled
Docker image / Build (linux/arm64) (push) Has been cancelled
Docker image / Merge release multi-arch manifest (push) Has been cancelled
Docker image / Merge debug multi-arch manifest (push) Has been cancelled
Docker image / Build public push gateway (linux/amd64) (push) Has been cancelled
Docker image / Build public push gateway (linux/arm64) (push) Has been cancelled
Docker image / Publish public push gateway image (push) Has been cancelled
Sprig image / Build (linux/amd64) (push) Has been cancelled
Sprig image / Build (linux/arm64) (push) Has been cancelled
Sprig image / Merge multi-arch manifest (push) Has been cancelled
Harbor Buzz Orchestra / Python tests and lint (push) Has been cancelled
CI / Detect Changed Paths (push) Has been cancelled
CI / Rust Lint (push) Has been cancelled
CI / Unit Tests (push) Has been cancelled
CI / Desktop Core (push) Has been cancelled
CI / Desktop Smoke E2E (1) (push) Has been cancelled
CI / Desktop Smoke E2E (2) (push) Has been cancelled
CI / Desktop Smoke E2E (3) (push) Has been cancelled
CI / Desktop Smoke E2E (4) (push) Has been cancelled
CI / Desktop (push) Has been cancelled
CI / Desktop E2E Relay (push) Has been cancelled
CI / Desktop E2E Integration (1/2) (push) Has been cancelled
CI / Desktop E2E Integration (2/2) (push) Has been cancelled
CI / Desktop E2E Integration (push) Has been cancelled
CI / Backend Integration (relay e2e) (push) Has been cancelled
CI / Relay E2E (push) Has been cancelled
CI / Web (push) Has been cancelled
CI / Mobile (push) Has been cancelled
CI / Security (push) Has been cancelled
CI / Dead Token Reference Guard (push) Has been cancelled
CI / Server Cross-Compile (aarch64-unknown-linux-musl) (push) Has been cancelled
CI / Server Cross-Compile (x86_64-unknown-linux-musl) (push) Has been cancelled
CI / Windows Rust (x86_64-pc-windows-msvc) (push) Has been cancelled
CI / Desktop Build (macOS) (push) Has been cancelled
helm chart / lint + unittest + render matrix (push) Has been cancelled
helm chart / install on kind (gated) (push) Has been cancelled
helm chart / publish chart to GHCR (push) Has been cancelled
Mesh Lifecycle / Relay-Driven Mesh Lifecycle Smoke (push) Has been cancelled
Sprig / Build (aarch64-unknown-linux-musl) (push) Has been cancelled
Sprig / Build (x86_64-unknown-linux-musl) (push) Has been cancelled
Sprig / Publish rolling release (push) Has been cancelled
Sprig / Publish tagged release (push) Has been cancelled
feat: import Chinese-localized Buzz source snapshot
Signed-off-by: cls_宁波本机 <908705107@qq.com>
2026-08-13 18:34:25 +08:00

85 lines
3.2 KiB
JavaScript

/**
* Generate the mobile emoji dataset from emoji-mart.
*
* Desktop's emoji picker, autocomplete, and reaction display names all read
* `@emoji-mart/data/sets/15/native.json` (see
* `desktop/src/features/custom-emoji/ui/EmojiPicker.tsx` and
* `desktop/src/shared/lib/emojiName.ts`). Mobile can't consume the npm package,
* so this script projects the same source into a trimmed JSON asset that ships
* with the Flutter app. Same ids, same names, same keywords, same category
* order — so a `:shortcode:` means the same thing on both clients.
*
* The output is committed. Regenerate with `just mobile-emoji-data` after
* bumping the emoji-mart dependency.
*/
import { mkdirSync, readFileSync, writeFileSync } from "node:fs";
import path from "node:path";
import { fileURLToPath } from "node:url";
const __dirname = path.dirname(fileURLToPath(import.meta.url));
const mobileRoot = path.resolve(__dirname, "..");
const repoRoot = path.resolve(mobileRoot, "..");
const DATA_SUBPATH = "@emoji-mart/data/sets/15/native.json";
// `EMOJI_MART_DATA` lets a git worktree (which has no desktop/node_modules of
// its own) point at the main checkout's install instead of paying for a full
// `pnpm install` just to regenerate a committed asset.
const SOURCE =
process.env.EMOJI_MART_DATA ??
path.join(repoRoot, "desktop/node_modules", DATA_SUBPATH);
const OUTPUT = path.join(mobileRoot, "assets/emoji/emoji-data.json");
let raw;
try {
raw = readFileSync(SOURCE, "utf8");
} catch {
console.error(
`Missing emoji-mart data at ${SOURCE}.\n` +
"Run `pnpm install` in desktop/ first — this script projects the same\n" +
"dataset the desktop picker uses so the two clients cannot drift.\n" +
"From a worktree, point EMOJI_MART_DATA at the main checkout's copy:\n" +
` EMOJI_MART_DATA=<main-checkout>/desktop/node_modules/${DATA_SUBPATH}`,
);
process.exit(1);
}
const data = JSON.parse(raw);
// Category order is emoji-mart's own, which is the order desktop's picker
// renders. Preserve it verbatim rather than re-sorting.
const categories = data.categories.map((category) => ({
id: category.id,
emoji: category.emojis.filter((id) => {
const entry = data.emojis[id];
return Boolean(entry?.skins?.some((skin) => skin.native));
}),
}));
// Keys are deliberately short (`n`/`u`/`k`) — the map is ~1.9k entries and the
// asset ships in the app bundle.
const emoji = {};
for (const category of categories) {
for (const id of category.emoji) {
const entry = data.emojis[id];
emoji[id] = {
n: entry.name,
// Keep every skin variation. The app flattens these into selectable
// tiles and maps every glyph back to this desktop-identical shortcode.
u: entry.skins.map((skin) => skin.native).filter(Boolean),
k: entry.keywords ?? [],
};
}
}
const payload = { categories, emoji };
mkdirSync(path.dirname(OUTPUT), { recursive: true });
// Trailing newline keeps the file diff-friendly; no indentation because the
// asset is machine-read only and indentation would roughly double its size.
writeFileSync(OUTPUT, `${JSON.stringify(payload)}\n`, "utf8");
console.log(
`Wrote ${path.relative(repoRoot, OUTPUT)}` +
`${categories.length} categories, ${Object.keys(emoji).length} emoji.`,
);