|
108 | 108 | var projectRoot = getProjectRoot(context)
|
109 | 109 | var projectPath = path.join(projectRoot, 'platforms', 'ios')
|
110 | 110 |
|
111 |
| - // try pre 5.0 cordova structure |
112 | 111 | try {
|
| 112 | + // pre 5.0 cordova structure |
113 | 113 | return context.requireCordovaModule('cordova-lib/src/plugman/platforms').ios.parseProjectFile(projectPath)
|
114 | 114 | } catch (e) {
|
115 |
| - // try pre 7.0 cordova structure |
116 | 115 | try {
|
| 116 | + // pre 7.0 cordova structure |
117 | 117 | return context.requireCordovaModule('cordova-lib/src/plugman/platforms/ios').parseProjectFile(projectPath)
|
118 | 118 | } catch (e) {
|
119 |
| - return getProjectModulePlugman(context) |
| 119 | + // post 7.0 cordova structure |
| 120 | + return getProjectModuleGlob(context) |
120 | 121 | }
|
121 | 122 | }
|
122 | 123 | }
|
123 | 124 |
|
124 |
| - function getProjectModulePlugman (context) { |
| 125 | + function getProjectModuleGlob (context) { |
| 126 | + // get xcodeproj |
125 | 127 | var projectRoot = getProjectRoot(context)
|
126 | 128 | var projectPath = path.join(projectRoot, 'platforms', 'ios')
|
127 | 129 | var projectFiles = context.requireCordovaModule('glob').sync(path.join(projectPath, '*.xcodeproj', 'project.pbxproj'))
|
128 |
| - |
129 |
| - if (projectFiles.length === 0) { |
130 |
| - throw new Error('BRANCH SDK: Unable to locate the Xcode project file.') |
131 |
| - } |
132 |
| - |
| 130 | + if (projectFiles.length === 0) return |
133 | 131 | var pbxPath = projectFiles[0]
|
134 | 132 | var xcodeproj = context.requireCordovaModule('xcode').project(pbxPath)
|
| 133 | + |
| 134 | + // add hash |
135 | 135 | xcodeproj.parseSync()
|
136 | 136 |
|
137 |
| - var xCodeProjectFile = { |
| 137 | + // return xcodeproj and write method |
| 138 | + return { |
138 | 139 | 'xcode': xcodeproj,
|
139 | 140 | 'write': function () {
|
| 141 | + // save xcodeproj |
140 | 142 | var fs = context.requireCordovaModule('fs')
|
| 143 | + fs.writeFileSync(pbxPath, xcodeproj.writeSync()) |
| 144 | + |
| 145 | + // pull framework dependencies |
141 | 146 | var frameworksFile = path.join(projectPath, 'frameworks.json')
|
142 | 147 | var frameworks = {}
|
| 148 | + |
143 | 149 | try {
|
144 | 150 | frameworks = context.requireCordovaModule(frameworksFile)
|
145 | 151 | } catch (e) {}
|
146 |
| - |
147 |
| - fs.writeFileSync(pbxPath, xcodeproj.writeSync()) |
| 152 | + // If there are no framework references, remove this file |
148 | 153 | if (Object.keys(frameworks).length === 0) {
|
149 |
| - // If there is no framework references remain in the project, just remove this file |
150 |
| - context.requireCordovaModule('shelljs').rm('-rf', frameworksFile) |
151 |
| - return |
| 154 | + return context.requireCordovaModule('shelljs').rm('-rf', frameworksFile) |
152 | 155 | }
|
153 |
| - fs.writeFileSync(frameworksFile, JSON.stringify(this.frameworks, null, 4)) |
| 156 | + |
| 157 | + // save frameworks |
| 158 | + fs.writeFileSync(frameworksFile, JSON.stringify(frameworks, null, 4)) |
154 | 159 | }
|
155 | 160 | }
|
156 |
| - |
157 |
| - return xCodeProjectFile |
158 | 161 | }
|
159 | 162 |
|
160 | 163 | // validate <branch-config> properties within config.xml
|
|
0 commit comments