Commit 221b26b2 by blopker

don't write to disk with --stdout

parent 6d507401
...@@ -18,9 +18,17 @@ function render(options, emitter) { ...@@ -18,9 +18,17 @@ function render(options, emitter) {
var done = function() { var done = function() {
if (--todo <= 0) { if (--todo <= 0) {
emitter.emit('done'); emitter.emit('done');
return;
} }
}; };
// Write to stdout
if (options.stdout) {
emitter.emit('log', css);
return done();
}
// Write to disk
emitter.emit('warn', chalk.green('Rendering Complete, saving .css file...')); emitter.emit('warn', chalk.green('Rendering Complete, saving .css file...'));
fs.writeFile(options.outFile, css, function(err) { fs.writeFile(options.outFile, css, function(err) {
...@@ -40,10 +48,6 @@ function render(options, emitter) { ...@@ -40,10 +48,6 @@ function render(options, emitter) {
}); });
} }
if (options.stdout) {
emitter.emit('log', css);
}
emitter.emit('render', css); emitter.emit('render', css);
}, },
error: function(error) { error: function(error) {
......
...@@ -28,6 +28,8 @@ var expectedSampleCustomImagePath = 'body {\n\ ...@@ -28,6 +28,8 @@ var expectedSampleCustomImagePath = 'body {\n\
background-image: url("/path/to/images/image.png"); }\n'; background-image: url("/path/to/images/image.png"); }\n';
var sampleScssPath = path.join(__dirname, 'sample.scss'); var sampleScssPath = path.join(__dirname, 'sample.scss');
var sampleCssOutputPath = path.join(__dirname, '../sample.css');
var sampleCssMapOutputPath = path.join(__dirname, '../sample.css.map');
describe('cli', function() { describe('cli', function() {
it('should print help when run with no arguments', function(done) { it('should print help when run with no arguments', function(done) {
...@@ -127,6 +129,18 @@ describe('cli', function() { ...@@ -127,6 +129,18 @@ describe('cli', function() {
}); });
}); });
it('should not write to disk with the --stdout option', function(done){
var emitter = cli(['--stdout', sampleScssPath]);
emitter.on('error', done);
emitter.on('done', function(){
fs.exists(sampleCssOutputPath, function(exists) {
assert(!exists);
if (exists) {fs.unlinkSync(sampleCssOutputPath);}
done();
});
});
});
it('should not exit with the --watch option', function(done){ it('should not exit with the --watch option', function(done){
var command = cliPath + ' --watch ' + sampleScssPath; var command = cliPath + ' --watch ' + sampleScssPath;
var child = exec('node ' + command); var child = exec('node ' + command);
...@@ -150,15 +164,15 @@ describe('cli', function() { ...@@ -150,15 +164,15 @@ describe('cli', function() {
var emitter = cli([sampleScssPath, '--source-map']); var emitter = cli([sampleScssPath, '--source-map']);
emitter.on('error', done); emitter.on('error', done);
emitter.on('write-source-map', function(err, file) { emitter.on('write-source-map', function(err, file) {
assert.equal(file, path.join(__dirname, '../sample.css.map')); assert.equal(file, sampleCssMapOutputPath);
fs.exists(file, function(exists) { fs.exists(file, function(exists) {
assert(exists); assert(exists);
}); });
}); });
emitter.on('done', function() { emitter.on('done', function() {
fs.unlink(path.join(__dirname, '../sample.css.map'), function() { fs.unlink(sampleCssMapOutputPath, function() {
fs.unlink(path.join(__dirname, '../sample.css'), function() { fs.unlink(sampleCssOutputPath, function() {
done(); done();
}); });
}); });
...@@ -176,7 +190,7 @@ describe('cli', function() { ...@@ -176,7 +190,7 @@ describe('cli', function() {
}); });
emitter.on('done', function() { emitter.on('done', function() {
fs.unlink(path.join(__dirname, '../sample.map'), function() { fs.unlink(path.join(__dirname, '../sample.map'), function() {
fs.unlink(path.join(__dirname, '../sample.css'), function() { fs.unlink(sampleCssOutputPath, function() {
done(); done();
}); });
}); });
...@@ -187,14 +201,14 @@ describe('cli', function() { ...@@ -187,14 +201,14 @@ describe('cli', function() {
var emitter = cli([sampleScssPath, '--source-comments', 'map']); var emitter = cli([sampleScssPath, '--source-comments', 'map']);
emitter.on('error', done); emitter.on('error', done);
emitter.on('write-source-map', function(err, file) { emitter.on('write-source-map', function(err, file) {
assert.equal(file, path.join(__dirname, '../sample.css.map')); assert.equal(file, sampleCssMapOutputPath);
fs.exists(file, function(exists) { fs.exists(file, function(exists) {
assert(exists); assert(exists);
}); });
}); });
emitter.on('done', function() { emitter.on('done', function() {
fs.unlink(path.join(__dirname, '../sample.css.map'), function() { fs.unlink(sampleCssMapOutputPath, function() {
fs.unlink(path.join(__dirname, '../sample.css'), function() { fs.unlink(sampleCssOutputPath, function() {
done(); done();
}); });
}); });
......
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