`react-native link` and `react-native unlink` update.

Summary:
1. Fix bug: Android project do not delete font files when run `react-native unlink`.
2. Add feature, link images to iOS project when run `react-native link`.
Closes https://github.com/facebook/react-native/pull/14801

Differential Revision: D5890051

Pulled By: hramos

fbshipit-source-id: 28223d181ac5ed51d70df29a56eb56b2cce9aecb
This commit is contained in:
Steven 2017-09-22 05:41:32 -07:00 committed by Facebook Github Bot
parent 0aa12939fd
commit c1058b1e90
3 changed files with 32 additions and 20 deletions

View File

@ -9,12 +9,12 @@ const groupFilesByType = require('../groupFilesByType');
* - Fonts (otf, ttf) - copied to targetPath/fonts under original name
*/
module.exports = function unlinkAssetsAndroid(files, targetPath) {
const grouped = groupFilesByType(files);
const assets = groupFilesByType(files);
grouped.font.forEach((file) => {
const filename = path.basename(file);
if (fs.existsSync(filename)) {
fs.unlinkSync(path.join(targetPath, 'fonts', filename));
(assets.font || []).forEach((file) => {
const filePath = path.join(targetPath, 'fonts', path.basename(file));
if (fs.existsSync(filePath)) {
fs.unlinkSync(filePath);
}
});
};

View File

@ -18,15 +18,21 @@ module.exports = function linkAssetsIOS(files, projectConfig) {
createGroupWithMessage(project, 'Resources');
const fonts = (assets.font || [])
.map(asset =>
project.addResourceFile(
path.relative(projectConfig.sourceDir, asset),
{ target: project.getFirstTarget().uuid }
function addResourceFile(f) {
return (f || [])
.map(asset =>
project.addResourceFile(
path.relative(projectConfig.sourceDir, asset),
{ target: project.getFirstTarget().uuid }
)
)
)
.filter(file => file) // xcode returns false if file is already there
.map(file => file.basename);
.filter(file => file) // xcode returns false if file is already there
.map(file => file.basename);
}
addResourceFile(assets.image);
const fonts = addResourceFile(assets.font);
const existingFonts = (plist.UIAppFonts || []);
const allFonts = [...existingFonts, ...fonts];

View File

@ -30,14 +30,20 @@ module.exports = function unlinkAssetsIOS(files, projectConfig) {
);
}
const fonts = (assets.font || [])
.map(asset =>
project.removeResourceFile(
path.relative(projectConfig.sourceDir, asset),
{ target: project.getFirstTarget().uuid }
const removeResourceFile = function (f) {
(f || [])
.map(asset =>
project.removeResourceFile(
path.relative(projectConfig.sourceDir, asset),
{ target: project.getFirstTarget().uuid }
)
)
)
.map(file => file.basename);
.map(file => file.basename);
}
removeResourceFile(assets.image);
const fonts = removeResourceFile(assets.font);
plist.UIAppFonts = difference(plist.UIAppFonts || [], fonts);