Skip to content

Commit

Permalink
CLI: Adds --quiet flag
Browse files Browse the repository at this point in the history
  • Loading branch information
paulcpederson committed Apr 14, 2015
1 parent fce0993 commit 6a818b5
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,7 @@ Output will be saved with the same name as input SASS file into the current work
-o, --output Output directory
-x, --omit-source-map-url Omit source map URL comment from output
-i, --indented-syntax Treat data from stdin as sass code (versus scss)
-q, --quiet Suppress log output except on error
-v, --version Prints version info
--output-style CSS output style (nested | expanded | compact | compressed)
--indent-type Indent type for output CSS (space | tab)
Expand Down
8 changes: 7 additions & 1 deletion bin/node-sass
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ var cli = meow({
' -o, --output Output directory',
' -x, --omit-source-map-url Omit source map URL comment from output',
' -i, --indented-syntax Treat data from stdin as sass code (versus scss)',
' -q, --quiet Suppress log output except on error',
' -v, --version Prints version info',
' --output-style CSS output style (nested | expanded | compact | compressed)',
' --indent-type Indent type for output CSS (space | tab)',
Expand All @@ -54,6 +55,7 @@ var cli = meow({
boolean: [
'indented-syntax',
'omit-source-map-url',
'quiet',
'recursive',
'source-map-embed',
'source-map-contents',
Expand All @@ -74,6 +76,7 @@ var cli = meow({
alias: {
c: 'source-comments',
i: 'indented-syntax',
q: 'quiet',
o: 'output',
r: 'recursive',
x: 'omit-source-map-url',
Expand All @@ -87,6 +90,7 @@ var cli = meow({
linefeed: 'lf',
'output-style': 'nested',
precision: 5,
quiet: false,
recursive: true
}
});
Expand Down Expand Up @@ -139,7 +143,9 @@ function getEmitter() {
});

emitter.on('warn', function(data) {
console.warn(data);
if (!options.quiet) {
console.warn(data);
}
});

emitter.on('log', function(data) {
Expand Down
75 changes: 75 additions & 0 deletions test/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,20 @@ describe('cli', function() {
src.pipe(bin.stdin);
});

it('should compile with the --quiet option', function(done) {
var src = fs.createReadStream(fixture('simple/index.scss'));
var expected = read(fixture('simple/expected.css'), 'utf8').trim();
var bin = spawn(cli, ['--quiet']);

bin.stdout.setEncoding('utf8');
bin.stdout.once('data', function(data) {
assert.equal(data.trim(), expected.replace(/\r\n/g, '\n'));
done();
});

src.pipe(bin.stdin);
});

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();
Expand Down Expand Up @@ -150,6 +164,45 @@ describe('cli', function() {
});
});

it('should compile silently using the --quiet option', function(done) {
process.chdir(fixture('simple'));

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

bin.stderr.once('data', function() {
didEmit = true;
});

bin.once('close', function() {
assert.equal(didEmit, false);
fs.unlinkSync(dest);
process.chdir(__dirname);
done();
});
});

it('should still report errors with the --quiet option', function(done) {
process.chdir(fixture('invalid'));

var src = fixture('invalid/index.scss');
var dest = fixture('invalid/index.css');
var bin = spawn(cli, [src, dest, '--quiet']);
var didEmit = false;

bin.stderr.once('data', function() {
didEmit = true;
});

bin.once('close', function() {
assert.equal(didEmit, true);
process.chdir(__dirname);
done();
});
});

it('should not exit with the --watch option', function(done) {
var src = fixture('simple/index.scss');
var bin = spawn(cli, [src, '--watch']);
Expand Down Expand Up @@ -188,6 +241,28 @@ describe('cli', function() {
}, 500);
});

it('should emit nothing on file change when using --watch and --quiet options', function(done) {
var src = fixture('simple/tmp.scss');
var didEmit = false;
fs.writeFileSync(src, '');

var bin = spawn(cli, ['--watch', '--quiet', src]);

bin.stderr.setEncoding('utf8');
bin.stderr.once('data', function() {
didEmit = true;
});

setTimeout(function() {
fs.appendFileSync(src, 'body {}');
setTimeout(function() {
assert.equal(didEmit, false);
done();
fs.unlinkSync(src);
}, 200);
}, 500);
});

it('should render all watched files', function(done) {
var src = fixture('simple/bar.scss');

Expand Down
3 changes: 3 additions & 0 deletions test/fixtures/invalid/index.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
body {
background-color: $green;
}

0 comments on commit 6a818b5

Please sign in to comment.