@expo-harmony/config-plugins 55.0.10-harmony.2 → 55.0.10-harmony.4
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.
- package/README.md +203 -11
- package/build/compiler.d.ts +7 -0
- package/build/compiler.js +12 -0
- package/build/composition.d.ts +24 -0
- package/build/composition.js +11 -0
- package/build/config.d.ts +2 -15
- package/build/customFiles.d.ts +15 -0
- package/build/customFiles.js +108 -0
- package/build/files.d.ts +1 -1
- package/build/files.js +2 -2
- package/build/generatedFiles.d.ts +15 -0
- package/build/generatedFiles.js +70 -0
- package/build/index.d.ts +20 -5
- package/build/index.js +53 -6
- package/build/internal.d.ts +3 -0
- package/build/internal.js +13 -0
- package/build/manifest.d.ts +38 -0
- package/build/manifest.js +71 -0
- package/build/mods.d.ts +37 -31
- package/build/mods.js +118 -86
- package/build/normalizeConfig.d.ts +10 -3
- package/build/normalizeConfig.js +45 -47
- package/build/ownership.d.ts +4 -3
- package/build/ownership.js +17 -0
- package/build/paths.d.ts +13 -10
- package/build/paths.js +32 -31
- package/build/permissions.d.ts +12 -0
- package/build/permissions.js +60 -0
- package/build/pluginTypes.d.ts +15 -0
- package/build/pluginTypes.js +2 -0
- package/build/resources.d.ts +13 -0
- package/build/resources.js +55 -0
- package/package.json +9 -9
- package/src/compiler.ts +21 -0
- package/src/composition.ts +45 -0
- package/src/config.ts +3 -19
- package/src/customFiles.ts +142 -0
- package/src/files.ts +3 -4
- package/src/generatedFiles.ts +85 -0
- package/src/index.ts +20 -11
- package/src/internal.ts +3 -0
- package/src/manifest.ts +151 -0
- package/src/mods.ts +180 -128
- package/src/nativeInputs.ts +0 -1
- package/src/normalizeConfig.ts +56 -59
- package/src/ownership.ts +25 -5
- package/src/paths.ts +41 -45
- package/src/permissions.ts +68 -0
- package/src/pluginTypes.ts +24 -0
- package/src/resources.ts +65 -0
package/src/resources.ts
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { HarmonyConfigPluginError } from './errors';
|
|
2
|
+
|
|
3
|
+
export interface HarmonyResourceItem extends Record<string, unknown> {
|
|
4
|
+
name: string;
|
|
5
|
+
value: string;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export interface HarmonyResourceFile extends Record<string, unknown> {
|
|
9
|
+
string?: HarmonyResourceItem[];
|
|
10
|
+
color?: HarmonyResourceItem[];
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
function setItem(file: HarmonyResourceFile, kind: 'string' | 'color', item: HarmonyResourceItem): HarmonyResourceFile {
|
|
14
|
+
if (!item || typeof item.name !== 'string' || !/^[A-Za-z0-9_.-]+$/.test(item.name)
|
|
15
|
+
|| item.name.includes('..') || typeof item.value !== 'string') {
|
|
16
|
+
throw new HarmonyConfigPluginError('ERR_HARMONY_RESOURCE_INVALID', `Invalid Harmony ${kind} resource.`, { operation: 'edit-resource' });
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const items = readItems(file, kind);
|
|
20
|
+
const existing = items.find(value => value?.name === item.name);
|
|
21
|
+
file[kind] = [...items.filter(value => value?.name !== item.name), { ...existing, ...item }];
|
|
22
|
+
|
|
23
|
+
return file;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function readItems(file: HarmonyResourceFile, kind: 'string' | 'color'): HarmonyResourceItem[] {
|
|
27
|
+
if (file[kind] !== undefined && !Array.isArray(file[kind])) {
|
|
28
|
+
throw new HarmonyConfigPluginError('ERR_HARMONY_RESOURCE_INVALID', `Harmony ${kind} resources must be an array.`, { operation: 'edit-resource' });
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
return file[kind] ?? [];
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export function setString(file: HarmonyResourceFile, item: HarmonyResourceItem): HarmonyResourceFile {
|
|
35
|
+
return setItem(file, 'string', item);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export function removeString(file: HarmonyResourceFile, name: string): HarmonyResourceFile {
|
|
39
|
+
const items = readItems(file, 'string');
|
|
40
|
+
if (file.string) file.string = items.filter(item => item?.name !== name);
|
|
41
|
+
return file;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export function setColor(file: HarmonyResourceFile, item: HarmonyResourceItem): HarmonyResourceFile {
|
|
45
|
+
return setItem(file, 'color', item);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export function removeColor(file: HarmonyResourceFile, name: string): HarmonyResourceFile {
|
|
49
|
+
const items = readItems(file, 'color');
|
|
50
|
+
if (file.color) file.color = items.filter(item => item?.name !== name);
|
|
51
|
+
return file;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export function toArgb(value: string | number): string {
|
|
55
|
+
let hex: string;
|
|
56
|
+
if (typeof value === 'number' && Number.isInteger(value) && value >= 0 && value <= 0xffffffff) {
|
|
57
|
+
hex = value.toString(16).padStart(8, '0');
|
|
58
|
+
} else if (typeof value === 'string' && /^#[0-9a-f]{6}(?:[0-9a-f]{2})?$/i.test(value)) {
|
|
59
|
+
hex = value.slice(1);
|
|
60
|
+
} else {
|
|
61
|
+
throw new HarmonyConfigPluginError('ERR_HARMONY_CONFIG_INVALID', 'Color must be #RRGGBB, #RRGGBBAA or an unsigned RGBA integer.', { operation: 'convert-color' });
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
return `#${hex.length === 8 ? hex.slice(6, 8) + hex.slice(0, 6) : hex}`.toUpperCase();
|
|
65
|
+
}
|