Skip to content

Commit

Permalink
Merge 317ce92 into 40ffccc
Browse files Browse the repository at this point in the history
  • Loading branch information
marcomontalbano committed Mar 12, 2022
2 parents 40ffccc + 317ce92 commit c45bfb1
Show file tree
Hide file tree
Showing 9 changed files with 47 additions and 7 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ Following an example:
Alternatively you can use `npx` to use it on the fly:

```sh
npx @figma-export/cli help
npx @figma-export/cli --help
```

### Global Setup
Expand All @@ -157,7 +157,7 @@ yarn add @figma-export/cli --global
```

```sh
figma-export help
figma-export --help
```

### Advanced
Expand Down
6 changes: 3 additions & 3 deletions packages/cli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ npx figma-export COMMAND
### `help`

```sh
npx figma-export help
npx figma-export --help
```


Expand All @@ -47,7 +47,7 @@ Exports components from a Figma file
npx figma-export components FILEID

# help
npx figma-export help components
npx figma-export components --help
```

#### transformers
Expand Down Expand Up @@ -127,7 +127,7 @@ Exports styles from a Figma file
npx figma-export styles FILEID

# help
npx figma-export help styles
npx figma-export styles --help
```


Expand Down
3 changes: 3 additions & 0 deletions packages/cli/src/commands/components.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export const addComponents = (prog: Sade, spinner: Ora) => prog
.option('-O, --outputter', 'Outputter module or path')
.option('-T, --transformer', 'Transformer module or path')
.option('-c, --concurrency', 'Concurrency when fetching', 30)
.option('-r, --retries', 'Maximum number of retries when fetching fails', 3)
.option('-o, --output', 'Output directory', 'output')
.option('-p, --page', 'Figma page names (all pages when not specified)')
.option('--fileVersion', `A specific version ID to get. Omitting this will get the current version of the file.
Expand All @@ -21,6 +22,7 @@ export const addComponents = (prog: Sade, spinner: Ora) => prog
(fileId, {
fileVersion,
concurrency,
retries,
output,
...opts
}) => {
Expand All @@ -36,6 +38,7 @@ export const addComponents = (prog: Sade, spinner: Ora) => prog
fileId,
version: fileVersion,
concurrency,
retries,
token: process.env.FIGMA_TOKEN || '',
onlyFromPages: page,
transformers: requirePackages<FigmaExport.StringTransformer>(transformer),
Expand Down
3 changes: 2 additions & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@
"@figma-export/types": "^4.0.1",
"axios": "~0.24.0",
"figma-js": "~1.14.0",
"p-limit": "^3.1.0"
"p-limit": "^3.1.0",
"p-retry": "^4.6.1"
},
"engines": {
"node": "^12.22.0 || ^14.17.0 || >=16.0.0"
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/lib/export-components.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ describe('export-component', () => {
await expect(exportComponents({
fileId: 'fileABCD',
token: 'token1234',
retries: 0,
})).to.be.rejectedWith(Error, 'while fetching svg "https://example.com/10:8.svg": some error');
});
});
2 changes: 2 additions & 0 deletions packages/core/src/lib/export-components.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export const components: FigmaExport.ComponentsCommand = async ({
transformers = [],
outputters = [],
concurrency = 30,
retries = 3,
log = (msg): void => {
// eslint-disable-next-line no-console
console.log(msg);
Expand All @@ -32,6 +33,7 @@ export const components: FigmaExport.ComponentsCommand = async ({
const pagesWithSvg = await enrichPagesWithSvg(client, fileId, pages, {
transformers,
concurrency,
retries,
onFetchCompleted: ({ index, total }) => {
log(`fetching components ${index}/${total}`);
},
Expand Down
7 changes: 6 additions & 1 deletion packages/core/src/lib/figma.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import * as Figma from 'figma-js';

import { basename, dirname } from 'path';
import pLimit from 'p-limit';
import pRetry from 'p-retry';
import * as FigmaExport from '@figma-export/types';

import {
Expand Down Expand Up @@ -101,6 +102,7 @@ type FigmaExportFileSvg = {
type FileSvgOptions = {
transformers?: FigmaExport.StringTransformer[]
concurrency?: number
retries?: number
onFetchCompleted?: (data: { index: number, total: number }) => void
}

Expand All @@ -110,6 +112,7 @@ const fileSvgs = async (
ids: string[],
{
concurrency = 30,
retries = 3,
transformers = [],
// eslint-disable-next-line @typescript-eslint/no-empty-function
onFetchCompleted = () => {},
Expand All @@ -119,7 +122,9 @@ const fileSvgs = async (
const limit = pLimit(concurrency);
let index = 0;
const svgPromises = Object.entries(images).map(async ([id, url]) => {
const svg = await limit(() => fetchAsSvgXml(url));
const svg = await limit(
() => pRetry(() => fetchAsSvgXml(url), { retries }),
);
const svgTransformed = await promiseSequentially(transformers, svg);

onFetchCompleted({
Expand Down
3 changes: 3 additions & 0 deletions packages/types/src/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ export type ComponentsCommandOptions = {

/** Concurrency when fetching */
concurrency?: number;

/** Maximum number of retries when fetching fails */
retries?: number;
}

export type StylesCommandOptions = {
Expand Down
25 changes: 25 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -633,6 +633,7 @@ __metadata:
axios: ~0.24.0
figma-js: ~1.14.0
p-limit: ^3.1.0
p-retry: ^4.6.1
languageName: unknown
linkType: soft

Expand Down Expand Up @@ -2390,6 +2391,13 @@ __metadata:
languageName: node
linkType: hard

"@types/retry@npm:^0.12.0":
version: 0.12.1
resolution: "@types/retry@npm:0.12.1"
checksum: 5f46b2556053655f78262bb33040dc58417c900457cc63ff37d6c35349814471453ef511af0cec76a540c601296cd2b22f64bab1ab649c0dacc0223765ba876c
languageName: node
linkType: hard

"@types/scheduler@npm:*":
version: 0.16.2
resolution: "@types/scheduler@npm:0.16.2"
Expand Down Expand Up @@ -9144,6 +9152,16 @@ __metadata:
languageName: node
linkType: hard

"p-retry@npm:^4.6.1":
version: 4.6.1
resolution: "p-retry@npm:4.6.1"
dependencies:
"@types/retry": ^0.12.0
retry: ^0.13.1
checksum: e6d540413bb3d0b96e0db44f74a7af1dce41f5005e6e84d617960110b148348c86a3987be07797749e3ddd55817dd3a8ffd6eae3428758bc2994d987e48c3a70
languageName: node
linkType: hard

"p-timeout@npm:^3.2.0":
version: 3.2.0
resolution: "p-timeout@npm:3.2.0"
Expand Down Expand Up @@ -10262,6 +10280,13 @@ __metadata:
languageName: node
linkType: hard

"retry@npm:^0.13.1":
version: 0.13.1
resolution: "retry@npm:0.13.1"
checksum: 47c4d5be674f7c13eee4cfe927345023972197dbbdfba5d3af7e461d13b44de1bfd663bfc80d2f601f8ef3fc8164c16dd99655a221921954a65d044a2fc1233b
languageName: node
linkType: hard

"reusify@npm:^1.0.4":
version: 1.0.4
resolution: "reusify@npm:1.0.4"
Expand Down

0 comments on commit c45bfb1

Please sign in to comment.