Skip to content

Commit

Permalink
semi flattened object
Browse files Browse the repository at this point in the history
  • Loading branch information
CCAyl committed Aug 15, 2022
1 parent c0334f8 commit 6c94acf
Showing 1 changed file with 39 additions and 7 deletions.
46 changes: 39 additions & 7 deletions build.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,17 +59,49 @@ StyleDictionary.registerFormat({
fileHeader({ file }) +
Object.entries(dictionary.properties.colors)
.map((tokens) => {
return `export const ${tokens[0]} : {${Object.entries(tokens[1]).map(
(token) => {
return `${token[0]} : ${getTypeScriptType(token[1].value)}`;
}
)}};`;
const colorObj = tokens[0];
const filtered = dictionary.allTokens.filter(
(token) => token.attributes.type === colorObj
);
return (
`export const ${colorObj} : { ` +
filtered.map((token) => {
return `${token.name} : ${getTypeScriptType(token.value)}`;
}) +
`};`
);
})
.join(`\n`)
);
},
});

StyleDictionary.registerFormat({
name: `javascript/colors`,
formatter: ({ dictionary, file }) => {
return (
fileHeader({ file }) +
`module.exports = {` +
Object.entries(dictionary.properties.colors)
.map((tokens) => {
const colorObj = tokens[0];
const filtered = dictionary.allTokens.filter(
(token) => token.attributes.type === colorObj
);
return (
`${colorObj} : { ` +
filtered.map((token) => {
return `${token.name} : "${token.value}"`;
}) +
`},`
);
})
.join(`\n`) +
`};`
);
},
});

StyleDictionary.registerTransformGroup({
name: "custom/aviary",
transforms: [
Expand Down Expand Up @@ -130,7 +162,7 @@ const getStyleDictionaryConfig = (theme) => {
filter: "filter-typography",
},
{
format: "javascript/module-flat",
format: "javascript/colors",
destination: core ? "colors.js" : `themes/${theme}.js`,
filter: {
type: "color",
Expand Down Expand Up @@ -161,7 +193,7 @@ const getStyleDictionaryConfig = (theme) => {
filter: "filter-typography",
},
{
format: "javascript/module-flat",
format: "javascript/colors",
destination: core ? "colors.js" : `themes/${theme}.js`,
filter: {
type: "color",
Expand Down

0 comments on commit 6c94acf

Please sign in to comment.