`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:
parent
0aa12939fd
commit
c1058b1e90
|
@ -9,12 +9,12 @@ const groupFilesByType = require('../groupFilesByType');
|
||||||
* - Fonts (otf, ttf) - copied to targetPath/fonts under original name
|
* - Fonts (otf, ttf) - copied to targetPath/fonts under original name
|
||||||
*/
|
*/
|
||||||
module.exports = function unlinkAssetsAndroid(files, targetPath) {
|
module.exports = function unlinkAssetsAndroid(files, targetPath) {
|
||||||
const grouped = groupFilesByType(files);
|
const assets = groupFilesByType(files);
|
||||||
|
|
||||||
grouped.font.forEach((file) => {
|
(assets.font || []).forEach((file) => {
|
||||||
const filename = path.basename(file);
|
const filePath = path.join(targetPath, 'fonts', path.basename(file));
|
||||||
if (fs.existsSync(filename)) {
|
if (fs.existsSync(filePath)) {
|
||||||
fs.unlinkSync(path.join(targetPath, 'fonts', filename));
|
fs.unlinkSync(filePath);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
|
@ -18,7 +18,8 @@ module.exports = function linkAssetsIOS(files, projectConfig) {
|
||||||
|
|
||||||
createGroupWithMessage(project, 'Resources');
|
createGroupWithMessage(project, 'Resources');
|
||||||
|
|
||||||
const fonts = (assets.font || [])
|
function addResourceFile(f) {
|
||||||
|
return (f || [])
|
||||||
.map(asset =>
|
.map(asset =>
|
||||||
project.addResourceFile(
|
project.addResourceFile(
|
||||||
path.relative(projectConfig.sourceDir, asset),
|
path.relative(projectConfig.sourceDir, asset),
|
||||||
|
@ -27,6 +28,11 @@ module.exports = function linkAssetsIOS(files, projectConfig) {
|
||||||
)
|
)
|
||||||
.filter(file => file) // xcode returns false if file is already there
|
.filter(file => file) // xcode returns false if file is already there
|
||||||
.map(file => file.basename);
|
.map(file => file.basename);
|
||||||
|
}
|
||||||
|
|
||||||
|
addResourceFile(assets.image);
|
||||||
|
|
||||||
|
const fonts = addResourceFile(assets.font);
|
||||||
|
|
||||||
const existingFonts = (plist.UIAppFonts || []);
|
const existingFonts = (plist.UIAppFonts || []);
|
||||||
const allFonts = [...existingFonts, ...fonts];
|
const allFonts = [...existingFonts, ...fonts];
|
||||||
|
|
|
@ -30,7 +30,8 @@ module.exports = function unlinkAssetsIOS(files, projectConfig) {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const fonts = (assets.font || [])
|
const removeResourceFile = function (f) {
|
||||||
|
(f || [])
|
||||||
.map(asset =>
|
.map(asset =>
|
||||||
project.removeResourceFile(
|
project.removeResourceFile(
|
||||||
path.relative(projectConfig.sourceDir, asset),
|
path.relative(projectConfig.sourceDir, asset),
|
||||||
|
@ -38,6 +39,11 @@ module.exports = function unlinkAssetsIOS(files, projectConfig) {
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
.map(file => file.basename);
|
.map(file => file.basename);
|
||||||
|
}
|
||||||
|
|
||||||
|
removeResourceFile(assets.image);
|
||||||
|
|
||||||
|
const fonts = removeResourceFile(assets.font);
|
||||||
|
|
||||||
plist.UIAppFonts = difference(plist.UIAppFonts || [], fonts);
|
plist.UIAppFonts = difference(plist.UIAppFonts || [], fonts);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue