Skip to content

Commit

Permalink
Pipe http response straight to file
Browse files Browse the repository at this point in the history
  • Loading branch information
arthuralee committed Apr 17, 2015
1 parent a8e471d commit 598635b
Showing 1 changed file with 6 additions and 16 deletions.
22 changes: 6 additions & 16 deletions local-cli/bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,21 @@ var fs = require('fs');

var OUT_PATH = 'iOS/main.jsbundle';

function getBundle(flags, callback) {
function getBundle(flags) {
var options = {
host: 'localhost',
port: 8081,
path: '/index.ios.bundle?dev=' + flags.dev + '&minify=' + flags.minify
};

var file = fs.createWriteStream(OUT_PATH);

console.log('Requesting bundle from local server');
var req = http.request(options, function(res) {
var bundle = '';

res.on('data', function (chunk) {
bundle += chunk;
});
res.pipe(file);

res.on('end', function () {
console.log('Got bundle');
callback(bundle);
console.log('Successfully saved bundle to ' + OUT_PATH);
});
});

Expand Down Expand Up @@ -55,14 +52,7 @@ module.exports = {
if (flags.help) {
showHelp();
} else {
getBundle(flags, function(bundle) {
fs.writeFile(OUT_PATH, bundle, function(err) {
if(err) {
return console.err('Error writing bundle to file', err);
}
console.log('Successfully saved bundle to ' + OUT_PATH);
});
});
getBundle(flags);
}
}
}

0 comments on commit 598635b

Please sign in to comment.