@papyrus-sdk/ui-react-native 0.2.20 → 0.2.21

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,41 @@
1
+ import { readFile, writeFile } from "node:fs/promises";
2
+ import { dirname, resolve } from "node:path";
3
+ import { fileURLToPath } from "node:url";
4
+
5
+ const runtimeDirectory = dirname(fileURLToPath(import.meta.url));
6
+ const source = await readFile(resolve(runtimeDirectory, "comicRuntime.js"), "utf8");
7
+
8
+ const replaceMarkedSource = (content, start, end, replacement) => {
9
+ const startIndex = content.indexOf(start);
10
+ const endIndex = content.indexOf(end);
11
+ if (startIndex < 0 || endIndex < startIndex) {
12
+ throw new Error(`Runtime marker not found: ${start}`);
13
+ }
14
+ return `${content.slice(0, startIndex)}${start}${replacement}${content.slice(
15
+ endIndex
16
+ )}`;
17
+ };
18
+
19
+ const runtimePath = resolve(runtimeDirectory, "runtime.js");
20
+ const runtime = await readFile(runtimePath, "utf8");
21
+ await writeFile(
22
+ runtimePath,
23
+ replaceMarkedSource(
24
+ runtime,
25
+ "/* @papyrus-comic-runtime:start */",
26
+ "/* @papyrus-comic-runtime:end */",
27
+ `\n${source.trim()}\n`
28
+ )
29
+ );
30
+
31
+ const htmlPath = resolve(runtimeDirectory, "index.html");
32
+ const html = await readFile(htmlPath, "utf8");
33
+ await writeFile(
34
+ htmlPath,
35
+ replaceMarkedSource(
36
+ html,
37
+ "<!-- @papyrus-comic-runtime:start -->",
38
+ "<!-- @papyrus-comic-runtime:end -->",
39
+ `\n <script>\n${source}\n </script>\n`
40
+ )
41
+ );