-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathplatforms.ts
More file actions
33 lines (29 loc) · 968 Bytes
/
platforms.ts
File metadata and controls
33 lines (29 loc) · 968 Bytes
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
import assert from "node:assert/strict";
import { platform as android } from "./platforms/android.js";
import { platform as apple } from "./platforms/apple.js";
import { platform as node } from "./platforms/node.js";
import { Platform } from "./platforms/types.js";
export const platforms: Platform[] = [android, apple, node] as const;
export const allTargets = [
...android.targets,
...apple.targets,
...node.targets,
] as const;
export function platformHasTarget<P extends Platform>(
platform: P,
target: unknown,
): target is P["targets"][number] {
return (platform.targets as unknown[]).includes(target);
}
export function findPlatformForTarget(target: unknown) {
const platform = Object.values(platforms).find((platform) =>
platformHasTarget(platform, target),
);
assert(
platform,
`Unable to determine platform from target: ${
typeof target === "string" ? target : JSON.stringify(target)
}`,
);
return platform;
}