forked from Telerik-Verified-Plugins/iosrtc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathiosrtc-swift-support.js
executable file
·140 lines (107 loc) · 4.54 KB
/
iosrtc-swift-support.js
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
#!/usr/bin/env node
'use strict';
console.error('running iosrtc hook');
// This hook automates this:
// https://github.com/eface2face/cordova-plugin-iosrtc/blob/master/docs/Building.md
var
fs = require("fs"),
path = require("path")
BUILD_VERSION = '9.0',
BUILD_VERSION_XCODE = '"' + BUILD_VERSION + '"',
SWIFT_VERSION = '2.3',
SWIFT_VERSION_XCODE = '"' + SWIFT_VERSION + '"',
RUNPATH_SEARCH_PATHS = '@executable_path/Frameworks',
RUNPATH_SEARCH_PATHS_XCODE = '"' + RUNPATH_SEARCH_PATHS + '"',
ENABLE_BITCODE = 'NO',
ENABLE_BITCODE_XCODE = '"' + ENABLE_BITCODE + '"',
BRIDGING_HEADER_END = '/Plugins/cordova-plugin-iosrtc/cordova-plugin-iosrtc-Bridging-Header.h',
COMMENT_KEY = /_comment$/;
// Helpers
// Drops the comments
function nonComments(obj) {
var
keys = Object.keys(obj),
newObj = {},
i = 0;
for (i; i < keys.length; i += 1) {
if (!COMMENT_KEY.test(keys[i])) {
newObj[keys[i]] = obj[keys[i]];
}
}
return newObj;
}
// Starting here
module.exports = function (context) {
var
projectRoot = context.opts.projectRoot,
xcodeProjectPath = fs.readdirSync(projectRoot).filter(function (file) { return ~file.indexOf('.xcodeproj') && fs.statSync(path.join(projectRoot, file)).isDirectory(); })[0],
projectName = xcodeProjectPath.slice(0, -'.xcodeproj'.length),
xcconfigPath = path.join(projectRoot, 'cordova', 'build.xcconfig'),
swiftBridgingHead = projectName + BRIDGING_HEADER_END,
swiftBridgingHeadXcode = '"' + swiftBridgingHead + '"',
swiftOptions = [''], // <-- begin to file appending AFTER initial newline
xcodeProject;
debug('".xcodeproj" project file found: ' + xcodeProjectPath);
// xcodeProjectPath = path.join(projectRoot, 'platforms', 'ios', xcodeProjectPath, 'project.pbxproj');
xcodeProjectPath = path.join(xcodeProjectPath, 'project.pbxproj');
// Checking if the project files are in the right place
if (!fs.existsSync(xcodeProjectPath)) {
debugerror('an error occurred searching the project file at: "' + xcodeProjectPath + '"');
return;
}
debug('".pbxproj" project file found: ' + xcodeProjectPath);
if (!fs.existsSync(xcconfigPath)) {
debugerror('an error occurred searching the project file at: "' + xcconfigPath + '"');
return;
}
debug('".xcconfig" project file found: ' + xcconfigPath);
var projectFile = context.opts.cordova.project.parseProjectFile(projectRoot);
xcodeProject = projectFile.xcode;
// Showing info about the tasks to do
debug('fixing issues in the generated project files:');
debug('- "iOS Deployment Target" and "Deployment Target" to: ' + BUILD_VERSION_XCODE);
debug('- "Runpath Search Paths" to: ' + RUNPATH_SEARCH_PATHS_XCODE);
debug('- "Objective-C Bridging Header" to: ' + swiftBridgingHeadXcode);
debug('- "ENABLE_BITCODE" set to: ' + ENABLE_BITCODE_XCODE);
debug('- "SWIFT_VERSION" set to: ' + SWIFT_VERSION_XCODE);
// Massaging the files
// "build.xcconfig"
swiftOptions.push('LD_RUNPATH_SEARCH_PATHS = ' + RUNPATH_SEARCH_PATHS);
swiftOptions.push('SWIFT_OBJC_BRIDGING_HEADER = ' + swiftBridgingHead);
swiftOptions.push('IPHONEOS_DEPLOYMENT_TARGET = ' + BUILD_VERSION);
swiftOptions.push('ENABLE_BITCODE = ' + ENABLE_BITCODE);
// NOTE: Not needed
// swiftOptions.push('EMBEDDED_CONTENT_CONTAINS_SWIFT = YES');
fs.appendFileSync(xcconfigPath, swiftOptions.join('\n'));
debug('file correctly fixed: ' + xcconfigPath);
// "project.pbxproj"
// Parsing it
// xcodeProject.parse(function (error) {
var configurations, buildSettings;
// if (error) {
// debugerror('an error occurred during the parsing of the project file: ' + error);
// return;
// }
configurations = nonComments(xcodeProject.pbxXCBuildConfigurationSection());
// Adding or changing the parameters we need
Object.keys(configurations).forEach(function (config) {
buildSettings = configurations[config].buildSettings;
buildSettings.LD_RUNPATH_SEARCH_PATHS = RUNPATH_SEARCH_PATHS_XCODE;
buildSettings.SWIFT_OBJC_BRIDGING_HEADER = swiftBridgingHeadXcode;
buildSettings.IPHONEOS_DEPLOYMENT_TARGET = BUILD_VERSION_XCODE;
buildSettings.ENABLE_BITCODE = ENABLE_BITCODE_XCODE;
buildSettings.SWIFT_VERSION = SWIFT_VERSION_XCODE;
});
// Writing the file again
fs.writeFileSync(xcodeProjectPath, xcodeProject.writeSync(), 'utf-8');
debug('file correctly fixed: ' + xcodeProjectPath);
// });
};
function debug(msg) {
// console.log('iosrtc-swift-support.js [INFO] ' + msg);
// since console.log doesn't show up in the TP log we're routing these to debugerror
debugerror("[INFO, really] " + msg);
}
function debugerror(msg) {
console.error('iosrtc-swift-support.js [ERROR] ' + msg);
}