react-native/local-cli/link/ios/unlinkAssets.js
Sophie Alpert 1490ab12ef Update license headers for MIT license
Summary:
Includes React Native and its dependencies Fresco, Metro, and Yoga. Excludes samples/examples/docs.

find: ^(?:( *)|( *(?:[\*~#]|::))( )? *)?Copyright (?:\(c\) )?(\d{4})\b.+Facebook[\s\S]+?BSD[\s\S]+?(?:this source tree|the same directory)\.$
replace: $1$2$3Copyright (c) $4-present, Facebook, Inc.\n$2\n$1$2$3This source code is licensed under the MIT license found in the\n$1$2$3LICENSE file in the root directory of this source tree.

Reviewed By: TheSavior, yungsters

Differential Revision: D7007050

fbshipit-source-id: 37dd6bf0ffec0923bfc99c260bb330683f35553e
2018-02-16 18:31:53 -08:00

64 lines
1.8 KiB
JavaScript

/**
* Copyright (c) 2015-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
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');
const writePlist = require('./writePlist');
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',
'Could not locate Info.plist file. Check if your project has \'INFOPLIST_FILE\' set properly'
);
}
if (!project.pbxGroupByName('Resources')) {
return log.error(
'ERRGROUP',
'Group \'Resources\' does not exist in your Xcode project. There is nothing to unlink.'
);
}
const removeResourceFile = function (f) {
(f || [])
.map(asset =>
project.removeResourceFile(
path.relative(projectConfig.sourceDir, asset),
{ target: project.getFirstTarget().uuid }
)
)
.map(file => file.basename);
};
removeResourceFile(assets.image);
const fonts = removeResourceFile(assets.font);
plist.UIAppFonts = difference(plist.UIAppFonts || [], fonts);
fs.writeFileSync(
projectConfig.pbxprojPath,
project.writeSync()
);
writePlist(project, projectConfig.sourceDir, plist);
};