From 26cd064a89bd340d47e057f34890c02afef46ecc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oliver=20Sch=C3=BCrch?= Date: Thu, 18 Jul 2024 08:12:45 +0200 Subject: [PATCH] test(workflows): build-tokens --- .github/workflows/build-documentation.yaml | 2 +- .github/workflows/build-tokens.yaml | 11 ++++++++--- packages/documentation/update | 0 packages/tokens/build.js | 10 ++++------ 4 files changed, 13 insertions(+), 10 deletions(-) create mode 100644 packages/documentation/update diff --git a/.github/workflows/build-documentation.yaml b/.github/workflows/build-documentation.yaml index 168fd01d45..cb0bcdb1ed 100644 --- a/.github/workflows/build-documentation.yaml +++ b/.github/workflows/build-documentation.yaml @@ -26,7 +26,7 @@ jobs: uses: actions/checkout@v4 - name: Create preview message - uses: ./.github/actions/preview/message/create + uses: swisspost/design-system/.github/actions/preview/message/create with: access-token: ${{ secrets.SWISSPOSTDEVS_ACCESS_TOKEN }} diff --git a/.github/workflows/build-tokens.yaml b/.github/workflows/build-tokens.yaml index d463475e55..1dd0aebfc3 100644 --- a/.github/workflows/build-tokens.yaml +++ b/.github/workflows/build-tokens.yaml @@ -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') })) @@ -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 diff --git a/packages/documentation/update b/packages/documentation/update new file mode 100644 index 0000000000..e69de29bb2 diff --git a/packages/tokens/build.js b/packages/tokens/build.js index b6d126d193..c788960ace 100644 --- a/packages/tokens/build.js +++ b/packages/tokens/build.js @@ -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( @@ -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( @@ -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,