2018-02-09 01:10:29 +00:00
|
|
|
/**
|
|
|
|
* Copyright (c) 2015-present, Facebook, Inc.
|
|
|
|
*
|
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');
|
|
|
|
const getPlist = require('./getPlist');
|
2017-03-31 09:58:02 +00:00
|
|
|
const writePlist = require('./writePlist');
|
2016-05-20 11:52:08 +00:00
|
|
|
const difference = require('lodash').difference;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Unlinks assets from iOS project. Removes references for fonts from `Info.plist`
|
|
|
|
* fonts provided by application and from `Resources` group
|
|
|
|
*/
|
|
|
|
module.exports = function unlinkAssetsIOS(files, projectConfig) {
|
|
|
|
const project = xcode.project(projectConfig.pbxprojPath).parseSync();
|
|
|
|
const assets = groupFilesByType(files);
|
|
|
|
const plist = getPlist(project, projectConfig.sourceDir);
|
|
|
|
|
|
|
|
if (!plist) {
|
|
|
|
return log.error(
|
|
|
|
'ERRPLIST',
|
2018-05-11 19:43:49 +00:00
|
|
|
"Could not locate Info.plist file. Check if your project has 'INFOPLIST_FILE' set properly",
|
2016-05-20 11:52:08 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!project.pbxGroupByName('Resources')) {
|
|
|
|
return log.error(
|
|
|
|
'ERRGROUP',
|
2018-05-11 19:43:49 +00:00
|
|
|
"Group 'Resources' does not exist in your Xcode project. There is nothing to unlink.",
|
2016-05-20 11:52:08 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2018-05-11 19:43:49 +00:00
|
|
|
const removeResourceFile = function(f) {
|
2017-09-22 12:41:32 +00:00
|
|
|
(f || [])
|
|
|
|
.map(asset =>
|
|
|
|
project.removeResourceFile(
|
|
|
|
path.relative(projectConfig.sourceDir, asset),
|
2018-05-11 19:43:49 +00:00
|
|
|
{target: project.getFirstTarget().uuid},
|
|
|
|
),
|
2016-05-20 11:52:08 +00:00
|
|
|
)
|
2017-09-22 12:41:32 +00:00
|
|
|
.map(file => file.basename);
|
2017-10-10 00:37:08 +00:00
|
|
|
};
|
2017-09-22 12:41:32 +00:00
|
|
|
|
|
|
|
removeResourceFile(assets.image);
|
|
|
|
|
|
|
|
const fonts = removeResourceFile(assets.font);
|
2016-05-20 11:52:08 +00:00
|
|
|
|
|
|
|
plist.UIAppFonts = difference(plist.UIAppFonts || [], fonts);
|
|
|
|
|
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
|
|
|
};
|