Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export default function linkAssetsIOS(
files: Array,
projectConfig: IOSProjectConfig,
) {
const project = xcode.project(projectConfig.pbxprojPath).parseSync();
const assets = groupFilesByType(files);
const plist = getPlist(project, projectConfig.sourceDir);
createGroupWithMessage(project, 'Resources');
function addResourceFile(f: Array) {
return (f || [])
.map(asset => {
logger.debug(`Linking asset ${asset}`);
return project.addResourceFile(
path.relative(projectConfig.sourceDir, asset),
{target: project.getFirstTarget().uuid},
);
})
.filter(Boolean) // xcode returns false if file is already there
.map(file => file.basename);
}
export default function copyAssetsAndroid(
files: Array,
project: {assetsPath: string},
) {
const assets = groupFilesByType(files);
logger.debug(`Assets path: ${project.assetsPath}`);
(assets.font || []).forEach(asset => {
const fontsDir = path.join(project.assetsPath, 'fonts');
logger.debug(`Copying asset ${asset}`);
// @todo: replace with fs.mkdirSync(path, {recursive}) + fs.copyFileSync
// and get rid of fs-extra once we move to Node 10
fs.copySync(asset, path.join(fontsDir, path.basename(asset)));
});
}
export default function unlinkAssetsIOS(
files: any,
projectConfig: IOSProjectConfig,
) {
const project = xcode.project(projectConfig.pbxprojPath).parseSync();
const assets = groupFilesByType(files);
const plist = getPlist(project, projectConfig.sourceDir);
if (!plist) {
logger.error(
'Could not locate "Info.plist" file. Check if your project has "INFOPLIST_FILE" set properly',
);
return;
}
if (!project.pbxGroupByName('Resources')) {
logger.error(
'Group "Resources" does not exist in your Xcode project. There is nothing to unlink.',
);
return;
}
export default function unlinkAssetsAndroid(
files: Array,
project: {assetsPath: string},
) {
const assets = groupFilesByType(files);
logger.debug(`Assets path: ${project.assetsPath}`);
(assets.font || []).forEach(file => {
const filePath = path.join(
project.assetsPath,
'fonts',
path.basename(file),
);
if (fs.existsSync(filePath)) {
logger.debug(`Removing asset ${filePath}`);
fs.unlinkSync(filePath);
}
});
}