Commit db49b30c by deepak1556

reading file from stdin

parent 2c6fbef8
......@@ -2,9 +2,10 @@ var watch = require('node-watch'),
render = require('./render'),
path = require('path'),
Emitter = require('events').EventEmitter,
cwd = process.cwd();
cwd = process.cwd(),
stdin = require('get-stdin');
var optimist = require('optimist')
var yargs = require('yargs')
.usage('Compile .scss files with node-sass.\nUsage: $0 [options] <input.scss> [<output.css>]')
.options('output-style', {
describe: 'CSS output style (nested|expanded|compact|compressed)',
......@@ -53,8 +54,8 @@ var optimist = require('optimist')
alias: 'help'
})
.check(function(argv){
if (!argv.stdout && argv.o === undefined && argv._.length === 0) { return false; }
if (argv.help) { return true; }
if (argv._.length < 1) { return false; }
});
// throttle function, used so when multiple files change at the same time
......@@ -76,10 +77,10 @@ function isSassFile(file) {
}
exports = module.exports = function(args) {
var argv = optimist.parse(args);
var argv = yargs.parse(args);
if (argv.help) {
optimist.showHelp();
yargs.showHelp();
process.exit(0);
return;
}
......@@ -168,10 +169,17 @@ exports = module.exports = function(args) {
throttledRender();
} else {
if (inFile === undefined && args.length > 0) {
stdin(function(data){
options.data = data.toString().trim();
render(options, emitter);
});
} else {
render(options, emitter);
}
}
return emitter;
};
exports.optimist = optimist;
exports.yargs = yargs;
......@@ -6,6 +6,7 @@ function render(options, emitter) {
sass.render({
file: options.inFile,
data: options.data,
includePaths: options.includePaths,
imagePath: options.imagePath,
outputStyle: options.outputStyle,
......
......@@ -44,10 +44,10 @@
"nan": "~1.3.0",
"node-watch": "~0.3.4",
"object-assign": "^0.3.1",
"optimist": "~0.6.1",
"shelljs": "~0.2.6",
"sinon": "~1.9.1",
"node-sass-middleware": "~0.2.0"
"node-sass-middleware": "~0.2.0",
"yargs": "~1.3.1"
},
"devDependencies": {
"coveralls": "^2.11.1",
......
......@@ -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