postcss-cli
Advanced tools
Comparing version 1.2.1 to 1.3.0
32
index.js
var argv = require("yargs") | ||
.usage('Usage: $0 -use|-p plugin [--config|-c config.json] --output|-o output.css input.css') | ||
.usage('Usage: $0 -use|-p plugin [--config|-c config.json] [--output|-o output.css] [input.css]') | ||
.example('postcss --use autoprefixer -c options.json -o screen.css screen.css', | ||
@@ -9,3 +9,2 @@ 'Use autoprefixer as a postcss plugin') | ||
'Use multiple plugins and multiple input files') | ||
.demand(1, 'Please specify at least one input file.') | ||
.config('c') | ||
@@ -18,3 +17,3 @@ .alias('c', 'config') | ||
.alias('o', 'output') | ||
.describe('o', 'Output file') | ||
.describe('o', 'Output file (stdout if not provided)') | ||
.alias('d', 'dir') | ||
@@ -34,3 +33,2 @@ .describe('d', 'Output directory') | ||
.alias('h', 'help') | ||
.wrap() | ||
.check(function(argv) { | ||
@@ -43,5 +41,2 @@ if (argv._.length > 1 && !argv.dir) { | ||
} | ||
if (!argv.output && !argv.dir) { | ||
throw 'Please specify --output [output file name] or --dir [out files location]'; | ||
} | ||
return true; | ||
@@ -68,2 +63,3 @@ }) | ||
var fs = require('fs'); | ||
var readFile = require('read-file-stdin'); | ||
var path = require('path'); | ||
@@ -73,2 +69,11 @@ var postcss = require('postcss'); | ||
function writeFile(name, content, fn) { | ||
if (!name) { | ||
process.stdout.write(content); | ||
return fn(); | ||
} | ||
fs.writeFile(name, content, fn); | ||
} | ||
function processCSS(processor, input, output, fn) { | ||
@@ -80,3 +85,3 @@ function doProcess(css, fn) { | ||
} | ||
fn(null, result); | ||
fn(null, result.css); | ||
} | ||
@@ -97,11 +102,16 @@ | ||
async.waterfall([ | ||
async.apply(fs.readFile, input, 'utf8'), | ||
async.apply(readFile, input), | ||
doProcess, | ||
async.apply(fs.writeFile, output) | ||
async.apply(writeFile, output) | ||
], fn); | ||
} | ||
if (!argv._.length) { | ||
// use stdin if nothing else is specified | ||
argv._ = [undefined]; | ||
} | ||
async.forEach(argv._, function(input, fn) { | ||
var output = argv.output; | ||
if(!output) { | ||
if (argv.dir) { | ||
output = path.join(argv.dir, path.basename(input)); | ||
@@ -108,0 +118,0 @@ } |
{ | ||
"name": "postcss-cli", | ||
"version": "1.2.1", | ||
"version": "1.3.0", | ||
"description": "CLI for postcss", | ||
@@ -23,3 +23,4 @@ "main": "index.js", | ||
"postcss": "^4.0.6", | ||
"yargs": "^3.6.0" | ||
"read-file-stdin": "^0.2.0", | ||
"yargs": "^3.8.0" | ||
}, | ||
@@ -26,0 +27,0 @@ "devDependencies": { |
@@ -15,8 +15,12 @@ [![Build Status](https://img.shields.io/travis/code42day/postcss-cli.svg)](http://travis-ci.org/code42day/postcss-cli) | ||
postcss [options] -o output-file input-file | ||
postcss [options] [-o output-file|-d output-directory] [input-file] | ||
#### `--output|-o` | ||
Output file name | ||
Output file name. If no output file is specified, `postcss` will write to `stdout`, however plugins | ||
that rely on output file location will not work properly. | ||
Similarly, if no input file is specified, `postcss` will read from `stdin`. | ||
Plugins that rely on input file location will not work properly. | ||
#### `--dir|-d` | ||
@@ -23,0 +27,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
6403
111
92
4
+ Addedread-file-stdin@^0.2.0
+ Addedgather-stream@1.0.0(transitive)
+ Addedread-file-stdin@0.2.1(transitive)
Updatedyargs@^3.8.0