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 #593 from SebastianOsuna/output-directory
Browse files Browse the repository at this point in the history
Output directory is created if it doesn't exists.
  • Loading branch information
am11 committed Jan 5, 2015
2 parents 21035b3 + cfa4341 commit f7a2ee5
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 5 deletions.
18 changes: 13 additions & 5 deletions lib/render.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
var fs = require('fs'),
chalk = require('chalk'),
sass = require('./');
sass = require('./'),
path = require('path'),
mkdirp = require('mkdirp');

/**
* Render
Expand Down Expand Up @@ -47,14 +49,20 @@ module.exports = function(options, emitter) {

emitter.emit('warn', chalk.green('Rendering Complete, saving .css file...'));

fs.writeFile(options.dest, result.css, function(err) {
mkdirp(path.dirname(options.dest), function(err) {
if (err) {
return emitter.emit('error', chalk.red(err));
}

emitter.emit('warn', chalk.green('Wrote CSS to ' + options.dest));
emitter.emit('write', err, options.dest, result.css);
done();
fs.writeFile(options.dest, result.css, function (err) {
if (err) {
return emitter.emit('error', chalk.red(err));
}

emitter.emit('warn', chalk.green('Wrote CSS to ' + options.dest));
emitter.emit('write', err, options.dest, result.css);
done();
});
});

if (options.sourceMap) {
Expand Down
20 changes: 20 additions & 0 deletions test/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,26 @@ describe('cli', function() {
});
});

describe('node-sass in.scss --output path/to/file/out.css', function() {
it('should create the output directory', function(done) {
var src = fixture('output-directory/index.scss');
var dest = fixture('output-directory/path/to/file/index.css');
var bin = spawn(cli, [src, '--output', path.dirname(dest)]);

bin.on('close', function() {
assert(fs.existsSync(path.dirname(dest)));
fs.unlinkSync(dest);
fs.rmdirSync(path.dirname(dest));
dest = path.dirname(dest);
fs.rmdirSync(path.dirname(dest));
dest = path.dirname(dest);
fs.rmdirSync(path.dirname(dest));
done();
});
});

});

describe('importer', function() {
var dest = fixture('include-files/index.css');
var src = fixture('include-files/index.scss');
Expand Down
16 changes: 16 additions & 0 deletions test/fixtures/output-directory/index.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#navbar {
width: 80%;
height: 23px;
}

#navbar ul {
list-style-type: none;
}

#navbar li {
float: left;

a {
font-weight: bold;
}
}

0 comments on commit f7a2ee5

Please # to comment.