mirror of
https://github.com/tailwindlabs/tailwindcss.git
synced 2025-12-08 21:36:08 +00:00
Add command to process with tailwind from file with custom json config
This commit is contained in:
parent
dfdee29876
commit
9cfe3aa25d
@ -3,6 +3,9 @@
|
||||
"version": "0.1.0",
|
||||
"description": "A utility-first CSS framework for rapid UI development.",
|
||||
"license": "MIT",
|
||||
"bin": {
|
||||
"tailwind": "lib/index.js"
|
||||
},
|
||||
"contributors": [
|
||||
"Adam Wathan <adam.wathan@gmail.com>",
|
||||
"Jonathan Reinink <jonathan@reinink.ca>",
|
||||
@ -29,6 +32,7 @@
|
||||
"stylefmt": "^6.0.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"commander": "^2.11.0",
|
||||
"lodash": "^4.17.4",
|
||||
"nodemon": "^1.11.0",
|
||||
"normalize.css": "^6.0.0",
|
||||
|
||||
54
src/index.js
Executable file
54
src/index.js
Executable file
@ -0,0 +1,54 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
import fs from 'fs'
|
||||
import path from 'path'
|
||||
import postcss from 'postcss'
|
||||
import defaultConfig from './defaultConfig'
|
||||
import program from 'commander'
|
||||
import tailwind from './tailwind'
|
||||
|
||||
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,
|
||||
}
|
||||
|
||||
console.log('Building Tailwind!')
|
||||
|
||||
fs.readFile(inputFile, (err, css) => {
|
||||
postcss([tailwind(finalConfig)])
|
||||
.process(css)
|
||||
.then(result => {
|
||||
fs.writeFileSync(outputFile, result.css)
|
||||
})
|
||||
.catch(error => console.log(error))
|
||||
})
|
||||
|
||||
console.log('Finished building Tailwind!')
|
||||
})
|
||||
Loading…
x
Reference in New Issue
Block a user