Skip to content

Commit

Permalink
Ensure path to outfile exists before opening stream
Browse files Browse the repository at this point in the history
  • Loading branch information
jackwanders committed Nov 16, 2014
1 parent 691efa3 commit a0a81e9
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
3 changes: 3 additions & 0 deletions bin/cmd.js
Expand Up @@ -2,6 +2,8 @@
var fs = require('fs');
var JSONStream = require('JSONStream');
var through = require('through2');
var mkdirp = require('mkdirp');
var path = require('path');

var b = require('./args')(process.argv.slice(2));
process.stdout.on('error', process.exit);
Expand Down Expand Up @@ -57,6 +59,7 @@ bundle.on('error', errorExit);

var outfile = b.argv.o || b.argv.outfile;
if (outfile) {
mkdirp.sync(path.dirname(outfile));
bundle.pipe(fs.createWriteStream(outfile));
}
else {
Expand Down
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -45,6 +45,7 @@
"insert-module-globals": "^6.1.0",
"isarray": "0.0.1",
"labeled-stream-splicer": "^1.0.0",
"mkdirp": "^0.5.0",
"module-deps": "^3.5.0",
"os-browserify": "~0.1.1",
"parents": "~0.0.1",
Expand Down
8 changes: 4 additions & 4 deletions test/externalize.js
Expand Up @@ -28,18 +28,18 @@ fs.writeFileSync(

test('externalize bin', function (t) {
t.plan(5);

var commands = [
[ '-r', './robot.js', '-o', path.join(pubdir, 'common.js') ],
[ '-x', './robot.js', 'beep.js', '-o', path.join(pubdir, 'beep.js') ],
[ '-x', './robot.js', 'boop.js', '-o', path.join(pubdir, 'boop.js') ]
[ '-x', './robot.js', 'boop.js', '-o', path.join(pubdir, 'boop/bop.js') ]
];
(function next () {
if (commands.length === 0) {
var common = fs.readFileSync(path.join(pubdir, 'common.js'));
var beep = fs.readFileSync(path.join(pubdir, 'beep.js'));
var boop = fs.readFileSync(path.join(pubdir, 'boop.js'));
var boop = fs.readFileSync(path.join(pubdir, 'boop/bop.js'));

vm.runInNewContext(common + beep, {
console: { log: function (msg) { t.equal(msg, 'BEEP!') } }
});
Expand Down

0 comments on commit a0a81e9

Please sign in to comment.