mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-04-23 20:01:01 +08:00
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`](e57683e420/local-cli/default.config.js (L33)), so they are available on the `new Config()` [instance](e57683e420/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 https://github.com/facebook/react-native/pull/7899 Differential Revision: D3613193 Pulled By: bestander fbshipit-source-id: 09a072f3b21e5239dfcd8da88a205bd28dc5d037
This commit is contained in:
committed by
Facebook Github Bot
parent
a37d5a825e
commit
e8b508144f
@@ -21,69 +21,56 @@ function saveBundle(output, bundle, args) {
|
||||
}
|
||||
|
||||
function buildBundle(args, config, output = outputBundle, packagerInstance) {
|
||||
return new Promise((resolve, reject) => {
|
||||
// This is used by a bazillion of npm modules we don't control so we don't
|
||||
// have other choice than defining it as an env variable here.
|
||||
process.env.NODE_ENV = args.dev ? 'development' : 'production';
|
||||
|
||||
// This is used by a bazillion of npm modules we don't control so we don't
|
||||
// have other choice than defining it as an env variable here.
|
||||
if (!process.env.NODE_ENV) {
|
||||
// If you're inlining environment variables, you can use babel to remove
|
||||
// this line:
|
||||
// https://www.npmjs.com/package/babel-remove-process-env-assignment
|
||||
process.env.NODE_ENV = args.dev ? 'development' : 'production';
|
||||
}
|
||||
const options = {
|
||||
projectRoots: config.getProjectRoots(),
|
||||
assetRoots: config.getAssetRoots(),
|
||||
blacklistRE: config.getBlacklistRE(args.platform),
|
||||
getTransformOptionsModulePath: config.getTransformOptionsModulePath,
|
||||
transformModulePath: args.transformer,
|
||||
extraNodeModules: config.extraNodeModules,
|
||||
nonPersistent: true,
|
||||
resetCache: args.resetCache,
|
||||
};
|
||||
|
||||
const transformModulePath =
|
||||
args.transformer ? path.resolve(args.transformer) :
|
||||
typeof config.getTransformModulePath === 'function' ? config.getTransformModulePath() :
|
||||
undefined;
|
||||
const requestOpts = {
|
||||
entryFile: args.entryFile,
|
||||
sourceMapUrl: args.sourcemapOutput,
|
||||
dev: args.dev,
|
||||
minify: !args.dev,
|
||||
platform: args.platform,
|
||||
};
|
||||
|
||||
const options = {
|
||||
projectRoots: config.getProjectRoots(),
|
||||
assetRoots: config.getAssetRoots(),
|
||||
blacklistRE: config.getBlacklistRE(args.platform),
|
||||
getTransformOptionsModulePath: config.getTransformOptionsModulePath,
|
||||
transformModulePath: transformModulePath,
|
||||
extraNodeModules: config.extraNodeModules,
|
||||
nonPersistent: true,
|
||||
resetCache: args['reset-cache'],
|
||||
};
|
||||
// If a packager instance was not provided, then just create one for this
|
||||
// bundle command and close it down afterwards.
|
||||
var shouldClosePackager = false;
|
||||
if (!packagerInstance) {
|
||||
packagerInstance = new Server(options);
|
||||
shouldClosePackager = true;
|
||||
}
|
||||
|
||||
const requestOpts = {
|
||||
entryFile: args['entry-file'],
|
||||
sourceMapUrl: args['sourcemap-output'],
|
||||
dev: args.dev,
|
||||
minify: !args.dev,
|
||||
platform: args.platform,
|
||||
};
|
||||
const bundlePromise = output.build(packagerInstance, requestOpts)
|
||||
.then(bundle => {
|
||||
if (shouldClosePackager) {
|
||||
packagerInstance.end();
|
||||
}
|
||||
return saveBundle(output, bundle, args);
|
||||
});
|
||||
|
||||
// If a packager instance was not provided, then just create one for this
|
||||
// bundle command and close it down afterwards.
|
||||
var shouldClosePackager = false;
|
||||
if (!packagerInstance) {
|
||||
packagerInstance = new Server(options);
|
||||
shouldClosePackager = true;
|
||||
}
|
||||
// Save the assets of the bundle
|
||||
const assets = bundlePromise
|
||||
.then(bundle => bundle.getAssets())
|
||||
.then(outputAssets => saveAssets(
|
||||
outputAssets,
|
||||
args.platform,
|
||||
args.assetsDest,
|
||||
));
|
||||
|
||||
const bundlePromise = output.build(packagerInstance, requestOpts)
|
||||
.then(bundle => {
|
||||
if (shouldClosePackager) {
|
||||
packagerInstance.end();
|
||||
}
|
||||
return saveBundle(output, bundle, args);
|
||||
});
|
||||
|
||||
// Save the assets of the bundle
|
||||
const assets = bundlePromise
|
||||
.then(bundle => bundle.getAssets())
|
||||
.then(outputAssets => saveAssets(
|
||||
outputAssets,
|
||||
args.platform,
|
||||
args['assets-dest']
|
||||
));
|
||||
|
||||
// When we're done saving bundle output and the assets, we're done.
|
||||
resolve(assets);
|
||||
});
|
||||
// When we're done saving bundle output and the assets, we're done.
|
||||
return assets;
|
||||
}
|
||||
|
||||
module.exports = buildBundle;
|
||||
|
||||
Reference in New Issue
Block a user