Skip to content

Commit

Permalink
feat: add 'ids' to cli
Browse files Browse the repository at this point in the history
  • Loading branch information
marcomontalbano committed Feb 12, 2024
1 parent ee96d91 commit e5e7889
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
4 changes: 4 additions & 0 deletions packages/cli/src/commands/components.ts
Expand Up @@ -14,12 +14,14 @@ export const addComponents = (prog: Sade, spinner: Ora) => prog
.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('-i, --ids', 'Export only these node IDs (`--page` is always ignored when set)')
.option('-p, --page', 'Figma page names or IDs (all pages when not specified)')
.option('-t, --types', 'Node types to be exported (COMPONENT or INSTANCE)', 'COMPONENT')
.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')
.example('components fzYhvQpqwhZDUImRz431Qo -O @figma-export/output-components-as-svg -t COMPONENT -t INSTANCE -o dist')
.example('components fzYhvQpqwhZDUImRz431Qo -O @figma-export/output-components-as-svg -o dist -i 54:22 -i 138:52')
.action(
(fileId, {
fileVersion,
Expand All @@ -32,6 +34,7 @@ export const addComponents = (prog: Sade, spinner: Ora) => prog

const outputter = asArray<string>(opts.outputter);
const transformer = asArray<string>(opts.transformer);
const ids = asArray<string>(opts.ids);
const page = asArray<string>(opts.page);
const types = asUndefinableArray<string>(opts.types) as IncludeTypes;

Expand All @@ -45,6 +48,7 @@ export const addComponents = (prog: Sade, spinner: Ora) => prog
concurrency,
retries,
token: process.env.FIGMA_TOKEN || '',
ids,
onlyFromPages: page,
includeTypes: types,
transformers: requirePackages<FigmaExport.StringTransformer>(transformer),
Expand Down
3 changes: 3 additions & 0 deletions packages/cli/src/commands/styles.ts
Expand Up @@ -11,6 +11,7 @@ export const addStyles = (prog: Sade, spinner: Ora) => prog
.describe('Export styles from a Figma file.')
.option('-O, --outputter', 'Outputter module or path')
.option('-o, --output', 'Output directory', 'output')
.option('-i, --ids', 'Figma node IDs (`--page` is always ignored when set)')
.option('-p, --page', 'Figma page names or IDs (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`)
Expand All @@ -22,6 +23,7 @@ export const addStyles = (prog: Sade, spinner: Ora) => prog
...opts
}) => {
const outputter = asArray<string>(opts.outputter);
const ids = asArray<string>(opts.ids);
const page = asArray<string>(opts.page);

spinner.info(`Exporting ${fileId} as [${outputter.join(', ')}]`);
Expand All @@ -32,6 +34,7 @@ export const addStyles = (prog: Sade, spinner: Ora) => prog
fileId,
version: fileVersion,
token: process.env.FIGMA_TOKEN || '',
ids,
onlyFromPages: page,
outputters: requirePackages<FigmaExport.StyleOutputter>(outputter, { output }),

Expand Down
10 changes: 8 additions & 2 deletions packages/types/src/commands.ts
Expand Up @@ -29,7 +29,10 @@ export type ComponentsCommandOptions = {
*/
version?: string;

/** // TODO: add description */
/**
* Export only specified node IDs.
* The `onlyFromPages` option is always ignored when set.
*/
ids?: string[];

/** Figma page names or IDs (all pages when not specified) */
Expand Down Expand Up @@ -67,7 +70,10 @@ export type StylesCommandOptions = {
*/
version?: string;

/** // TODO: add description */
/**
* Export only specified node IDs.
* The `onlyFromPages` option is always ignored when set.
*/
ids?: string[];

/** Figma page names or IDs (all pages when not specified) */
Expand Down

0 comments on commit e5e7889

Please sign in to comment.