Skip to content

Commit

Permalink
feat: supports platform with entry for selector setting
Browse files Browse the repository at this point in the history
  • Loading branch information
yarastqt committed Aug 7, 2020
1 parent ee854c8 commit 7ed567e
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/core/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const store = new Map()
StyleDictionaryApi.registerFormat({
name: 'css/whitepaper',
formatter(dictionary, config) {
const defaultOptions = { selector: ':root', useAliasVariables: false }
const defaultOptions = { useAliasVariables: false }
const options = Object.assign(defaultOptions, (this as any).options)

const whitepaper = store.get('whitepaper')
Expand All @@ -43,14 +43,19 @@ StyleDictionaryApi.registerFormat({
formatter(dictionary, config) {
const defaultOptions = { selector: ':root', useAliasVariables: false }
const options = Object.assign(defaultOptions, (this as any).options)
const { entry, platform } = store.get('meta')
const selector = options.selector
.replace(/\[entry\]/, entry)
.replace(/\[platform\]/, platform)
.replace(/common\/?/, '')

const transformers = config.transforms.filter((transform) => transform.type === 'name')

const props = options.useAliasVariables
? replaceAliasToVariable(dictionary.allProperties, transformers)
: dictionary.allProperties

return `${options.selector} {\n${variablesWithPrefix(' --', props)}\n}\n`
return `${selector} {\n${variablesWithPrefix(' --', props)}\n}\n`
},
})

Expand Down Expand Up @@ -112,6 +117,7 @@ export async function build(config: Config): Promise<void> {
// TODO: Load mappers in themes?
store.set('mapper', await loadMappers(theme.mappers))
store.set('whitepaper', enhanceWhitepaperConfig(theme.whitepaper, platform))
store.set('meta', { entry, platform })

const StyleDictionary = StyleDictionaryApi.extend(
createStyleDictionaryConfig({
Expand Down

0 comments on commit 7ed567e

Please sign in to comment.