import { mkdir, exists, readdir, copyFile } from "node:fs/promises" import * as path from 'path' const emojiDir = './emoji' if(!await exists(emojiDir)) await mkdir(emojiDir) const fluentDir = './sources/fluentui-emoji/assets' const fluentList = await readdir(fluentDir) const animatedDir = `./sources/Animated-Fluent-Emojis/Emojis` const animatedCatList = await readdir(animatedDir) const animatedList:Map = new Map() for(let c in animatedCatList) { const category = animatedCatList[c] const catDir = `${animatedDir}/${category}` const catFiles = await readdir(catDir) catFiles.forEach((filename) => { animatedList.set(path.parse(filename).name, `${catDir}/${filename}`) }) } const mapping = [] await fluentList.forEach(async (folder) => { let thisEmojiIn = `${fluentDir}/${folder}` const metadataFile = Bun.file(`${thisEmojiIn}/metadata.json`) const metadata = await metadataFile.json() const thisEmojiOut = `${emojiDir}/${metadata.glyph}` if(!await exists(thisEmojiOut)) await mkdir(thisEmojiOut) if(!await exists(`${thisEmojiOut}/metadata.json`)) await Bun.write(`${thisEmojiOut}/metadata.json`, metadataFile) if(metadata.unicodeSkintones) thisEmojiIn = `${thisEmojiIn}/Default` const in3d = `${thisEmojiIn}/3D` const inColor = `${thisEmojiIn}/Color` const inFlat = `${thisEmojiIn}/Flat` const inHighContrast = `${thisEmojiIn}/High Contrast` // we have to search for the appropriate animated folder let title = folder if(metadata.unicodeSkintones) title += ' Light Skin Tone' let imgAnim = Bun.file(animatedList.get(title) || `${in3d}/${(await readdir(in3d))[0]}`) const img3d = Bun.file(`${in3d}/${(await readdir(in3d))[0]}`) const imgColor = Bun.file(`${inColor}/${(await readdir(inColor))[0]}`) const imgFlat = Bun.file(`${inFlat}/${(await readdir(inFlat))[0]}`) const imgHighContrast = Bun.file(`${inHighContrast}/${(await readdir(inHighContrast))[0]}`) if(!await exists(`${thisEmojiOut}/animated.png`)) await Bun.write(`${thisEmojiOut}/animated.png`, imgAnim) if(!await exists(`${thisEmojiOut}/3d.png`)) await Bun.write(`${thisEmojiOut}/3d.png`, img3d) if(!await exists(`${thisEmojiOut}/color.svg`)) await Bun.write(`${thisEmojiOut}/color.svg`, imgColor) if(!await exists(`${thisEmojiOut}/flat.svg`)) await Bun.write(`${thisEmojiOut}/flat.svg`, imgFlat) if(!await exists(`${thisEmojiOut}/high-contrast.svg`)) await Bun.write(`${thisEmojiOut}/high-contrast.svg`, imgHighContrast) })