forked from react-native-community/cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
build: deprecate link all behavior (react-native-community#85)
* build: deprecate link all behavior * Link project assets too This reverts previous behaviour * Fix small issue * Add URL to an issue
- Loading branch information
Showing
4 changed files
with
178 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
// @flow | ||
|
||
import type { ContextT, PlatformsT, ProjectConfigT } from '../core/types.flow'; | ||
|
||
const log = require('npmlog'); | ||
const { uniqBy, flatten } = require('lodash'); | ||
const path = require('path'); | ||
const getAssets = require('../core/getAssets'); | ||
const getProjectDependencies = require('./getProjectDependencies'); | ||
const getDependencyConfig = require('./getDependencyConfig'); | ||
const promiseWaterfall = require('./promiseWaterfall'); | ||
const commandStub = require('./commandStub'); | ||
const promisify = require('./promisify'); | ||
const linkAssets = require('./linkAssets'); | ||
const linkDependency = require('./linkDependency'); | ||
|
||
log.heading = 'rnpm-link'; | ||
|
||
const dedupeAssets = assets => uniqBy(assets, asset => path.basename(asset)); | ||
|
||
function linkAll( | ||
context: ContextT, | ||
platforms: PlatformsT, | ||
project: ProjectConfigT | ||
) { | ||
log.warn( | ||
'Running `react-native link` without package name is deprecated and will be removed ' + | ||
'in next release. If you are using `react-native link` to link your project assets, ' + | ||
' let us know about your use case here: https://goo.gl/RKTeoc' | ||
); | ||
|
||
const projectAssets = getAssets(context.root); | ||
const dependencies = getProjectDependencies(context.root); | ||
const depenendenciesConfig = dependencies.map(dependnecy => | ||
getDependencyConfig(context, platforms, dependnecy) | ||
); | ||
|
||
const assets = dedupeAssets( | ||
depenendenciesConfig.reduce( | ||
(acc, dependency) => acc.concat(dependency.assets), | ||
projectAssets | ||
) | ||
); | ||
|
||
const tasks = flatten( | ||
depenendenciesConfig.map(config => [ | ||
() => promisify(config.commands.prelink || commandStub), | ||
() => linkDependency(platforms, project, config), | ||
() => promisify(config.commands.postlink || commandStub), | ||
() => linkAssets(platforms, project, assets), | ||
]) | ||
); | ||
|
||
return promiseWaterfall(tasks).catch(err => { | ||
log.error( | ||
`Something went wrong while linking. Error: ${err.message} \n` + | ||
'Please file an issue here: https://github.com/facebook/react-native/issues' | ||
); | ||
throw err; | ||
}); | ||
} | ||
|
||
module.exports = linkAll; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// @flow | ||
|
||
import type { PlatformsT, ProjectConfigT } from '../core/types.flow'; | ||
|
||
const log = require('npmlog'); | ||
const { isEmpty } = require('lodash'); | ||
|
||
log.heading = 'rnpm-link'; | ||
|
||
const linkAssets = ( | ||
platforms: PlatformsT, | ||
project: ProjectConfigT, | ||
dependency: * | ||
) => { | ||
if (isEmpty(dependency.assets)) { | ||
return; | ||
} | ||
|
||
Object.keys(platforms || {}).forEach(platform => { | ||
const linkConfig = | ||
platforms[platform] && | ||
platforms[platform].linkConfig && | ||
platforms[platform].linkConfig(); | ||
|
||
if (!linkConfig || !linkConfig.copyAssets || !project[platform]) { | ||
return; | ||
} | ||
|
||
log.info(`Linking assets to ${platform} project`); | ||
// $FlowFixMe: We check for existence of project[platform] | ||
linkConfig.copyAssets(dependency.assets, project[platform]); | ||
}); | ||
|
||
log.info('Assets have been successfully linked to your project'); | ||
}; | ||
|
||
module.exports = linkAssets; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
// @flow | ||
|
||
import type { PlatformsT, ProjectConfigT } from '../core/types.flow'; | ||
|
||
const log = require('npmlog'); | ||
const chalk = require('chalk'); | ||
const pollParams = require('./pollParams'); | ||
|
||
log.heading = 'rnpm-link'; | ||
|
||
const linkDependency = async ( | ||
platforms: PlatformsT, | ||
project: ProjectConfigT, | ||
dependency: * | ||
) => { | ||
const params = await pollParams(dependency.params); | ||
|
||
Object.keys(platforms || {}).forEach(platform => { | ||
if (!project[platform] || !dependency.config[platform]) { | ||
return; | ||
} | ||
|
||
const linkConfig = | ||
platforms[platform] && | ||
platforms[platform].linkConfig && | ||
platforms[platform].linkConfig(); | ||
if (!linkConfig || !linkConfig.isInstalled || !linkConfig.register) { | ||
return; | ||
} | ||
|
||
const isInstalled = linkConfig.isInstalled( | ||
project[platform], | ||
dependency.name, | ||
dependency.config[platform] | ||
); | ||
|
||
if (isInstalled) { | ||
log.info( | ||
chalk.grey( | ||
`Platform '${platform}' module ${dependency.name} is already linked` | ||
) | ||
); | ||
return; | ||
} | ||
|
||
log.info(`Linking ${dependency.name} ${platform} dependency`); | ||
|
||
linkConfig.register( | ||
dependency.name, | ||
// $FlowFixMe: We check if dependency.config[platform] exists on line 42 | ||
dependency.config[platform], | ||
params, | ||
// $FlowFixMe: We check if project[platform] exists on line 42 | ||
project[platform] | ||
); | ||
|
||
log.info( | ||
`Platform '${platform}' module ${ | ||
dependency.name | ||
} has been successfully linked` | ||
); | ||
}); | ||
}; | ||
|
||
module.exports = linkDependency; |