diff --git a/package.json b/package.json index fa9c98776..1742ffb12 100644 --- a/package.json +++ b/package.json @@ -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 ", "Jonathan Reinink ", @@ -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", diff --git a/src/index.js b/src/index.js new file mode 100755 index 000000000..d6c6c4d08 --- /dev/null +++ b/src/index.js @@ -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] ') + .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!') +})