Skip to content

Commit 161f797

Browse files
step 1: add custom variable formatter
1 parent dc7190e commit 161f797

File tree

10 files changed

+451
-35
lines changed

10 files changed

+451
-35
lines changed

.changeset/violet-lemons-greet.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@primer/primitives': minor
3+
---
4+
5+
Enable token references in composite tokens

eslint.config.mjs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ export default tseslint.config([
2525
...eslintPluginReactHooks.configs.recommended.rules,
2626
...eslintPluginReact.configs['jsx-runtime'].rules,
2727
...eslintPluginGithub.getFlatConfigs().rules,
28+
'eslint-comments/no-use': 'off',
2829
},
2930
},
3031
eslintPluginPrettierRecommended,
@@ -70,6 +71,7 @@ export default tseslint.config([
7071
},
7172
// rules which apply to JS, TS, etc.
7273
rules: {
74+
'eslint-comments/no-use': 'off',
7375
'i18n-text/no-en': 0,
7476
'importPlugin/no-nodejs-modules': 'off',
7577
'importPlugin/extensions': [
@@ -111,7 +113,7 @@ export default tseslint.config([
111113
{
112114
files: ['**/*.{js,jsx}'],
113115
rules: {
114-
'eslint-comments/no-use': 0,
116+
'eslint-comments/no-use': 'off',
115117
'import/no-namespace': 0,
116118
'no-shadow': 0,
117119
'import/no-commonjs': 0,
@@ -138,6 +140,7 @@ export default tseslint.config([
138140
},
139141
files: ['**/*.{ts,tsx}'],
140142
rules: {
143+
'eslint-comments/no-use': 'off',
141144
'no-shadow': 'off',
142145
'@typescript-eslint/no-shadow': 'error',
143146
'@typescript-eslint/no-explicit-any': 2,
@@ -157,6 +160,7 @@ export default tseslint.config([
157160
{
158161
files: ['**/*.test.{ts,tsx,js,jsx}'],
159162
rules: {
163+
'eslint-comments/no-use': 'off',
160164
'i18n-text/no-en': 0,
161165
},
162166
},

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,10 @@
6262
"console-table-printer": "^2.12.1",
6363
"eslint": "9.16",
6464
"eslint-config-prettier": "^9.1.0",
65-
"eslint-plugin-react": "7.37",
6665
"eslint-import-resolver-typescript": "3.6",
6766
"eslint-plugin-github": "^5.1.3",
6867
"eslint-plugin-jsx-a11y": "6.10",
68+
"eslint-plugin-react": "7.37",
6969
"eslint-plugin-react-hooks": "^5.0.0",
7070
"json5": "^2.2.1",
7171
"markdown-table-ts": "^1.0.3",

scripts/buildTokens.ts

Lines changed: 32 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type {Config} from 'style-dictionary/types'
1+
import type {Config, LogConfig} from 'style-dictionary/types'
22
import {PrimerStyleDictionary} from '../src/primerStyleDictionary.js'
33
import {copyFromDir} from '../src/utilities/index.js'
44
import {deprecatedJson, css, docJson, fallbacks, styleLint} from '../src/platforms/index.js'
@@ -12,6 +12,14 @@ import {themes} from './themes.config.js'
1212
import fs from 'fs'
1313
import {getFallbackTheme} from './utilities/getFallbackTheme.js'
1414

15+
const log: LogConfig = {
16+
warnings: 'disabled', // 'warn' | 'error' | 'disabled'
17+
verbosity: 'silent', // 'default' | 'silent' | 'verbose'
18+
errors: {
19+
brokenReferences: 'throw', // 'throw' | 'console'
20+
},
21+
}
22+
1523
/**
1624
* getStyleDictionaryConfig
1725
* @param filename output file name without extension
@@ -29,21 +37,15 @@ const getStyleDictionaryConfig: StyleDictionaryConfigGenerator = (
2937
): Config => ({
3038
source, // build the special formats
3139
include,
32-
log: {
33-
warnings: 'disabled', // 'warn' | 'error' | 'disabled'
34-
verbosity: 'silent', // 'default' | 'silent' | 'verbose'
35-
errors: {
36-
brokenReferences: 'throw', // 'throw' | 'console'
37-
},
38-
},
40+
log,
3941
platforms: Object.fromEntries(
4042
Object.entries({
4143
css: css(`css/${filename}.css`, options.prefix, options.buildPath, {
4244
themed: options.themed,
43-
theme: options.theme,
45+
theme: [options.theme, getFallbackTheme(options.theme)],
4446
}),
4547
docJson: docJson(`docs/${filename}.json`, options.prefix, options.buildPath, {
46-
theme: options.theme,
48+
theme: [options.theme, getFallbackTheme(options.theme)],
4749
}),
4850
styleLint: styleLint(`styleLint/${filename}.json`, options.prefix, options.buildPath, {
4951
theme: options.theme,
@@ -58,25 +60,26 @@ export const buildDesignTokens = async (buildOptions: ConfigGeneratorOptions): P
5860
/** -----------------------------------
5961
* Internal Colors
6062
* ----------------------------------- */
61-
try {
62-
for (const {filename, source, include, theme} of themes) {
63-
// build functional scales
64-
const extendedSD = await PrimerStyleDictionary.extend({
65-
source: [...source, ...include], // build the special formats
66-
include,
67-
platforms: {
68-
css: css(`internalCss/${filename}.css`, buildOptions.prefix, buildOptions.buildPath, {
69-
themed: true,
70-
theme: [theme, getFallbackTheme(theme)],
71-
}),
72-
},
73-
})
74-
await extendedSD.buildAllPlatforms()
75-
}
76-
} catch (e) {
77-
// eslint-disable-next-line no-console
78-
console.error('🛑 Error trying to build internal css colors for code output:', e)
79-
}
63+
// try {
64+
// for (const {filename, source, include, theme} of themes) {
65+
// // build functional scales
66+
// const extendedSD = await PrimerStyleDictionary.extend({
67+
// source: [...source, ...include], // build the special formats
68+
// include,
69+
// log,
70+
// platforms: {
71+
// css: css(`internalCss/${filename}.css`, buildOptions.prefix, buildOptions.buildPath, {
72+
// themed: true,
73+
// theme: [theme, getFallbackTheme(theme)],
74+
// }),
75+
// },
76+
// })
77+
// await extendedSD.buildAllPlatforms()
78+
// }
79+
// } catch (e) {
80+
// // eslint-disable-next-line no-console
81+
// console.error('🛑 Error trying to build internal css colors for code output:', e)
82+
// }
8083

8184
/** -----------------------------------
8285
* Colors, shadows & borders

src/formats/cssAdvanced.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import type {TransformedToken, FormatFn, FormatFnArguments, FormattingOptions} from 'style-dictionary/types'
22
import {format} from 'prettier'
3-
import {fileHeader, formattedVariables, sortByName} from 'style-dictionary/utils'
3+
import {fileHeader, sortByName} from 'style-dictionary/utils'
4+
import getFormattedVariables from './utilities/getFormattedVariables.js'
45

56
const wrapWithSelector = (css: string, selector: string | false): string => {
67
// return without selector
@@ -74,7 +75,7 @@ export const cssAdvanced: FormatFn = async ({
7475
// early abort if no matches
7576
if (!filteredDictionary.allTokens.length) continue
7677
// add tokens into root
77-
const css = formattedVariables({
78+
const css = getFormattedVariables({
7879
format: 'css',
7980
dictionary: filteredDictionary,
8081
outputReferences,

0 commit comments

Comments
 (0)