Permalink
Browse files

`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 #14801

Differential Revision: D5890051

Pulled By: hramos

fbshipit-source-id: 28223d181ac5ed51d70df29a56eb56b2cce9aecb
  • Loading branch information...
iineva authored and facebook-github-bot committed Sep 22, 2017
1 parent 0aa1293 commit c1058b1e9084313e6132ae7ea605f96187231989
Showing with 32 additions and 20 deletions.
  1. +5 −5 local-cli/link/android/unlinkAssets.js
  2. +14 −8 local-cli/link/ios/copyAssets.js
  3. +13 −7 local-cli/link/ios/unlinkAssets.js
@@ -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);
}
});
};
@@ -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];
@@ -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);

0 comments on commit c1058b1

Please sign in to comment.