-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #35 from patternfly/enable-selector-cli-arg
feat(build): Add CLI for scss build with option for custom selector
- Loading branch information
Showing
5 changed files
with
87 additions
and
65 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,73 +1,78 @@ | ||
/* eslint-disable no-console */ | ||
const StyleDictionary = require('style-dictionary'); | ||
const { fileHeader, formattedVariables } = StyleDictionary.formatHelpers; | ||
|
||
console.log('Build started...'); | ||
console.log('\n============================'); | ||
const build = (selector) => { | ||
const { fileHeader, formattedVariables } = StyleDictionary.formatHelpers; | ||
|
||
//Register comment format | ||
StyleDictionary.registerFormat({ | ||
name: 'customFormat', | ||
formatter: function ({ dictionary, file, options }) { | ||
const { outputReferences } = options; | ||
return ( | ||
fileHeader({ file, commentStyle: 'short' }) + | ||
':root {\n' + | ||
formattedVariables({ format: 'css', dictionary, outputReferences }) + | ||
'\n}\n' | ||
); | ||
} | ||
}); | ||
console.log('Build started...'); | ||
console.log('\n============================'); | ||
|
||
// Register custom transforms | ||
StyleDictionary.registerTransform({ | ||
name: 'patternfly/global/px', | ||
type: 'value', | ||
matcher: (token) => | ||
token.attributes.type === 'spacer' || | ||
token.attributes.type === 'border' || | ||
token.attributes.type === 'icon' || | ||
(token.attributes.type === 'box-shadow' && token.attributes.item !== 'color') || | ||
token.attributes.type === 'font', | ||
transformer: (token) => `${token.value}px` | ||
}); | ||
//Register comment format | ||
StyleDictionary.registerFormat({ | ||
name: 'customFormat', | ||
formatter: function ({ dictionary, file, options }) { | ||
const { outputReferences } = options; | ||
return ( | ||
fileHeader({ file, commentStyle: 'short' }) + | ||
`${selector} {\n` + | ||
formattedVariables({ format: 'css', dictionary, outputReferences }) + | ||
'\n}\n' | ||
); | ||
} | ||
}); | ||
|
||
StyleDictionary.registerTransform({ | ||
name: 'patternfly/doublekebab', | ||
type: 'name', | ||
transformer: (token, options) => `${options.prefix}--${token.path.join('--')}` | ||
}); | ||
// Register custom transforms | ||
StyleDictionary.registerTransform({ | ||
name: 'patternfly/global/px', | ||
type: 'value', | ||
matcher: (token) => | ||
token.attributes.type === 'spacer' || | ||
token.attributes.type === 'border' || | ||
token.attributes.type === 'icon' || | ||
(token.attributes.type === 'box-shadow' && token.attributes.item !== 'color') || | ||
token.attributes.type === 'font', | ||
transformer: (token) => `${token.value}px` | ||
}); | ||
|
||
// Reigster custom transform group | ||
StyleDictionary.registerTransformGroup({ | ||
name: 'patternfly/css', | ||
transforms: [ | ||
// "css" group transforms | ||
'attribute/cti', | ||
// 'name/cti/kebab' -- replaced with "patternfly/doublekebab" | ||
'time/seconds', | ||
'content/icon', | ||
'size/rem', | ||
'color/css', | ||
// custom transforms | ||
'patternfly/global/px', | ||
'patternfly/doublekebab' | ||
] | ||
}); | ||
StyleDictionary.registerTransform({ | ||
name: 'patternfly/doublekebab', | ||
type: 'name', | ||
transformer: (token, options) => `${options.prefix}--${token.path.join('--')}` | ||
}); | ||
|
||
// Apply configuration | ||
const defaultExtendedSD = StyleDictionary.extend(__dirname + '/config.default.json'); | ||
const darkExtendedSD = StyleDictionary.extend(__dirname + '/config.dark.json'); | ||
const paletteExtendedSD = StyleDictionary.extend(__dirname + '/config.palette-colors.json'); | ||
const chartExtendedSD = StyleDictionary.extend(__dirname + '/config.chart.json'); | ||
const chartDarkExtendedSD = StyleDictionary.extend(__dirname + '/config.chart.dark.json'); | ||
// Reigster custom transform group | ||
StyleDictionary.registerTransformGroup({ | ||
name: 'patternfly/css', | ||
transforms: [ | ||
// "css" group transforms | ||
'attribute/cti', | ||
// 'name/cti/kebab' -- replaced with "patternfly/doublekebab" | ||
'time/seconds', | ||
'content/icon', | ||
'size/rem', | ||
'color/css', | ||
// custom transforms | ||
'patternfly/global/px', | ||
'patternfly/doublekebab' | ||
] | ||
}); | ||
|
||
// Build all | ||
defaultExtendedSD.buildAllPlatforms(); | ||
darkExtendedSD.buildAllPlatforms(); | ||
paletteExtendedSD.buildAllPlatforms(); | ||
chartExtendedSD.buildAllPlatforms(); | ||
chartDarkExtendedSD.buildAllPlatforms(); | ||
// Apply configuration | ||
const defaultExtendedSD = StyleDictionary.extend(__dirname + '/config.default.json'); | ||
const darkExtendedSD = StyleDictionary.extend(__dirname + '/config.dark.json'); | ||
const paletteExtendedSD = StyleDictionary.extend(__dirname + '/config.palette-colors.json'); | ||
const chartExtendedSD = StyleDictionary.extend(__dirname + '/config.chart.json'); | ||
const chartDarkExtendedSD = StyleDictionary.extend(__dirname + '/config.chart.dark.json'); | ||
|
||
console.log('\n============================'); | ||
console.log('\nBuild completed.'); | ||
// Build all | ||
defaultExtendedSD.buildAllPlatforms(); | ||
darkExtendedSD.buildAllPlatforms(); | ||
paletteExtendedSD.buildAllPlatforms(); | ||
chartExtendedSD.buildAllPlatforms(); | ||
chartDarkExtendedSD.buildAllPlatforms(); | ||
|
||
console.log('\n============================'); | ||
console.log('\nBuild completed.'); | ||
}; | ||
|
||
module.exports = { 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,10 @@ | ||
const { program } = require('commander'); | ||
const {build} = require('./build'); | ||
|
||
program | ||
.version(require('./package.json').version) | ||
.description('Builds the PF design tokens using style dictionary') | ||
.option('-s, --selector <selector>', 'CSS selector to use for the output', ':root') | ||
.action((cliOptions) => build(cliOptions.selector)); | ||
|
||
program.parse(process.argv); |
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