1 | "use strict";
|
2 | var __importDefault = (this && this.__importDefault) || function (mod) {
|
3 | return (mod && mod.__esModule) ? mod : { "default": mod };
|
4 | };
|
5 | Object.defineProperty(exports, "__esModule", { value: true });
|
6 | const fs_extra_1 = __importDefault(require("fs-extra"));
|
7 | const glob_1 = require("glob");
|
8 | const path_1 = require("path");
|
9 |
|
10 | const xcode_1 = require("xcode");
|
11 | const plist_1 = __importDefault(require("@expo/plist"));
|
12 | function getBundleIdentifier(config) {
|
13 | return config.ios && config.ios.bundleIdentifier ? config.ios.bundleIdentifier : null;
|
14 | }
|
15 | exports.getBundleIdentifier = getBundleIdentifier;
|
16 |
|
17 |
|
18 |
|
19 |
|
20 | function setBundleIdentifier(config, infoPlist) {
|
21 | let bundleIdentifier = getBundleIdentifier(config);
|
22 | if (!bundleIdentifier) {
|
23 | return infoPlist;
|
24 | }
|
25 | return Object.assign(Object.assign({}, infoPlist), { CFBundleIdentifier: bundleIdentifier });
|
26 | }
|
27 | exports.setBundleIdentifier = setBundleIdentifier;
|
28 |
|
29 |
|
30 |
|
31 |
|
32 |
|
33 | function updateBundleIdentifierForPbxproj(pbxprojPath, bundleIdentifier) {
|
34 | const project = xcode_1.project(pbxprojPath);
|
35 | project.parseSync();
|
36 | Object.entries(project.pbxXCBuildConfigurationSection())
|
37 | .filter(filterComments)
|
38 | .filter(filterConfig)
|
39 | .filter(filterHosts)
|
40 | .forEach(({ 1: { buildSettings } }) => {
|
41 | var _a;
|
42 | if (buildSettings.PRODUCT_BUNDLE_IDENTIFIER === bundleIdentifier) {
|
43 | return;
|
44 | }
|
45 | buildSettings.PRODUCT_BUNDLE_IDENTIFIER = `"${bundleIdentifier}"`;
|
46 | const productName = bundleIdentifier.split('.').pop();
|
47 | if (!((_a = productName) === null || _a === void 0 ? void 0 : _a.includes('$'))) {
|
48 | buildSettings.PRODUCT_NAME = productName;
|
49 | }
|
50 | });
|
51 | fs_extra_1.default.writeFileSync(pbxprojPath, project.writeSync());
|
52 | }
|
53 | exports.updateBundleIdentifierForPbxproj = updateBundleIdentifierForPbxproj;
|
54 |
|
55 |
|
56 |
|
57 |
|
58 |
|
59 |
|
60 | function setBundleIdentifierForPbxproj(projectRoot, bundleIdentifier) {
|
61 |
|
62 | const pbxprojPaths = glob_1.sync(path_1.join(projectRoot, 'ios', '*', 'project.pbxproj'));
|
63 | for (const pbxprojPath of pbxprojPaths) {
|
64 | updateBundleIdentifierForPbxproj(pbxprojPath, bundleIdentifier);
|
65 | }
|
66 | }
|
67 | exports.setBundleIdentifierForPbxproj = setBundleIdentifierForPbxproj;
|
68 |
|
69 |
|
70 |
|
71 | const defaultBundleId = '$(PRODUCT_BUNDLE_IDENTIFIER)';
|
72 | function resetAllPlistBundleIdentifiers(projectRoot) {
|
73 | const infoPlistPaths = glob_1.sync(path_1.join(projectRoot, 'ios', '*', 'Info.plist'));
|
74 | for (const plistPath of infoPlistPaths) {
|
75 | resetPlistBundleIdentifier(plistPath);
|
76 | }
|
77 | }
|
78 | exports.resetAllPlistBundleIdentifiers = resetAllPlistBundleIdentifiers;
|
79 | function resetPlistBundleIdentifier(plistPath) {
|
80 | const rawPlist = fs_extra_1.default.readFileSync(plistPath, 'utf8');
|
81 | const plistObject = plist_1.default.parse(rawPlist);
|
82 | if (plistObject.CFBundleIdentifier) {
|
83 | if (plistObject.CFBundleIdentifier === defaultBundleId)
|
84 | return;
|
85 |
|
86 | const format = { pretty: true, indent: `\t` };
|
87 | const xml = plist_1.default.build(Object.assign(Object.assign({}, plistObject), { CFBundleIdentifier: defaultBundleId }), format);
|
88 | if (xml !== rawPlist) {
|
89 | fs_extra_1.default.writeFileSync(plistPath, xml);
|
90 | }
|
91 | }
|
92 | }
|
93 | exports.resetPlistBundleIdentifier = resetPlistBundleIdentifier;
|
94 | function filterComments([item]) {
|
95 | return !item.endsWith(`_comment`);
|
96 | }
|
97 | function filterConfig(input) {
|
98 | const { 1: { isa }, } = input;
|
99 | return isa === 'XCBuildConfiguration';
|
100 | }
|
101 | function filterHosts(input) {
|
102 | const { 1: { buildSettings }, } = input;
|
103 | return !buildSettings.TEST_HOST;
|
104 | }
|
105 |
|
\ | No newline at end of file |