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 plistParser = require('plist');
|
|
|
|
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');
|
|
|
|
const getPlistPath = require('./getPlistPath');
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This function works in a similar manner to its Android version,
|
|
|
|
* except it does not copy fonts but creates XCode Group references
|
|
|
|
*/
|
|
|
|
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
|
|
|
|
|
|
|
const fonts = (assets.font || [])
|
|
|
|
.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);
|
|
|
|
|
2017-02-15 01:02:23 +00:00
|
|
|
const existingFonts = (plist.UIAppFonts || []);
|
|
|
|
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
|
|
|
|
|
|
|
fs.writeFileSync(
|
|
|
|
projectConfig.pbxprojPath,
|
|
|
|
project.writeSync()
|
|
|
|
);
|
|
|
|
|
|
|
|
fs.writeFileSync(
|
|
|
|
getPlistPath(project, projectConfig.sourceDir),
|
|
|
|
plistParser.build(plist)
|
|
|
|
);
|
|
|
|
};
|