Skip to content
This repository has been archived by the owner on Jul 24, 2024. It is now read-only.

Commit

Permalink
Merge pull request #761 from am11/master
Browse files Browse the repository at this point in the history
CLI: Do not require input file on watch
  • Loading branch information
am11 committed Mar 14, 2015
2 parents 2c88e9c + 7a9238d commit c97411e
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 34 deletions.
10 changes: 5 additions & 5 deletions bin/node-sass
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ var cli = meow({
'include-path',
'output',
'output-style',
'precision'
'precision',
'watch'
],
alias: {
c: 'source-comments',
Expand Down Expand Up @@ -125,7 +126,7 @@ function getEmitter() {
*/

function getOptions(args, options) {
options.src = args[0];
options.src = options.watch ? options.watch : args[0];

if (args[1]) {
options.dest = path.resolve(process.cwd(), args[1]);
Expand Down Expand Up @@ -227,15 +228,14 @@ function run(options, emitter) {
* Arguments and options
*/

var input = cli.input;
var options = getOptions(input, cli.flags);
var options = getOptions(cli.input, cli.flags);
var emitter = getEmitter();

/**
* Show usage if no arguments are supplied
*/

if (!input.length && process.stdin.isTTY) {
if (!options.src && process.stdin.isTTY) {
emitter.emit('error', [
'Provide a Sass file to render',
'',
Expand Down
55 changes: 26 additions & 29 deletions test/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ describe('cli', function() {
var dest = fixture('simple/index.css');
var bin = spawn(cli, [src, dest]);

bin.on('close', function() {
bin.once('close', function() {
assert(fs.existsSync(dest));
fs.unlinkSync(dest);
process.chdir(__dirname);
Expand All @@ -88,7 +88,7 @@ describe('cli', function() {
var dest = fixture('simple/index-custom.css');
var bin = spawn(cli, [src, dest]);

bin.on('close', function() {
bin.once('close', function() {
assert(fs.existsSync(dest));
fs.unlinkSync(dest);
process.chdir(__dirname);
Expand Down Expand Up @@ -118,7 +118,7 @@ describe('cli', function() {
var bin = spawn(cli, [src, '--watch']);
var exited;

bin.on('close', function() {
bin.once('close', function() {
exited = true;
});

Expand All @@ -133,15 +133,15 @@ describe('cli', function() {
});

it('should emit `warn` on file change when using --watch option', function(done) {
fs.writeFileSync(fixture('simple/tmp.scss'), '');

var src = fixture('simple/tmp.scss');
var bin = spawn(cli, [src, '--watch']);

fs.writeFileSync(src, '');

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

bin.stderr.setEncoding('utf8');
bin.stderr.on('data', function(data) {
bin.stderr.once('data', function(data) {
assert(data.trim() === '=> changed: ' + src);
bin.kill();
fs.unlinkSync(src);
done();
});
Expand All @@ -152,27 +152,24 @@ describe('cli', function() {
});

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

fs.writeFileSync(src, '');

var src = fixture('simple/foo.scss');
var watched = fixture('simple/bar.scss');
var bin = spawn(cli, [
src, '--watch', watched,
'--output-style', 'compressed'
'--output-style', 'compressed',
'--watch', src
]);

bin.stdout.setEncoding('utf8');
bin.stdout.on('data', function(data) {
bin.stdout.once('data', function(data) {
assert(data.trim() === 'body{background:white}');
bin.kill();
fs.unlinkSync(src);
fs.unlinkSync(watched);
done();
});

setTimeout(function() {
fs.appendFileSync(watched, 'body{background:white}');
fs.appendFileSync(src, 'body{background:white}');
}, 500);
});
});
Expand All @@ -183,7 +180,7 @@ describe('cli', function() {
var dest = fixture('simple/index.css');
var bin = spawn(cli, [src, '--output', path.dirname(dest)]);

bin.on('close', function() {
bin.once('close', function() {
assert(fs.existsSync(dest));
fs.unlinkSync(dest);
done();
Expand All @@ -198,7 +195,7 @@ describe('cli', function() {
var expectedMap = read(fixture('source-map/expected.map'), 'utf8').trim().replace(/\r\n/g, '\n');
var bin = spawn(cli, [src, '--output', path.dirname(destCss), '--source-map', destMap]);

bin.on('close', function() {
bin.once('close', function() {
assert.equal(read(destCss, 'utf8').trim(), expectedCss);
assert.equal(read(destMap, 'utf8').trim(), expectedMap);
fs.unlinkSync(destCss);
Expand All @@ -216,7 +213,7 @@ describe('cli', function() {
'--source-map', map, '--omit-source-map-url'
]);

bin.on('close', function() {
bin.once('close', function() {
assert(read(dest, 'utf8').indexOf('sourceMappingURL') === -1);
assert(fs.existsSync(map));
fs.unlinkSync(map);
Expand All @@ -232,7 +229,7 @@ describe('cli', function() {
var dest = fixture('output-directory/path/to/file/index.css');
var bin = spawn(cli, [src, '--output', path.dirname(dest)]);

bin.on('close', function() {
bin.once('close', function() {
assert(fs.existsSync(path.dirname(dest)));
fs.unlinkSync(dest);
fs.rmdirSync(path.dirname(dest));
Expand All @@ -257,7 +254,7 @@ describe('cli', function() {
'--importer', fixture('extras/my_custom_importer_file_and_data_cb.js')
]);

bin.on('close', function() {
bin.once('close', function() {
assert.equal(read(dest, 'utf8').trim(), expected);
fs.unlinkSync(dest);
done();
Expand All @@ -270,7 +267,7 @@ describe('cli', function() {
'--importer', fixture('extras/my_custom_importer_file_cb.js')
]);

bin.on('close', function() {
bin.once('close', function() {
if (fs.existsSync(dest)) {
assert.equal(read(dest, 'utf8').trim(), '');
fs.unlinkSync(dest);
Expand All @@ -286,7 +283,7 @@ describe('cli', function() {
'--importer', fixture('extras/my_custom_importer_data_cb.js')
]);

bin.on('close', function() {
bin.once('close', function() {
assert.equal(read(dest, 'utf8').trim(), expected);
fs.unlinkSync(dest);
done();
Expand All @@ -299,7 +296,7 @@ describe('cli', function() {
'--importer', fixture('extras/my_custom_importer_file_and_data.js')
]);

bin.on('close', function() {
bin.once('close', function() {
assert.equal(read(dest, 'utf8').trim(), expected);
fs.unlinkSync(dest);
done();
Expand All @@ -312,7 +309,7 @@ describe('cli', function() {
'--importer', fixture('extras/my_custom_importer_file.js')
]);

bin.on('close', function() {
bin.once('close', function() {
if (fs.existsSync(dest)) {
assert.equal(read(dest, 'utf8').trim(), '');
fs.unlinkSync(dest);
Expand All @@ -328,7 +325,7 @@ describe('cli', function() {
'--importer', fixture('extras/my_custom_importer_data.js')
]);

bin.on('close', function() {
bin.once('close', function() {
assert.equal(read(dest, 'utf8').trim(), expected);
fs.unlinkSync(dest);
done();
Expand All @@ -341,7 +338,7 @@ describe('cli', function() {
'--importer', fixture('non/existing/path')
]);

bin.on('close', function(code) {
bin.once('close', function(code) {
assert(code !== 0);
done();
});
Expand Down

0 comments on commit c97411e

Please sign in to comment.