forked from apache/cordova-ios
/
Api.js
711 lines (654 loc) · 29.9 KB
/
Api.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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
/**
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
*/
/* jslint node: true */
var fs = require('fs');
var path = require('path');
var unorm = require('unorm');
var projectFile = require('./lib/projectFile');
var check_reqs = require('./lib/check_reqs');
var CordovaError = require('cordova-common').CordovaError;
var CordovaLogger = require('cordova-common').CordovaLogger;
var events = require('cordova-common').events;
var PluginManager = require('cordova-common').PluginManager;
var Q = require('q');
var util = require('util');
var xcode = require('xcode');
var ConfigParser = require('cordova-common').ConfigParser;
function setupEvents (externalEventEmitter) {
if (externalEventEmitter) {
// This will make the platform internal events visible outside
events.forwardEventsTo(externalEventEmitter);
} else {
// There is no logger if external emitter is not present,
// so attach a console logger
CordovaLogger.get().subscribe(events);
}
}
/**
* Creates a new PlatformApi instance.
*
* @param {String} [platform] Platform name, used for backward compatibility
* w/ PlatformPoly (CordovaLib).
* @param {String} [platformRootDir] Platform root location, used for backward
* compatibility w/ PlatformPoly (CordovaLib).
* @param {EventEmitter} [events] An EventEmitter instance that will be used for
* logging purposes. If no EventEmitter provided, all events will be logged to
* console
*/
function Api (platform, platformRootDir, events) {
// 'platform' property is required as per PlatformApi spec
this.platform = platform || 'ios';
this.root = platformRootDir || path.resolve(__dirname, '..');
setupEvents(events);
var xcodeProjDir;
var xcodeCordovaProj;
try {
var xcodeProjDir_array = fs.readdirSync(this.root).filter(function (e) { return e.match(/\.xcodeproj$/i); });
if (xcodeProjDir_array.length > 1) {
for (var x = 0; x < xcodeProjDir_array.length; x++) {
if (xcodeProjDir_array[x].substring(0, 2) === '._') {
xcodeProjDir_array.splice(x, 1);
}
}
}
xcodeProjDir = xcodeProjDir_array[0];
if (!xcodeProjDir) {
throw new CordovaError('The provided path "' + this.root + '" is not a Cordova iOS project.');
}
var cordovaProjName = xcodeProjDir.substring(xcodeProjDir.lastIndexOf(path.sep) + 1, xcodeProjDir.indexOf('.xcodeproj'));
xcodeCordovaProj = path.join(this.root, cordovaProjName);
} catch (e) {
throw new CordovaError('The provided path "' + this.root + '" is not a Cordova iOS project.');
}
this.locations = {
root: this.root,
www: path.join(this.root, 'www'),
platformWww: path.join(this.root, 'platform_www'),
configXml: path.join(xcodeCordovaProj, 'config.xml'),
defaultConfigXml: path.join(this.root, 'cordova/defaults.xml'),
pbxproj: path.join(this.root, xcodeProjDir, 'project.pbxproj'),
xcodeProjDir: path.join(this.root, xcodeProjDir),
xcodeCordovaProj: xcodeCordovaProj,
// NOTE: this is required by browserify logic.
// As per platformApi spec we return relative to template root paths here
cordovaJs: 'bin/CordovaLib/cordova.js',
cordovaJsSrc: 'bin/cordova-js-src'
};
}
/**
* Creates platform in a specified directory.
*
* @param {String} destination Destination directory, where install platform to
* @param {ConfigParser} [config] ConfgiParser instance, used to retrieve
* project creation options, such as package id and project name.
* @param {Object} [options] An options object. The most common options are:
* @param {String} [options.customTemplate] A path to custom template, that
* should override the default one from platform.
* @param {Boolean} [options.link] Flag that indicates that platform's
* sources will be linked to installed platform instead of copying.
* @param {EventEmitter} [events] An EventEmitter instance that will be used for
* logging purposes. If no EventEmitter provided, all events will be logged to
* console
*
* @return {Promise<PlatformApi>} Promise either fulfilled with PlatformApi
* instance or rejected with CordovaError.
*/
Api.createPlatform = function (destination, config, options, events) {
setupEvents(events);
// CB-6992 it is necessary to normalize characters
// because node and shell scripts handles unicode symbols differently
// We need to normalize the name to NFD form since iOS uses NFD unicode form
var name = unorm.nfd(config.name());
var result;
try {
result = require('../../../lib/create')
.createProject(destination, config.packageName(), name, options)
.then(function () {
// after platform is created we return Api instance based on new Api.js location
// This is required to correctly resolve paths in the future api calls
var PlatformApi = require(path.resolve(destination, 'cordova/Api'));
return new PlatformApi('ios', destination, events);
});
} catch (e) {
events.emit('error', 'createPlatform is not callable from the iOS project API.');
throw (e);
}
return result;
};
/**
* Updates already installed platform.
*
* @param {String} destination Destination directory, where platform installed
* @param {Object} [options] An options object. The most common options are:
* @param {String} [options.customTemplate] A path to custom template, that
* should override the default one from platform.
* @param {Boolean} [options.link] Flag that indicates that platform's
* sources will be linked to installed platform instead of copying.
* @param {EventEmitter} [events] An EventEmitter instance that will be used for
* logging purposes. If no EventEmitter provided, all events will be logged to
* console
*
* @return {Promise<PlatformApi>} Promise either fulfilled with PlatformApi
* instance or rejected with CordovaError.
*/
Api.updatePlatform = function (destination, options, events) {
setupEvents(events);
var result;
try {
result = require('../../../lib/create')
.updateProject(destination, options)
.then(function () {
var PlatformApi = require(path.resolve(destination, 'cordova/Api'));
return new PlatformApi('ios', destination, events);
});
} catch (e) {
events.emit('error', 'updatePlatform is not callable from the iOS project API, you will need to do this manually.');
throw (e);
}
return result;
};
/**
* Gets a CordovaPlatform object, that represents the platform structure.
*
* @return {CordovaPlatform} A structure that contains the description of
* platform's file structure and other properties of platform.
*/
Api.prototype.getPlatformInfo = function () {
var result = {};
result.locations = this.locations;
result.root = this.root;
result.name = this.platform;
result.version = require('./version');
result.projectConfig = new ConfigParser(this.locations.configXml);
return result;
};
/**
* Updates installed platform with provided www assets and new app
* configuration. This method is required for CLI workflow and will be called
* each time before build, so the changes, made to app configuration and www
* code, will be applied to platform.
*
* @param {CordovaProject} cordovaProject A CordovaProject instance, that defines a
* project structure and configuration, that should be applied to platform
* (contains project's www location and ConfigParser instance for project's
* config).
*
* @return {Promise} Return a promise either fulfilled, or rejected with
* CordovaError instance.
*/
Api.prototype.prepare = function (cordovaProject) {
return require('./lib/prepare').prepare.call(this, cordovaProject);
};
/**
* Installs a new plugin into platform. It doesn't resolves plugin dependencies.
*
* @param {PluginInfo} plugin A PluginInfo instance that represents plugin
* that will be installed.
* @param {Object} installOptions An options object. Possible options below:
* @param {Boolean} installOptions.link: Flag that specifies that plugin
* sources will be symlinked to app's directory instead of copying (if
* possible).
* @param {Object} installOptions.variables An object that represents
* variables that will be used to install plugin. See more details on plugin
* variables in documentation:
* https://cordova.apache.org/docs/en/4.0.0/plugin_ref_spec.md.html
*
* @return {Promise} Return a promise either fulfilled, or rejected with
* CordovaError instance.
*/
Api.prototype.addPlugin = function (plugin, installOptions) {
var xcodeproj = projectFile.parse(this.locations);
var self = this;
installOptions = installOptions || {};
installOptions.variables = installOptions.variables || {};
// Add PACKAGE_NAME variable into vars
if (!installOptions.variables.PACKAGE_NAME) {
installOptions.variables.PACKAGE_NAME = xcodeproj.getPackageName();
}
return PluginManager.get(self.platform, self.locations, xcodeproj)
.addPlugin(plugin, installOptions)
.then(function () {
if (plugin != null) {
var headerTags = plugin.getHeaderFiles(self.platform);
var bridgingHeaders = headerTags.filter(function (obj) {
return (obj.type === 'BridgingHeader');
});
if (bridgingHeaders.length > 0) {
var project_dir = self.locations.root;
var project_name = self.locations.xcodeCordovaProj.split('/').pop();
var BridgingHeader = require('./lib/BridgingHeader').BridgingHeader;
var bridgingHeaderFile = new BridgingHeader(path.join(project_dir, project_name, 'Bridging-Header.h'));
events.emit('verbose', 'Adding Bridging-Headers since the plugin contained <header-file> with type="BridgingHeader"');
bridgingHeaders.forEach(function (obj) {
var bridgingHeaderPath = path.basename(obj.src);
bridgingHeaderFile.addHeader(plugin.id, bridgingHeaderPath);
});
bridgingHeaderFile.write();
}
}
})
.then(function () {
if (plugin != null) {
var podSpecs = plugin.getPodSpecs ? plugin.getPodSpecs(self.platform) : [];
var frameworkTags = plugin.getFrameworks(self.platform);
var frameworkPods = frameworkTags.filter(function (obj) {
return (obj.type === 'podspec');
});
return self.addPodSpecs(plugin, podSpecs, frameworkPods);
}
})
// CB-11022 return non-falsy value to indicate
// that there is no need to run prepare after
.thenResolve(true);
};
/**
* Removes an installed plugin from platform.
*
* Since method accepts PluginInfo instance as input parameter instead of plugin
* id, caller shoud take care of managing/storing PluginInfo instances for
* future uninstalls.
*
* @param {PluginInfo} plugin A PluginInfo instance that represents plugin
* that will be installed.
*
* @return {Promise} Return a promise either fulfilled, or rejected with
* CordovaError instance.
*/
Api.prototype.removePlugin = function (plugin, uninstallOptions) {
var xcodeproj = projectFile.parse(this.locations);
var self = this;
return PluginManager.get(self.platform, self.locations, xcodeproj)
.removePlugin(plugin, uninstallOptions)
.then(function () {
if (plugin != null) {
var headerTags = plugin.getHeaderFiles(self.platform);
var bridgingHeaders = headerTags.filter(function (obj) {
return (obj.type === 'BridgingHeader');
});
if (bridgingHeaders.length > 0) {
var project_dir = self.locations.root;
var project_name = self.locations.xcodeCordovaProj.split('/').pop();
var BridgingHeader = require('./lib/BridgingHeader').BridgingHeader;
var bridgingHeaderFile = new BridgingHeader(path.join(project_dir, project_name, 'Bridging-Header.h'));
events.emit('verbose', 'Removing Bridging-Headers since the plugin contained <header-file> with type="BridgingHeader"');
bridgingHeaders.forEach(function (obj) {
var bridgingHeaderPath = path.basename(obj.src);
bridgingHeaderFile.removeHeader(plugin.id, bridgingHeaderPath);
});
bridgingHeaderFile.write();
}
}
})
.then(function () {
if (plugin != null) {
var podSpecs = plugin.getPodSpecs ? plugin.getPodSpecs(self.platform) : [];
var frameworkTags = plugin.getFrameworks(self.platform);
var frameworkPods = frameworkTags.filter(function (obj) {
return (obj.type === 'podspec');
});
return self.removePodSpecs(plugin, podSpecs, frameworkPods);
}
})
// CB-11022 return non-falsy value to indicate
// that there is no need to run prepare after
.thenResolve(true);
};
/**
* adding CocoaPods libraries
*
* @param {PluginInfo} plugin A PluginInfo instance that represents plugin
* that will be installed.
* @param {Object} podSpecs: the return value of plugin.getPodSpecs(self.platform)
* @param {Object} frameworkPods: framework tags object with type === 'podspec'
* @return {Promise} Return a promise
*/
Api.prototype.addPodSpecs = function (plugin, podSpecs, frameworkPods) {
var self = this;
var project_dir = self.locations.root;
var project_name = self.locations.xcodeCordovaProj.split('/').pop();
var minDeploymentTarget = self.getPlatformInfo().projectConfig.getPreference('deployment-target', 'ios');
var Podfile = require('./lib/Podfile').Podfile;
var PodsJson = require('./lib/PodsJson').PodsJson;
var podsjsonFile = new PodsJson(path.join(project_dir, PodsJson.FILENAME));
var podfileFile = new Podfile(path.join(project_dir, Podfile.FILENAME), project_name, minDeploymentTarget);
if (podSpecs.length) {
events.emit('verbose', 'Adding pods since the plugin contained <podspecs>');
podSpecs.forEach(function (obj) {
// declarations
Object.keys(obj.declarations).forEach(function (key) {
if (obj.declarations[key] === 'true') {
var declaration = Podfile.proofDeclaration(key);
var podJson = {
declaration: declaration
};
var val = podsjsonFile.getDeclaration(declaration);
if (val) {
podsjsonFile.incrementDeclaration(declaration);
} else {
podJson.count = 1;
podsjsonFile.setJsonDeclaration(declaration, podJson);
podfileFile.addDeclaration(podJson.declaration);
}
}
});
// sources
Object.keys(obj.sources).forEach(function (key) {
var podJson = {
source: obj.sources[key].source
};
var val = podsjsonFile.getSource(key);
if (val) {
podsjsonFile.incrementSource(key);
} else {
podJson.count = 1;
podsjsonFile.setJsonSource(key, podJson);
podfileFile.addSource(podJson.source);
}
});
// libraries
Object.keys(obj.libraries).forEach(function (key) {
var podJson = Object.assign({}, obj.libraries[key]);
var val = podsjsonFile.getLibrary(key);
if (val) {
events.emit('warn', plugin.id + ' depends on ' + podJson.name + ', which may conflict with another plugin. ' + podJson.name + '@' + val.spec + ' is already installed and was not overwritten.');
podsjsonFile.incrementLibrary(key);
} else {
podJson.count = 1;
podsjsonFile.setJsonLibrary(key, podJson);
podfileFile.addSpec(podJson.name, podJson);
}
});
});
}
if (frameworkPods.length) {
events.emit('warn', '"framework" tag with type "podspec" is deprecated and will be removed. Please use the "podspec" tag.');
events.emit('verbose', 'Adding pods since the plugin contained <framework>(s) with type="podspec"');
frameworkPods.forEach(function (obj) {
var podJson = {
name: obj.src,
type: obj.type,
spec: obj.spec
};
var val = podsjsonFile.getLibrary(podJson.name);
if (val) { // found
if (podJson.spec !== val.spec) { // exists, different spec, print warning
events.emit('warn', plugin.id + ' depends on ' + podJson.name + '@' + podJson.spec + ', which conflicts with another plugin. ' + podJson.name + '@' + val.spec + ' is already installed and was not overwritten.');
}
// increment count, but don't add in Podfile because it already exists
podsjsonFile.incrementLibrary(podJson.name);
} else { // not found, write new
podJson.count = 1;
podsjsonFile.setJsonLibrary(podJson.name, podJson);
// add to Podfile
podfileFile.addSpec(podJson.name, podJson.spec);
}
});
}
if (podSpecs.length > 0 || frameworkPods.length > 0) {
// now that all the pods have been processed, write to pods.json
podsjsonFile.write();
// only write and pod install if the Podfile changed
if (podfileFile.isDirty()) {
podfileFile.write();
events.emit('verbose', 'Running `pod install` (to install plugins)');
projectFile.purgeProjectFileCache(self.locations.root);
return podfileFile.install(check_reqs.check_cocoapods)
.then(function () {
self.setSwiftVersionForCocoaPodsLibraries(podsjsonFile);
});
} else {
events.emit('verbose', 'Podfile unchanged, skipping `pod install`');
}
}
return Q.when();
};
/**
* removing CocoaPods libraries
*
* @param {PluginInfo} plugin A PluginInfo instance that represents plugin
* that will be installed.
* @param {Object} podSpecs: the return value of plugin.getPodSpecs(self.platform)
* @param {Object} frameworkPods: framework tags object with type === 'podspec'
* @return {Promise} Return a promise
*/
Api.prototype.removePodSpecs = function (plugin, podSpecs, frameworkPods) {
var self = this;
var project_dir = self.locations.root;
var project_name = self.locations.xcodeCordovaProj.split('/').pop();
var Podfile = require('./lib/Podfile').Podfile;
var PodsJson = require('./lib/PodsJson').PodsJson;
var podsjsonFile = new PodsJson(path.join(project_dir, PodsJson.FILENAME));
var podfileFile = new Podfile(path.join(project_dir, Podfile.FILENAME), project_name);
if (podSpecs.length) {
events.emit('verbose', 'Adding pods since the plugin contained <podspecs>');
podSpecs.forEach(function (obj) {
// declarations
Object.keys(obj.declarations).forEach(function (key) {
if (obj.declarations[key] === 'true') {
var declaration = Podfile.proofDeclaration(key);
var podJson = {
declaration: declaration
};
var val = podsjsonFile.getDeclaration(declaration);
if (val) {
podsjsonFile.decrementDeclaration(declaration);
} else {
var message = util.format('plugin \"%s\" declaration \"%s\" does not seem to be in pods.json, nothing to remove. Will attempt to remove from Podfile.', plugin.id, podJson.declaration); /* eslint no-useless-escape : 0 */
events.emit('verbose', message);
}
if (!val || val.count === 0) {
podfileFile.removeDeclaration(podJson.declaration);
}
}
});
// sources
Object.keys(obj.sources).forEach(function (key) {
var podJson = {
source: obj.sources[key].source
};
var val = podsjsonFile.getSource(key);
if (val) {
podsjsonFile.decrementSource(key);
} else {
var message = util.format('plugin \"%s\" source \"%s\" does not seem to be in pods.json, nothing to remove. Will attempt to remove from Podfile.', plugin.id, podJson.source); /* eslint no-useless-escape : 0 */
events.emit('verbose', message);
}
if (!val || val.count === 0) {
podfileFile.removeSource(podJson.source);
}
});
// libraries
Object.keys(obj.libraries).forEach(function (key) {
var podJson = Object.assign({}, obj.libraries[key]);
var val = podsjsonFile.getLibrary(key);
if (val) {
podsjsonFile.decrementLibrary(key);
} else {
var message = util.format('plugin \"%s\" podspec \"%s\" does not seem to be in pods.json, nothing to remove. Will attempt to remove from Podfile.', plugin.id, podJson.name); /* eslint no-useless-escape : 0 */
events.emit('verbose', message);
}
if (!val || val.count === 0) {
podfileFile.removeSpec(podJson.name);
}
});
});
}
if (frameworkPods.length) {
events.emit('warn', '"framework" tag with type "podspec" is deprecated and will be removed. Please use the "podspec" tag.');
events.emit('verbose', 'Adding pods since the plugin contained <framework>(s) with type=\"podspec\"'); /* eslint no-useless-escape : 0 */
frameworkPods.forEach(function (obj) {
var podJson = {
name: obj.src,
type: obj.type,
spec: obj.spec
};
var val = podsjsonFile.getLibrary(podJson.name);
if (val) { // found, decrement count
podsjsonFile.decrementLibrary(podJson.name);
} else { // not found (perhaps a sync error)
var message = util.format('plugin \"%s\" podspec \"%s\" does not seem to be in pods.json, nothing to remove. Will attempt to remove from Podfile.', plugin.id, podJson.name); /* eslint no-useless-escape : 0 */
events.emit('verbose', message);
}
// always remove from the Podfile
podfileFile.removeSpec(podJson.name);
});
}
if (podSpecs.length > 0 || frameworkPods.length > 0) {
// now that all the pods have been processed, write to pods.json
podsjsonFile.write();
if (podfileFile.isDirty()) {
podfileFile.write();
events.emit('verbose', 'Running `pod install` (to uninstall pods)');
return podfileFile.install(check_reqs.check_cocoapods)
.then(function () {
self.setSwiftVersionForCocoaPodsLibraries(podsjsonFile);
});
} else {
events.emit('verbose', 'Podfile unchanged, skipping `pod install`');
}
}
return Q.when();
};
/**
* set Swift Version for all CocoaPods libraries
*
* @param {PodsJson} podsjsonFile A PodsJson instance that represents pods.json
*/
Api.prototype.setSwiftVersionForCocoaPodsLibraries = function (podsjsonFile) {
var self = this;
var __dirty = false;
var podPbxPath = path.join(self.root, 'Pods', 'Pods.xcodeproj', 'project.pbxproj');
var podXcodeproj = xcode.project(podPbxPath);
podXcodeproj.parseSync();
var podTargets = podXcodeproj.pbxNativeTargetSection();
var podConfigurationList = podXcodeproj.pbxXCConfigurationList();
var podConfigs = podXcodeproj.pbxXCBuildConfigurationSection();
var libraries = podsjsonFile.getLibraries();
Object.keys(libraries).forEach(function (key) {
var podJson = libraries[key];
var name = podJson.name;
var swiftVersion = podJson['swift-version'];
if (swiftVersion) {
__dirty = true;
Object.keys(podTargets).filter(function (targetKey) {
return podTargets[targetKey].productName === name;
}).map(function (targetKey) {
return podTargets[targetKey].buildConfigurationList;
}).map(function (buildConfigurationListId) {
return podConfigurationList[buildConfigurationListId];
}).map(function (buildConfigurationList) {
return buildConfigurationList.buildConfigurations;
}).reduce(function (acc, buildConfigurations) {
return acc.concat(buildConfigurations);
}, []).map(function (buildConfiguration) {
return buildConfiguration.value;
}).forEach(function (buildId) {
__dirty = true;
podConfigs[buildId].buildSettings['SWIFT_VERSION'] = swiftVersion;
});
}
});
if (__dirty) {
fs.writeFileSync(podPbxPath, podXcodeproj.writeSync(), 'utf-8');
}
};
/**
* Builds an application package for current platform.
*
* @param {Object} buildOptions A build options. This object's structure is
* highly depends on platform's specific. The most common options are:
* @param {Boolean} buildOptions.debug Indicates that packages should be
* built with debug configuration. This is set to true by default unless the
* 'release' option is not specified.
* @param {Boolean} buildOptions.release Indicates that packages should be
* built with release configuration. If not set to true, debug configuration
* will be used.
* @param {Boolean} buildOptions.device Specifies that built app is intended
* to run on device
* @param {Boolean} buildOptions.emulator: Specifies that built app is
* intended to run on emulator
* @param {String} buildOptions.target Specifies the device id that will be
* used to run built application.
* @param {Boolean} buildOptions.nobuild Indicates that this should be a
* dry-run call, so no build artifacts will be produced.
* @param {String[]} buildOptions.archs Specifies chip architectures which
* app packages should be built for. List of valid architectures is depends on
* platform.
* @param {String} buildOptions.buildConfig The path to build configuration
* file. The format of this file is depends on platform.
* @param {String[]} buildOptions.argv Raw array of command-line arguments,
* passed to `build` command. The purpose of this property is to pass a
* platform-specific arguments, and eventually let platform define own
* arguments processing logic.
*
* @return {Promise} Return a promise either fulfilled, or rejected with
* CordovaError instance.
*/
Api.prototype.build = function (buildOptions) {
var self = this;
return check_reqs.run()
.then(function () {
return require('./lib/build').run.call(self, buildOptions);
});
};
/**
* Builds an application package for current platform and runs it on
* specified/default device. If no 'device'/'emulator'/'target' options are
* specified, then tries to run app on default device if connected, otherwise
* runs the app on emulator.
*
* @param {Object} runOptions An options object. The structure is the same
* as for build options.
*
* @return {Promise} A promise either fulfilled if package was built and ran
* successfully, or rejected with CordovaError.
*/
Api.prototype.run = function (runOptions) {
var self = this;
return check_reqs.run()
.then(function () {
return require('./lib/run').run.call(self, runOptions);
});
};
/**
* Cleans out the build artifacts from platform's directory.
*
* @return {Promise} Return a promise either fulfilled, or rejected with
* CordovaError.
*/
Api.prototype.clean = function (cleanOptions) {
var self = this;
return check_reqs.run()
.then(function () {
return require('./lib/clean').run.call(self, cleanOptions);
})
.then(function () {
return require('./lib/prepare').clean.call(self, cleanOptions);
});
};
/**
* Performs a requirements check for current platform. Each platform defines its
* own set of requirements, which should be resolved before platform can be
* built successfully.
*
* @return {Promise<Requirement[]>} Promise, resolved with set of Requirement
* objects for current platform.
*/
Api.prototype.requirements = function () {
return check_reqs.check_all();
};
module.exports = Api;