Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Excluded collections containing a specific string from the export target #276

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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();
}