Summary: Bumps [adobe/node-fetch-retry](https://github.com/adobe/node-fetch-retry) from 2.0.0 to 2.1.0. <details> <summary>Release notes</summary> <p><em>Sourced from <a href="https://github.com/adobe/node-fetch-retry/releases"><code>@adobe/node-fetch-retry</code>'s releases</a>.</em></p> <blockquote> <h2>v2.1.0</h2> <h1><a href="https://github.com/adobe/node-fetch-retry/compare/v2.0.0...v2.1.0">2.1.0</a> (2022-01-24)</h1> </blockquote> </details> <details> <summary>Commits</summary> <ul> <li><a href="aaf1b7195d"><code>aaf1b71</code></a> [ci skip] no-release: version number update</li> <li><a href="24d20a624b"><code>24d20a6</code></a> FEATURE-RELEASE: Add Typescript declarations (<a href="https://github-redirect.dependabot.com/adobe/node-fetch-retry/issues/42">https://github.com/facebook/flipper/issues/42</a>)</li> <li>See full diff in <a href="https://github.com/adobe/node-fetch-retry/compare/v2.0.0...v2.1.0">compare view</a></li> </ul> </details> <br /> [](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores) Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting `dependabot rebase`. [//]: # (dependabot-automerge-start) [//]: # (dependabot-automerge-end) --- <details> <summary>Dependabot commands and options</summary> <br /> You can trigger Dependabot actions by commenting on this PR: - `dependabot rebase` will rebase this PR - `dependabot recreate` will recreate this PR, overwriting any edits that have been made to it - `dependabot merge` will merge this PR after your CI passes on it - `dependabot squash and merge` will squash and merge this PR after your CI passes on it - `dependabot cancel merge` will cancel a previously requested merge and block automerging - `dependabot reopen` will reopen this PR if it is closed - `dependabot close` will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually - `dependabot ignore this major version` will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself) - `dependabot ignore this minor version` will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself) - `dependabot ignore this dependency` will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself) </details> Pull Request resolved: https://github.com/facebook/flipper/pull/3384 Reviewed By: passy Differential Revision: D33892201 Pulled By: cekkaewnumchai fbshipit-source-id: e318850d9bcad6908a92e41080fb64d8efafb183
99 lines
3.1 KiB
TypeScript
99 lines
3.1 KiB
TypeScript
/**
|
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
*
|
|
* This source code is licensed under the MIT license found in the
|
|
* LICENSE file in the root directory of this source tree.
|
|
*
|
|
* @format
|
|
*/
|
|
|
|
import path from 'path';
|
|
import fs from 'fs-extra';
|
|
import fetch from '@adobe/node-fetch-retry';
|
|
// eslint-disable-next-line node/no-extraneous-import
|
|
import type {Icon} from 'flipper-ui-core';
|
|
|
|
export type Icons = {
|
|
[key: string]: Icon['size'][];
|
|
};
|
|
|
|
// Takes a string like 'star', or 'star-outline', and converts it to
|
|
// {trimmedName: 'star', variant: 'filled'} or {trimmedName: 'star', variant: 'outline'}
|
|
function getIconPartsFromName(icon: string): {
|
|
trimmedName: string;
|
|
variant: 'outline' | 'filled';
|
|
} {
|
|
const isOutlineVersion = icon.endsWith('-outline');
|
|
const trimmedName = isOutlineVersion ? icon.replace('-outline', '') : icon;
|
|
const variant = isOutlineVersion ? 'outline' : 'filled';
|
|
return {trimmedName: trimmedName, variant: variant};
|
|
}
|
|
|
|
export async function downloadIcons(buildFolder: string) {
|
|
const icons: Icons = JSON.parse(
|
|
await fs.promises.readFile(path.join(buildFolder, 'icons.json'), {
|
|
encoding: 'utf8',
|
|
}),
|
|
);
|
|
const iconURLs = Object.entries(icons).reduce<Icon[]>(
|
|
(acc, [entryName, sizes]) => {
|
|
const {trimmedName: name, variant} = getIconPartsFromName(entryName);
|
|
acc.push(
|
|
// get icons in @1x and @2x
|
|
...sizes.map((size) => ({name, variant, size, density: 1})),
|
|
...sizes.map((size) => ({name, variant, size, density: 2})),
|
|
);
|
|
return acc;
|
|
},
|
|
[],
|
|
);
|
|
|
|
return Promise.all(
|
|
iconURLs.map((icon) => {
|
|
const url = getPublicIconUrl(icon);
|
|
return fetch(url, {
|
|
retryOptions: {
|
|
retryMaxDuration: 120 * 1000,
|
|
// Be default, only 5xx are retried but we're getting the odd 404
|
|
// which goes away on a retry for some reason.
|
|
retryOnHttpResponse: (res) => res.status >= 400,
|
|
retryOnHttpError: () => true,
|
|
},
|
|
})
|
|
.then((res) => {
|
|
if (res.status !== 200) {
|
|
throw new Error(
|
|
// eslint-disable-next-line prettier/prettier
|
|
`Could not download the icon ${icon} from ${url}: got status ${res.status}`,
|
|
);
|
|
}
|
|
return res;
|
|
})
|
|
.then(
|
|
(res) =>
|
|
new Promise((resolve, reject) => {
|
|
const fileStream = fs.createWriteStream(
|
|
path.join(buildFolder, buildLocalIconPath(icon)),
|
|
);
|
|
res.body.pipe(fileStream);
|
|
res.body.on('error', reject);
|
|
fileStream.on('finish', resolve);
|
|
}),
|
|
);
|
|
}),
|
|
);
|
|
}
|
|
|
|
// should match flipper-ui-core/src/utils/icons.tsx
|
|
export function getPublicIconUrl({name, variant, size, density}: Icon) {
|
|
return `https://facebook.com/assets/?name=${name}&variant=${variant}&size=${size}&set=facebook_icons&density=${density}x`;
|
|
}
|
|
|
|
// should match app/src/utils/icons.tsx
|
|
function buildLocalIconPath(icon: Icon) {
|
|
return path.join(
|
|
'icons',
|
|
`${icon.name}-${icon.variant}-${icon.size}@${icon.density}x.png`,
|
|
);
|
|
}
|