Repositorio del curso CCOM4030 el semestre B91 del proyecto Artesanías con el Instituto de Cultura

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