1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | function getScheme(config) {
|
4 | return typeof config.scheme === 'string' ? config.scheme : null;
|
5 | }
|
6 | exports.getScheme = getScheme;
|
7 | function setScheme(config, infoPlist) {
|
8 | let scheme = getScheme(config);
|
9 | if (!scheme) {
|
10 | return infoPlist;
|
11 | }
|
12 | return Object.assign(Object.assign({}, infoPlist), { CFBundleURLTypes: [{ CFBundleURLSchemes: [scheme] }] });
|
13 | }
|
14 | exports.setScheme = setScheme;
|
15 |
|
16 | function appendScheme(scheme, infoPlist) {
|
17 | if (!scheme) {
|
18 | return infoPlist;
|
19 | }
|
20 | let existingSchemes = infoPlist.CFBundleURLTypes;
|
21 |
|
22 | if (!existingSchemes) {
|
23 | return setScheme({ scheme }, infoPlist);
|
24 | }
|
25 | return Object.assign(Object.assign({}, infoPlist), { CFBundleURLTypes: [
|
26 | ...existingSchemes,
|
27 | {
|
28 | CFBundleURLSchemes: [scheme],
|
29 | },
|
30 | ] });
|
31 | }
|
32 | exports.appendScheme = appendScheme;
|
33 | function removeScheme(scheme, infoPlist) {
|
34 | if (!scheme) {
|
35 | return infoPlist;
|
36 | }
|
37 |
|
38 | if (!infoPlist.CFBundleURLTypes) {
|
39 | return infoPlist;
|
40 | }
|
41 | infoPlist.CFBundleURLTypes = infoPlist.CFBundleURLTypes.map(bundleUrlType => {
|
42 | const index = bundleUrlType.CFBundleURLSchemes.indexOf(scheme);
|
43 | if (index > -1) {
|
44 | bundleUrlType.CFBundleURLSchemes.splice(index, 1);
|
45 | if (bundleUrlType.CFBundleURLSchemes.length === 0) {
|
46 | return undefined;
|
47 | }
|
48 | }
|
49 | return bundleUrlType;
|
50 | }).filter(Boolean);
|
51 | return infoPlist;
|
52 | }
|
53 | exports.removeScheme = removeScheme;
|
54 | function hasScheme(scheme, infoPlist) {
|
55 | const existingSchemes = infoPlist.CFBundleURLTypes;
|
56 | if (!Array.isArray(existingSchemes))
|
57 | return false;
|
58 | return existingSchemes.some(({ CFBundleURLSchemes: schemes }) => schemes.includes(scheme));
|
59 | }
|
60 | exports.hasScheme = hasScheme;
|
61 | function getSchemesFromPlist(infoPlist) {
|
62 | if (Array.isArray(infoPlist.CFBundleURLTypes)) {
|
63 | return infoPlist.CFBundleURLTypes.reduce((schemes, { CFBundleURLSchemes }) => {
|
64 | if (Array.isArray(CFBundleURLSchemes)) {
|
65 | return [...schemes, ...CFBundleURLSchemes];
|
66 | }
|
67 | return schemes;
|
68 | }, []);
|
69 | }
|
70 | return [];
|
71 | }
|
72 | exports.getSchemesFromPlist = getSchemesFromPlist;
|
73 |
|
\ | No newline at end of file |