Skip to content

Commit

Permalink
Merge pull request #161 from marcomontalbano/export-ids-directly
Browse files Browse the repository at this point in the history
Add support to exporting components and styles by node IDs
  • Loading branch information
marcomontalbano authored Feb 12, 2024
2 parents b323aba + 8da55e2 commit 4c10a8c
Show file tree
Hide file tree
Showing 17 changed files with 46,624 additions and 35,571 deletions.
2 changes: 1 addition & 1 deletion .figmaexportrc.example.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module.exports = {
['styles', {
fileId: 'fzYhvQpqwhZDUImRz431Qo',
// version: 'xxx123456', // optional - file's version history is only supported on paid Figma plans
// onlyFromPages: ['icons'], // optional - Figma page names (all pages when not specified)
// onlyFromPages: ['icons'], // optional - Figma page names or IDs (all pages when not specified)
outputters: [
require('@figma-export/output-styles-as-sass')({
output: './output'
Expand Down
2 changes: 1 addition & 1 deletion .figmaexportrc.example.local.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import outputComponentsAsSvgstore from './packages/output-components-as-svgstore

const styleOptions: StylesCommandOptions = {
fileId: 'fzYhvQpqwhZDUImRz431Qo',
// onlyFromPages: ['icons'], // optional - Figma page names (all pages when not specified)
// onlyFromPages: ['icons'], // optional - Figma page names or IDs (all pages when not specified)
outputters: [
outputStylesAsCss({
output: './output/styles/css'
Expand Down
4 changes: 3 additions & 1 deletion .figmaexportrc.example.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ import outputComponentsAsEs6 from '@figma-export/output-components-as-es6';
const styleOptions: StylesCommandOptions = {
fileId: 'fzYhvQpqwhZDUImRz431Qo',
// version: 'xxx123456', // optional - file's version history is only supported on paid Figma plans
// onlyFromPages: ['icons'], // optional - Figma page names (all pages when not specified)
// ids: ['138:52'], // optional - Export only specified node IDs (the `onlyFromPages` option is always ignored when set)
// onlyFromPages: ['icons'], // optional - Figma page names or IDs (all pages when not specified)
outputters: [
outputStylesAsSass({
output: './output'
Expand All @@ -25,6 +26,7 @@ const styleOptions: StylesCommandOptions = {
const componentOptions: ComponentsCommandOptions = {
fileId: 'fzYhvQpqwhZDUImRz431Qo',
// version: 'xxx123456', // optional - file's version history is only supported on paid Figma plans
// ids: ['54:22'], // optional - Export only specified node IDs (the `onlyFromPages` option is always ignored when set)
onlyFromPages: ['icons'],
transformers: [
transformSvgWithSvgo({
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,8 @@ module.exports = {
['styles', {
fileId: 'fzYhvQpqwhZDUImRz431Qo',
// version: 'xxx123456', // optional - file's version history is only supported on paid Figma plans
// onlyFromPages: ['icons'], // optional - Figma page names (all pages when not specified)
// ids: ['138:52'], // optional - Export only specified node IDs (the `onlyFromPages` option is always ignored when set)
// onlyFromPages: ['icons'], // optional - Figma page names or IDs (all pages when not specified)
outputters: [
require('@figma-export/output-styles-as-sass')({
output: './output/styles'
Expand All @@ -187,6 +188,7 @@ module.exports = {
['components', {
fileId: 'fzYhvQpqwhZDUImRz431Qo',
// version: 'xxx123456', // optional - file's version history is only supported on paid Figma plans
// ids: ['54:22'], // optional - Export only specified node IDs (the `onlyFromPages` option is always ignored when set)
onlyFromPages: ['icons'],
// filterComponent: (component) => !/^figma/.test(component.name), // optional
transformers: [
Expand Down
6 changes: 5 additions & 1 deletion packages/cli/src/commands/components.ts
Original file line number Diff line number Diff line change
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('-p, --page', 'Figma page names (all pages when not specified)')
.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
5 changes: 4 additions & 1 deletion packages/cli/src/commands/styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ 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('-p, --page', 'Figma page names (all pages when not specified)')
.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`)
.example('styles fzYhvQpqwhZDUImRz431Qo -O @figma-export/output-styles-as-css')
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
2 changes: 1 addition & 1 deletion packages/core/src/integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ describe('@figma-export/core', () => {
const pageNodes = await exportComponents({
fileId: 'fzYhvQpqwhZDUImRz431Qo',
token: process.env.FIGMA_TOKEN ?? '',
onlyFromPages: ['unit-test'],
onlyFromPages: ['138:28'],
// eslint-disable-next-line @typescript-eslint/no-empty-function
log: () => {},
});
Expand Down
Loading

0 comments on commit 4c10a8c

Please sign in to comment.