Skip to content

Commit

Permalink
Excluded collections containing a specific string from the export tar…
Browse files Browse the repository at this point in the history
…get (#276)
  • Loading branch information
hayawata3626 authored Sep 25, 2023
1 parent cba3527 commit 6eb2b54
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 15 deletions.
2 changes: 1 addition & 1 deletion dist/plugin.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/ui.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/ui.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions src/ui/components/GeneralSettings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ export const GeneralSettings = () => {
<Input
type="text"
pattern="^[#\+*\\/&%$!?;:~,\s]+$"
placeholder="#, @"
placeholder="exclusion prefix"
value={settings.exclusionPrefix}
onChange={(value) =>
updateSettings((draft: Settings) => {
Expand Down Expand Up @@ -232,7 +232,7 @@ export const GeneralSettings = () => {
Reference mode in variables
<Info
width={240}
label='If disabled, the exported json will not include the mode of variables.'
label="If disabled, the exported json will not include the mode of variables."
/>
</Title>
<Checkbox
Expand Down
2 changes: 1 addition & 1 deletion src/utilities/getTokenJson.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,6 @@ export const exportRawTokenArray = (figma: PluginAPI, settings: Settings) => {
...extractGrids(figmaData.gridStyles, getPrefixArray(settings.prefix.grid)),
...extractFonts(figmaData.textStyles, getPrefixArray(settings.prefix.font)),
...extractEffects(figmaData.effectStyles, getPrefixArray(settings.prefix.effect)),
...getVariables(figma, settings.modeReference)
...getVariables(figma, settings)
]
}
18 changes: 9 additions & 9 deletions src/utilities/getVariables.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { roundRgba } from './convertColor'
import { changeNotation } from './changeNotation'
import { getVariableTypeByValue } from './getVariableTypeByValue'
import roundWithDecimals from './roundWithDecimals'
import { Settings } from '@typings/settings'

const extractVariable = (variable, value) => {
let category: tokenCategoryType = 'color'
Expand Down Expand Up @@ -92,11 +93,13 @@ const processAliasModes = (variables) => {
}, [])
}

export const getVariables = (figma: PluginAPI, modeReference: boolean) => {
export const getVariables = (figma: PluginAPI, settings: Settings) => {
const excludedCollectionIds = figma.variables.getLocalVariableCollections().filter(collection => !['.', '_', ...settings.exclusionPrefix.split(',')].includes(collection.name.charAt(0))).map(collection => collection.id);
// get collections
const collections = Object.fromEntries(figma.variables.getLocalVariableCollections().map((collection) => [collection.id, collection]))

// get variables
const variables = figma.variables.getLocalVariables().map((variable) => {
const variables = figma.variables.getLocalVariables().filter(variable => excludedCollectionIds.includes(variable.variableCollectionId)).map((variable) => {
// get collection name and modes
const { variableCollectionId } = variable
const { name: collection, modes } = collections[variableCollectionId]
Expand All @@ -105,11 +108,11 @@ export const getVariables = (figma: PluginAPI, modeReference: boolean) => {
return {
...extractVariable(variable, value),
// name is contstructed from collection, mode and variable name
name: modeReference ? `${collection}/${modes.find(({ modeId }) => modeId === id).name}/${variable.name}` : `${collection}/${variable.name}`,
name: settings.modeReference ? `${collection}/${modes.find(({ modeId }) => modeId === id).name}/${variable.name}` : `${collection}/${variable.name}`,
// add mnetadata to extensions
extensions: {
[config.key.extensionPluginData]: {
mode: modeReference ? modes.find(({ modeId }) => modeId === id).name : undefined,
mode: settings.modeReference ? modes.find(({ modeId }) => modeId === id).name : undefined,
collection: collection,
scopes: variable.scopes,
[config.key.extensionVariableStyleId]: variable.id,
Expand All @@ -120,8 +123,5 @@ export const getVariables = (figma: PluginAPI, modeReference: boolean) => {
})
})

return modeReference ? processAliasModes(variables.flat()) : variables.flat();
}



return settings.modeReference ? processAliasModes(variables.flat()) : variables.flat();
}

0 comments on commit 6eb2b54

Please sign in to comment.