From 8a84bcbe29327184ee1c6914a701ae821c164607 Mon Sep 17 00:00:00 2001 From: Michel Weststrate Date: Thu, 2 Jan 2020 10:44:40 -0800 Subject: [PATCH] Make sure non-existing icons do break the build Summary: Builds didn't fail when using non-existing icons, and the error message was not very clear Also added verification that, before automatically adding an icon to the prefetcher, that icon does exists Reviewed By: jknoxville Differential Revision: D19264063 fbshipit-source-id: 4320d5b960e85e3f15bbca13d69f3063b983a511 --- scripts/build-release.js | 17 +++++++++++------ src/utils/icons.js | 31 +++++++++++++++++++++++++------ static/icons.json | 7 +++---- 3 files changed, 39 insertions(+), 16 deletions(-) diff --git a/scripts/build-release.js b/scripts/build-release.js index 21db50d0d..9dd275d55 100755 --- a/scripts/build-release.js +++ b/scripts/build-release.js @@ -132,11 +132,17 @@ function downloadIcons(buildFolder) { }, []); return Promise.all( - iconURLs.map(({name, size, density}) => - fetch(getIconURL(name, size, density)) + iconURLs.map(({name, size, density}) => { + const url = getIconURL(name, size, density); + return fetch(url) .then(res => { if (res.status !== 200) { - throw new Error(`Could not download the icon: ${name}`); + throw new Error( + // eslint-disable-next-line prettier/prettier + `Could not download the icon ${name} from ${url}: got status ${ + res.status + }`, + ); } return res; }) @@ -150,9 +156,8 @@ function downloadIcons(buildFolder) { res.body.on('error', reject); fileStream.on('finish', resolve); }), - ) - .catch(console.error), - ), + ); + }), ); } diff --git a/src/utils/icons.js b/src/utils/icons.js index 9c40fb12f..353c4da02 100644 --- a/src/utils/icons.js +++ b/src/utils/icons.js @@ -67,12 +67,31 @@ function buildIconURL(name, size, density) { if (!isProduction) { const existing = ICONS[name] || (ICONS[name] = []); if (!existing.includes(size)) { - existing.push(size); - existing.sort(); - fs.writeFileSync(iconsPath, JSON.stringify(ICONS, null, 2), 'utf8'); - console.warn( - `Added uncached icon "${name}: [${size}]" to /static/icons.json. Restart Flipper to apply the change.`, - ); + // Check if that icon actually exists! + fetch(url) + .then(res => { + if (res.status === 200) { + // the icon exists + existing.push(size); + existing.sort(); + fs.writeFileSync( + iconsPath, + JSON.stringify(ICONS, null, 2), + 'utf8', + ); + console.warn( + `Added uncached icon "${name}: [${size}]" to /static/icons.json. Restart Flipper to apply the change.`, + ); + } else { + throw new Error( + // eslint-disable-next-line prettier/prettier + `Trying to use icon '${name}' with size ${size} and density ${density}, however the icon doesn't seem to exists at ${url}: ${ + res.status + }`, + ); + } + }) + .catch(e => console.error(e)); } } else { console.warn( diff --git a/static/icons.json b/static/icons.json index 8f0b0c594..90c22804e 100644 --- a/static/icons.json +++ b/static/icons.json @@ -15,7 +15,6 @@ 12 ], "bell-null-outline": [ - 12, 24 ], "bell-null": [ @@ -73,7 +72,8 @@ 8 ], "chevron-left": [ - 12 + 12, + 16 ], "chevron-right": [ 8, @@ -205,7 +205,6 @@ 16 ], "star-outline": [ - 12, 16, 24 ], @@ -292,4 +291,4 @@ "crop": [ 16 ] -} \ No newline at end of file +}