Skip to content

Commit

Permalink
test(workflows): build-tokens
Browse files Browse the repository at this point in the history
  • Loading branch information
oliverschuerch committed Jul 18, 2024
1 parent 4db0dcc commit 3c73c4c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
11 changes: 8 additions & 3 deletions .github/workflows/build-tokens.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:
const inputFileNames = fs.readdirSync('packages/tokens/tokensstudio-generated')
const inputFiles = inputFileNames.map(fileName => ({
type: path.extname(fileName),
type: path.extname(fileName).replace(/^\./, ''),
name: fileName,
content: fs.readFileSync(`packages/tokens/tokensstudio-generated/${fileName}`, 'utf8')
}))
Expand All @@ -48,10 +48,15 @@ jobs:
]
const outputFileNames = fs.readdirSync('packages/tokens/dist')
const outputFiles = outputFileNames.map(fileName => ({
type: path.extname(fileName),
type: path.extname(fileName).replace(/^\./, ''),
name: fileName,
content: fs.readFileSync(`packages/tokens/dist/${fileName}`, 'utf8')
})).sort((a, b) => (outputOrder.includes(a.name) ? outputOrder.indexOf(a.name) : 1000) - (outputOrder.includes(b.name) ? outputOrder.indexOf(b.name) : 1000))
}))
.map(({ type, name, content }) => {
if (type === 'scss') content = content.replaceAll('\n\n', '\n \n').replaceAll('$', '$').replaceAll(' ', '  ')
return { type, name, content }
})
.sort((a, b) => (outputOrder.includes(a.name) ? outputOrder.indexOf(a.name) : 1000) - (outputOrder.includes(b.name) ? outputOrder.indexOf(b.name) : 1000))
return `# Token Build
## Input
Expand Down
10 changes: 4 additions & 6 deletions packages/tokens/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ StyleDictionary.registerFormat({

if (usesReferences(token.original.value)) {
try {
if (typeof token.original.value === 'object') {
if (token.type === 'typography') {
tokenValue = Object.entries(token.original.value).reduce(
(values, [key, value], i) =>
`${values}${getSeparator(
Expand All @@ -90,12 +90,8 @@ StyleDictionary.registerFormat({
)}${getReference(value)}`,
'',
);
} else if (typeof token.original.value === 'string') {
tokenValue = getReference(token.original.value);
} else {
throw new Error(
`\x1b[31mError: Unsupported value type in token \x1b[33m"${tokenName}"\x1b[31m within tokenset \x1b[33m"${dataSetName}"!\x1b[0m`,
);
tokenValue = getReference(token.original.value);
}
} catch (error) {
console.error(
Expand Down Expand Up @@ -125,6 +121,8 @@ StyleDictionary.registerFormat({
}

function getSeparator(pKey = '', cKey = '') {
if (pKey === '') return '';

return (
MULTIVALUE_SEPARATOR_RULES.find(
rule => rule.previousKey === pKey && rule.currentKey === cKey,
Expand Down

0 comments on commit 3c73c4c

Please sign in to comment.