Skip to content

Commit

Permalink
working on size tokens
Browse files Browse the repository at this point in the history
  • Loading branch information
lukasoppermann committed Jul 6, 2023
1 parent 3bbbc54 commit 8eae656
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
22 changes: 12 additions & 10 deletions scripts/buildPlatforms/buildFigma.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,13 @@ export const buildFigma = (buildOptions: ConfigGeneratorOptions): void => {
},
}).buildAllPlatforms()
}
// // build base scales
// PrimerStyleDictionary.extend(
// // using includes as source
// getStyleDictionaryConfig(`base/size/size`, ['src/tokens/base/size/size.json'], [], {
// buildPath: buildOptions.buildPath,
// prefix: undefined,
// }),
// ).buildAllPlatforms()
// build base scales
PrimerStyleDictionary.extend({
source: ['src/tokens/base/size/size.json'],
platforms: {
figma: figma(`figma/base/size.json`, buildOptions.prefix, buildOptions.buildPath),
},
}).buildAllPlatforms()

/** -----------------------------------
* Create list of files
Expand All @@ -92,11 +91,14 @@ export const buildFigma = (buildOptions: ConfigGeneratorOptions): void => {
return localFiles.map(file => `${buildOptions.buildPath}figma/${dir}/${file}`)
})

const tokens = files.flatMap(filePath => JSON.parse(fs.readFileSync(filePath, 'utf8')))
const tokens: {
collection: string
mode: string
}[] = files.flatMap(filePath => JSON.parse(fs.readFileSync(filePath, 'utf8')))
const collections: Record<string, string[]> = {}

for (const {collection, mode} of tokens) {
if (!collections[collection]) {
if (!(collection in collections)) {
collections[collection] = []
}
if (!collections[collection].includes(mode)) {
Expand Down
4 changes: 3 additions & 1 deletion src/transformers/figmaMode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ import type StyleDictionary from 'style-dictionary'
export const figmaMode: StyleDictionary.Transform = {
type: `attribute`,
transformer: (token: StyleDictionary.TransformedToken, platform: StyleDictionary.Platform = {}) => {
const {mode, collection} = token.$extension?.['org.primer.figma'] || {}
return {
mode: platform.options?.mode || token.mode || 'default',
mode: platform.options?.mode || mode || 'default',
collection,
}
},
}

0 comments on commit 8eae656

Please sign in to comment.