Commit e5f1bafb by Andrew Nesbitt

Merge pull request #407 from deepak1556/cli_patch

Read file from stdin
parents 399898be 1d80c3ba
...@@ -2,9 +2,10 @@ var watch = require('node-watch'), ...@@ -2,9 +2,10 @@ var watch = require('node-watch'),
render = require('./render'), render = require('./render'),
path = require('path'), path = require('path'),
Emitter = require('events').EventEmitter, Emitter = require('events').EventEmitter,
stdin = require('get-stdin'),
cwd = process.cwd(); cwd = process.cwd();
var optimist = require('optimist') var yargs = require('yargs')
.usage('Compile .scss files with node-sass.\nUsage: $0 [options] <input.scss> [<output.css>]') .usage('Compile .scss files with node-sass.\nUsage: $0 [options] <input.scss> [<output.css>]')
.options('output-style', { .options('output-style', {
describe: 'CSS output style (nested|expanded|compact|compressed)', describe: 'CSS output style (nested|expanded|compact|compressed)',
...@@ -53,8 +54,8 @@ var optimist = require('optimist') ...@@ -53,8 +54,8 @@ var optimist = require('optimist')
alias: 'help' alias: 'help'
}) })
.check(function(argv){ .check(function(argv){
if (!argv.stdout && argv.o === undefined && argv._.length === 0) { return false; }
if (argv.help) { return true; } if (argv.help) { return true; }
if (argv._.length < 1) { return false; }
}); });
// throttle function, used so when multiple files change at the same time // throttle function, used so when multiple files change at the same time
...@@ -76,10 +77,10 @@ function isSassFile(file) { ...@@ -76,10 +77,10 @@ function isSassFile(file) {
} }
exports = module.exports = function(args) { exports = module.exports = function(args) {
var argv = optimist.parse(args); var argv = yargs.parse(args);
if (argv.help) { if (argv.help) {
optimist.showHelp(); yargs.showHelp();
process.exit(0); process.exit(0);
return; return;
} }
...@@ -168,10 +169,17 @@ exports = module.exports = function(args) { ...@@ -168,10 +169,17 @@ exports = module.exports = function(args) {
throttledRender(); throttledRender();
} else { } else {
render(options, emitter); if (inFile === undefined && args.length > 0) {
stdin(function(data){
options.data = data.toString().trim();
render(options, emitter);
});
} else {
render(options, emitter);
}
} }
return emitter; return emitter;
}; };
exports.optimist = optimist; exports.yargs = yargs;
...@@ -6,6 +6,7 @@ function render(options, emitter) { ...@@ -6,6 +6,7 @@ function render(options, emitter) {
sass.render({ sass.render({
file: options.inFile, file: options.inFile,
data: options.data,
includePaths: options.includePaths, includePaths: options.includePaths,
imagePath: options.imagePath, imagePath: options.imagePath,
outputStyle: options.outputStyle, outputStyle: options.outputStyle,
......
...@@ -44,10 +44,11 @@ ...@@ -44,10 +44,11 @@
"nan": "~1.3.0", "nan": "~1.3.0",
"node-watch": "~0.3.4", "node-watch": "~0.3.4",
"object-assign": "^0.3.1", "object-assign": "^0.3.1",
"optimist": "~0.6.1",
"shelljs": "~0.2.6", "shelljs": "~0.2.6",
"sinon": "~1.9.1", "sinon": "~1.9.1",
"node-sass-middleware": "~0.2.0" "node-sass-middleware": "~0.2.0",
"yargs": "~1.3.1",
"get-stdin": "~3.0.0"
}, },
"devDependencies": { "devDependencies": {
"coveralls": "^2.11.1", "coveralls": "^2.11.1",
......
...@@ -215,4 +215,14 @@ describe('cli', function() { ...@@ -215,4 +215,14 @@ describe('cli', function() {
}); });
}); });
it('should compile with input from stdin', function(done){
var emitter = cli(['--stdout']);
emitter.on('error', done);
emitter.on('log', function(css){
done(assert.equal(css, '#navbar ul {\n list-style-type: none; }\n'));
});
process.stdin.emit('data', '#navbar ul{list-style-type:none;}');
process.stdin.emit('end');
});
}); });
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment