Skip to content

Commit

Permalink
build: upgrade to Style Dictionary v4 and experimental design token p…
Browse files Browse the repository at this point in the history
…ackage layout
  • Loading branch information
Robbert authored and Yolijn committed Oct 12, 2024
1 parent 275db34 commit 7fc1efc
Show file tree
Hide file tree
Showing 14 changed files with 574 additions and 388 deletions.
5 changes: 5 additions & 0 deletions .changeset/famous-knives-sparkle.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@utrecht/design-tokens": patch
---

Fix `propery.css` output. (The file was empty.)
5 changes: 5 additions & 0 deletions .changeset/popular-mugs-drop.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@utrecht/design-tokens": patch
---

No longer include `::backdrop` selectors, those are no longer needed in evergreen browsers.'
242 changes: 160 additions & 82 deletions pnpm-lock.yaml

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions proprietary/design-tokens/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"fullName": "Gemeente Utrecht",
"name": "Utrecht",
"prefix": "utrecht",
"npm": "@utrecht/design-tokens",
"cdn": "https://unpkg.com/@utrecht/design-tokens/dist/index.css",
"stories": []
}
8 changes: 4 additions & 4 deletions proprietary/design-tokens/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"directory": "proprietary/design-tokens"
},
"devDependencies": {
"@divriots/style-dictionary-to-figma": "0.4.0",
"@tokens-studio/sd-transforms": "1.2.3",
"chokidar-cli": "3.0.0",
"glob": "10.4.2",
"lodash.isplainobject": "4.0.6",
Expand All @@ -26,14 +26,14 @@
"regex-trie": "1.0.4",
"rimraf": "5.0.7",
"sass": "1.69.5",
"style-dictionary": "4.0.0-prerelease.8"
"style-dictionary": "4.0.1"
},
"scripts": {
"build": "pnpm run build:style-dictionary && pnpm run build:scss",
"build:scss": "sass --no-source-map src/:dist/",
"build:style-dictionary": "pnpm run '/^build:style-dictionary:.*/'",
"build:style-dictionary:default": "style-dictionary build --config src/style-dictionary-config.js",
"build:style-dictionary:dark": "style-dictionary build --config src/style-dictionary-config-dark.js",
"build:style-dictionary:default": "node ./style-dictionary-build.mjs",
"build:style-dictionary:dark": "node ./style-dictionary-build-dark.mjs",
"build:stylelint": "node ./build-stylelint.mjs",
"clean": "rimraf dist/",
"watch": "pnpm run --parallel '/^watch:.*/'",
Expand Down
35 changes: 0 additions & 35 deletions proprietary/design-tokens/src/css-property-formatter.js

This file was deleted.

46 changes: 46 additions & 0 deletions proprietary/design-tokens/src/css-property-formatter.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/**
* @license EUPL-1.2
* Copyright (c) 2021 Robbert Broersma
*/

const stringSort = (a, b) => (a === b ? 0 : a > b ? 1 : -1);

export const propertyFormatter = function ({ dictionary }) {
let { allTokens } = dictionary;

// https://drafts.css-houdini.org/css-properties-values-api/#the-css-property-rule-interface
const css = allTokens
.sort((tokenA, tokenB) => stringSort(tokenA.name, tokenB.name))
.filter(
(token) =>
token['$extensions'] &&
token['$extensions']['nl.nldesignsystem.css.property'] &&
token['$extensions']['nl.nldesignsystem.css.property'].syntax !== '*' &&
typeof token['$extensions']['nl.nldesignsystem.css.property'].inherits === 'boolean',
)
.map((token) => {
let str = `@property --${token.name} { `;
const cssProperty = token['$extensions']['nl.nldesignsystem.css.property'];

const syntax = Array.isArray(cssProperty.syntax) ? cssProperty.syntax.join(' | ') : cssProperty.syntax;

str += `syntax: '${syntax}'; `;

str += `inherits: ${cssProperty.inherits}; `;

if (cssProperty.initialValue) {
str += `initial-value: ${cssProperty.initialValue}; `;
}

str += `}`;

return str;
})
.join('\n');

return css;
};

export const propertyFormatterHooksConfig = {
'css/property': propertyFormatter,
};
7 changes: 2 additions & 5 deletions proprietary/design-tokens/src/index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@

@import "./responsive";

.utrecht-theme,
.utrecht-theme ::backdrop {
.utrecht-theme {
@include utrecht-theme;

utrecht-page-footer,
Expand All @@ -27,9 +26,7 @@

@media (prefers-color-scheme: dark) {
.utrecht-theme--media-query,
.utrecht-theme--media-query ::backdrop,
.utrecht-theme--media-query-color-scheme,
.utrecht-theme--media-query-color-scheme ::backdrop {
.utrecht-theme--media-query-color-scheme {
@include utrecht-theme--dark;
}
}
56 changes: 0 additions & 56 deletions proprietary/design-tokens/src/style-dictionary-config-dark.js

This file was deleted.

63 changes: 0 additions & 63 deletions proprietary/design-tokens/src/style-dictionary-config.js

This file was deleted.

64 changes: 64 additions & 0 deletions proprietary/design-tokens/style-dictionary-build-dark.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import { register } from '@tokens-studio/sd-transforms';
import StyleDictionary from 'style-dictionary';
import { typeDtcgDelegate } from 'style-dictionary/utils';
import { readFile } from 'node:fs/promises';
import { createStyleDictionaryConfig } from './style-dictionary-config.mjs';

const build = async () => {
const themeConfig = JSON.parse(await readFile('./config.json', 'utf-8'));
StyleDictionary.registerPreprocessor({
name: 'dtcg-delegate',
preprocessor: typeDtcgDelegate,
});

register(StyleDictionary, {
// TODO: Enable `excludeParentKeys` when Figma is the source of design tokens
// excludeParentKeys: true,
});

const config = {
...createStyleDictionaryConfig({
themeName: `${themeConfig.prefix}-theme--dark`,
}),
log: 'warn',
preprocessors: ['tokens-studio', 'dtcg-delegate'],
source: [
'../../components/**/tokens.json',
'../../components/**/*.tokens.json',
'./src/brand/tokens.json',
'./src/brand/**/*.tokens.json',
'./src/common/tokens.json',
'./src/common/**/*.tokens.json',
'./src/component/tokens.json',
'./src/component/**/*.tokens.json',

// Additional dark theme tokens
'./src/dark/tokens.json',
'./src/dark/*.tokens.json',
'./src/dark/**/tokens.json',
'./src/dark/**.tokens.json',
],
};

Object.values(config.platforms).forEach((platform) => {
platform.buildPath = 'dist/dark/';

if (Array.isArray(platform.files)) {
platform.files.forEach((file) => {
if (file.destination === 'variables.css') {
file.options.selector = '.utrecht-theme--dark, .utrecht-theme--dark ::backdrop';
}
if (file.destination === '_mixin.scss') {
file.options.selector = '@mixin utrecht-theme--dark';
}
});
}
});

const sd = new StyleDictionary(config);

await sd.cleanAllPlatforms();
await sd.buildAllPlatforms();
};

build();
41 changes: 41 additions & 0 deletions proprietary/design-tokens/style-dictionary-build.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { register } from '@tokens-studio/sd-transforms';
import StyleDictionary from 'style-dictionary';
import { typeDtcgDelegate } from 'style-dictionary/utils';
import { readFile } from 'node:fs/promises';
import { createStyleDictionaryConfig } from './style-dictionary-config.mjs';

const build = async () => {
const themeConfig = JSON.parse(await readFile('./config.json', 'utf-8'));
StyleDictionary.registerPreprocessor({
name: 'dtcg-delegate',
preprocessor: typeDtcgDelegate,
});

register(StyleDictionary, {
// TODO: Enable `excludeParentKeys` when Figma is the source of design tokens
// excludeParentKeys: true,
});

const sd = new StyleDictionary({
...createStyleDictionaryConfig({
themeName: `${themeConfig.prefix}-theme`,
}),
log: 'warn',
preprocessors: ['tokens-studio', 'dtcg-delegate'],
source: [
'../../components/**/tokens.json',
'../../components/**/*.tokens.json',
'./src/brand/tokens.json',
'./src/brand/**/*.tokens.json',
'./src/common/tokens.json',
'./src/common/**/*.tokens.json',
'./src/component/tokens.json',
'./src/component/**/*.tokens.json',
],
});

await sd.cleanAllPlatforms();
await sd.buildAllPlatforms();
};

build();
Loading

0 comments on commit 7fc1efc

Please sign in to comment.