Skip to content

Commit

Permalink
Merge pull request facebook#2809 from hzerica/master-pr-6
Browse files Browse the repository at this point in the history
[CLI]let 'react-native bundle' support 'platform' option.
  • Loading branch information
mkonicek committed Sep 18, 2015
2 parents 4eecef1 + 9e60d57 commit f6b97ea
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions local-cli/bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,18 @@ var chalk = require('chalk');
var blacklist = require('../packager/blacklist.js');
var ReactPackager = require('../packager/react-packager');

var OUT_PATH = 'ios/main.jsbundle';
var URL_PATH = '/index.ios.bundle?dev=';
var OUT_PATH = {
android: 'android/app/src/main/assets/index.android.bundle',
ios: 'ios/main.jsbundle'
};
var URL_PATH = {
android: '/index.android.bundle?platform=android&dev=',
ios: '/index.ios.bundle?platform=ios&dev='
};

function getBundle(flags) {

var outPath = flags.out ? flags.out : OUT_PATH;
var platform = flags.platform ? flags.platform : 'ios';
var outPath = flags.out ? flags.out : OUT_PATH[platform];

var projectRoots = [path.resolve(__dirname, '../../..')];
if (flags.root) {
Expand All @@ -30,10 +36,10 @@ function getBundle(flags) {
transformModulePath: require.resolve('../packager/transformer.js'),
assetRoots: assetRoots,
cacheVersion: '2',
blacklistRE: blacklist('ios'),
blacklistRE: blacklist(platform),
};

var url = flags.url ? flags.url.replace(/\.js$/i, '.bundle?dev=') : URL_PATH;
var url = flags.url ? flags.url.replace(/\.js$/i, '.bundle?dev=') : URL_PATH[platform];
url = url.match(/^\//) ? url : '/' + url;
url += flags.dev;

Expand Down Expand Up @@ -66,6 +72,7 @@ function showHelp() {
' --assetRoots\t\tspecify the root directories of app assets',
' --out\t\tspecify the output file',
' --url\t\tspecify the bundle file url',
' --platform\t\tspecify the platform(android/ios)',
].join('\n'));
process.exit(1);
}
Expand All @@ -77,6 +84,7 @@ module.exports = {
dev: args.indexOf('--dev') !== -1,
minify: args.indexOf('--minify') !== -1,
root: args.indexOf('--root') !== -1 ? args[args.indexOf('--root') + 1] : false,
platform: args.indexOf('--platform') !== -1 ? args[args.indexOf('--platform') + 1] : false,
assetRoots: args.indexOf('--assetRoots') !== -1 ? args[args.indexOf('--assetRoots') + 1] : false,
out: args.indexOf('--out') !== -1 ? args[args.indexOf('--out') + 1] : false,
url: args.indexOf('--url') !== -1 ? args[args.indexOf('--url') + 1] : false,
Expand Down

0 comments on commit f6b97ea

Please sign in to comment.