Skip to content
Prev Previous commit
Next Next commit
lint
  • Loading branch information
shawnbot committed Nov 15, 2019
commit d6240d3bc9c05e59c1da3fd135eda1179b5998a7
8 changes: 3 additions & 5 deletions lib/generate-theme.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@ const postcss = require('postcss')

module.exports = function generateTheme(transform) {
const {variables} = transform(theme)
const entries = Object.entries(variables).filter(([name, value]) => typeof value !== 'undefined')
const entries = Object.entries(variables).filter(([, value]) => typeof value !== 'undefined')

const sheet = postcss.root()
const root = postcss.rule({selector: ':root'})
for (const [name, value] of entries) {
const prop = postcss.decl({
prop: `--${name}`,
value: `#{${value}}`,
raws: {after: '\n'}
value: `#{${value}}`
})
root.append(prop)
}
Expand All @@ -20,8 +19,7 @@ module.exports = function generateTheme(transform) {
for (const [name, value] of entries) {
const prop = postcss.decl({
prop: `$${name}`,
value: `var(--${name}, #{${value}})`,
raws: {after: '\n'}
value: `var(--${name}, #{${value}})`
})
sheet.append(prop)
}
Expand Down
10 changes: 5 additions & 5 deletions script/dist.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,10 @@ async function dist() {

const themeFiles = await globby(`${inDir}/themes/*.js`)
for (const themeFile of themeFiles) {
const name = themeFile.split('/').pop().replace('.js', '')
const name = themeFile
.split('/')
.pop()
.replace('.js', '')
const theme = require(`../${themeFile}`)
const preamble = generateTheme(theme)

Expand All @@ -82,10 +85,7 @@ async function dist() {
const to = join(themeDir, `${name}.css`)
const map = `${to}.map`
const result = await processor.process(scss, Object.assign({from, to}, options))
await Promise.all([
writeFile(to, result.css, encoding),
result.map ? writeFile(map, result.map, encoding) : null
])
await Promise.all([writeFile(to, result.css, encoding), result.map ? writeFile(map, result.map, encoding) : null])
themes[name] = {
css: to,
map
Expand Down