-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(all): #1153 switch to DTCG token format & migrate to latest style…
…dictionary and ts-transform (#1160) * using SD v4.00 and latest tokenStudio transforms * adds function to write themes_generated.cjs * removes themes.mjs * dynamically generated theme names and utilize them * renames theme: light -> light_value * renames theme: dark -> dark_value * moves radios.css into radio and radio-group directories
- Loading branch information
1 parent
44a8b05
commit 6f91b28
Showing
113 changed files
with
8,677 additions
and
8,189 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 3 additions & 3 deletions
6
packages/figma-design-tokens/config/generate-json-structure.mjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,15 @@ | ||
import fs from 'fs'; | ||
|
||
import { componentTokens } from '../../ui-library/src/foundation/_tokens-generated/__component-tokens.Light.generated.mjs'; | ||
import { semanticTokens } from '../../ui-library/src/foundation/_tokens-generated/__semantic-tokens.Light.generated.mjs'; | ||
import { componentTokens } from '../../ui-library/src/foundation/_tokens-generated/__component-tokens.Light_value.generated.mjs'; | ||
import { semanticTokens } from '../../ui-library/src/foundation/_tokens-generated/__semantic-tokens.Light_value.generated.mjs'; | ||
|
||
const componentFileOutput = JSON.stringify(componentTokens); | ||
const semanticFileOutput = JSON.stringify(semanticTokens); | ||
|
||
fs.writeFileSync( | ||
`../ui-library/src/foundation/_tokens-generated/component.generated.json`, | ||
componentFileOutput, | ||
'utf-8' | ||
'utf-8', | ||
); | ||
|
||
fs.writeFileSync(`../ui-library/src/foundation/_tokens-generated/semantic.generated.json`, semanticFileOutput, 'utf-8'); |
92 changes: 0 additions & 92 deletions
92
packages/figma-design-tokens/config/style-dictionary.config.cjs
This file was deleted.
Oops, something went wrong.
153 changes: 153 additions & 0 deletions
153
packages/figma-design-tokens/config/style-dictionary.config.mjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,153 @@ | ||
// get an themes array not needed anymore if we derive themes from $themes.json | ||
// import * as hardCodedThemes from './themes.cjs'; | ||
// console.log(hardCodedThemes.array); | ||
|
||
import { register, permutateThemes, expandTypesMap, excludeParentKeys } from '@tokens-studio/sd-transforms'; | ||
import StyleDictionary from 'style-dictionary'; | ||
import { fileHeader, minifyDictionary } from 'style-dictionary/utils'; | ||
import * as fs from 'fs'; | ||
import { Buffer } from 'node:buffer'; | ||
|
||
register(StyleDictionary, { | ||
/* options here if needed */ | ||
}); | ||
|
||
//-- registered formats | ||
StyleDictionary.registerFormat({ | ||
name: 'custom/format/semanticTokens', | ||
format: async ({ dictionary, file }) => { | ||
const tokenObj = dictionary.tokens; | ||
return ( | ||
(await fileHeader({ file })) + `export const semanticTokens = ` + JSON.stringify(minifyDictionary(tokenObj, true)) | ||
); | ||
}, | ||
}); | ||
|
||
StyleDictionary.registerFormat({ | ||
name: 'custom/format/componentTokens', | ||
format: async ({ dictionary, file }) => { | ||
const tokenObj = dictionary.tokens; | ||
return ( | ||
(await fileHeader({ file })) + | ||
`export const componentTokens = ` + | ||
JSON.stringify(minifyDictionary(tokenObj, true)) | ||
); | ||
}, | ||
}); | ||
|
||
StyleDictionary.registerFormat({ | ||
name: 'custom/format/componentConfig', | ||
format: async ({ dictionary, file }) => { | ||
const tokenObj = dictionary.tokens; | ||
return ( | ||
(await fileHeader({ file })) + | ||
`export const componentConfig = ` + | ||
JSON.stringify(minifyDictionary(tokenObj, true)) | ||
); | ||
}, | ||
}); | ||
|
||
//registered custom transforms | ||
StyleDictionary.registerTransform({ | ||
type: `value`, | ||
name: `custom/strReplace`, | ||
transitive: true, | ||
filter: (token) => typeof token.value === 'string', | ||
transform: (token) => token.value.replace('pxpx', 'px'), | ||
}); | ||
|
||
// directory where our tokens live | ||
const tokenDir = './input/tokens/'; | ||
|
||
// generate themes file | ||
function writeThemesFile(themesObj) { | ||
console.log('themes:'); | ||
console.log(themesObj); | ||
const themes = JSON.stringify(Object.keys(themesObj)); | ||
|
||
console.log(`Themes: ${themes}`); | ||
|
||
const data = new Uint8Array(Buffer.from(`const themes = ${themes} \nexports.array = themes;`)); | ||
fs.writeFile('./config/themes_generated.cjs', data, (err) => { | ||
if (err) throw err; | ||
console.log(`\nThe file 'themes_generated.cjs' has been saved!`); | ||
}); | ||
} | ||
|
||
// # # # # # # # # # # | ||
// main process | ||
// # # # # # # # # # # | ||
|
||
async function run() { | ||
const $themes = JSON.parse(fs.readFileSync(`${tokenDir}$themes.json`, 'utf-8')); | ||
|
||
const themes = permutateThemes($themes, { separator: '_' }); | ||
writeThemesFile(themes); | ||
|
||
// This is an interim solution. We should switch to using permutatedThemes everywhere | ||
// const translateThemesToHardCoded = { | ||
// Light_value: 'Light', | ||
// Dark_value: 'Dark', | ||
// }; | ||
|
||
const config = Object.entries(themes).map(([name, tokensets]) => { | ||
// const src = tokensets.map((tokenset) => `${tokenset}.json`); | ||
// console.log(src); | ||
return { | ||
source: tokensets.map((tokenset) => `${tokenDir}${tokenset}.json`), | ||
preprocessors: ['tokens-studio'], // <-- since 0.16.0 this must be explicit | ||
expand: { | ||
typesMap: expandTypesMap, | ||
}, | ||
platforms: { | ||
js: { | ||
transforms: [ | ||
'attribute/cti', | ||
'name/pascal', | ||
'ts/resolveMath', | ||
'ts/size/px', | ||
'ts/typography/fontWeight', | ||
'custom/strReplace', | ||
], | ||
buildPath: '../ui-library/src/foundation/_tokens-generated/', | ||
files: [ | ||
{ | ||
format: 'custom/format/semanticTokens', | ||
destination: `__semantic-tokens.${name}.generated.mjs`, | ||
// destination: `__semantic-tokens.${translateThemesToHardCoded[name]}.generated.mjs`, | ||
filter: (token) => { | ||
return token.attributes.category === 'sem'; | ||
}, | ||
}, | ||
{ | ||
format: 'custom/format/componentTokens', | ||
destination: `__component-tokens.${name}.generated.mjs`, | ||
// destination: `__component-tokens.${translateThemesToHardCoded[name]}.generated.mjs`, | ||
filter: (token) => { | ||
return token.attributes.category === 'cmp' && token.$type !== 'componentConfig'; | ||
}, | ||
}, | ||
{ | ||
format: 'custom/format/componentConfig', | ||
destination: 'config-tokens/__component-config.generated.mjs', | ||
filter: (token) => { | ||
return token.$type === 'componentConfig'; | ||
}, | ||
}, | ||
], | ||
}, | ||
}, | ||
}; | ||
}); | ||
|
||
async function cleanAndBuild(cfg) { | ||
// console.log(cfg); | ||
const sd = new StyleDictionary(cfg); | ||
await sd.cleanAllPlatforms(); // optionally, cleanup files first.. | ||
await sd.buildAllPlatforms(); | ||
} | ||
|
||
await Promise.all(config.map(cleanAndBuild)); | ||
} | ||
|
||
run(); |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
const themes = ["Light_value","Dark_value"] | ||
exports.array = themes; |
23 changes: 0 additions & 23 deletions
23
packages/figma-design-tokens/config/transforms/__README.md
This file was deleted.
Oops, something went wrong.
9 changes: 0 additions & 9 deletions
9
packages/figma-design-tokens/config/transforms/_font-to-rem.js
This file was deleted.
Oops, something went wrong.
13 changes: 0 additions & 13 deletions
13
packages/figma-design-tokens/config/transforms/_font-weight.js
This file was deleted.
Oops, something went wrong.
11 changes: 0 additions & 11 deletions
11
packages/figma-design-tokens/config/transforms/_resolve-math.js
This file was deleted.
Oops, something went wrong.
9 changes: 0 additions & 9 deletions
9
packages/figma-design-tokens/config/transforms/_str-replace-pxpx.js
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.