2018-02-09 01:10:29 +00:00
|
|
|
/**
|
2018-09-11 22:27:47 +00:00
|
|
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
2018-02-09 01:10:29 +00:00
|
|
|
*
|
2018-02-17 02:24:55 +00:00
|
|
|
* This source code is licensed under the MIT license found in the
|
|
|
|
* LICENSE file in the root directory of this source tree.
|
2018-05-11 19:43:49 +00:00
|
|
|
*
|
|
|
|
* @format
|
2018-02-09 01:10:29 +00:00
|
|
|
*/
|
|
|
|
|
2016-05-20 11:52:08 +00:00
|
|
|
const fs = require('fs-extra');
|
|
|
|
const path = require('path');
|
|
|
|
const xcode = require('xcode');
|
|
|
|
const log = require('npmlog');
|
|
|
|
const groupFilesByType = require('../groupFilesByType');
|
2016-07-30 15:59:16 +00:00
|
|
|
const createGroupWithMessage = require('./createGroupWithMessage');
|
2016-05-20 11:52:08 +00:00
|
|
|
const getPlist = require('./getPlist');
|
2017-03-31 09:58:02 +00:00
|
|
|
const writePlist = require('./writePlist');
|
2016-05-20 11:52:08 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* This function works in a similar manner to its Android version,
|
2017-02-28 06:46:00 +00:00
|
|
|
* except it does not copy fonts but creates Xcode Group references
|
2016-05-20 11:52:08 +00:00
|
|
|
*/
|
|
|
|
module.exports = function linkAssetsIOS(files, projectConfig) {
|
|
|
|
const project = xcode.project(projectConfig.pbxprojPath).parseSync();
|
|
|
|
const assets = groupFilesByType(files);
|
|
|
|
const plist = getPlist(project, projectConfig.sourceDir);
|
|
|
|
|
2016-07-30 15:59:16 +00:00
|
|
|
createGroupWithMessage(project, 'Resources');
|
2016-05-20 11:52:08 +00:00
|
|
|
|
2017-09-22 12:41:32 +00:00
|
|
|
function addResourceFile(f) {
|
|
|
|
return (f || [])
|
|
|
|
.map(asset =>
|
2018-05-11 19:43:49 +00:00
|
|
|
project.addResourceFile(path.relative(projectConfig.sourceDir, asset), {
|
|
|
|
target: project.getFirstTarget().uuid,
|
|
|
|
}),
|
2016-05-20 11:52:08 +00:00
|
|
|
)
|
2018-05-11 19:43:49 +00:00
|
|
|
.filter(file => file) // xcode returns false if file is already there
|
2017-09-22 12:41:32 +00:00
|
|
|
.map(file => file.basename);
|
|
|
|
}
|
|
|
|
|
|
|
|
addResourceFile(assets.image);
|
|
|
|
|
|
|
|
const fonts = addResourceFile(assets.font);
|
2016-05-20 11:52:08 +00:00
|
|
|
|
2018-05-11 19:43:49 +00:00
|
|
|
const existingFonts = plist.UIAppFonts || [];
|
2017-02-15 01:02:23 +00:00
|
|
|
const allFonts = [...existingFonts, ...fonts];
|
|
|
|
plist.UIAppFonts = Array.from(new Set(allFonts)); // use Set to dedupe w/existing
|
2016-05-20 11:52:08 +00:00
|
|
|
|
2018-05-11 19:43:49 +00:00
|
|
|
fs.writeFileSync(projectConfig.pbxprojPath, project.writeSync());
|
2016-05-20 11:52:08 +00:00
|
|
|
|
2017-03-31 09:58:02 +00:00
|
|
|
writePlist(project, projectConfig.sourceDir, plist);
|
2016-05-20 11:52:08 +00:00
|
|
|
};
|