Skip to content

Commit 3ad80ff

Browse files
committed
Fix icon paths not working for some templates
1 parent 097915e commit 3ad80ff

3 files changed

Lines changed: 559 additions & 1424 deletions

File tree

ci-scripts/build-all.mjs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -270,12 +270,7 @@ function hasBuiltManifest(exampleDirectory, browser) {
270270
for (const baseDir of baseDirs) {
271271
for (const root of OUTPUT_ROOTS) {
272272
for (const channel of channels) {
273-
const manifestPath = path.join(
274-
baseDir,
275-
root,
276-
channel,
277-
'manifest.json'
278-
)
273+
const manifestPath = path.join(baseDir, root, channel, 'manifest.json')
279274
if (fs.existsSync(manifestPath)) return true
280275
}
281276
}

ci-scripts/generate-templates-meta.mjs

Lines changed: 45 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,21 @@ const CURATED_ALLOWED_KEYS = [
4747
'docsUrl'
4848
]
4949

50+
const FALLBACK_ICON_CANDIDATES = [
51+
['public', 'logo.png'],
52+
['public', 'logo.svg'],
53+
['public', 'icon.png'],
54+
['public', 'icon.svg'],
55+
['public', 'app-icon.png'],
56+
['public', 'app-icon.svg'],
57+
['src', 'images', 'logo.png'],
58+
['src', 'images', 'logo.svg'],
59+
['src', 'images', 'icon.png'],
60+
['src', 'images', 'icon.svg'],
61+
['src', 'images', 'extension.png'],
62+
['src', 'images', 'extension.svg']
63+
]
64+
5065
function readJsonSafe(filePath) {
5166
try {
5267
return JSON.parse(fs.readFileSync(filePath, 'utf8'))
@@ -485,14 +500,40 @@ function resolveManifestIconFile(exampleDirectory, iconPath) {
485500
return null
486501
}
487502

503+
function resolveFallbackIconFile(exampleDirectory, slug) {
504+
for (const candidate of FALLBACK_ICON_CANDIDATES) {
505+
const filePath = path.join(exampleDirectory, ...candidate)
506+
507+
if (exists(filePath)) return filePath
508+
}
509+
510+
const slugCandidates = [
511+
path.join(exampleDirectory, 'public', `${slug}.png`),
512+
path.join(exampleDirectory, 'public', `${slug}.svg`),
513+
path.join(exampleDirectory, 'src', 'images', `${slug}.png`),
514+
path.join(exampleDirectory, 'src', 'images', `${slug}.svg`)
515+
]
516+
517+
for (const filePath of slugCandidates) {
518+
if (exists(filePath)) return filePath
519+
}
520+
521+
return null
522+
}
523+
488524
function detectTemplateIcon(exampleDirectory, manifest) {
489525
const iconPath = pickManifestIconPath(manifest || {})
490-
if (!iconPath) return null
526+
if (iconPath) {
527+
const resolved = resolveManifestIconFile(exampleDirectory, iconPath)
528+
if (resolved) return path.relative(repoRoot, resolved).replace(/\\/g, '/')
529+
}
530+
531+
const slug = path.basename(exampleDirectory)
532+
const fallback = resolveFallbackIconFile(exampleDirectory, slug)
491533

492-
const resolved = resolveManifestIconFile(exampleDirectory, iconPath)
493-
if (!resolved) return null
534+
if (!fallback) return null
494535

495-
return path.relative(repoRoot, resolved).replace(/\\/g, '/')
536+
return path.relative(repoRoot, fallback).replace(/\\/g, '/')
496537
}
497538

498539
function getGitCommit() {

0 commit comments

Comments
 (0)