UNPKG

react-native-asset

Version:

Linking and unlinking of assets in your react-native app, works for fonts and sounds

31 lines (30 loc) 1.84 kB
import * as dntShim from "../_dnt.shims.js"; import * as path from "../deps/jsr.io/@std/path/1.1.4/mod.js"; import * as xcode from "xcode"; import * as xcodeParserUntyped from "xcode/lib/parser/pbxproj.js"; const xcodeParser = xcodeParserUntyped; import createGroupWithMessage from "../react-native-lib/ios/createGroupWithMessage.js"; import getPlist from "../react-native-lib/ios/getPlist.js"; import writePlist from "../react-native-lib/ios/writePlist.js"; import { getTargetUUIDs } from "../utils.js"; export default async function cleanAssetsIos(filePaths, platformConfig, options) { const project = xcode.project(platformConfig.pbxprojPath); const pbxprojContent = await dntShim.Deno.readFile(platformConfig.pbxprojPath).then((buf) => new TextDecoder("utf-8").decode(buf)); project.hash = xcodeParser.parse(pbxprojContent); createGroupWithMessage(project, "Resources"); for (const targetUUID of getTargetUUIDs(project)) { // deno-lint-ignore no-await-in-loop -- sequential read/write to same plist file const plist = await getPlist(project, platformConfig.path, targetUUID); const removedFiles = filePaths.map((p) => { return project.removeResourceFile(path.relative(platformConfig.path, p), { target: targetUUID }); }).filter((x) => x).map((file) => file.basename); if (options.addFont) { const existingFonts = plist.UIAppFonts || []; const allFonts = existingFonts.filter((file) => removedFiles.indexOf(file) === -1); plist.UIAppFonts = Array.from(new Set(allFonts)); // use Set to dedupe w/existing } // deno-lint-ignore no-await-in-loop await writePlist(project, platformConfig.path, plist, targetUUID); } await dntShim.Deno.writeTextFile(platformConfig.pbxprojPath, project.writeSync()); }