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