generated from nl-design-system/example
-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
build: upgrade to Style Dictionary v4 and experimental design token p…
…ackage layout
- Loading branch information
Showing
14 changed files
with
574 additions
and
388 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.' |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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": [] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 0 additions & 56 deletions
56
proprietary/design-tokens/src/style-dictionary-config-dark.js
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); |
Oops, something went wrong.