Repositorio del curso CCOM4030 el semestre B91 del proyecto Paz para la Mujer

Api.js 30KB

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