Skip to content

Commit e8b5081

Browse files
grabbouFacebook Github Bot
authored andcommitted
Merge rnpm cli into react-native
Summary: This is an initial step of rewriting the CLI interface to use `rnpm` one (commander, plugins etc.). It's scope is to move all existing commands to use rnpm CLI interface, so that we get plugins, flags and our existing ecosystem working out of the box. <s>This is still WIP and some of the commands are left commented out.</s> For the `config` of `rnpm` (functions get info about project and dependency), <s>I am thinking we can merge them with</s> we decided to merge it with [`default.config.js`](https://github.com/grabbou/react-native/blob/e57683e420210749a5a6b802b4e70adb69675786/local-cli/default.config.js#L33), so they are available on the `new Config()` [instance](https://github.com/grabbou/react-native/blob/e57683e420210749a5a6b802b4e70adb69675786/local-cli/cliEntry.js#L59) (which means we don't have to change anything and current plugins, like runIOS and runAndroid can just start using it [w/o depending on any extra argument](https://github.com/grabbou/react-native/blob/e57683e420210749a5a6b802b4e Closes facebook#7899 Differential Revision: D3613193 Pulled By: bestander fbshipit-source-id: 09a072f3b21e5239dfcd8da88a205bd28dc5d037
1 parent a37d5a8 commit e8b5081

File tree

127 files changed

+1151
-1382
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

127 files changed

+1151
-1382
lines changed

jestSupport/env.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ global.regeneratorRuntime = require.requireActual('regenerator-runtime/runtime')
2323
jest
2424
.mock('ensureComponentIsNative')
2525
.mock('Image')
26+
.mock('npmlog')
2627
.mock('NativeModules')
2728
.mock('Text')
2829
.mock('View');

local-cli/bundle/buildBundle.js

Lines changed: 44 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -21,69 +21,56 @@ function saveBundle(output, bundle, args) {
2121
}
2222

2323
function buildBundle(args, config, output = outputBundle, packagerInstance) {
24-
return new Promise((resolve, reject) => {
24+
// This is used by a bazillion of npm modules we don't control so we don't
25+
// have other choice than defining it as an env variable here.
26+
process.env.NODE_ENV = args.dev ? 'development' : 'production';
2527

26-
// This is used by a bazillion of npm modules we don't control so we don't
27-
// have other choice than defining it as an env variable here.
28-
if (!process.env.NODE_ENV) {
29-
// If you're inlining environment variables, you can use babel to remove
30-
// this line:
31-
// https://www.npmjs.com/package/babel-remove-process-env-assignment
32-
process.env.NODE_ENV = args.dev ? 'development' : 'production';
33-
}
28+
const options = {
29+
projectRoots: config.getProjectRoots(),
30+
assetRoots: config.getAssetRoots(),
31+
blacklistRE: config.getBlacklistRE(args.platform),
32+
getTransformOptionsModulePath: config.getTransformOptionsModulePath,
33+
transformModulePath: args.transformer,
34+
extraNodeModules: config.extraNodeModules,
35+
nonPersistent: true,
36+
resetCache: args.resetCache,
37+
};
3438

35-
const transformModulePath =
36-
args.transformer ? path.resolve(args.transformer) :
37-
typeof config.getTransformModulePath === 'function' ? config.getTransformModulePath() :
38-
undefined;
39+
const requestOpts = {
40+
entryFile: args.entryFile,
41+
sourceMapUrl: args.sourcemapOutput,
42+
dev: args.dev,
43+
minify: !args.dev,
44+
platform: args.platform,
45+
};
3946

40-
const options = {
41-
projectRoots: config.getProjectRoots(),
42-
assetRoots: config.getAssetRoots(),
43-
blacklistRE: config.getBlacklistRE(args.platform),
44-
getTransformOptionsModulePath: config.getTransformOptionsModulePath,
45-
transformModulePath: transformModulePath,
46-
extraNodeModules: config.extraNodeModules,
47-
nonPersistent: true,
48-
resetCache: args['reset-cache'],
49-
};
47+
// If a packager instance was not provided, then just create one for this
48+
// bundle command and close it down afterwards.
49+
var shouldClosePackager = false;
50+
if (!packagerInstance) {
51+
packagerInstance = new Server(options);
52+
shouldClosePackager = true;
53+
}
5054

51-
const requestOpts = {
52-
entryFile: args['entry-file'],
53-
sourceMapUrl: args['sourcemap-output'],
54-
dev: args.dev,
55-
minify: !args.dev,
56-
platform: args.platform,
57-
};
55+
const bundlePromise = output.build(packagerInstance, requestOpts)
56+
.then(bundle => {
57+
if (shouldClosePackager) {
58+
packagerInstance.end();
59+
}
60+
return saveBundle(output, bundle, args);
61+
});
5862

59-
// If a packager instance was not provided, then just create one for this
60-
// bundle command and close it down afterwards.
61-
var shouldClosePackager = false;
62-
if (!packagerInstance) {
63-
packagerInstance = new Server(options);
64-
shouldClosePackager = true;
65-
}
63+
// Save the assets of the bundle
64+
const assets = bundlePromise
65+
.then(bundle => bundle.getAssets())
66+
.then(outputAssets => saveAssets(
67+
outputAssets,
68+
args.platform,
69+
args.assetsDest,
70+
));
6671

67-
const bundlePromise = output.build(packagerInstance, requestOpts)
68-
.then(bundle => {
69-
if (shouldClosePackager) {
70-
packagerInstance.end();
71-
}
72-
return saveBundle(output, bundle, args);
73-
});
74-
75-
// Save the assets of the bundle
76-
const assets = bundlePromise
77-
.then(bundle => bundle.getAssets())
78-
.then(outputAssets => saveAssets(
79-
outputAssets,
80-
args.platform,
81-
args['assets-dest']
82-
));
83-
84-
// When we're done saving bundle output and the assets, we're done.
85-
resolve(assets);
86-
});
72+
// When we're done saving bundle output and the assets, we're done.
73+
return assets;
8774
}
8875

8976
module.exports = buildBundle;

local-cli/bundle/bundle.js

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,26 +8,30 @@
88
*/
99

1010
const buildBundle = require('./buildBundle');
11-
const bundleCommandLineArgs = require('./bundleCommandLineArgs');
12-
const parseCommandLine = require('../util/parseCommandLine');
1311
const outputBundle = require('./output/bundle');
1412
const outputPrepack = require('./output/prepack');
13+
const bundleCommandLineArgs = require('./bundleCommandLineArgs');
1514

1615
/**
1716
* Builds the bundle starting to look for dependencies at the given entry path.
1817
*/
19-
function bundleWithOutput(argv, config, output, packagerInstance) {
20-
const args = parseCommandLine(bundleCommandLineArgs, argv);
18+
function bundleWithOutput(argv, config, args, output, packagerInstance) {
2119
if (!output) {
2220
output = args.prepack ? outputPrepack : outputBundle;
2321
}
2422
return buildBundle(args, config, output, packagerInstance);
25-
2623
}
2724

28-
function bundle(argv, config, packagerInstance) {
29-
return bundleWithOutput(argv, config, undefined, packagerInstance);
25+
function bundle(argv, config, args, packagerInstance) {
26+
return bundleWithOutput(argv, config, args, undefined, packagerInstance);
3027
}
3128

32-
module.exports = bundle;
33-
module.exports.withOutput = bundleWithOutput;
29+
module.exports = {
30+
name: 'bundle',
31+
description: 'builds the javascript bundle for offline use',
32+
func: bundle,
33+
options: bundleCommandLineArgs,
34+
35+
// not used by the CLI itself
36+
withOutput: bundleWithOutput,
37+
};

local-cli/bundle/bundleCommandLineArgs.js

Lines changed: 19 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -10,56 +10,47 @@
1010

1111
module.exports = [
1212
{
13-
command: 'entry-file',
13+
command: '--entry-file <path>',
1414
description: 'Path to the root JS file, either absolute or relative to JS root',
15-
type: 'string',
16-
required: true,
1715
}, {
18-
command: 'platform',
16+
command: '--platform [string]',
1917
description: 'Either "ios" or "android"',
20-
type: 'string',
18+
default: 'ios',
2119
}, {
22-
command: 'transformer',
23-
description: 'Specify a custom transformer to be used',
24-
type: 'string',
25-
default: null,
20+
command: '--transformer [string]',
21+
description: 'Specify a custom transformer to be used (absolute path)',
22+
default: require.resolve('../../packager/transformer'),
2623
}, {
27-
command: 'dev',
24+
command: '--dev [boolean]',
2825
description: 'If false, warnings are disabled and the bundle is minified',
26+
parse: (val) => val === 'false' ? false : true,
2927
default: true,
3028
}, {
31-
command: 'prepack',
32-
description: 'If true, the output bundle will use the Prepack format.',
33-
default: false
29+
command: '--prepack',
30+
description: 'When passed, the output bundle will use the Prepack format.',
3431
}, {
35-
command: 'bridge-config',
32+
command: '--bridge-config [string]',
3633
description: 'File name of a a JSON export of __fbBatchedBridgeConfig. Used by Prepack. Ex. ./bridgeconfig.json',
37-
type: 'string'
3834
}, {
39-
command: 'bundle-output',
35+
command: '--bundle-output <string>',
4036
description: 'File name where to store the resulting bundle, ex. /tmp/groups.bundle',
41-
type: 'string',
42-
required: true,
4337
}, {
44-
command: 'bundle-encoding',
38+
command: '--bundle-encoding [string]',
4539
description: 'Encoding the bundle should be written in (https://nodejs.org/api/buffer.html#buffer_buffer).',
46-
type: 'string',
4740
default: 'utf8',
4841
}, {
49-
command: 'sourcemap-output',
42+
command: '--sourcemap-output [string]',
5043
description: 'File name where to store the sourcemap file for resulting bundle, ex. /tmp/groups.map',
51-
type: 'string',
5244
}, {
53-
command: 'assets-dest',
45+
command: '--assets-dest [string]',
5446
description: 'Directory name where to store assets referenced in the bundle',
55-
type: 'string',
5647
}, {
57-
command: 'verbose',
48+
command: '--verbose',
5849
description: 'Enables logging',
5950
default: false,
6051
}, {
61-
command: 'reset-cache',
52+
command: '--reset-cache',
6253
description: 'Removes cached files',
63-
default: false
64-
}
54+
default: false,
55+
},
6556
];

local-cli/bundle/output/bundle.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@ function createCodeWithMap(bundle, dev) {
2828

2929
function saveBundleAndMap(bundle, options, log) {
3030
const {
31-
'bundle-output': bundleOutput,
32-
'bundle-encoding': encoding,
31+
bundleOutput,
32+
bundleEncoding: encoding,
3333
dev,
34-
'sourcemap-output': sourcemapOutput,
34+
sourcemapOutput
3535
} = options;
3636

3737
log('start');

local-cli/bundle/output/prepack.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ function buildPrepackBundle(packagerClient, requestOptions) {
1616

1717
function savePrepackBundle(bundle, options, log) {
1818
const {
19-
'bundle-output': bundleOutput,
20-
'bridge-config': bridgeConfig,
19+
bundleOutput,
20+
bridgeConfig,
2121
} = options;
2222

2323
const result = bundle.build({

local-cli/bundle/output/unbundle/as-assets.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ const MODULES_DIR = 'js-modules';
3030
*/
3131
function saveAsAssets(bundle, options, log) {
3232
const {
33-
'bundle-output': bundleOutput,
34-
'bundle-encoding': encoding,
35-
'sourcemap-output': sourcemapOutput,
33+
bundleOutput,
34+
bundleEncoding: encoding,
35+
sourcemapOutput
3636
} = options;
3737

3838
log('start');

local-cli/bundle/output/unbundle/as-indexed-file.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ const SIZEOF_UINT32 = 4;
2626
*/
2727
function saveAsIndexedFile(bundle, options, log) {
2828
const {
29-
'bundle-output': bundleOutput,
30-
'bundle-encoding': encoding,
31-
'sourcemap-output': sourcemapOutput,
29+
bundleOutput,
30+
bundleEncoding: encoding,
31+
sourcemapOutput
3232
} = options;
3333

3434
log('start');

local-cli/bundle/unbundle.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,19 @@
88
*/
99

1010
const bundleWithOutput = require('./bundle').withOutput;
11+
const bundleCommandLineArgs = require('./bundleCommandLineArgs');
1112
const outputUnbundle = require('./output/unbundle');
1213

1314
/**
1415
* Builds the bundle starting to look for dependencies at the given entry path.
1516
*/
16-
function unbundle(argv, config, packagerInstance) {
17-
return bundleWithOutput(argv, config, outputUnbundle, packagerInstance);
17+
function unbundle(argv, config, args, packagerInstance) {
18+
return bundleWithOutput(argv, config, args, outputUnbundle, packagerInstance);
1819
}
1920

20-
module.exports = unbundle;
21+
module.exports = {
22+
name: 'unbundle',
23+
description: 'builds javascript as "unbundle" for offline use',
24+
func: unbundle,
25+
options: bundleCommandLineArgs,
26+
};

0 commit comments

Comments
 (0)