Skip to content

Commit

Permalink
Update CLI documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
marcomontalbano committed Dec 20, 2021
1 parent f27fe44 commit eecb87d
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 9 deletions.
8 changes: 4 additions & 4 deletions packages/cli/src/commands/components.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export const addComponents = (prog: Sade, spinner: Ora) => prog
.option('-T, --transformer', 'Transformer module or path')
.option('-c, --concurrency', 'Concurrency when fetching', 30)
.option('-o, --output', 'Output directory', 'output')
.option('-p, --page', 'Figma page names (defaults to \'all pages\')')
.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.
https://help.figma.com/hc/en-us/articles/360038006754-View-a-file-s-version-history`)
.example('components fzYhvQpqwhZDUImRz431Qo -O @figma-export/output-components-as-svg')
Expand All @@ -24,9 +24,9 @@ export const addComponents = (prog: Sade, spinner: Ora) => prog
output,
...opts
}) => {
const outputter = asArray(opts.outputter);
const transformer = asArray(opts.transformer);
const page = asArray(opts.page);
const outputter = asArray<string>(opts.outputter);
const transformer = asArray<string>(opts.transformer);
const page = asArray<string>(opts.page);

spinner.info(`Exporting ${fileId} with [${transformer.join(', ')}] as [${outputter.join(', ')}]`);

Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/commands/styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export const addStyles = (prog: Sade, spinner: Ora) => prog
output,
...opts
}) => {
const outputter = asArray(opts.outputter);
const outputter = asArray<string>(opts.outputter);

spinner.info(`Exporting ${fileId} as [${outputter.join(', ')}]`);

Expand Down
6 changes: 4 additions & 2 deletions packages/core/src/lib/export-components.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,13 @@ describe('export-component', () => {
});
expect(clientFile).to.have.been.calledOnceWithExactly('fileABCD', { version: 'versionABCD' });

expect(logger).to.have.been.callCount(5);
expect(logger).to.have.been.callCount(6);
expect(logger.getCall(0)).to.have.been.calledWith('fetching document');
expect(logger.getCall(1)).to.have.been.calledWith('preparing components');
expect(logger.getCall(2)).to.have.been.calledWith('fetching components 1/3');
expect(logger.getCall(3)).to.have.been.calledWith('fetching components 2/3');
expect(logger.getCall(4)).to.have.been.calledWith('fetching components 3/3');
expect(logger.getCall(5)).to.have.been.calledWith('exported components from fileABCD');

expect(transformer).to.have.been.calledThrice;
expect(transformer.firstCall).to.have.been.calledWith(figmaDocument.svg.content);
Expand All @@ -112,12 +113,13 @@ describe('export-component', () => {
});

/* eslint-disable no-console */
expect(console.log).to.have.been.callCount(5);
expect(console.log).to.have.been.callCount(6);
expect((console.log as sinon.SinonSpy<unknown[], unknown>).getCall(0)).to.have.been.calledWith('fetching document');
expect((console.log as sinon.SinonSpy<unknown[], unknown>).getCall(1)).to.have.been.calledWith('preparing components');
expect((console.log as sinon.SinonSpy<unknown[], unknown>).getCall(2)).to.have.been.calledWith('fetching components 1/3');
expect((console.log as sinon.SinonSpy<unknown[], unknown>).getCall(3)).to.have.been.calledWith('fetching components 2/3');
expect((console.log as sinon.SinonSpy<unknown[], unknown>).getCall(4)).to.have.been.calledWith('fetching components 3/3');
expect((console.log as sinon.SinonSpy<unknown[], unknown>).getCall(5)).to.have.been.calledWith('exported components from fileABCD');
});

it('should throw an error when fetching file fails', async () => {
Expand Down
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 @@ -39,5 +39,7 @@ export const components: FigmaExport.ComponentsCommand = async ({

await Promise.all(outputters.map((outputter) => outputter(pagesWithSvg)));

log(`exported components from ${fileId}`);

return pagesWithSvg;
};
6 changes: 4 additions & 2 deletions packages/core/src/lib/export-styles.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,10 @@ describe('export-styles', () => {
expect(clientFileNodes).to.have.been.calledOnceWith('fileABCD', { ids: nodeIds, version: 'versionABCD' });
expect(clientFile).to.have.been.calledOnceWithExactly('fileABCD', { version: 'versionABCD' });

expect(logger).to.have.been.calledTwice;
expect(logger).to.have.been.calledThrice;
expect(logger.firstCall).to.have.been.calledWith('fetching styles');
expect(logger.secondCall).to.have.been.calledWith('parsing styles');
expect(logger.thirdCall).to.have.been.calledWith('exported styles from fileABCD');

expect(outputter).to.have.been.calledOnceWithExactly(pagesWithSvg);
});
Expand All @@ -71,9 +72,10 @@ describe('export-styles', () => {
});

/* eslint-disable no-console */
expect(console.log).to.have.been.calledTwice;
expect(console.log).to.have.been.calledThrice;
expect((console.log as sinon.SinonSpy<unknown[], unknown>).firstCall).to.have.been.calledWith('fetching styles');
expect((console.log as sinon.SinonSpy<unknown[], unknown>).secondCall).to.have.been.calledWith('parsing styles');
expect((console.log as sinon.SinonSpy<unknown[], unknown>).thirdCall).to.have.been.calledWith('exported styles from fileABCD');
});

it('should throw an error when fetching file fails', async () => {
Expand Down
2 changes: 2 additions & 0 deletions packages/core/src/lib/export-styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,7 @@ export const styles: FigmaExport.StylesCommand = async ({

await Promise.all(outputters.map((outputter) => outputter(parsedStyles)));

log(`exported styles from ${fileId}`);

return parsedStyles;
};
32 changes: 32 additions & 0 deletions packages/types/src/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,54 @@ import { StringTransformer, ComponentOutputter, PageNode } from './global';
import { StyleOutputter, Style } from './styles';

export type BaseCommandOptions = {
/**
* Personal access token.
* @see: https://www.figma.com/developers/api#access-tokens
*/
token: string;
log?: (msg: string) => void;
}

export type ComponentsCommandOptions = {
/**
* File to export Components from.
* The file key can be parsed from any Figma file url: https://www.figma.com/file/:key/:title.
*/
fileId: string;

/**
* A specific version ID to get. Omitting this will get the current version of the file
* @see https://help.figma.com/hc/en-us/articles/360038006754-View-a-file-s-version-history
*/
version?: string;

/** Figma page names (all pages when not specified) */
onlyFromPages?: string[];

/** Transformer module name or path */
transformers?: StringTransformer[];

/** Outputter module name or path */
outputters?: ComponentOutputter[];

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

export type StylesCommandOptions = {
/**
* File to export Styles from.
* The file key can be parsed from any Figma file url: https://www.figma.com/file/:key/:title.
*/
fileId: string;

/**
* A specific version ID to get. Omitting this will get the current version of the file
* @see https://help.figma.com/hc/en-us/articles/360038006754-View-a-file-s-version-history
*/
version?: string;

/** Outputter module name or path */
outputters?: StyleOutputter[];
}

Expand Down

0 comments on commit eecb87d

Please sign in to comment.