Skip to content

Commit

Permalink
feat: use style-dictionary as core build
Browse files Browse the repository at this point in the history
  • Loading branch information
yarastqt committed May 29, 2020
1 parent 9726684 commit 67025f1
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 15 deletions.
17 changes: 2 additions & 15 deletions src/cli/build.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import { resolve } from 'path'
import { Command, flags } from '@oclif/command'
import createSpinner, { Ora as Spinner } from 'ora'
import chalk from 'chalk'

import { loadConfig } from '../core/config'
import { build } from '../core/build'
import { build } from '../core-v2/build'

type Flags = { config: string }

Expand All @@ -20,19 +18,8 @@ export default class Build extends Command {
}

async run() {
let spinner: Spinner
const { flags } = this.parse<Flags, any>(Build)
const config = await loadConfig(resolve(flags.config))
await build(
config,
(format) => {
spinner = createSpinner().start(`Build ${chalk.cyan(format)}`)
},
(format, files) => {
spinner.stop()
this.log(chalk.cyan(`❯ ${format}`))
this.log(chalk.gray(`${files.map((file) => ` - ${file}`).join('\n')}`))
},
)
await build(config)
}
}
21 changes: 21 additions & 0 deletions src/core-v2/build.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import StyleDictionaryApi from 'style-dictionary'

import { createWhitepaperConfig } from './whitepaper-config'

export function build(config: any): any {
const normalizedConfig = Array.isArray(config) ? config : [config]

for (const themeConfig of normalizedConfig) {
for (const themeFileConfig of themeConfig.files) {
let styleDictionaryConfig: any = {}
if (themeFileConfig.format === 'css/whitepaper') {
styleDictionaryConfig = createWhitepaperConfig({
source: themeConfig.source,
theme: themeConfig.name,
})
}
const StyleDictionary = StyleDictionaryApi.extend(styleDictionaryConfig)
StyleDictionary.buildPlatform('css')
}
}
}
24 changes: 24 additions & 0 deletions src/core-v2/whitepaper-config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
const whitepaper = {
space: '',
size: '',
capacity: '',
cosmetic: '',
color: '',
}

export function createWhitepaperConfig({ source, theme }: any): any {
return {
source,
platforms: {
css: {
buildPath: 'build/',
transformGroup: 'css',
files: Object.keys(whitepaper).map((file: any) => ({
destination: `${theme}/${file}.css`,
format: 'css/variables',
filter: (token: any) => token.group === file,
})),
},
},
}
}

0 comments on commit 67025f1

Please sign in to comment.