Files
supabase/scripts/generate-favicons.mjs
Danny White 7b48b298ee feat(apps): distinguish local development with blue blueprint favicons (#51420)
## Problem

- Local apps are hard to distinguish from hosted apps in browser tabs.

## Solution

- Add blue blueprint icons to local development in all 8 apps and Studio
CLI.
- Keep normal branding for production, hosted staging and self-hosted
Studio.
- Builds on #51419.


| Before | After |
| --- | --- |
| <img width="1290" height="76" alt="CleanShot 2026-10-08 at 13 29
14@2x"
src="https://github.com/user-attachments/assets/72bc50d7-37e0-47d0-8dfd-50e233a443bd"
/> | <img width="1282" height="72" alt="CleanShot 2026-10-08 at 13 30
03@2x"
src="https://github.com/user-attachments/assets/afb15a70-3938-4cff-9b41-dc6c25460b7c"
/> |

## Review instructions

- Start an app locally. Its browser tab should show the blue icon.
- Check Studio CLI uses blue and hosted staging uses white.
- Check production icons are unchanged, including Learn's black and
white icon.
- Run `node scripts/validate-favicons.mjs`. All 16 sets should pass.

Asset and routing checks, formatting and Common/Studio type checks
passed. Full builds have not been run.

## Checklist

- [x] I have read
[CONTRIBUTING.md](https://github.com/supabase/supabase/blob/master/CONTRIBUTING.md)
2026-10-12 10:26:51 +11:00

64 lines
2.5 KiB
JavaScript

import { mkdir, readFile, writeFile } from 'node:fs/promises'
import { createRequire } from 'node:module'
import path from 'node:path'
import { fileURLToPath } from 'node:url'
import { faviconTargets } from './favicon-targets.mjs'
const root = fileURLToPath(new URL('../', import.meta.url))
const require = createRequire(path.join(root, 'apps/kb/package.json'))
const sharp = require('sharp')
// ICO directory entries contain individually rendered PNG images, never an upscaled bitmap.
function encodeIco(images) {
const header = Buffer.alloc(6 + images.length * 16)
header.writeUInt16LE(1, 2)
header.writeUInt16LE(images.length, 4)
let offset = header.length
images.forEach(({ size, data }, index) => {
const entry = 6 + index * 16
header[entry] = size
header[entry + 1] = size
header.writeUInt16LE(1, entry + 4)
header.writeUInt16LE(32, entry + 6)
header.writeUInt32LE(data.length, entry + 8)
header.writeUInt32LE(offset, entry + 12)
offset += data.length
})
return Buffer.concat([header, ...images.map(({ data }) => data)])
}
for (const [variant, relativeDirectory] of faviconTargets) {
const directory = path.join(root, relativeDirectory)
await mkdir(directory, { recursive: true })
const svg = await readFile(path.join(root, `assets/favicons/${variant}.svg`))
const background = variant === 'staging' ? '#FFFFFF' : variant === 'local' ? '#087BFF' : '#1C1C1C'
const render = (size) => sharp(svg).resize(size, size)
const images = await Promise.all(
[16, 32, 48].map(async (size) => ({ size, data: await render(size).png().toBuffer() }))
)
await writeFile(path.join(directory, 'favicon.ico'), encodeIco(images))
await render(180)
.flatten({ background })
.png()
.toFile(path.join(directory, 'apple-icon-180x180.png'))
for (const size of [192, 512]) {
await render(size)
.png()
.toFile(path.join(directory, `android-icon-${size}x${size}.png`))
}
const manifestPath = path.join(directory, 'manifest.json')
const manifest = JSON.parse(await readFile(manifestPath, 'utf8'))
// Relative icon URLs resolve beside the manifest, including under /docs and /kb.
manifest.icons = [192, 512].map((size) => ({
src: `android-icon-${size}x${size}.png`,
sizes: `${size}x${size}`,
type: 'image/png',
purpose: 'any',
}))
await writeFile(manifestPath, `${JSON.stringify(manifest, null, 2)}\n`)
}
// Next.js layouts declare their icons explicitly. Do not add app/favicon.ico,
// which would also advertise the production artwork during local development.