Skip to content

Commit

Permalink
CLI: Retires stdout option.
Browse files Browse the repository at this point in the history
When no destination or output folder is provided,
it will print the output to stdout.

If the source-map option was set, it will print
it as well.

Issue URL: sass#669.
PR URL: sass#701.
  • Loading branch information
am11 committed Feb 23, 2015
1 parent 19b5e3c commit 20d666f
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 29 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
--image-path Path to prepend when using the `image-url()` helper
--precision The amount of precision allowed in decimal numbers
--stdout Print the resulting CSS to stdout
--importer Path to custom importer
--help Print usage info
```
Expand Down
28 changes: 11 additions & 17 deletions bin/node-sass
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ var Emitter = require('events').EventEmitter,
path = require('path'),
Gaze = require('gaze'),
meow = require('meow'),
replaceExt = require('replace-ext'),
stdin = require('get-stdin'),
grapher = require('sass-graph'),
render = require('../lib/render');
Expand Down Expand Up @@ -39,7 +38,6 @@ var cli = meow({
' --include-path Path to look for imported files',
' --image-path Path to prepend when using the `image-url()` helper',
' --precision The amount of precision allowed in decimal numbers',
' --stdout Print the resulting CSS to stdout',
' --importer Path to custom importer',
' --help Print usage info'
].join('\n')
Expand All @@ -48,7 +46,6 @@ var cli = meow({
'indented-syntax',
'omit-source-map-url',
'recursive',
'stdout',
'source-map-embed',
'source-map-contents',
'source-comments'
Expand Down Expand Up @@ -129,21 +126,14 @@ function getEmitter() {
*/

function getOptions(args, options) {
var dir = options.output ? path.resolve(process.cwd(), options.output) : process.cwd();

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(''));
}

return options;
Expand Down Expand Up @@ -208,7 +198,11 @@ function run(options, emitter) {

if (options.sourceMap) {
if (options.sourceMap === 'true') {
options.sourceMap = options.dest + '.map';
if (options.dest) {
options.sourceMap = options.dest + '.map';
} else {
options.sourceMap = path.basename(options.src, path.extname(options.src)), '.css.map';
}
} else {
options.sourceMap = path.resolve(process.cwd(), options.sourceMap);
}
Expand Down
7 changes: 6 additions & 1 deletion lib/render.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

if (options.sourceMap) {
emitter.emit('log', result.map);
}

return done();
}

Expand Down
20 changes: 10 additions & 10 deletions test/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ describe('cli', function() {
it('should read data from stdin', function(done) {
var src = fs.createReadStream(fixture('simple/index.scss'));
var expected = read(fixture('simple/expected.css'), 'utf8').trim();
var bin = spawn(cli, ['--stdout']);
var bin = spawn(cli);

bin.stdout.setEncoding('utf8');
bin.stdout.once('data', function(data) {
Expand All @@ -25,7 +25,7 @@ describe('cli', function() {
it('should compile sass using the --indented-syntax option', function(done) {
var src = fs.createReadStream(fixture('indent/index.sass'));
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.once('data', function(data) {
Expand All @@ -39,7 +39,7 @@ describe('cli', function() {
it('should compile with the --output-style option', function(done) {
var src = fs.createReadStream(fixture('compressed/index.scss'));
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.once('data', function(data) {
Expand All @@ -53,7 +53,7 @@ describe('cli', function() {
it('should compile with the --source-comments option', function(done) {
var src = fs.createReadStream(fixture('source-comments/index.scss'));
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.once('data', function(data) {
Expand All @@ -67,7 +67,7 @@ describe('cli', function() {
it('should compile with the --image-path option', function(done) {
var src = fs.createReadStream(fixture('image-path/index.scss'));
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.once('data', function(data) {
Expand All @@ -85,7 +85,7 @@ describe('cli', function() {

var src = fixture('simple/index.scss');
var dest = fixture('simple/index.css');
var bin = spawn(cli, [src]);
var bin = spawn(cli, [src, dest]);

bin.on('close', function() {
assert(fs.existsSync(dest));
Expand Down Expand Up @@ -118,7 +118,7 @@ describe('cli', function() {

var src = fixture('include-path/index.scss');
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.once('data', function(data) {
Expand All @@ -129,7 +129,7 @@ describe('cli', function() {

it('should not exit with the --watch option', function(done) {
var src = fixture('simple/index.scss');
var bin = spawn(cli, [src, '--stdout', '--watch']);
var bin = spawn(cli, [src, '--watch']);
var exited;

bin.on('close', function () {
Expand All @@ -150,7 +150,7 @@ describe('cli', function() {
fs.writeFileSync(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.on('data', function(data) {
Expand All @@ -172,7 +172,7 @@ describe('cli', function() {
var src = fixture('simple/foo.scss');
var watched = fixture('simple/bar.scss');
var bin = spawn(cli, [
src, '--stdout', '--watch', watched,
src, '--watch', watched,
'--output-style', 'compressed'
]);

Expand Down

0 comments on commit 20d666f

Please sign in to comment.