-
Notifications
You must be signed in to change notification settings - Fork 24.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2cc3c50
commit a8e471d
Showing
2 changed files
with
74 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
var http = require('http'); | ||
var fs = require('fs'); | ||
|
||
var OUT_PATH = 'iOS/main.jsbundle'; | ||
|
||
function getBundle(flags, callback) { | ||
var options = { | ||
host: 'localhost', | ||
port: 8081, | ||
path: '/index.ios.bundle?dev=' + flags.dev + '&minify=' + flags.minify | ||
}; | ||
|
||
console.log('Requesting bundle from local server'); | ||
var req = http.request(options, function(res) { | ||
var bundle = ''; | ||
|
||
res.on('data', function (chunk) { | ||
bundle += chunk; | ||
}); | ||
|
||
res.on('end', function () { | ||
console.log('Got bundle'); | ||
callback(bundle); | ||
}); | ||
}); | ||
|
||
// set up error handler | ||
req.on('error', function(err) { | ||
console.error('An error occured while connecting to local server. Are you sure the server is running? Run npm start'); | ||
}); | ||
|
||
// end request | ||
req.end(); | ||
} | ||
|
||
function showHelp() { | ||
console.log([ | ||
'Usage: react-native bundle [options]', | ||
'', | ||
'Options:', | ||
' --dev\t\tsets DEV flag to true', | ||
' --minify\tminify js bundle' | ||
].join('\n')); | ||
process.exit(1); | ||
} | ||
|
||
module.exports = { | ||
init: function(args) { | ||
var flags = { | ||
help: args.indexOf('--help') !== -1, | ||
dev: args.indexOf('--dev') !== -1, | ||
minify: args.indexOf('--minify') !== -1 | ||
} | ||
|
||
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); | ||
}); | ||
}); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters