// Bring Home's canonical photographed objects and bottle caps into Android. // // The source artwork lives in CottonUI's asset catalogue. These files are // photographs, so this deliberately copies their PNG/JPEG bytes into // drawable-nodpi rather than redrawing or resampling them. Android's resource // names retain their source names (`tool-todos`, `cap-red` -> underscores). // // Run with `pnpm exec tsx apps/cotton-android/scripts/derive-home-assets.ts`. import { copyFileSync, mkdirSync, readdirSync, statSync } from "node:fs"; import { dirname, join } from "node:path"; import { fileURLToPath } from "node:url"; const androidDir = join(dirname(fileURLToPath(import.meta.url)), ".."); const repoRoot = join(androidDir, "..", ".."); const source = join(repoRoot, "apps", "cotton", "Sources", "CottonUI", "Media.xcassets"); const destination = join(androidDir, "app", "src", "main", "res", "drawable-nodpi"); const imageSets = [ ...readdirSync(source).filter((name) => name.startsWith("tool-") && name.endsWith(".imageset")), ...readdirSync(source).filter((name) => name.startsWith("cap-") && name.endsWith(".imageset")), "home-plaster.imageset", ]; function sourceImage(imageSet: string): string { const directory = join(source, imageSet); const images = readdirSync(directory).filter((name) => /\.(png|jpe?g)$/i.test(name)); if (images.length !== 1) throw new Error(`${directory} must contain exactly one canonical raster image`); return join(directory, images[0]!); } function androidName(imageSet: string, image: string): string { const stem = imageSet.replace(/\.imageset$/, "").replaceAll("-", "_"); const extension = image.match(/\.(png|jpe?g)$/i)?.[0]; if (!extension) throw new Error(`${image} has no supported raster extension`); return `${stem}${extension.toLowerCase()}`; } export function deriveHomeAssets(): void { mkdirSync(destination, { recursive: true }); for (const imageSet of imageSets) { const image = sourceImage(imageSet); statSync(image); copyFileSync(image, join(destination, androidName(imageSet, image))); } console.log(`Android Home assets copied losslessly from ${source}`); } if (process.argv[1] === fileURLToPath(import.meta.url)) deriveHomeAssets();