Skip to content

Commit

Permalink
Transform VADS tokens. Add custom formatter to remove 'color' prefix.…
Browse files Browse the repository at this point in the history
… Export as Colors
  • Loading branch information
narin committed Jan 17, 2024
1 parent 7118672 commit 42f7489
Showing 1 changed file with 36 additions and 2 deletions.
38 changes: 36 additions & 2 deletions packages/tokens/config.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,34 @@
/* eslint-disable @typescript-eslint/no-var-requires */
const tokenCategories = require('./src/tokens')
const StyleDictionary = require('style-dictionary')

StyleDictionary.registerFormat({
name: 'javascript/es6/vads-colors',
formatter: function (dictionary) {
console.log(`dictionary`, dictionary)
const colorTokens = dictionary.allProperties
.filter((token) => token.attributes.category === 'color')
.reduce((result, token) => {
result[token.name.replace('color', '')] = token.value
return result
}, {})

return `export const Colors = ${JSON.stringify(colorTokens, null, 2)};`
},
})

StyleDictionary.registerFormat({
name: 'typescript/es6-declarations/colors',
formatter: function () {
return `export declare const Colors: { [key: string]: string };`
},
})

module.exports = {
source: ['src/tokens/**/*.json'],
source: [
'../../node_modules/@department-of-veterans-affairs/css-library/dist/tokens/json/variables.json',
// 'src/uswds/*.json',
],
platforms: {
rn: {
transformGroup: 'react-native',
Expand All @@ -14,8 +40,16 @@ module.exports = {
format: 'javascript/es6',
},
{
format: 'typescript/es6-declarations',
destination: 'js/index.js',
format: 'javascript/es6/vads-colors',
},
// {
// format: 'typescript/es6-declarations',
// destination: 'index.d.ts',
// },
{
destination: 'index.d.ts',
format: 'typescript/es6-declarations/colors',
},
],
},
Expand Down

0 comments on commit 42f7489

Please sign in to comment.