Skip to content

Commit c15ec71

Browse files
sam-swarrfacebook-github-bot-9
authored andcommitted
Create script to generate NSURL builders for RN Routes
Reviewed By: martinbigio Differential Revision: D2513000 fb-gh-sync-id: 4ff695b4d5ea55ae9bb21df4000d2dead5b7ff97
1 parent 54b5b62 commit c15ec71

File tree

3 files changed

+111
-87
lines changed

3 files changed

+111
-87
lines changed
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/**
2+
* Copyright (c) 2015-present, Facebook, Inc.
3+
* All rights reserved.
4+
*
5+
* This source code is licensed under the BSD-style license found in the
6+
* LICENSE file in the root directory of this source tree. An additional grant
7+
* of patent rights can be found in the PATENTS file in the same directory.
8+
*/
9+
'use strict';
10+
11+
const log = require('../util/log').out('bundle');
12+
const processBundle = require('./processBundle');
13+
const Promise = require('promise');
14+
const ReactPackager = require('../../../packager/react-packager');
15+
const saveBundleAndMap = require('./saveBundleAndMap');
16+
17+
function buildBundle(args, config) {
18+
return new Promise((resolve, reject) => {
19+
20+
// This is used by a bazillion of npm modules we don't control so we don't
21+
// have other choice than defining it as an env variable here.
22+
process.env.NODE_ENV = args.dev ? 'development' : 'production';
23+
24+
const options = {
25+
projectRoots: config.getProjectRoots(),
26+
assetRoots: config.getAssetRoots(),
27+
blacklistRE: config.getBlacklistRE(),
28+
transformModulePath: args.transformer,
29+
verbose: args.verbose,
30+
};
31+
32+
const requestOpts = {
33+
entryFile: args['entry-file'],
34+
dev: args.dev,
35+
minify: !args.dev,
36+
platform: args.platform,
37+
};
38+
39+
resolve(ReactPackager.createClientFor(options).then(client => {
40+
log('Created ReactPackager');
41+
return client.buildBundle(requestOpts)
42+
.then(outputBundle => {
43+
log('Closing client');
44+
client.close();
45+
return outputBundle;
46+
})
47+
.then(outputBundle => processBundle(outputBundle, !args.dev))
48+
.then(outputBundle => saveBundleAndMap(
49+
outputBundle,
50+
args.platform,
51+
args['bundle-output'],
52+
args['sourcemap-output'],
53+
args['assets-dest']
54+
));
55+
}));
56+
});
57+
}
58+
59+
module.exports = buildBundle;

private-cli/src/bundle/bundle.js

Lines changed: 3 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -8,99 +8,15 @@
88
*/
99
'use strict';
1010

11-
const log = require('../util/log').out('bundle');
11+
const buildBundle = require('./buildBundle');
12+
const bundleCommandLineArgs = require('./bundleCommandLineArgs');
1213
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');
1714

1815
/**
1916
* Builds the bundle starting to look for dependencies at the given entry path.
2017
*/
2118
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);
10420
}
10521

10622
module.exports = bundle;
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/**
2+
* Copyright (c) 2015-present, Facebook, Inc.
3+
* All rights reserved.
4+
*
5+
* This source code is licensed under the BSD-style license found in the
6+
* LICENSE file in the root directory of this source tree. An additional grant
7+
* of patent rights can be found in the PATENTS file in the same directory.
8+
*/
9+
'use strict';
10+
11+
module.exports = [
12+
{
13+
command: 'entry-file',
14+
description: 'Path to the root JS file, either absolute or relative to JS root',
15+
type: 'string',
16+
required: true,
17+
}, {
18+
command: 'platform',
19+
description: 'Either "ios" or "android"',
20+
type: 'string',
21+
required: true,
22+
}, {
23+
command: 'transformer',
24+
description: 'Specify a custom transformer to be used (absolute path)',
25+
type: 'string',
26+
default: require.resolve('../../../packager/transformer'),
27+
}, {
28+
command: 'dev',
29+
description: 'If false, warnings are disabled and the bundle is minified',
30+
default: true,
31+
}, {
32+
command: 'bundle-output',
33+
description: 'File name where to store the resulting bundle, ex. /tmp/groups.bundle',
34+
type: 'string',
35+
required: true,
36+
}, {
37+
command: 'sourcemap-output',
38+
description: 'File name where to store the sourcemap file for resulting bundle, ex. /tmp/groups.map',
39+
type: 'string',
40+
}, {
41+
command: 'assets-dest',
42+
description: 'Directory name where to store assets referenced in the bundle',
43+
type: 'string',
44+
}, {
45+
command: 'verbose',
46+
description: 'Enables logging',
47+
default: false,
48+
}
49+
];

0 commit comments

Comments
 (0)