-
Notifications
You must be signed in to change notification settings - Fork 72
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: move design tokens CLI commands to paragon CLI (#2609)
* feat: move cli design tokens to paragon cli * feat: update paths for build-tokens.js * feat: added descriptions for CLI commands * refactor: removed commander implementation * refactor: added build-scss process status * feat: added ora compilation status * refactor: code refactoring * feat: added help description for single command * refactor: after review * refactor: refactoring after review * chore: update docs and cli params parsing --------- Co-authored-by: monteri <lansevermore> Co-authored-by: PKulkoRaccoonGang <[email protected]> Co-authored-by: Viktor Rusakov <[email protected]>
- Loading branch information
1 parent
3ec0c07
commit 23a9519
Showing
9 changed files
with
342 additions
and
218 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
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 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 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,119 @@ | ||
const path = require('path'); | ||
const minimist = require('minimist'); | ||
const { StyleDictionary, colorTransform, createCustomCSSVariables } = require('../tokens/style-dictionary'); | ||
const { createIndexCssFile } = require('../tokens/utils'); | ||
|
||
/** | ||
* Builds tokens for CSS styles from JSON source files. | ||
* | ||
* @param {string[]} commandArgs - Command line arguments for building tokens. | ||
* @param {string} [commandArgs.build-dir='./build/'] - The directory where the build output will be placed. | ||
* @param {string} [commandArgs.source] - The source directory containing JSON token files. | ||
* @param {boolean} [commandArgs.source-tokens-only=false] - Indicates whether to include only source tokens. | ||
* @param {string|string[]} [commandArgs.themes=['light']] - The themes (variants) for which to build tokens. | ||
*/ | ||
async function buildTokensCommand(commandArgs) { | ||
const defaultParams = { | ||
themes: ['light'], | ||
'build-dir': './build/', | ||
}; | ||
|
||
const alias = { | ||
'build-dir': 'b', | ||
themes: 't', | ||
}; | ||
|
||
const { | ||
'build-dir': buildDir, | ||
source: tokensSource, | ||
'source-tokens-only': hasSourceTokensOnly, | ||
themes, | ||
} = minimist(commandArgs, { alias, default: defaultParams, boolean: 'source-tokens-only' }); | ||
|
||
const coreConfig = { | ||
include: [path.resolve(__dirname, '../tokens/src/core/**/*.json')], | ||
source: tokensSource ? [`${tokensSource}/core/**/*.json`] : [], | ||
platforms: { | ||
css: { | ||
prefix: 'pgn', | ||
transformGroup: 'css', | ||
// NOTE: buildPath must end with a slash | ||
buildPath: buildDir.slice(-1) === '/' ? buildDir : `${buildDir}/`, | ||
files: [ | ||
{ | ||
format: 'css/custom-variables', | ||
destination: 'core/variables.css', | ||
filter: hasSourceTokensOnly ? 'isSource' : undefined, | ||
options: { | ||
outputReferences: !hasSourceTokensOnly, | ||
}, | ||
}, | ||
{ | ||
format: 'css/custom-media-breakpoints', | ||
destination: 'core/custom-media-breakpoints.css', | ||
filter: hasSourceTokensOnly ? 'isSource' : undefined, | ||
options: { | ||
outputReferences: !hasSourceTokensOnly, | ||
}, | ||
}, | ||
], | ||
transforms: StyleDictionary.transformGroup.css.filter(item => item !== 'size/rem').concat('color/sass-color-functions', 'str-replace'), | ||
options: { | ||
fileHeader: 'customFileHeader', | ||
}, | ||
}, | ||
}, | ||
}; | ||
|
||
const getStyleDictionaryConfig = (themeVariant) => ({ | ||
...coreConfig, | ||
include: [...coreConfig.include, path.resolve(__dirname, `../tokens/src/themes/${themeVariant}/**/*.json`)], | ||
source: tokensSource ? [`${tokensSource}/themes/${themeVariant}/**/*.json`] : [], | ||
transform: { | ||
'color/sass-color-functions': { | ||
...StyleDictionary.transform['color/sass-color-functions'], | ||
transformer: (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, | ||
options: { | ||
outputReferences: !hasSourceTokensOnly, | ||
}, | ||
}, | ||
{ | ||
format: 'css/utility-classes', | ||
destination: `themes/${themeVariant}/utility-classes.css`, | ||
filter: hasSourceTokensOnly ? 'isSource' : undefined, | ||
options: { | ||
outputReferences: !hasSourceTokensOnly, | ||
}, | ||
}, | ||
], | ||
}, | ||
}, | ||
}); | ||
|
||
StyleDictionary.extend(coreConfig).buildAllPlatforms(); | ||
createIndexCssFile({ buildDir, isTheme: false }); | ||
|
||
themes.forEach((themeVariant) => { | ||
const config = getStyleDictionaryConfig(themeVariant); | ||
StyleDictionary.extend(config).buildAllPlatforms(); | ||
createIndexCssFile({ buildDir, isTheme: true, themeVariant }); | ||
}); | ||
} | ||
|
||
module.exports = buildTokensCommand; |
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
Oops, something went wrong.