-
Notifications
You must be signed in to change notification settings - Fork 24.9k
Enable platforms to configure CLI commands #17745
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,7 +15,6 @@ const Config = require('../util/Config'); | |
| const findPlugins = require('./findPlugins'); | ||
| const findAssets = require('./findAssets'); | ||
| const ios = require('./ios'); | ||
| const windows = require('./windows'); | ||
| const wrapCommands = require('./wrapCommands'); | ||
|
|
||
| /* $FlowFixMe(>=0.54.0 site=react_native_oss) This comment suppresses an error | ||
|
|
@@ -33,6 +32,10 @@ import type {ConfigT} from 'metro'; | |
|
|
||
| export type RNConfig = { | ||
| ...ConfigT, | ||
| /** | ||
| * Returns an object with all platform configurations. | ||
| */ | ||
| getPlatformConfig(): Object, | ||
| /** | ||
| * Returns an array of project commands used by the CLI to load | ||
| */ | ||
|
|
@@ -55,10 +58,21 @@ const attachPackage = (command, pkg) => Array.isArray(command) | |
| ? command.map(cmd => attachPackage(cmd, pkg)) | ||
| : { ...command, pkg }; | ||
|
|
||
| const appRoot = process.cwd(); | ||
| const plugins = findPlugins([appRoot]); | ||
| const pluginPlatforms = plugins | ||
| .platforms | ||
| .reduce((acc, pathToPlatforms) => { | ||
| // $FlowFixMe non-literal require | ||
| return Object.assign(acc, require(path.join(appRoot, 'node_modules', pathToPlatforms))); | ||
| }, | ||
| {}); | ||
|
|
||
| const defaultRNConfig = { | ||
|
|
||
| getProjectCommands(): Array<CommandT> { | ||
| const appRoot = process.cwd(); | ||
| const plugins = findPlugins([appRoot]) | ||
| const commands = plugins | ||
| .commands | ||
| .map(pathToCommands => { | ||
| const name = pathToCommands.split(path.sep)[0]; | ||
|
|
||
|
|
@@ -70,35 +84,51 @@ const defaultRNConfig = { | |
| ); | ||
| }); | ||
|
|
||
| return flatten(plugins); | ||
| return flatten(commands); | ||
| }, | ||
|
|
||
| getPlatformConfig(): Object { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks like this can be just a function, so that no need to call There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. True. I'll fix. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. #WontFix - @grabbou, we need to expose the |
||
| return { | ||
| ios, | ||
| android, | ||
| ...pluginPlatforms | ||
| }; | ||
| }, | ||
|
|
||
| getProjectConfig(): Object { | ||
| const platforms = this.getPlatformConfig(); | ||
| const folder = process.cwd(); | ||
| const rnpm = getRNPMConfig(folder); | ||
|
|
||
| return Object.assign({}, rnpm, { | ||
| ios: ios.projectConfig(folder, rnpm.ios || {}), | ||
| android: android.projectConfig(folder, rnpm.android || {}), | ||
| windows: windows.projectConfig(folder, rnpm.windows || {}), | ||
| let config = Object.assign({}, rnpm, { | ||
| assets: findAssets(folder, rnpm.assets), | ||
| }); | ||
|
|
||
| Object.keys(platforms).forEach(key => { | ||
| config[key] = platforms[key].projectConfig(folder, rnpm[key] || {}); | ||
| }); | ||
|
|
||
| return config; | ||
| }, | ||
|
|
||
| getDependencyConfig(packageName: string) { | ||
| const platforms = this.getPlatformConfig(); | ||
| const folder = path.join(process.cwd(), 'node_modules', packageName); | ||
| const rnpm = getRNPMConfig( | ||
| path.join(process.cwd(), 'node_modules', packageName) | ||
| ); | ||
|
|
||
| return Object.assign({}, rnpm, { | ||
| ios: ios.dependencyConfig(folder, rnpm.ios || {}), | ||
| android: android.dependencyConfig(folder, rnpm.android || {}), | ||
| windows: windows.dependencyConfig(folder, rnpm.windows || {}), | ||
| let config = Object.assign({}, rnpm, { | ||
| assets: findAssets(folder, rnpm.assets), | ||
| commands: wrapCommands(rnpm.commands), | ||
| params: rnpm.params || [], | ||
| }); | ||
|
|
||
| Object.keys(platforms).forEach(key => { | ||
| config[key] = platforms[key].dependencyConfig(folder, rnpm[key] || {}); | ||
| }); | ||
|
|
||
| return config; | ||
| }, | ||
| }; | ||
|
|
||
|
|
||
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no-trailing-spaces: Trailing spaces not allowed.