From 169af1fb585d0de856d37903ddca14a918a756b1 Mon Sep 17 00:00:00 2001 From: John Days Date: Wed, 27 May 2015 19:02:26 +0100 Subject: [PATCH 1/4] Add similar options from packager.sh to bundle.js, so we can develop and package with the same functionality --- local-cli/bundle.js | 33 ++++++++++++++++++++++++++------- 1 file changed, 26 insertions(+), 7 deletions(-) diff --git a/local-cli/bundle.js b/local-cli/bundle.js index f77480106..88bc2d520 100644 --- a/local-cli/bundle.js +++ b/local-cli/bundle.js @@ -9,12 +9,25 @@ var OUT_PATH = 'iOS/main.jsbundle'; function getBundle(flags) { + var outPath = flags.out ? flags.out : OUT_PATH; + + var projectRoots = [path.resolve(__dirname, '../../..')]; + if(flags.root){ + projectRoots.push(path.resolve(flags.root)); + } + + var assetRoots = [path.resolve(__dirname, '../../..')]; + if(flags.assetRoot){ + assetRoots.push(path.resolve(flags.assetRoot)); + } + + var options = { - projectRoots: [path.resolve(__dirname, '../../..')], + projectRoots: projectRoots, transformModulePath: require.resolve('../packager/transformer.js'), - assetRoots: [path.resolve(__dirname, '../../..')], + assetRoots: assetRoots, cacheVersion: '2', - blacklistRE: blacklist('ios') + blacklistRE: blacklist('ios'), }; var url = '/index.ios.bundle?dev=' + flags.dev; @@ -23,7 +36,7 @@ function getBundle(flags) { ReactPackager.buildPackageFromUrl(options, url) .done(function(bundle) { console.log('Build complete'); - fs.writeFile(OUT_PATH, bundle.getSource({ + fs.writeFile(outPath, bundle.getSource({ inlineSourceMap: false, minify: flags.minify }), function(err) { @@ -31,7 +44,7 @@ function getBundle(flags) { console.log(chalk.red('Error saving bundle to disk')); throw err; } else { - console.log('Successfully saved bundle to ' + OUT_PATH); + console.log('Successfully saved bundle to ' + outPath); } }); }); @@ -43,7 +56,10 @@ function showHelp() { '', 'Options:', ' --dev\t\tsets DEV flag to true', - ' --minify\tminify js bundle' + ' --minify\tminify js bundle', + ' --root\t\tadd another root(s) to be used in bundling in this project', + ' --assetRoot\t\tspecify the root directory of app assets', + ' --out\t\tspecify the output file', ].join('\n')); process.exit(1); } @@ -53,7 +69,10 @@ module.exports = { var flags = { help: args.indexOf('--help') !== -1, dev: args.indexOf('--dev') !== -1, - minify: args.indexOf('--minify') !== -1 + minify: args.indexOf('--minify') !== -1, + root: args.indexOf('--root') !== -1 ? args[args.indexOf('--root') + 1] : false, + assetRoot: args.indexOf('--assetRoot') !== -1 ? args[args.indexOf('--assetRoot') + 1] : false, + out: args.indexOf('--out') !== -1 ? args[args.indexOf('--out') + 1] : false, } if (flags.help) { From 34546e3bc89e77e6510b842eeb29ea0336581ad9 Mon Sep 17 00:00:00 2001 From: John Days Date: Tue, 2 Jun 2015 23:32:49 +0100 Subject: [PATCH 2/4] Spaces before and after if conditions --- local-cli/bundle.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/local-cli/bundle.js b/local-cli/bundle.js index 88bc2d520..9a2530514 100644 --- a/local-cli/bundle.js +++ b/local-cli/bundle.js @@ -12,12 +12,12 @@ function getBundle(flags) { var outPath = flags.out ? flags.out : OUT_PATH; var projectRoots = [path.resolve(__dirname, '../../..')]; - if(flags.root){ + if (flags.root) { projectRoots.push(path.resolve(flags.root)); } var assetRoots = [path.resolve(__dirname, '../../..')]; - if(flags.assetRoot){ + if (flags.assetRoot) { assetRoots.push(path.resolve(flags.assetRoot)); } From fcc4e4f8de3edb6dc536c65024c17610898bca37 Mon Sep 17 00:00:00 2001 From: John Days Date: Fri, 12 Jun 2015 13:06:31 +0100 Subject: [PATCH 3/4] [Bundler] Support multiple asset roots, for consistency with the packager --- local-cli/bundle.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/local-cli/bundle.js b/local-cli/bundle.js index 9a2530514..0dd374da5 100644 --- a/local-cli/bundle.js +++ b/local-cli/bundle.js @@ -17,8 +17,10 @@ function getBundle(flags) { } var assetRoots = [path.resolve(__dirname, '../../..')]; - if (flags.assetRoot) { - assetRoots.push(path.resolve(flags.assetRoot)); + if (flags.assetRoots) { + assetRoots = assetRoots.concat(flags.assetRoots.split(",").map(function(root) { + return path.resolve(root); + }); } @@ -58,7 +60,7 @@ function showHelp() { ' --dev\t\tsets DEV flag to true', ' --minify\tminify js bundle', ' --root\t\tadd another root(s) to be used in bundling in this project', - ' --assetRoot\t\tspecify the root directory of app assets', + ' --assetRoots\t\tspecify the root directories of app assets', ' --out\t\tspecify the output file', ].join('\n')); process.exit(1); @@ -71,7 +73,7 @@ module.exports = { dev: args.indexOf('--dev') !== -1, minify: args.indexOf('--minify') !== -1, root: args.indexOf('--root') !== -1 ? args[args.indexOf('--root') + 1] : false, - assetRoot: args.indexOf('--assetRoot') !== -1 ? args[args.indexOf('--assetRoot') + 1] : false, + assetRoots: args.indexOf('--assetRoots') !== -1 ? args[args.indexOf('--assetRoots') + 1] : false, out: args.indexOf('--out') !== -1 ? args[args.indexOf('--out') + 1] : false, } From a877c6bc68ef601a6e14f34bae32640a6d063254 Mon Sep 17 00:00:00 2001 From: John Days Date: Fri, 12 Jun 2015 14:03:28 +0100 Subject: [PATCH 4/4] Fix syntax error (missing ')') --- local-cli/bundle.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/local-cli/bundle.js b/local-cli/bundle.js index 0dd374da5..6a629b921 100644 --- a/local-cli/bundle.js +++ b/local-cli/bundle.js @@ -20,7 +20,7 @@ function getBundle(flags) { if (flags.assetRoots) { assetRoots = assetRoots.concat(flags.assetRoots.split(",").map(function(root) { return path.resolve(root); - }); + })); }