-
Notifications
You must be signed in to change notification settings - Fork 69
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: expose --output-references CLI arg for building tokens, registers filters, and updates CSS vars format #3203
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
.PHONY: build | ||
build: | ||
rm -rf ./dist | ||
tsc --project tsconfig.build.json | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -85,11 +85,21 @@ const COMMANDS = { | |
description: 'Include only source design tokens in the build.', | ||
defaultValue: false, | ||
}, | ||
{ | ||
name: '--output-references', | ||
description: 'Include references in the build output.', | ||
defaultValue: true, | ||
}, | ||
{ | ||
name: '-t, --themes', | ||
description: 'Specify themes to include in the token build.', | ||
defaultValue: 'light', | ||
}, | ||
{ | ||
name: '-v, --verbose', | ||
description: 'Enable verbose logging.', | ||
defaultValue: false, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [inform] Improves the utility of warning/error messages resulting from |
||
}, | ||
], | ||
}, | ||
'replace-variables': { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,9 @@ | ||
const path = require('path'); | ||
const minimist = require('minimist'); | ||
const { initializeStyleDictionary, createCustomCSSVariables, colorTransform } = require('../tokens/style-dictionary'); | ||
const { | ||
initializeStyleDictionary, | ||
colorTransform, | ||
} = require('../tokens/style-dictionary'); | ||
const { createIndexCssFile } = require('../tokens/utils'); | ||
|
||
/** | ||
|
@@ -13,24 +16,37 @@ const { createIndexCssFile } = require('../tokens/utils'); | |
* @param {string|string[]} [commandArgs.themes=['light']] - The themes (variants) for which to build tokens. | ||
*/ | ||
async function buildTokensCommand(commandArgs) { | ||
const StyleDictionary = await initializeStyleDictionary(); | ||
|
||
const defaultParams = { | ||
themes: ['light'], | ||
'build-dir': './build/', | ||
'source-tokens-only': false, | ||
'output-references': true, | ||
verbose: false, | ||
}; | ||
|
||
const alias = { | ||
'build-dir': 'b', | ||
themes: 't', | ||
verbose: '-v', | ||
}; | ||
|
||
const { | ||
'build-dir': buildDir, | ||
source: tokensSource, | ||
'source-tokens-only': hasSourceTokensOnly, | ||
'output-references': outputReferences, | ||
themes, | ||
} = minimist(commandArgs, { alias, default: defaultParams, boolean: 'source-tokens-only' }); | ||
verbose, | ||
} = minimist( | ||
commandArgs, | ||
{ | ||
alias, | ||
default: defaultParams, | ||
boolean: ['source-tokens-only', 'output-references', 'verbose'], | ||
}, | ||
); | ||
|
||
const StyleDictionary = await initializeStyleDictionary({ themes }); | ||
|
||
const coreConfig = { | ||
include: [ | ||
|
@@ -43,33 +59,35 @@ async function buildTokensCommand(commandArgs) { | |
platforms: { | ||
css: { | ||
prefix: 'pgn', | ||
transformGroup: 'css', | ||
// NOTE: buildPath must end with a slash | ||
buildPath: buildDir.slice(-1) === '/' ? buildDir : `${buildDir}/`, | ||
options: { | ||
fileHeader: 'customFileHeader', | ||
}, | ||
files: [ | ||
{ | ||
format: 'css/custom-variables', | ||
destination: 'core/variables.css', | ||
filter: hasSourceTokensOnly ? 'isSource' : undefined, | ||
options: { | ||
outputReferences: !hasSourceTokensOnly, | ||
outputReferences, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [inform] Now relies on the CLI option; |
||
}, | ||
}, | ||
{ | ||
format: 'css/custom-media-breakpoints', | ||
destination: 'core/custom-media-breakpoints.css', | ||
filter: hasSourceTokensOnly ? 'isSource' : undefined, | ||
options: { | ||
outputReferences: !hasSourceTokensOnly, | ||
outputReferences, | ||
}, | ||
}, | ||
], | ||
transforms: StyleDictionary.hooks.transformGroups.css.filter(item => item !== 'size/rem').concat('color/sass-color-functions', 'str-replace'), | ||
options: { | ||
fileHeader: 'customFileHeader', | ||
}, | ||
}, | ||
}, | ||
log: { | ||
verbosity: verbose ? 'verbose' : 'default', | ||
}, | ||
}; | ||
|
||
const getStyleDictionaryConfig = (themeVariant) => ({ | ||
|
@@ -91,45 +109,56 @@ async function buildTokensCommand(commandArgs) { | |
transform: (token) => colorTransform(token, themeVariant), | ||
}, | ||
}, | ||
format: { | ||
'css/custom-variables': formatterArgs => createCustomCSSVariables({ | ||
formatterArgs, | ||
themeVariant, | ||
}), | ||
}, | ||
platforms: { | ||
css: { | ||
...coreConfig.platforms.css, | ||
files: [ | ||
{ | ||
format: 'css/custom-variables', | ||
destination: `themes/${themeVariant}/variables.css`, | ||
filter: hasSourceTokensOnly ? 'isSource' : undefined, | ||
filter: hasSourceTokensOnly | ||
? `isSource.${themeVariant}` | ||
: `isThemeVariant.${themeVariant}`, | ||
Comment on lines
+119
to
+121
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [inform] Currently, the registered format Note that other custom filters (e.g., There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just trying to wrap my head around this change a little bit. Before this change if There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Previously, There's some more detailed rationale about this change provided on my review of Peter's PR here, notably:
See the current implementation of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for the added context! 100% agree that it's better to have
than
|
||
options: { | ||
outputReferences: !hasSourceTokensOnly, | ||
outputReferences, | ||
}, | ||
}, | ||
{ | ||
format: 'css/utility-classes', | ||
destination: `themes/${themeVariant}/utility-classes.css`, | ||
filter: hasSourceTokensOnly ? 'isSource' : undefined, | ||
options: { | ||
outputReferences: !hasSourceTokensOnly, | ||
outputReferences, | ||
}, | ||
}, | ||
], | ||
}, | ||
}, | ||
}); | ||
|
||
new StyleDictionary(coreConfig).buildAllPlatforms(); | ||
createIndexCssFile({ buildDir, isTheme: false }); | ||
// Create list of style-dictionary configurations to build (core + theme variants) | ||
const configs = [ | ||
{ config: coreConfig }, | ||
...themes.map((themeVariant) => { | ||
const config = getStyleDictionaryConfig(themeVariant); | ||
return { | ||
config, | ||
themeVariant, | ||
}; | ||
}), | ||
]; | ||
|
||
themes.forEach(async (themeVariant) => { | ||
const config = getStyleDictionaryConfig(themeVariant); | ||
new StyleDictionary(config).buildAllPlatforms(); | ||
createIndexCssFile({ buildDir, isTheme: true, themeVariant }); | ||
}); | ||
// Build tokens for each configuration | ||
await Promise.all(configs.map(async ({ config, isThemeVariant, themeVariant }) => { | ||
const sd = new StyleDictionary(config); | ||
await sd.cleanAllPlatforms(); | ||
await sd.buildAllPlatforms(); | ||
createIndexCssFile({ | ||
buildDir, | ||
isThemeVariant: !!isThemeVariant, | ||
themeVariant, | ||
}); | ||
})); | ||
} | ||
|
||
module.exports = buildTokensCommand; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -52,7 +52,8 @@ | |
"prepare": "husky || true", | ||
"build-tokens": "./bin/paragon-scripts.js build-tokens --build-dir ./styles/css", | ||
"replace-variables-usage-with-css": "./bin/paragon-scripts.js replace-variables -p src -t usage", | ||
"replace-variables-definition-with-css": "./bin/paragon-scripts.js replace-variables -p src -t definition" | ||
"replace-variables-definition-with-css": "./bin/paragon-scripts.js replace-variables -p src -t definition", | ||
"cli:help": "./bin/paragon-scripts.js help" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [inform] Adds a way to run the CLI |
||
}, | ||
"dependencies": { | ||
"@popperjs/core": "^2.11.4", | ||
|
@@ -114,7 +115,7 @@ | |
"@babel/preset-typescript": "^7.16.7", | ||
"@edx/eslint-config": "^3.2.0", | ||
"@edx/stylelint-config-edx": "^2.3.0", | ||
"@edx/typescript-config": "^1.0.1", | ||
"@edx/typescript-config": "^1.1.0", | ||
adamstankiewicz marked this conversation as resolved.
Show resolved
Hide resolved
|
||
"@formatjs/cli": "^5.0.2", | ||
"@semantic-release/changelog": "^6.0.1", | ||
"@semantic-release/git": "^10.0.1", | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
.pgn__form-text { | ||
font-size: var(--pgn-typography-font-size-small-base); | ||
font-size: var(--pgn-typography-font-size-sm); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The token representing There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
We will also need to update the changed design tokens in the edx/elm-theme and ensure that in the consuming MFEs that have already switched to the design tokens in the test format, all tokens will be relevant. I have described this issue before, maybe we should come back to it in the future. Please let me know your thoughts. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @PKulkoRaccoonGang I have a draft PR brewing to account for Note: this linked PR also accounts for a few style bug fixes as well that I noticed while QA'ing
100% agreed we should explore opportunities for linting and/or other validation of tokens, but as a future initiative. |
||
display: flex; | ||
align-items: center; | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,12 +4,12 @@ | |
min-height: 36px; | ||
display: flex; | ||
flex-wrap: nowrap; | ||
font-size: var(--pgn-typography-font-size-small-x); | ||
font-size: var(--pgn-typography-font-size-xs); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The token representing |
||
background-color: var(--pgn-page-baner-bg, inherit); | ||
color: var(--pgn-page-baner-color, inherit); | ||
|
||
@include media-breakpoint-up(md) { | ||
font-size: var(--pgn-typography-font-size-small-base); | ||
font-size: var(--pgn-typography-font-size-sm); | ||
} | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[inform] Currently, running
build-tokens
with the CLI for a brand package (e.g.,@edx/elm-theme
), the CSS build output does not include the references, i.e. CSS variables, instead hardcoding the raw value.I believe we want to default to always including references, even for brand packages, to mitigate risk that updating a reference for a style property, won't change the actual style due to the missing use of the CSS variable.
However, I think it's also reasonable to not want this in some cases so having it be an option seems reasonable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
100% agree. Good call/addition!