1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 | 'use strict';
|
21 |
|
22 | require('./setupBabel');
|
23 |
|
24 | var fs = require('fs');
|
25 | var path = require('path');
|
26 | var commander = require('commander');
|
27 | var Util = require('./utils');
|
28 | var Parser = require('./parser');
|
29 | var bundle = require('./bundler');
|
30 |
|
31 | function main() {
|
32 | commander.description('React Native Bundle Spliter').option('--output <path>', 'Path to store bundle.', 'build').option('--config <path>', 'Config file for react-native-split.').option('--platform', 'Specify bundle platform. ', 'android').option('--dev [boolean]', 'Generate dev module.').parse(process.argv);
|
33 |
|
34 | if (!commander.config) {
|
35 | throw new Error('You must enter an config file (by --config).');
|
36 | }
|
37 |
|
38 | function isFileExists(fname) {
|
39 | try {
|
40 | fs.accessSync(fname, fs.F_OK);
|
41 | return true;
|
42 | } catch (e) {
|
43 | return false;
|
44 | }
|
45 | }
|
46 |
|
47 | var configFile = path.resolve(process.cwd(), commander.config);
|
48 | var outputDir = path.resolve(process.cwd(), commander.output);
|
49 |
|
50 | if (!isFileExists(configFile)) {
|
51 | console.log('Config file ' + configFile + ' is not exists!');
|
52 | process.exit(-1);
|
53 | }
|
54 |
|
55 | var rawConfig = JSON.parse(fs.readFileSync(configFile, 'utf-8'));
|
56 | var workRoot = path.dirname(configFile);
|
57 | var outputRoot = path.join(outputDir, 'bundle-output');
|
58 | Util.ensureFolder(outputRoot);
|
59 |
|
60 | var config = {
|
61 | root: workRoot,
|
62 | dev: commander.dev === 'true',
|
63 | packageName: rawConfig['package'],
|
64 | platform: commander.platform,
|
65 | outputDir: path.join(outputRoot, 'split'),
|
66 | bundleDir: path.join(outputRoot, 'bundle'),
|
67 | baseEntry: {
|
68 | index: rawConfig.base.index,
|
69 | includes: rawConfig.base.includes
|
70 | },
|
71 | customEntries: rawConfig.custom
|
72 | };
|
73 | if (!isFileExists(config.baseEntry.index)) {
|
74 | console.log('Index of base does not exists!');
|
75 | }
|
76 |
|
77 | console.log('Work on root: ' + config.root);
|
78 | console.log('Dev mode: ' + config.dev);
|
79 | bundle(config, function (err, data) {
|
80 | if (err) throw err;
|
81 | console.log('===[Bundle] Finish!===');
|
82 | var parser = new Parser(data, config);
|
83 | parser.splitBundle();
|
84 | });
|
85 | }
|
86 |
|
87 | exports.default = main; |
\ | No newline at end of file |