-
Notifications
You must be signed in to change notification settings - Fork 4
/
writePDXInfo.ts
47 lines (41 loc) · 1.1 KB
/
writePDXInfo.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import * as fs from "fs/promises";
import * as path from "path";
import { compareAlphabetic, sort } from "../util";
import { PDXInfo, PDXInfoKey } from "./PDXInfo";
const knownKeyOrder: PDXInfoKey[] = [
"name",
"author",
"description",
"bundleID",
"version",
"buildNumber",
"imagePath",
"launchSoundPath",
"contentWarning",
"contentWarning2",
];
export async function writePDXInfo(
pdxInfo: PDXInfo,
sourcePath: string
): Promise<void> {
const knownKeys: string[] = knownKeyOrder;
const unknownKeys = Object.keys(pdxInfo).filter(
(key) => !knownKeys.includes(key)
);
const unknownKeyOrder = sort(unknownKeys, compareAlphabetic);
const keyOrder = knownKeys.concat(unknownKeyOrder);
const lines = [];
for (const key of keyOrder) {
const value = pdxInfo[key];
if (value !== undefined) {
lines.push(`${key}=${value}`);
}
}
const infoPath = path.resolve(sourcePath, "pdxinfo");
const data = lines.join("\n") + "\n";
try {
await fs.writeFile(infoPath, data);
} catch (err) {
throw new Error(`Could not write pdxinfo file at ${infoPath}`);
}
}