mirror of
https://github.com/tailwindlabs/tailwindcss.git
synced 2025-12-08 21:36:08 +00:00
Allow using a custom config with option to replace instead of default merging
This commit is contained in:
parent
8eb25475b4
commit
dd2ffec934
88
src/index.js
88
src/index.js
@ -1,6 +1,7 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
import fs from 'fs'
|
||||
import _ from 'lodash'
|
||||
import path from 'path'
|
||||
import postcss from 'postcss'
|
||||
import defaultConfig from './defaultConfig'
|
||||
@ -11,38 +12,11 @@ let splitFileName = filename => {
|
||||
return filename.split('.')
|
||||
}
|
||||
|
||||
program
|
||||
.version('0.1.0')
|
||||
.usage('[options] <file ...>')
|
||||
.option('-c, --config [value]', 'Pass custom configuration')
|
||||
.parse(process.argv)
|
||||
|
||||
let inputFile = program.args[0]
|
||||
let outputFile =
|
||||
program.args[1] || `${splitFileName(program.args[0])[0]}-output.css`
|
||||
|
||||
if (!inputFile) {
|
||||
console.error('No input file given!')
|
||||
process.exit(1)
|
||||
}
|
||||
|
||||
fs.readFile(path.join(program.config), (err, config) => {
|
||||
if (err) {
|
||||
console.error(`config file ${program.config} does not exist`)
|
||||
process.exit(1)
|
||||
}
|
||||
|
||||
const customConfig = JSON.parse(config.toString())
|
||||
|
||||
let finalConfig = {
|
||||
...defaultConfig,
|
||||
...customConfig,
|
||||
}
|
||||
|
||||
let buildTailwind = config => {
|
||||
console.log('Building Tailwind!')
|
||||
|
||||
fs.readFile(inputFile, (err, css) => {
|
||||
postcss([tailwind(finalConfig)])
|
||||
postcss([tailwind(config)])
|
||||
.process(css)
|
||||
.then(result => {
|
||||
fs.writeFileSync(outputFile, result.css)
|
||||
@ -51,4 +25,58 @@ fs.readFile(path.join(program.config), (err, config) => {
|
||||
})
|
||||
|
||||
console.log('Finished building Tailwind!')
|
||||
})
|
||||
}
|
||||
|
||||
let getConfig = (customConfig, merge) => {
|
||||
if (merge) {
|
||||
return customConfig
|
||||
} else {
|
||||
return _.merge(defaultConfig, customConfig)
|
||||
}
|
||||
}
|
||||
|
||||
program
|
||||
.version('0.1.0')
|
||||
.usage('[options] <file ...>')
|
||||
.option('-c, --config [path]', 'set config path')
|
||||
.option(
|
||||
'-r, --replace',
|
||||
'replace the built-in configuration with the provided config file'
|
||||
)
|
||||
.parse(process.argv)
|
||||
|
||||
let inputFile = program.args[0]
|
||||
|
||||
if (!inputFile) {
|
||||
console.error('No input file given!')
|
||||
process.exit(1)
|
||||
}
|
||||
|
||||
let outputFile =
|
||||
program.args[1] || `${splitFileName(program.args[0])[0]}-output.css`
|
||||
|
||||
if (program.config !== undefined) {
|
||||
fs.exists(program.config, exists => {
|
||||
if (!exists) {
|
||||
console.error(`Config file [${program.config}] does not exist.`)
|
||||
process.exit(1)
|
||||
}
|
||||
|
||||
fs.readFile(program.config, (err, config) => {
|
||||
if (err) {
|
||||
console.error(
|
||||
`There was a problem reading config file [${program.config}].`
|
||||
)
|
||||
process.exit(1)
|
||||
}
|
||||
|
||||
const customConfig = JSON.parse(config.toString())
|
||||
|
||||
let finalConfig = getConfig(customConfig, program.replace)
|
||||
|
||||
buildTailwind(finalConfig)
|
||||
})
|
||||
})
|
||||
} else {
|
||||
buildTailwind(defaultConfig)
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user