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
This commit is contained in:
Michel Weststrate
2020-01-02 10:44:40 -08:00
committed by Facebook Github Bot
parent b7c8d5b996
commit 8a84bcbe29
3 changed files with 39 additions and 16 deletions

View File

@@ -132,11 +132,17 @@ function downloadIcons(buildFolder) {
}, []); }, []);
return Promise.all( return Promise.all(
iconURLs.map(({name, size, density}) => iconURLs.map(({name, size, density}) => {
fetch(getIconURL(name, size, density)) const url = getIconURL(name, size, density);
return fetch(url)
.then(res => { .then(res => {
if (res.status !== 200) { 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; return res;
}) })
@@ -150,9 +156,8 @@ function downloadIcons(buildFolder) {
res.body.on('error', reject); res.body.on('error', reject);
fileStream.on('finish', resolve); fileStream.on('finish', resolve);
}), }),
) );
.catch(console.error), }),
),
); );
} }

View File

@@ -67,12 +67,31 @@ function buildIconURL(name, size, density) {
if (!isProduction) { if (!isProduction) {
const existing = ICONS[name] || (ICONS[name] = []); const existing = ICONS[name] || (ICONS[name] = []);
if (!existing.includes(size)) { if (!existing.includes(size)) {
// Check if that icon actually exists!
fetch(url)
.then(res => {
if (res.status === 200) {
// the icon exists
existing.push(size); existing.push(size);
existing.sort(); existing.sort();
fs.writeFileSync(iconsPath, JSON.stringify(ICONS, null, 2), 'utf8'); fs.writeFileSync(
iconsPath,
JSON.stringify(ICONS, null, 2),
'utf8',
);
console.warn( console.warn(
`Added uncached icon "${name}: [${size}]" to /static/icons.json. Restart Flipper to apply the change.`, `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 { } else {
console.warn( console.warn(

View File

@@ -15,7 +15,6 @@
12 12
], ],
"bell-null-outline": [ "bell-null-outline": [
12,
24 24
], ],
"bell-null": [ "bell-null": [
@@ -73,7 +72,8 @@
8 8
], ],
"chevron-left": [ "chevron-left": [
12 12,
16
], ],
"chevron-right": [ "chevron-right": [
8, 8,
@@ -205,7 +205,6 @@
16 16
], ],
"star-outline": [ "star-outline": [
12,
16, 16,
24 24
], ],