|
8 | 8 | */ |
9 | 9 | 'use strict'; |
10 | 10 |
|
11 | | -const log = require('../util/log').out('bundle'); |
| 11 | +const buildBundle = require('./buildBundle'); |
| 12 | +const bundleCommandLineArgs = require('./bundleCommandLineArgs'); |
12 | 13 | const parseCommandLine = require('../../../packager/parseCommandLine'); |
13 | | -const processBundle = require('./processBundle'); |
14 | | -const Promise = require('promise'); |
15 | | -const ReactPackager = require('../../../packager/react-packager'); |
16 | | -const saveBundleAndMap = require('./saveBundleAndMap'); |
17 | 14 |
|
18 | 15 | /** |
19 | 16 | * Builds the bundle starting to look for dependencies at the given entry path. |
20 | 17 | */ |
21 | 18 | function bundle(argv, config) { |
22 | | - return new Promise((resolve, reject) => { |
23 | | - _bundle(argv, config, resolve, reject); |
24 | | - }); |
25 | | -} |
26 | | - |
27 | | -function _bundle(argv, config, resolve, reject) { |
28 | | - const args = parseCommandLine([ |
29 | | - { |
30 | | - command: 'entry-file', |
31 | | - description: 'Path to the root JS file, either absolute or relative to JS root', |
32 | | - type: 'string', |
33 | | - required: true, |
34 | | - }, { |
35 | | - command: 'platform', |
36 | | - description: 'Either "ios" or "android"', |
37 | | - type: 'string', |
38 | | - required: true, |
39 | | - }, { |
40 | | - command: 'transformer', |
41 | | - description: 'Specify a custom transformer to be used (absolute path)', |
42 | | - type: 'string', |
43 | | - default: require.resolve('../../../packager/transformer'), |
44 | | - }, { |
45 | | - command: 'dev', |
46 | | - description: 'If false, warnings are disabled and the bundle is minified', |
47 | | - default: true, |
48 | | - }, { |
49 | | - command: 'bundle-output', |
50 | | - description: 'File name where to store the resulting bundle, ex. /tmp/groups.bundle', |
51 | | - type: 'string', |
52 | | - required: true, |
53 | | - }, { |
54 | | - command: 'sourcemap-output', |
55 | | - description: 'File name where to store the sourcemap file for resulting bundle, ex. /tmp/groups.map', |
56 | | - type: 'string', |
57 | | - }, { |
58 | | - command: 'assets-dest', |
59 | | - description: 'Directory name where to store assets referenced in the bundle', |
60 | | - type: 'string', |
61 | | - }, { |
62 | | - command: 'verbose', |
63 | | - description: 'Enables logging', |
64 | | - default: false, |
65 | | - }, |
66 | | - ], argv); |
67 | | - |
68 | | - // This is used by a bazillion of npm modules we don't control so we don't |
69 | | - // have other choice than defining it as an env variable here. |
70 | | - process.env.NODE_ENV = args.dev ? 'development' : 'production'; |
71 | | - |
72 | | - const options = { |
73 | | - projectRoots: config.getProjectRoots(), |
74 | | - assetRoots: config.getAssetRoots(), |
75 | | - blacklistRE: config.getBlacklistRE(args.platform), |
76 | | - transformModulePath: args.transformer, |
77 | | - verbose: args.verbose, |
78 | | - }; |
79 | | - |
80 | | - const requestOpts = { |
81 | | - entryFile: args['entry-file'], |
82 | | - dev: args.dev, |
83 | | - minify: !args.dev, |
84 | | - platform: args.platform, |
85 | | - }; |
86 | | - |
87 | | - resolve(ReactPackager.createClientFor(options).then(client => { |
88 | | - log('Created ReactPackager'); |
89 | | - return client.buildBundle(requestOpts) |
90 | | - .then(outputBundle => { |
91 | | - log('Closing client'); |
92 | | - client.close(); |
93 | | - return outputBundle; |
94 | | - }) |
95 | | - .then(outputBundle => processBundle(outputBundle, !args.dev)) |
96 | | - .then(outputBundle => saveBundleAndMap( |
97 | | - outputBundle, |
98 | | - args.platform, |
99 | | - args['bundle-output'], |
100 | | - args['sourcemap-output'], |
101 | | - args['assets-dest'] |
102 | | - )); |
103 | | - })); |
| 19 | + return buildBundle(parseCommandLine(bundleCommandLineArgs, argv), config); |
104 | 20 | } |
105 | 21 |
|
106 | 22 | module.exports = bundle; |
0 commit comments