Skip to content

Commit 6eb2b54

Browse files
authored
Excluded collections containing a specific string from the export target (#276)
1 parent cba3527 commit 6eb2b54

File tree

6 files changed

+15
-15
lines changed

6 files changed

+15
-15
lines changed

dist/plugin.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/ui.html

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

dist/ui.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/ui/components/GeneralSettings.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ export const GeneralSettings = () => {
193193
<Input
194194
type="text"
195195
pattern="^[#\+*\\/&%$!?;:~,\s]+$"
196-
placeholder="#, @"
196+
placeholder="exclusion prefix"
197197
value={settings.exclusionPrefix}
198198
onChange={(value) =>
199199
updateSettings((draft: Settings) => {
@@ -232,7 +232,7 @@ export const GeneralSettings = () => {
232232
Reference mode in variables
233233
<Info
234234
width={240}
235-
label='If disabled, the exported json will not include the mode of variables.'
235+
label="If disabled, the exported json will not include the mode of variables."
236236
/>
237237
</Title>
238238
<Checkbox

src/utilities/getTokenJson.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,6 @@ export const exportRawTokenArray = (figma: PluginAPI, settings: Settings) => {
3131
...extractGrids(figmaData.gridStyles, getPrefixArray(settings.prefix.grid)),
3232
...extractFonts(figmaData.textStyles, getPrefixArray(settings.prefix.font)),
3333
...extractEffects(figmaData.effectStyles, getPrefixArray(settings.prefix.effect)),
34-
...getVariables(figma, settings.modeReference)
34+
...getVariables(figma, settings)
3535
]
3636
}

src/utilities/getVariables.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { roundRgba } from './convertColor'
77
import { changeNotation } from './changeNotation'
88
import { getVariableTypeByValue } from './getVariableTypeByValue'
99
import roundWithDecimals from './roundWithDecimals'
10+
import { Settings } from '@typings/settings'
1011

1112
const extractVariable = (variable, value) => {
1213
let category: tokenCategoryType = 'color'
@@ -92,11 +93,13 @@ const processAliasModes = (variables) => {
9293
}, [])
9394
}
9495

95-
export const getVariables = (figma: PluginAPI, modeReference: boolean) => {
96+
export const getVariables = (figma: PluginAPI, settings: Settings) => {
97+
const excludedCollectionIds = figma.variables.getLocalVariableCollections().filter(collection => !['.', '_', ...settings.exclusionPrefix.split(',')].includes(collection.name.charAt(0))).map(collection => collection.id);
9698
// get collections
9799
const collections = Object.fromEntries(figma.variables.getLocalVariableCollections().map((collection) => [collection.id, collection]))
100+
98101
// get variables
99-
const variables = figma.variables.getLocalVariables().map((variable) => {
102+
const variables = figma.variables.getLocalVariables().filter(variable => excludedCollectionIds.includes(variable.variableCollectionId)).map((variable) => {
100103
// get collection name and modes
101104
const { variableCollectionId } = variable
102105
const { name: collection, modes } = collections[variableCollectionId]
@@ -105,11 +108,11 @@ export const getVariables = (figma: PluginAPI, modeReference: boolean) => {
105108
return {
106109
...extractVariable(variable, value),
107110
// name is contstructed from collection, mode and variable name
108-
name: modeReference ? `${collection}/${modes.find(({ modeId }) => modeId === id).name}/${variable.name}` : `${collection}/${variable.name}`,
111+
name: settings.modeReference ? `${collection}/${modes.find(({ modeId }) => modeId === id).name}/${variable.name}` : `${collection}/${variable.name}`,
109112
// add mnetadata to extensions
110113
extensions: {
111114
[config.key.extensionPluginData]: {
112-
mode: modeReference ? modes.find(({ modeId }) => modeId === id).name : undefined,
115+
mode: settings.modeReference ? modes.find(({ modeId }) => modeId === id).name : undefined,
113116
collection: collection,
114117
scopes: variable.scopes,
115118
[config.key.extensionVariableStyleId]: variable.id,
@@ -120,8 +123,5 @@ export const getVariables = (figma: PluginAPI, modeReference: boolean) => {
120123
})
121124
})
122125

123-
return modeReference ? processAliasModes(variables.flat()) : variables.flat();
124-
}
125-
126-
127-
126+
return settings.modeReference ? processAliasModes(variables.flat()) : variables.flat();
127+
}

0 commit comments

Comments
 (0)