2024-05-20 07:05:38 +00:00
|
|
|
import { mkdir, exists, readdir } from "node:fs/promises"
|
2024-05-17 02:17:10 +00:00
|
|
|
import * as path from 'path'
|
|
|
|
|
2024-05-20 07:05:38 +00:00
|
|
|
// setup output dirs
|
|
|
|
const distDir = process.env.DIST_DIR || './dist'
|
|
|
|
if(!await exists(distDir)) await mkdir(distDir)
|
|
|
|
const emojiDir = distDir + '/emoji'
|
2024-05-17 02:17:10 +00:00
|
|
|
if(!await exists(emojiDir)) await mkdir(emojiDir)
|
2024-05-20 07:05:38 +00:00
|
|
|
const cssDir = distDir + '/css'
|
2024-05-17 07:07:36 +00:00
|
|
|
if(!await exists(cssDir)) await mkdir(cssDir)
|
2024-05-17 02:17:10 +00:00
|
|
|
|
2024-05-20 07:05:38 +00:00
|
|
|
// setup input dirs
|
|
|
|
const fluentDir = (process.env.FLUENTUI_EMOJI_DIR || './sources/fluentui-emoji') + '/assets'
|
2024-05-17 02:17:10 +00:00
|
|
|
const fluentList = await readdir(fluentDir)
|
2024-05-20 07:05:38 +00:00
|
|
|
const animatedDir = (process.env.ANIMATED_FLUENT_EMOJIS_DIR || './sources/Animated-Fluent-Emojis') + '/Emojis'
|
2024-05-17 02:17:10 +00:00
|
|
|
const animatedCatList = await readdir(animatedDir)
|
2024-05-20 07:05:38 +00:00
|
|
|
|
|
|
|
// generate a list of all the animated emojis,
|
|
|
|
// so we don't have to search through the folder later
|
2024-05-17 02:17:10 +00:00
|
|
|
const animatedList:Map<string, string> = new Map<string, string>()
|
|
|
|
for(let c in animatedCatList) {
|
|
|
|
const category = animatedCatList[c]
|
|
|
|
const catDir = `${animatedDir}/${category}`
|
|
|
|
const catFiles = await readdir(catDir)
|
|
|
|
catFiles.forEach((filename) => {
|
2024-05-17 07:07:36 +00:00
|
|
|
let key = path.parse(filename).name.toLowerCase()//.replace(/[\(\)'’“”]/g, '')
|
|
|
|
animatedList.set(key, `${catDir}/${filename}`)
|
2024-05-17 02:17:10 +00:00
|
|
|
})
|
|
|
|
}
|
2024-05-20 07:05:38 +00:00
|
|
|
|
|
|
|
// set up the root url for the css rules
|
|
|
|
const rootURL = process.env.ROOT_URL || "https://flumoji.pages.dev"
|
2024-05-17 07:07:36 +00:00
|
|
|
const cssRules = {
|
|
|
|
animated: [] as string[],
|
|
|
|
threeD: [] as string[],
|
|
|
|
color: [] as string[],
|
|
|
|
flat: [] as string[],
|
2024-05-20 07:05:38 +00:00
|
|
|
highContrast: [] as string[],
|
|
|
|
highContrastMask: [] as string[]
|
2024-05-17 07:07:36 +00:00
|
|
|
}
|
2024-05-20 07:05:38 +00:00
|
|
|
const htmlTags = [] as string[]
|
2024-05-17 02:17:10 +00:00
|
|
|
|
2024-05-20 07:05:38 +00:00
|
|
|
// now, we're going to loop through all the emoji from the official repo
|
2024-05-17 07:07:36 +00:00
|
|
|
await Promise.all(fluentList.map(async (folder) => {
|
2024-05-20 07:05:38 +00:00
|
|
|
// gather the necessary information
|
2024-05-17 02:17:10 +00:00
|
|
|
let thisEmojiIn = `${fluentDir}/${folder}`
|
|
|
|
const metadataFile = Bun.file(`${thisEmojiIn}/metadata.json`)
|
|
|
|
const metadata = await metadataFile.json()
|
2024-05-20 07:05:38 +00:00
|
|
|
const thisEmojiDir = metadata.unicode.replaceAll(' ', '-')
|
|
|
|
const thisEmojiOut = `${emojiDir}/${thisEmojiDir}`
|
|
|
|
// create the output directory
|
2024-05-17 02:17:10 +00:00
|
|
|
if(!await exists(thisEmojiOut)) await mkdir(thisEmojiOut)
|
2024-05-20 07:05:38 +00:00
|
|
|
// copy the metadata across (not necessary?)
|
2024-05-17 02:17:10 +00:00
|
|
|
if(!await exists(`${thisEmojiOut}/metadata.json`)) await Bun.write(`${thisEmojiOut}/metadata.json`, metadataFile)
|
2024-05-20 07:05:38 +00:00
|
|
|
// for the purposes of this excersise, I'm only worried about default skin-tone
|
2024-05-17 02:17:10 +00:00
|
|
|
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
|
2024-05-20 07:05:38 +00:00
|
|
|
const inAnim = metadata.tts.toLowerCase().replace(/[:]/g, '')
|
2024-05-17 02:17:10 +00:00
|
|
|
|
2024-05-20 07:05:38 +00:00
|
|
|
// get the correct image file
|
|
|
|
let imgAnimPath = animatedList.get(inAnim)
|
2024-05-17 07:07:36 +00:00
|
|
|
const img3DPath = `${in3d}/${(await readdir(in3d))[0]}`
|
|
|
|
const imgColorPath = `${inColor}/${(await readdir(inColor))[0]}`
|
|
|
|
const imgFlatPath = `${inFlat}/${(await readdir(inFlat))[0]}`
|
|
|
|
const imgHighContrastPath = `${inHighContrast}/${(await readdir(inHighContrast))[0]}`
|
2024-05-17 02:17:10 +00:00
|
|
|
|
2024-05-17 07:07:36 +00:00
|
|
|
if(!imgAnimPath){
|
|
|
|
// hard-coded matches:
|
2024-05-20 07:05:38 +00:00
|
|
|
switch(inAnim){
|
2024-05-17 07:07:36 +00:00
|
|
|
case 'keycap 0': imgAnimPath = animatedList.get("keycap digit zero"); break;
|
|
|
|
case 'keycap 1': imgAnimPath = animatedList.get("keycap digit one"); break;
|
|
|
|
case 'keycap 2': imgAnimPath = animatedList.get("keycap digit two"); break;
|
|
|
|
case 'keycap 3': imgAnimPath = animatedList.get("keycap digit three"); break;
|
|
|
|
case 'keycap 4': imgAnimPath = animatedList.get("keycap digit four"); break;
|
|
|
|
case 'keycap 5': imgAnimPath = animatedList.get("keycap digit five"); break;
|
|
|
|
case 'keycap 6': imgAnimPath = animatedList.get("keycap digit six"); break;
|
|
|
|
case 'keycap 7': imgAnimPath = animatedList.get("keycap digit seven"); break;
|
|
|
|
case 'keycap 8': imgAnimPath = animatedList.get("keycap digit eight"); break;
|
|
|
|
case 'keycap 9': imgAnimPath = animatedList.get("keycap digit nine"); break;
|
|
|
|
case 'keycap #': imgAnimPath = animatedList.get("keycap number sign"); break;
|
|
|
|
case 'keycap *': imgAnimPath = animatedList.get("keycap asterisk"); break;
|
|
|
|
case 'pouting face': imgAnimPath = animatedList.get("enraged face"); break;
|
2024-05-20 07:05:38 +00:00
|
|
|
case 'melting face': imgAnimPath = './sources/melting-face_1fae0.png'; break;
|
|
|
|
default: console.warn(`could not find animated ${metadata.glyph} ${inAnim}. Defaulting to 3D version: ${img3DPath}`)
|
2024-05-17 07:07:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-05-20 07:05:38 +00:00
|
|
|
// create file references
|
2024-05-17 07:07:36 +00:00
|
|
|
const imgAnim = Bun.file(imgAnimPath || img3DPath)
|
|
|
|
const img3d = Bun.file(img3DPath)
|
|
|
|
const imgColor = Bun.file(imgColorPath)
|
|
|
|
const imgFlat = Bun.file(imgFlatPath)
|
|
|
|
const imgHighContrast = Bun.file(imgHighContrastPath)
|
2024-05-17 02:17:10 +00:00
|
|
|
|
2024-05-20 07:05:38 +00:00
|
|
|
// output the files to the output folder
|
2024-05-17 02:17:10 +00:00
|
|
|
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)
|
2024-05-17 07:07:36 +00:00
|
|
|
|
2024-05-20 07:05:38 +00:00
|
|
|
// create the css rule ('{file}' to be replaced next)
|
|
|
|
const cssRule = `[data-emoji|="${metadata.glyph}"]{ content: url(${rootURL}/emoji/${thisEmojiDir}/{file}); }`
|
2024-05-17 07:07:36 +00:00
|
|
|
|
2024-05-20 07:05:38 +00:00
|
|
|
// replace '{file}' with the appropriate file name
|
2024-05-17 07:07:36 +00:00
|
|
|
cssRules.animated.push(cssRule.replace("{file}", "animated.png"))
|
|
|
|
cssRules.threeD.push(cssRule.replace("{file}", "3d.png"))
|
|
|
|
cssRules.color.push(cssRule.replace("{file}", "color.svg"))
|
|
|
|
cssRules.flat.push(cssRule.replace("{file}", "flat.svg"))
|
|
|
|
cssRules.highContrast.push(cssRule.replace("{file}", "high-contrast.svg"))
|
2024-05-20 07:05:38 +00:00
|
|
|
cssRules.highContrastMask.push(`[data-emoji|="${metadata.glyph}"]{ mask-size: cover; background-color: var(--fluentui-high-contrast-color); mask-image: url(${rootURL}/emoji/${thisEmojiDir}/high-contrast.svg); }`)
|
|
|
|
|
|
|
|
htmlTags.push(`<figure><i data-emoji="${metadata.glyph}" title="${metadata.tts}" loading="lazy"></i><figcaption>${metadata.glyph} ${folder}<br><textarea><i data-emoji="${metadata.glyph}" title="${metadata.tts}"></i></textarea></figcaption></figure>`)
|
2024-05-17 07:07:36 +00:00
|
|
|
}))
|
|
|
|
|
2024-05-20 07:05:38 +00:00
|
|
|
// create file references for the css files
|
2024-05-17 07:07:36 +00:00
|
|
|
const cssAnim = Bun.file(path.join(cssDir, 'animated.css'))
|
|
|
|
const css3d = Bun.file(path.join(cssDir, '3d.css'))
|
|
|
|
const cssColor = Bun.file(path.join(cssDir, 'color.css'))
|
|
|
|
const cssFlat = Bun.file(path.join(cssDir, 'flat.css'))
|
|
|
|
const cssHighContrast = Bun.file(path.join(cssDir, 'high-contrast.css'))
|
2024-05-20 07:05:38 +00:00
|
|
|
const cssHighContrastMask = Bun.file(path.join(cssDir, 'high-contrast-mask.css'))
|
2024-05-17 07:07:36 +00:00
|
|
|
|
2024-05-20 07:05:38 +00:00
|
|
|
// output the css files
|
2024-05-17 07:07:36 +00:00
|
|
|
await Bun.write(cssAnim, cssRules.animated.join('\n'))
|
|
|
|
await Bun.write(css3d, cssRules.threeD.join('\n'))
|
|
|
|
await Bun.write(cssColor, cssRules.color.join('\n'))
|
|
|
|
await Bun.write(cssFlat, cssRules.flat.join('\n'))
|
2024-05-20 07:05:38 +00:00
|
|
|
await Bun.write(cssHighContrast, cssRules.highContrast.join('\n'))
|
|
|
|
await Bun.write(cssHighContrastMask, `:root{--fluentui-high-contrast-color:#212121}\n${cssRules.highContrastMask.join('\n')}`)
|
|
|
|
|
|
|
|
const templateHtml = Bun.file('./index.html')
|
|
|
|
const html = (await templateHtml.text()).replace('{{content}}', htmlTags.join('\n '))
|
|
|
|
|
|
|
|
const htmlFile = Bun.file(path.join(distDir, 'index.html'))
|
|
|
|
await Bun.write(htmlFile, html)
|