UNPKG

react-native-asset

Version:

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

36 lines (35 loc) 1.22 kB
import * as dntShim from "../_dnt.shims.js"; import * as path from "../deps/jsr.io/@std/path/1.1.4/mod.js"; const manifestFileName = "link-assets-manifest.json"; export default function getManifest(projectPath) { const manifestPath = path.resolve(projectPath, manifestFileName); return { read: async () => { try { const data = await dntShim.Deno.readFile(manifestPath); return JSON.parse(new TextDecoder().decode(data)).data; } catch (e) { if (!(e instanceof dntShim.Deno.errors.NotFound)) { throw e; } return []; } }, write: async (files) => { try { const dir = path.dirname(manifestPath); try { dntShim.Deno.lstatSync(dir); } catch (_) { await dntShim.Deno.mkdir(dir, { recursive: true }); } await dntShim.Deno.writeTextFile(manifestPath, JSON.stringify({ migIndex: 1, data: files }, null, 2)); } catch (e) { throw e; } }, }; }