Don't do any merging of config values at all

Leave this up to the user; their config file is a JS file and we give
them access to the default config, so they can do as much merging of
defaults as they like.
This commit is contained in:
Adam Wathan 2017-10-24 08:53:47 -04:00
parent 42150826aa
commit 4478b04090
4 changed files with 4 additions and 156 deletions

View File

@ -1,83 +0,0 @@
import mergeConfig from '../src/util/mergeConfig'
/**
* Tests
*/
it('replaces simple top level keys', () => {
const defaultConfig = {
colors: {
'red': '#f25451',
'green-light': '#b1f3be',
'blue-dark': '#3687c8',
'indigo': '#6574cd',
}
}
const userConfig = {
colors: {
'orange': '#ffb82b',
'green': '#57d06f',
'blue': '#4aa2ea',
'indigo-dark': '#4957a5',
}
}
expect(mergeConfig(defaultConfig, userConfig)).toMatchObject(userConfig)
})
it('merges keys found in the "extend" section', () => {
const defaultConfig = {
colors: {
'red': '#f25451',
},
text: {
sizes: {
'base': '1rem',
'lg': '1.25rem',
}
},
spacing: {
padding: {
'0': '0',
'1': '0.25rem',
'2': '0.5rem',
}
}
}
const userConfig = {
extend: {
colors: {
'blue': '#4aa2ea',
},
text: {
sizes: {
'xl': '1.5rem'
}
},
spacing: {
padding: {
'10': '2.5rem'
}
}
}
}
expect(mergeConfig(defaultConfig, userConfig)).toMatchObject({
colors: {
'red': '#f25451',
'blue': '#4aa2ea',
},
text: {
sizes: {
'base': '1rem',
'lg': '1.25rem',
'xl': '1.5rem',
}
},
spacing: {
padding: {
'0': '0',
'1': '0.25rem',
'2': '0.5rem',
'10': '2.5rem',
}
}
})
})

View File

@ -1,13 +1,12 @@
import fs from 'fs'
import postcss from 'postcss'
import tailwind from '..'
import defaultConfig from '../defaultConfig'
import CleanCSS from 'clean-css'
console.info('Building Tailwind!')
fs.readFile('./css/tailwind.css', (err, css) => {
postcss([tailwind(defaultConfig)])
postcss([tailwind()])
.process(css, {
from: './css/tailwind.css',
to: './dist/tailwind.css',

View File

@ -6,7 +6,6 @@ import postcss from 'postcss'
import stylefmt from 'stylefmt'
import defaultConfig from '../defaultConfig'
import mergeConfig from './util/mergeConfig'
import substituteResetAtRule from './lib/substituteResetAtRule'
import evaluateTailwindFunctions from './lib/evaluateTailwindFunctions'
@ -17,13 +16,11 @@ import substituteResponsiveAtRules from './lib/substituteResponsiveAtRules'
import substituteScreenAtRules from './lib/substituteScreenAtRules'
import substituteClassApplyAtRules from './lib/substituteClassApplyAtRules'
const plugin = postcss.plugin('tailwind', (options = {}) => {
if (_.isString(options)) {
options = require(path.resolve(options))
const plugin = postcss.plugin('tailwind', (config = defaultConfig) => {
if (_.isString(config)) {
config = require(path.resolve(config))
}
const config = mergeConfig(defaultConfig, options)
return postcss([
substituteResetAtRule(config),
evaluateTailwindFunctions(config),

View File

@ -1,65 +0,0 @@
import _ from 'lodash'
const configTemplate = {
screens: null,
colors: null,
text: {
fonts: null,
sizes: null,
weights: null,
leading: null,
tracking: null,
colors: null,
},
backgrounds: {
colors: null,
},
borders: {
widths: null,
colors: null,
},
radiuses: null,
sizing: {
width: null,
height: null,
minHeight: null,
maxHeight: null,
minWidth: null,
maxWidth: null,
},
spacing: {
padding: null,
margin: null,
negativeMargin: null,
},
shadows: null,
zIndex: null,
opacity: null,
}
function replaceDefaults(template, defaults, replacements) {
return Object.keys(template).reduce((merged, key) => {
const value = template[key]
if (_.isPlainObject(value)) {
merged[key] = replaceDefaults(value, _.get(defaults, key), _.get(replacements, key))
} else {
merged[key] = _.get(replacements, key, _.get(defaults, key))
}
return merged
}, {})
}
function appendConfig(base, appends) {
return _.mergeWith({}, base, appends, (baseValue, appendsValue) => {
if (_.isArray(baseValue)) {
return baseValue.concat(appendsValue);
}
})
}
export default function mergeConfig(base, other) {
const replaced = replaceDefaults(configTemplate, base, other)
return appendConfig(replaced, _.get(other, 'extend', {}))
}