Permalink
Browse files

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 #7899

Differential Revision: D3613193

Pulled By: bestander

fbshipit-source-id: 09a072f3b21e5239dfcd8da88a205bd28dc5d037
  • Loading branch information...
grabbou authored and Facebook Github Bot committed Jul 30, 2016
1 parent a37d5a8 commit e8b508144fdcdea436cf4d80d99daec757505c70
Showing with 1,151 additions and 1,382 deletions.
  1. +1 −0 jestSupport/env.js
  2. +44 −57 local-cli/bundle/buildBundle.js
  3. +13 −9 local-cli/bundle/bundle.js
  4. +19 −28 local-cli/bundle/bundleCommandLineArgs.js
  5. +3 −3 local-cli/bundle/output/bundle.js
  6. +2 −2 local-cli/bundle/output/prepack.js
  7. +3 −3 local-cli/bundle/output/unbundle/as-assets.js
  8. +3 −3 local-cli/bundle/output/unbundle/as-indexed-file.js
  9. +9 −3 local-cli/bundle/unbundle.js
  10. +111 −131 local-cli/cliEntry.js
  11. +70 −0 local-cli/commands.js
  12. +4 −0 local-cli/default.config.js
  13. +28 −41 local-cli/dependencies/dependencies.js
  14. +55 −0 local-cli/init/init.js
  15. +13 −19 local-cli/library/library.js
  16. +7 −4 local-cli/logAndroid/logAndroid.js
  17. +11 −8 local-cli/logIOS/logIOS.js
  18. 0 local-cli/rnpm/core/{test/fixtures → __fixtures__}/android.js
  19. 0 local-cli/rnpm/core/{test/fixtures → __fixtures__}/commands.js
  20. 0 local-cli/rnpm/core/{test/fixtures → __fixtures__}/dependencies.js
  21. 0 local-cli/rnpm/core/{test/fixtures → __fixtures__}/files/AndroidManifest.xml
  22. 0 local-cli/rnpm/core/{test/fixtures → __fixtures__}/files/Main.java
  23. 0 local-cli/rnpm/core/{test/fixtures → __fixtures__}/files/ReactPackage.java
  24. 0 local-cli/rnpm/core/{test/fixtures → __fixtures__}/files/package.json
  25. 0 local-cli/rnpm/core/{test/fixtures → __fixtures__}/files/project.pbxproj
  26. 0 local-cli/rnpm/core/{test/fixtures → __fixtures__}/ios.js
  27. 0 local-cli/rnpm/core/{test/fixtures → __fixtures__}/projects.js
  28. +1 −1 local-cli/rnpm/core/{test → __tests__}/android/findAndroidAppFolder.spec.js
  29. +1 −1 local-cli/rnpm/core/{test → __tests__}/android/findManifest.spec.js
  30. +1 −1 local-cli/rnpm/core/{test → __tests__}/android/findPackageClassName.spec.js
  31. +1 −1 local-cli/rnpm/core/{test → __tests__}/android/getDependencyConfig.spec.js
  32. +1 −1 local-cli/rnpm/core/{test → __tests__}/android/getProjectConfig.spec.js
  33. +1 −1 local-cli/rnpm/core/{test → __tests__}/android/readManifest.spec.js
  34. +1 −1 local-cli/rnpm/core/{test → __tests__}/findAssets.spec.js
  35. 0 local-cli/rnpm/core/{test/findPlugins.js → __tests__/findPlugins.spec.js}
  36. +2 −2 local-cli/rnpm/core/{test → __tests__}/ios/findProject.spec.js
  37. +11 −1 local-cli/rnpm/core/{test → __tests__}/ios/getProjectConfig.spec.js
  38. 0 local-cli/rnpm/core/{test → __tests__}/makeCommand.spec.js
  39. +14 −0 local-cli/rnpm/core/src/config/ios/index.js
  40. +1 −2 local-cli/rnpm/core/src/findPlugins.js
  41. +1 −10 local-cli/rnpm/core/src/getCommands.js
  42. +0 −171 local-cli/rnpm/core/test/getCommands.spec.js
  43. +0 −11 local-cli/rnpm/install/index.js
  44. +5 −0 local-cli/rnpm/install/install.js
  45. +1 −1 local-cli/rnpm/install/src/install.js
  46. +1 −1 local-cli/rnpm/install/src/uninstall.js
  47. +5 −0 local-cli/rnpm/install/uninstall.js
  48. 0 local-cli/rnpm/link/{test/fixtures → __fixtures__}/android/0.17/MainActivity.java
  49. 0 local-cli/rnpm/link/{test/fixtures → __fixtures__}/android/0.17/patchedMainActivity.java
  50. 0 local-cli/rnpm/link/{test/fixtures → __fixtures__}/android/0.18/MainActivity.java
  51. 0 local-cli/rnpm/link/{test/fixtures → __fixtures__}/android/0.18/patchedMainActivity.java
  52. 0 local-cli/rnpm/link/{test/fixtures → __fixtures__}/android/0.20/MainActivity.java
  53. 0 local-cli/rnpm/link/{test/fixtures → __fixtures__}/android/build.gradle
  54. 0 local-cli/rnpm/link/{test/fixtures → __fixtures__}/android/patchedBuild.gradle
  55. 0 local-cli/rnpm/link/{test/fixtures → __fixtures__}/android/patchedSettings.gradle
  56. 0 local-cli/rnpm/link/{test/fixtures → __fixtures__}/android/settings.gradle
  57. 0 local-cli/rnpm/link/{test/fixtures → __fixtures__}/linearGradient.pbxproj
  58. 0 local-cli/rnpm/link/{test/fixtures → __fixtures__}/project.pbxproj
  59. +7 −5 local-cli/rnpm/link/{test/android/patches/applyPatch.js → __tests__/android/applyPatch.spec.js}
  60. +20 −0 local-cli/rnpm/link/__tests__/android/isInstalled.spec.js
  61. +18 −0 local-cli/rnpm/link/__tests__/android/makeBuildPatch.spec.js
  62. +20 −0 local-cli/rnpm/link/__tests__/android/makeImportPatch.spec.js
  63. +28 −0 local-cli/rnpm/link/__tests__/android/makePackagePatch.spec.js
  64. +12 −9 local-cli/rnpm/link/{test/android/patches → __tests__/android}/makeSettingsPatch.spec.js
  65. +7 −5 local-cli/rnpm/link/{test → __tests__}/getDependencyConfig.spec.js
  66. +9 −13 local-cli/rnpm/link/{test → __tests__}/getProjectDependencies.spec.js
  67. +6 −4 local-cli/rnpm/link/{test → __tests__}/groupFilesByType.spec.js
  68. +27 −0 local-cli/rnpm/link/__tests__/ios/addFileToProject.spec.js
  69. +10 −7 local-cli/rnpm/link/{test → __tests__}/ios/addProjectToLibraries.spec.js
  70. +45 −0 local-cli/rnpm/link/__tests__/ios/addSharedLibraries.spec.js
  71. +17 −10 local-cli/rnpm/link/{test → __tests__}/ios/createGroup.spec.js
  72. +9 −6 local-cli/rnpm/link/{test → __tests__}/ios/getBuildProperty.spec.js
  73. +14 −9 local-cli/rnpm/link/{test → __tests__}/ios/getGroup.spec.js
  74. +7 −6 local-cli/rnpm/link/{test → __tests__}/ios/getHeaderSearchPath.spec.js
  75. +9 −14 local-cli/rnpm/link/{test → __tests__}/ios/getHeadersInFolder.spec.js
  76. +10 −9 local-cli/rnpm/link/{test → __tests__}/ios/getPlist.spec.js
  77. +9 −6 local-cli/rnpm/link/{test → __tests__}/ios/getPlistPath.spec.js
  78. +10 −7 local-cli/rnpm/link/{test → __tests__}/ios/getProducts.spec.js
  79. +10 −7 local-cli/rnpm/link/{test → __tests__}/ios/hasLibraryImported.spec.js
  80. +8 −18 local-cli/rnpm/link/{test → __tests__}/ios/isInstalled.spec.js
  81. +9 −8 local-cli/rnpm/link/{test → __tests__}/ios/mapHeaderSearchPaths.spec.js
  82. +9 −6 local-cli/rnpm/link/{test → __tests__}/ios/removeProjectFromLibraries.js
  83. +13 −9 local-cli/rnpm/link/{test → __tests__}/ios/removeProjectFromProject.spec.js
  84. +37 −0 local-cli/rnpm/link/__tests__/ios/removeSharedLibrary.spec.js
  85. +35 −40 local-cli/rnpm/link/{test → __tests__}/link.spec.js
  86. +8 −6 local-cli/rnpm/link/{test → __tests__}/promiseWaterfall.spec.js
  87. +0 −9 local-cli/rnpm/link/index.js
  88. +5 −0 local-cli/rnpm/link/link.js
  89. +0 −16 local-cli/rnpm/link/src/android/getPrefix.js
  90. +1 −1 local-cli/rnpm/link/src/android/isInstalled.js
  91. +0 −6 local-cli/rnpm/link/src/android/patches/0.17/makeImportPatch.js
  92. +0 −10 local-cli/rnpm/link/src/android/patches/0.17/makePackagePatch.js
  93. +0 −6 local-cli/rnpm/link/src/android/patches/0.18/makeImportPatch.js
  94. +0 −10 local-cli/rnpm/link/src/android/patches/0.18/makePackagePatch.js
  95. 0 local-cli/rnpm/link/src/android/patches/{0.20 → }/makeImportPatch.js
  96. +1 −1 local-cli/rnpm/link/src/android/patches/{0.20 → }/makePackagePatch.js
  97. +4 −9 local-cli/rnpm/link/src/android/registerNativeModule.js
  98. +2 −5 local-cli/rnpm/link/src/android/unregisterNativeModule.js
  99. +0 −5 local-cli/rnpm/link/src/getReactNativeVersion.js
  100. +13 −0 local-cli/rnpm/link/src/ios/addSharedLibraries.js
  101. +2 −16 local-cli/rnpm/link/src/ios/copyAssets.js
  102. +25 −0 local-cli/rnpm/link/src/ios/createGroupWithMessage.js
  103. +2 −13 local-cli/rnpm/link/src/ios/registerNativeModule.js
  104. +8 −0 local-cli/rnpm/link/src/ios/removeSharedLibraries.js
  105. +14 −5 local-cli/rnpm/link/src/ios/unregisterNativeModule.js
  106. +1 −1 local-cli/rnpm/link/src/link.js
  107. +10 −7 local-cli/rnpm/link/src/unlink.js
  108. +0 −28 local-cli/rnpm/link/test/android/isInstalled.spec.js
  109. +0 −31 local-cli/rnpm/link/test/android/patches/0.17/makeImportPatch.js
  110. +0 −36 local-cli/rnpm/link/test/android/patches/0.17/makePackagePatch.js
  111. +0 −31 local-cli/rnpm/link/test/android/patches/0.18/makeImportPatch.js
  112. +0 −36 local-cli/rnpm/link/test/android/patches/0.18/makePackagePatch.js
  113. +0 −31 local-cli/rnpm/link/test/android/patches/0.20/makeImportPatch.js
  114. +0 −36 local-cli/rnpm/link/test/android/patches/0.20/makePackagePatch.js
  115. +0 −17 local-cli/rnpm/link/test/android/patches/makeBuildPatch.spec.js
  116. +0 −20 local-cli/rnpm/link/test/getPrefix.spec.js
  117. +0 −22 local-cli/rnpm/link/test/ios/addFileToProject.spec.js
  118. +5 −0 local-cli/rnpm/link/unlink.js
  119. +48 −61 local-cli/runAndroid/runAndroid.js
  120. +45 −72 local-cli/runIOS/runIOS.js
  121. +1 −1 local-cli/server/runServer.js
  122. +47 −90 local-cli/server/server.js
  123. +11 −4 local-cli/upgrade/upgrade.js
  124. +32 −0 local-cli/util/assertRequiredOptions.js
  125. +3 −0 local-cli/util/parseCommandLine.js
  126. +0 −22 local-cli/version/version.js
  127. +4 −3 package.json
View
@@ -23,6 +23,7 @@ global.regeneratorRuntime = require.requireActual('regenerator-runtime/runtime')
jest
.mock('ensureComponentIsNative')
.mock('Image')
.mock('npmlog')
.mock('NativeModules')
.mock('Text')
.mock('View');
@@ -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 comment has been minimized.

Show comment
Hide comment
@xsdlr
@xsdlr
// 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;
View
@@ -8,26 +8,30 @@
*/
const buildBundle = require('./buildBundle');
const bundleCommandLineArgs = require('./bundleCommandLineArgs');
const parseCommandLine = require('../util/parseCommandLine');
const outputBundle = require('./output/bundle');
const outputPrepack = require('./output/prepack');
const bundleCommandLineArgs = require('./bundleCommandLineArgs');
/**
* Builds the bundle starting to look for dependencies at the given entry path.
*/
function bundleWithOutput(argv, config, output, packagerInstance) {
const args = parseCommandLine(bundleCommandLineArgs, argv);
function bundleWithOutput(argv, config, args, output, packagerInstance) {
if (!output) {
output = args.prepack ? outputPrepack : outputBundle;
}
return buildBundle(args, config, output, packagerInstance);
}
function bundle(argv, config, packagerInstance) {
return bundleWithOutput(argv, config, undefined, packagerInstance);
function bundle(argv, config, args, packagerInstance) {
return bundleWithOutput(argv, config, args, undefined, packagerInstance);
}
module.exports = bundle;
module.exports.withOutput = bundleWithOutput;
module.exports = {
name: 'bundle',
description: 'builds the javascript bundle for offline use',
func: bundle,
options: bundleCommandLineArgs,
// not used by the CLI itself
withOutput: bundleWithOutput,
};
@@ -10,56 +10,47 @@
module.exports = [
{
command: 'entry-file',
command: '--entry-file <path>',
description: 'Path to the root JS file, either absolute or relative to JS root',
type: 'string',
required: true,
}, {
command: 'platform',
command: '--platform [string]',
description: 'Either "ios" or "android"',
type: 'string',
default: 'ios',
}, {
command: 'transformer',
description: 'Specify a custom transformer to be used',
type: 'string',
default: null,
command: '--transformer [string]',
description: 'Specify a custom transformer to be used (absolute path)',
default: require.resolve('../../packager/transformer'),
}, {
command: 'dev',
command: '--dev [boolean]',
description: 'If false, warnings are disabled and the bundle is minified',
parse: (val) => val === 'false' ? false : true,
default: true,
}, {
command: 'prepack',
description: 'If true, the output bundle will use the Prepack format.',
default: false
command: '--prepack',
description: 'When passed, the output bundle will use the Prepack format.',
}, {
command: 'bridge-config',
command: '--bridge-config [string]',
description: 'File name of a a JSON export of __fbBatchedBridgeConfig. Used by Prepack. Ex. ./bridgeconfig.json',
type: 'string'
}, {
command: 'bundle-output',
command: '--bundle-output <string>',
description: 'File name where to store the resulting bundle, ex. /tmp/groups.bundle',
type: 'string',
required: true,
}, {
command: 'bundle-encoding',
command: '--bundle-encoding [string]',
description: 'Encoding the bundle should be written in (https://nodejs.org/api/buffer.html#buffer_buffer).',
type: 'string',
default: 'utf8',
}, {
command: 'sourcemap-output',
command: '--sourcemap-output [string]',
description: 'File name where to store the sourcemap file for resulting bundle, ex. /tmp/groups.map',
type: 'string',
}, {
command: 'assets-dest',
command: '--assets-dest [string]',
description: 'Directory name where to store assets referenced in the bundle',
type: 'string',
}, {
command: 'verbose',
command: '--verbose',
description: 'Enables logging',
default: false,
}, {
command: 'reset-cache',
command: '--reset-cache',
description: 'Removes cached files',
default: false
}
default: false,
},
];
@@ -28,10 +28,10 @@ function createCodeWithMap(bundle, dev) {
function saveBundleAndMap(bundle, options, log) {
const {
'bundle-output': bundleOutput,
'bundle-encoding': encoding,
bundleOutput,
bundleEncoding: encoding,
dev,
'sourcemap-output': sourcemapOutput,
sourcemapOutput
} = options;
log('start');
@@ -16,8 +16,8 @@ function buildPrepackBundle(packagerClient, requestOptions) {
function savePrepackBundle(bundle, options, log) {
const {
'bundle-output': bundleOutput,
'bridge-config': bridgeConfig,
bundleOutput,
bridgeConfig,
} = options;
const result = bundle.build({
@@ -30,9 +30,9 @@ const MODULES_DIR = 'js-modules';
*/
function saveAsAssets(bundle, options, log) {
const {
'bundle-output': bundleOutput,
'bundle-encoding': encoding,
'sourcemap-output': sourcemapOutput,
bundleOutput,
bundleEncoding: encoding,
sourcemapOutput
} = options;
log('start');
@@ -26,9 +26,9 @@ const SIZEOF_UINT32 = 4;
*/
function saveAsIndexedFile(bundle, options, log) {
const {
'bundle-output': bundleOutput,
'bundle-encoding': encoding,
'sourcemap-output': sourcemapOutput,
bundleOutput,
bundleEncoding: encoding,
sourcemapOutput
} = options;
log('start');
@@ -8,13 +8,19 @@
*/
const bundleWithOutput = require('./bundle').withOutput;
const bundleCommandLineArgs = require('./bundleCommandLineArgs');
const outputUnbundle = require('./output/unbundle');
/**
* Builds the bundle starting to look for dependencies at the given entry path.
*/
function unbundle(argv, config, packagerInstance) {
return bundleWithOutput(argv, config, outputUnbundle, packagerInstance);
function unbundle(argv, config, args, packagerInstance) {
return bundleWithOutput(argv, config, args, outputUnbundle, packagerInstance);
}
module.exports = unbundle;
module.exports = {
name: 'unbundle',
description: 'builds javascript as "unbundle" for offline use',
func: unbundle,
options: bundleCommandLineArgs,
};
Oops, something went wrong.

5 comments on commit e8b5081

@danielbraun

This comment has been minimized.

Show comment
Hide comment
@danielbraun

danielbraun Aug 2, 2016

Contributor

@grabbou Something is broken with --reset-cache. It seems the cli bundle command no longer recognises it - it just prompts the available CLI commands.
It breaks bundling.

Try running:
node ./node_modules/react-native/local-cli/cli.js bundle --platform android --dev false --entry-file index.android.js --bundle-output main.jsbundle --reset-cache true

Contributor

danielbraun replied Aug 2, 2016

@grabbou Something is broken with --reset-cache. It seems the cli bundle command no longer recognises it - it just prompts the available CLI commands.
It breaks bundling.

Try running:
node ./node_modules/react-native/local-cli/cli.js bundle --platform android --dev false --entry-file index.android.js --bundle-output main.jsbundle --reset-cache true

@danielbraun

This comment has been minimized.

Show comment
Hide comment
@danielbraun

danielbraun Aug 2, 2016

Contributor

Related issue: #9134

Contributor

danielbraun replied Aug 2, 2016

Related issue: #9134

@danielbraun

This comment has been minimized.

Show comment
Hide comment
@danielbraun

danielbraun Aug 2, 2016

Contributor

I think the issue is that --reset-cache no longer accept a boolean parameter.

Contributor

danielbraun replied Aug 2, 2016

I think the issue is that --reset-cache no longer accept a boolean parameter.

@danielbraun

This comment has been minimized.

Show comment
Hide comment
@danielbraun

danielbraun Aug 2, 2016

Contributor

I've submitted a PR: #9163

Contributor

danielbraun replied Aug 2, 2016

I've submitted a PR: #9163

@xsdlr

This comment has been minimized.

Show comment
Hide comment
@xsdlr

xsdlr Aug 16, 2016

at local-cli/bundle/buildBundle.js function buildBundle #8057

xsdlr replied Aug 16, 2016

at local-cli/bundle/buildBundle.js function buildBundle #8057

Please sign in to comment.