Commit 43dbafb8 by Adeel Mujahid

Merge pull request #701 from am11/master

CLI: Retires stdout option
parents 92456685 433e939d
...@@ -316,7 +316,6 @@ Output will be saved with the same name as input SASS file into the current work ...@@ -316,7 +316,6 @@ Output will be saved with the same name as input SASS file into the current work
--include-path Path to look for imported files --include-path Path to look for imported files
--image-path Path to prepend when using the `image-url()` helper --image-path Path to prepend when using the `image-url()` helper
--precision The amount of precision allowed in decimal numbers --precision The amount of precision allowed in decimal numbers
--stdout Print the resulting CSS to stdout
--importer Path to custom importer --importer Path to custom importer
--help Print usage info --help Print usage info
``` ```
......
...@@ -3,7 +3,6 @@ var Emitter = require('events').EventEmitter, ...@@ -3,7 +3,6 @@ var Emitter = require('events').EventEmitter,
path = require('path'), path = require('path'),
Gaze = require('gaze'), Gaze = require('gaze'),
meow = require('meow'), meow = require('meow'),
replaceExt = require('replace-ext'),
stdin = require('get-stdin'), stdin = require('get-stdin'),
grapher = require('sass-graph'), grapher = require('sass-graph'),
render = require('../lib/render'); render = require('../lib/render');
...@@ -39,7 +38,6 @@ var cli = meow({ ...@@ -39,7 +38,6 @@ var cli = meow({
' --include-path Path to look for imported files', ' --include-path Path to look for imported files',
' --image-path Path to prepend when using the `image-url()` helper', ' --image-path Path to prepend when using the `image-url()` helper',
' --precision The amount of precision allowed in decimal numbers', ' --precision The amount of precision allowed in decimal numbers',
' --stdout Print the resulting CSS to stdout',
' --importer Path to custom importer', ' --importer Path to custom importer',
' --help Print usage info' ' --help Print usage info'
].join('\n') ].join('\n')
...@@ -48,7 +46,6 @@ var cli = meow({ ...@@ -48,7 +46,6 @@ var cli = meow({
'indented-syntax', 'indented-syntax',
'omit-source-map-url', 'omit-source-map-url',
'recursive', 'recursive',
'stdout',
'source-map-embed', 'source-map-embed',
'source-map-contents', 'source-map-contents',
'source-comments' 'source-comments'
...@@ -129,21 +126,14 @@ function getEmitter() { ...@@ -129,21 +126,14 @@ function getEmitter() {
*/ */
function getOptions(args, options) { function getOptions(args, options) {
var dir = options.output ? path.resolve(process.cwd(), options.output) : process.cwd();
options.src = args[0]; options.src = args[0];
options.dest = args[1] ? path.resolve(dir, args[1]) : undefined;
if (!options.dest && !options.stdout) {
var ext = path.extname(options.src);
var out = path.basename(options.src);
var suffix = '.css';
if (ext !== suffix) {
out = replaceExt(out, suffix);
}
options.dest = path.join(dir, out); if (args[1]) {
options.dest = path.resolve(process.cwd(), args[1]);
} else if (options.output) {
options.dest = path.join(
path.resolve(process.cwd(), options.output),
[path.basename(options.src, path.extname(options.src)), '.css'].join('')); // replace ext.
} }
return options; return options;
...@@ -208,7 +198,12 @@ function run(options, emitter) { ...@@ -208,7 +198,12 @@ function run(options, emitter) {
if (options.sourceMap) { if (options.sourceMap) {
if (options.sourceMap === 'true') { if (options.sourceMap === 'true') {
options.sourceMap = options.dest + '.map'; if (options.dest) {
options.sourceMap = options.dest + '.map';
} else {
// replace ext.
options.sourceMap = [path.basename(options.src, path.extname(options.src)), '.css.map'].join('');
}
} else { } else {
options.sourceMap = path.resolve(process.cwd(), options.sourceMap); options.sourceMap = path.resolve(process.cwd(), options.sourceMap);
} }
......
...@@ -42,8 +42,13 @@ module.exports = function(options, emitter) { ...@@ -42,8 +42,13 @@ module.exports = function(options, emitter) {
} }
}; };
if (options.stdout || (!options.dest && !process.stdout.isTTY) || options.stdin) { if (!options.dest || options.stdin) {
emitter.emit('log', result.css); emitter.emit('log', result.css);
if (options.sourceMap) {
emitter.emit('log', result.map);
}
return done(); return done();
} }
......
...@@ -53,7 +53,6 @@ ...@@ -53,7 +53,6 @@
"nan": "^1.6.2", "nan": "^1.6.2",
"npmconf": "^2.1.1", "npmconf": "^2.1.1",
"object-assign": "^2.0.0", "object-assign": "^2.0.0",
"replace-ext": "0.0.1",
"request": "^2.53.0", "request": "^2.53.0",
"sass-graph": "^1.0.3", "sass-graph": "^1.0.3",
"shelljs": "^0.3.0" "shelljs": "^0.3.0"
......
...@@ -11,7 +11,7 @@ describe('cli', function() { ...@@ -11,7 +11,7 @@ describe('cli', function() {
it('should read data from stdin', function(done) { it('should read data from stdin', function(done) {
var src = fs.createReadStream(fixture('simple/index.scss')); var src = fs.createReadStream(fixture('simple/index.scss'));
var expected = read(fixture('simple/expected.css'), 'utf8').trim(); var expected = read(fixture('simple/expected.css'), 'utf8').trim();
var bin = spawn(cli, ['--stdout']); var bin = spawn(cli);
bin.stdout.setEncoding('utf8'); bin.stdout.setEncoding('utf8');
bin.stdout.once('data', function(data) { bin.stdout.once('data', function(data) {
...@@ -25,7 +25,7 @@ describe('cli', function() { ...@@ -25,7 +25,7 @@ describe('cli', function() {
it('should compile sass using the --indented-syntax option', function(done) { it('should compile sass using the --indented-syntax option', function(done) {
var src = fs.createReadStream(fixture('indent/index.sass')); var src = fs.createReadStream(fixture('indent/index.sass'));
var expected = read(fixture('indent/expected.css'), 'utf8').trim(); var expected = read(fixture('indent/expected.css'), 'utf8').trim();
var bin = spawn(cli, ['--stdout', '--indented-syntax']); var bin = spawn(cli, ['--indented-syntax']);
bin.stdout.setEncoding('utf8'); bin.stdout.setEncoding('utf8');
bin.stdout.once('data', function(data) { bin.stdout.once('data', function(data) {
...@@ -39,7 +39,7 @@ describe('cli', function() { ...@@ -39,7 +39,7 @@ describe('cli', function() {
it('should compile with the --output-style option', function(done) { it('should compile with the --output-style option', function(done) {
var src = fs.createReadStream(fixture('compressed/index.scss')); var src = fs.createReadStream(fixture('compressed/index.scss'));
var expected = read(fixture('compressed/expected.css'), 'utf8').trim(); var expected = read(fixture('compressed/expected.css'), 'utf8').trim();
var bin = spawn(cli, ['--stdout', '--output-style', 'compressed']); var bin = spawn(cli, ['--output-style', 'compressed']);
bin.stdout.setEncoding('utf8'); bin.stdout.setEncoding('utf8');
bin.stdout.once('data', function(data) { bin.stdout.once('data', function(data) {
...@@ -53,7 +53,7 @@ describe('cli', function() { ...@@ -53,7 +53,7 @@ describe('cli', function() {
it('should compile with the --source-comments option', function(done) { it('should compile with the --source-comments option', function(done) {
var src = fs.createReadStream(fixture('source-comments/index.scss')); var src = fs.createReadStream(fixture('source-comments/index.scss'));
var expected = read(fixture('source-comments/expected.css'), 'utf8').trim(); var expected = read(fixture('source-comments/expected.css'), 'utf8').trim();
var bin = spawn(cli, ['--stdout', '--source-comments']); var bin = spawn(cli, ['--source-comments']);
bin.stdout.setEncoding('utf8'); bin.stdout.setEncoding('utf8');
bin.stdout.once('data', function(data) { bin.stdout.once('data', function(data) {
...@@ -67,7 +67,7 @@ describe('cli', function() { ...@@ -67,7 +67,7 @@ describe('cli', function() {
it('should compile with the --image-path option', function(done) { it('should compile with the --image-path option', function(done) {
var src = fs.createReadStream(fixture('image-path/index.scss')); var src = fs.createReadStream(fixture('image-path/index.scss'));
var expected = read(fixture('image-path/expected.css'), 'utf8').trim(); var expected = read(fixture('image-path/expected.css'), 'utf8').trim();
var bin = spawn(cli, ['--stdout', '--image-path', '/path/to/images']); var bin = spawn(cli, ['--image-path', '/path/to/images']);
bin.stdout.setEncoding('utf8'); bin.stdout.setEncoding('utf8');
bin.stdout.once('data', function(data) { bin.stdout.once('data', function(data) {
...@@ -85,7 +85,7 @@ describe('cli', function() { ...@@ -85,7 +85,7 @@ describe('cli', function() {
var src = fixture('simple/index.scss'); var src = fixture('simple/index.scss');
var dest = fixture('simple/index.css'); var dest = fixture('simple/index.css');
var bin = spawn(cli, [src]); var bin = spawn(cli, [src, dest]);
bin.on('close', function() { bin.on('close', function() {
assert(fs.existsSync(dest)); assert(fs.existsSync(dest));
...@@ -118,7 +118,7 @@ describe('cli', function() { ...@@ -118,7 +118,7 @@ describe('cli', function() {
var src = fixture('include-path/index.scss'); var src = fixture('include-path/index.scss');
var expected = read(fixture('include-path/expected.css'), 'utf8').trim(); var expected = read(fixture('include-path/expected.css'), 'utf8').trim();
var bin = spawn(cli, [src, '--stdout'].concat(includePaths)); var bin = spawn(cli, [src].concat(includePaths));
bin.stdout.setEncoding('utf8'); bin.stdout.setEncoding('utf8');
bin.stdout.once('data', function(data) { bin.stdout.once('data', function(data) {
...@@ -129,7 +129,7 @@ describe('cli', function() { ...@@ -129,7 +129,7 @@ describe('cli', function() {
it('should not exit with the --watch option', function(done) { it('should not exit with the --watch option', function(done) {
var src = fixture('simple/index.scss'); var src = fixture('simple/index.scss');
var bin = spawn(cli, [src, '--stdout', '--watch']); var bin = spawn(cli, [src, '--watch']);
var exited; var exited;
bin.on('close', function () { bin.on('close', function () {
...@@ -150,7 +150,7 @@ describe('cli', function() { ...@@ -150,7 +150,7 @@ describe('cli', function() {
fs.writeFileSync(fixture('simple/tmp.scss'), ''); fs.writeFileSync(fixture('simple/tmp.scss'), '');
var src = fixture('simple/tmp.scss'); var src = fixture('simple/tmp.scss');
var bin = spawn(cli, [src, '--stdout', '--watch']); var bin = spawn(cli, [src, '--watch']);
bin.stderr.setEncoding('utf8'); bin.stderr.setEncoding('utf8');
bin.stderr.on('data', function(data) { bin.stderr.on('data', function(data) {
...@@ -172,7 +172,7 @@ describe('cli', function() { ...@@ -172,7 +172,7 @@ describe('cli', function() {
var src = fixture('simple/foo.scss'); var src = fixture('simple/foo.scss');
var watched = fixture('simple/bar.scss'); var watched = fixture('simple/bar.scss');
var bin = spawn(cli, [ var bin = spawn(cli, [
src, '--stdout', '--watch', watched, src, '--watch', watched,
'--output-style', 'compressed' '--output-style', 'compressed'
]); ]);
......
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