-
-
Notifications
You must be signed in to change notification settings - Fork 8
/
ios.dart
152 lines (133 loc) · 4.94 KB
/
ios.dart
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
part of '../package_rename.dart';
void _setIOSConfigurations(dynamic iosConfig) {
try {
if (iosConfig == null) return;
if (iosConfig is! Map) throw _PackageRenameErrors.invalidIOSConfig;
final iosConfigMap = Map<String, dynamic>.from(iosConfig);
_setIOSDisplayName(iosConfigMap[_appNameKey]);
_setIOSBundleName(iosConfigMap[_bundleNameKey]);
_setIOSPackageName(iosConfigMap[_packageNameKey]);
} on _PackageRenameException catch (e) {
_logger
..e('${e.message}ERR Code: ${e.code}')
..e('Skipping iOS configuration!!!');
} catch (e) {
_logger
..w(e.toString())
..e('ERR Code: 255')
..e('Skipping iOS configuration!!!');
} finally {
if (iosConfig != null) _logger.w(_majorTaskDoneLine);
}
}
void _setIOSDisplayName(dynamic appName) {
try {
if (appName == null) return;
if (appName is! String) throw _PackageRenameErrors.invalidAppName;
final iosInfoPlistFile = File(_iosInfoPlistFilePath);
if (!iosInfoPlistFile.existsSync()) {
throw _PackageRenameErrors.iosInfoPlistNotFound;
}
final iosInfoPlistString = iosInfoPlistFile.readAsStringSync();
final newDisplayNameIOSInfoPlistString = iosInfoPlistString.replaceAll(
RegExp(r'<key>CFBundleDisplayName</key>\s*<string>(.*?)</string>'),
'<key>CFBundleDisplayName</key>\n\t<string>$appName</string>',
);
iosInfoPlistFile.writeAsStringSync(newDisplayNameIOSInfoPlistString);
_logger.i('iOS display name set to: `$appName` (Info.plist)');
} on _PackageRenameException catch (e) {
_logger
..e('${e.message}ERR Code: ${e.code}')
..e('iOS Display Name change failed!!!');
} catch (e) {
_logger
..w(e.toString())
..e('ERR Code: 255')
..e('iOS Display Name change failed!!!');
} finally {
if (appName != null) _logger.f(_minorTaskDoneLine);
}
}
void _setIOSBundleName(dynamic bundleName) {
try {
if (bundleName == null) return;
if (bundleName is! String) throw _PackageRenameErrors.invalidBundleName;
if (bundleName.length > 15) {
_logger.w(
'Bundle name is too long. Maximum length should be 15 characters.',
);
}
final iosInfoPlistFile = File(_iosInfoPlistFilePath);
if (!iosInfoPlistFile.existsSync()) {
throw _PackageRenameErrors.iosInfoPlistNotFound;
}
final iosInfoPlistString = iosInfoPlistFile.readAsStringSync();
final newBundleNameIOSInfoPlistString = iosInfoPlistString.replaceAll(
RegExp(r'<key>CFBundleName</key>\s*<string>(.*?)</string>'),
'<key>CFBundleName</key>\n\t<string>$bundleName</string>',
);
iosInfoPlistFile.writeAsStringSync(newBundleNameIOSInfoPlistString);
_logger.i('iOS bundle name set to: `$bundleName` (Info.plist)');
} on _PackageRenameException catch (e) {
_logger
..e('${e.message}ERR Code: ${e.code}')
..e('iOS Bundle Name change failed!!!');
} catch (e) {
_logger
..w(e.toString())
..e('ERR Code: 255')
..e('iOS Bundle Name change failed!!!');
} finally {
if (bundleName != null) _logger.f(_minorTaskDoneLine);
}
}
void _setIOSPackageName(dynamic packageName) {
try {
if (packageName == null) return;
if (packageName is! String) throw _PackageRenameErrors.invalidPackageName;
final iosProjectFile = File(_iosProjectFilePath);
if (!iosProjectFile.existsSync()) {
throw _PackageRenameErrors.iosProjectFileNotFound;
}
final iosProjectString = iosProjectFile.readAsStringSync();
final newBundleIDIOSProjectString = iosProjectString
// Replaces old bundle id from
// `PRODUCT_BUNDLE_IDENTIFIER = {{BUNDLE_ID}};`
.replaceAll(
RegExp(
r'PRODUCT_BUNDLE_IDENTIFIER = ([A-Za-z0-9.-]+)(?<!\.RunnerTests);',
),
'PRODUCT_BUNDLE_IDENTIFIER = $packageName;',
)
// Replaces old bundle id from
// `PRODUCT_BUNDLE_IDENTIFIER = {{BUNDLE_ID}}.RunnerTests;`
.replaceAll(
RegExp('PRODUCT_BUNDLE_IDENTIFIER = (.*?).RunnerTests;'),
'PRODUCT_BUNDLE_IDENTIFIER = $packageName.RunnerTests;',
)
// Removes old bundle id from
// `PRODUCT_BUNDLE_IDENTIFIER = "{{BUNDLE_ID}}.{{EXTENSION_NAME}}";`
.replaceAllMapped(
RegExp(
r'PRODUCT_BUNDLE_IDENTIFIER = "([A-Za-z0-9.-]+)\.([A-Za-z0-9.-]+)";',
),
(match) {
final extensionName = match.group(2);
return 'PRODUCT_BUNDLE_IDENTIFIER = "$packageName.$extensionName";';
},
);
iosProjectFile.writeAsStringSync(newBundleIDIOSProjectString);
_logger.i('iOS bundle identifier set to: `$packageName` (project.pbxproj)');
} on _PackageRenameException catch (e) {
_logger
..e('${e.message}ERR Code: ${e.code}')
..e('iOS Bundle Identifier change failed!!!');
} catch (e) {
_logger
..w(e.toString())
..e('ERR Code: 255')
..e('iOS Bundle Identifier change failed!!!');
} finally {
if (packageName != null) _logger.f(_minorTaskDoneLine);
}
}