Skip to content

Commit

Permalink
build: switch to custom token-transformer script with exclude list
Browse files Browse the repository at this point in the history
  • Loading branch information
Robbert committed Jul 29, 2024
1 parent 2256c38 commit 06f7690
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 2 deletions.
4 changes: 2 additions & 2 deletions proprietary/design-tokens/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
"url": "git@github.com:nl-design-system/rijkshuisstijl-community.git"
},
"scripts": {
"clean": "rimraf dist/",
"clean": "rimraf dist/* src/generated/*",
"build": "npm-run-all clean build:figma-tokens build:style-dictionary",
"build:figma-tokens": "token-transformer --throwErrorWhenNotResolved=true figma/*.tokens.json src/generated/figma.tokens.json",
"build:figma-tokens": "node ./token-transformer.mjs",
"build:scss": "sass --no-source-map src/:dist/",
"build:style-dictionary": "style-dictionary build --config ./style-dictionary.config.json",
"watch": "npm-run-all watch:**",
Expand Down
71 changes: 71 additions & 0 deletions proprietary/design-tokens/token-transformer.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import { transformTokens } from 'token-transformer';
import { readFile, writeFile, mkdir } from 'node:fs/promises';
import { dirname } from 'node:path';

const init = async ({ input, output }) => {
const json = await readFile(input, 'utf-8');
const rawTokens = JSON.parse(json);

const setsToUse = [];

// The following components didn't work yet because of broken design token references.
// You can remove excludes from this list at any time, as long as they don't break the build.
const excludes = [
'components/accordion',
'components/alert',
'components/avatar',
'components/backdrop',
'components/blockquote',
'components/breadcrumb',
'components/button-group',
'components/checkbox',
'components/checkbox-group',
'components/counter-badge',
'components/drawer',
'components/form-field-error-message',
'components/form-field-option-label',
'components/form-field-radio-option',
'components/heading',
'components/icon-only-button',
'components/modal-dialog',
'components/ordered-list',
'components/pagination',
'components/paragraph',
'components/radio',
'components/radio-group',
'components/select',
'components/separator',
'components/side-nav',
'components/skip-link',
'components/status-badge',
'components/summary-list',
'components/table',
'components/task-list',
'components/textarea',
'components/toolbar-button',
'components/unordered-list',
];

const transformerOptions = {
// expandTypography: true,
// expandShadow: true,
// expandComposition: true,
// expandBorder: true,
// preserveRawValue: false,
// throwErrorWhenNotResolved: true,
// resolveReferences: true,
};

let resolved = transformTokens(rawTokens, setsToUse, excludes, transformerOptions);

delete resolved['tokenSetOrder'];

await mkdir(dirname(output), { recursive: true });

await writeFile(output, JSON.stringify(resolved, null, 2));
};

init({
input: './figma/figma.tokens.json',
output: './src/generated/figma.tokens.json',
});

0 comments on commit 06f7690

Please sign in to comment.