Commit 6a818b5d by Paul C Pederson

CLI: Adds --quiet flag

parent fce09934
...@@ -452,6 +452,7 @@ Output will be saved with the same name as input SASS file into the current work ...@@ -452,6 +452,7 @@ Output will be saved with the same name as input SASS file into the current work
-o, --output Output directory -o, --output Output directory
-x, --omit-source-map-url Omit source map URL comment from output -x, --omit-source-map-url Omit source map URL comment from output
-i, --indented-syntax Treat data from stdin as sass code (versus scss) -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 -v, --version Prints version info
--output-style CSS output style (nested | expanded | compact | compressed) --output-style CSS output style (nested | expanded | compact | compressed)
--indent-type Indent type for output CSS (space | tab) --indent-type Indent type for output CSS (space | tab)
......
...@@ -34,6 +34,7 @@ var cli = meow({ ...@@ -34,6 +34,7 @@ var cli = meow({
' -o, --output Output directory', ' -o, --output Output directory',
' -x, --omit-source-map-url Omit source map URL comment from output', ' -x, --omit-source-map-url Omit source map URL comment from output',
' -i, --indented-syntax Treat data from stdin as sass code (versus scss)', ' -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', ' -v, --version Prints version info',
' --output-style CSS output style (nested | expanded | compact | compressed)', ' --output-style CSS output style (nested | expanded | compact | compressed)',
' --indent-type Indent type for output CSS (space | tab)', ' --indent-type Indent type for output CSS (space | tab)',
...@@ -54,6 +55,7 @@ var cli = meow({ ...@@ -54,6 +55,7 @@ var cli = meow({
boolean: [ boolean: [
'indented-syntax', 'indented-syntax',
'omit-source-map-url', 'omit-source-map-url',
'quiet',
'recursive', 'recursive',
'source-map-embed', 'source-map-embed',
'source-map-contents', 'source-map-contents',
...@@ -74,6 +76,7 @@ var cli = meow({ ...@@ -74,6 +76,7 @@ var cli = meow({
alias: { alias: {
c: 'source-comments', c: 'source-comments',
i: 'indented-syntax', i: 'indented-syntax',
q: 'quiet',
o: 'output', o: 'output',
r: 'recursive', r: 'recursive',
x: 'omit-source-map-url', x: 'omit-source-map-url',
...@@ -87,6 +90,7 @@ var cli = meow({ ...@@ -87,6 +90,7 @@ var cli = meow({
linefeed: 'lf', linefeed: 'lf',
'output-style': 'nested', 'output-style': 'nested',
precision: 5, precision: 5,
quiet: false,
recursive: true recursive: true
} }
}); });
...@@ -139,7 +143,9 @@ function getEmitter() { ...@@ -139,7 +143,9 @@ function getEmitter() {
}); });
emitter.on('warn', function(data) { emitter.on('warn', function(data) {
console.warn(data); if (!options.quiet) {
console.warn(data);
}
}); });
emitter.on('log', function(data) { emitter.on('log', function(data) {
......
...@@ -39,6 +39,20 @@ describe('cli', function() { ...@@ -39,6 +39,20 @@ describe('cli', function() {
src.pipe(bin.stdin); 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) { 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();
...@@ -150,6 +164,45 @@ describe('cli', function() { ...@@ -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) { 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, '--watch']); var bin = spawn(cli, [src, '--watch']);
...@@ -188,6 +241,28 @@ describe('cli', function() { ...@@ -188,6 +241,28 @@ describe('cli', function() {
}, 500); }, 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) { it('should render all watched files', function(done) {
var src = fixture('simple/bar.scss'); var src = fixture('simple/bar.scss');
......
body {
background-color: $green;
}
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