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

projectFile.js 4.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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. var xcode = require('xcode');
  18. var plist = require('plist');
  19. var _ = require('underscore');
  20. var path = require('path');
  21. var fs = require('fs');
  22. var shell = require('shelljs');
  23. var pluginHandlers = require('./plugman/pluginHandlers');
  24. var CordovaError = require('cordova-common').CordovaError;
  25. var cachedProjectFiles = {};
  26. function parseProjectFile (locations) {
  27. var project_dir = locations.root;
  28. var pbxPath = locations.pbxproj;
  29. if (cachedProjectFiles[project_dir]) {
  30. return cachedProjectFiles[project_dir];
  31. }
  32. var xcodeproj = xcode.project(pbxPath);
  33. xcodeproj.parseSync();
  34. var xcBuildConfiguration = xcodeproj.pbxXCBuildConfigurationSection();
  35. var plist_file_entry = _.find(xcBuildConfiguration, function (entry) { return entry.buildSettings && entry.buildSettings.INFOPLIST_FILE; });
  36. var plist_file = path.join(project_dir, plist_file_entry.buildSettings.INFOPLIST_FILE.replace(/^"(.*)"$/g, '$1').replace(/\\&/g, '&'));
  37. var config_file = path.join(path.dirname(plist_file), 'config.xml');
  38. if (!fs.existsSync(plist_file) || !fs.existsSync(config_file)) {
  39. throw new CordovaError('Could not find *-Info.plist file, or config.xml file.');
  40. }
  41. var frameworks_file = path.join(project_dir, 'frameworks.json');
  42. var frameworks = {};
  43. try {
  44. frameworks = require(frameworks_file);
  45. } catch (e) { }
  46. var xcode_dir = path.dirname(plist_file);
  47. var pluginsDir = path.resolve(xcode_dir, 'Plugins');
  48. var resourcesDir = path.resolve(xcode_dir, 'Resources');
  49. cachedProjectFiles[project_dir] = {
  50. plugins_dir: pluginsDir,
  51. resources_dir: resourcesDir,
  52. xcode: xcodeproj,
  53. xcode_path: xcode_dir,
  54. pbx: pbxPath,
  55. projectDir: project_dir,
  56. platformWww: path.join(project_dir, 'platform_www'),
  57. www: path.join(project_dir, 'www'),
  58. write: function () {
  59. fs.writeFileSync(pbxPath, xcodeproj.writeSync());
  60. if (Object.keys(this.frameworks).length === 0) {
  61. // If there is no framework references remain in the project, just remove this file
  62. shell.rm('-rf', frameworks_file);
  63. return;
  64. }
  65. fs.writeFileSync(frameworks_file, JSON.stringify(this.frameworks, null, 4));
  66. },
  67. getPackageName: function () {
  68. return plist.parse(fs.readFileSync(plist_file, 'utf8')).CFBundleIdentifier;
  69. },
  70. getInstaller: function (name) {
  71. return pluginHandlers.getInstaller(name);
  72. },
  73. getUninstaller: function (name) {
  74. return pluginHandlers.getUninstaller(name);
  75. },
  76. frameworks: frameworks
  77. };
  78. return cachedProjectFiles[project_dir];
  79. }
  80. function purgeProjectFileCache (project_dir) {
  81. delete cachedProjectFiles[project_dir];
  82. }
  83. module.exports = {
  84. parse: parseProjectFile,
  85. purgeProjectFileCache: purgeProjectFileCache
  86. };
  87. xcode.project.prototype.pbxEmbedFrameworksBuildPhaseObj = function (target) {
  88. return this.buildPhaseObject('PBXCopyFilesBuildPhase', 'Embed Frameworks', target);
  89. };
  90. xcode.project.prototype.addToPbxEmbedFrameworksBuildPhase = function (file) {
  91. var sources = this.pbxEmbedFrameworksBuildPhaseObj(file.target);
  92. if (sources) {
  93. sources.files.push(pbxBuildPhaseObj(file));
  94. }
  95. };
  96. xcode.project.prototype.removeFromPbxEmbedFrameworksBuildPhase = function (file) {
  97. var sources = this.pbxEmbedFrameworksBuildPhaseObj(file.target);
  98. if (sources) {
  99. sources.files = _.reject(sources.files, function (file) {
  100. return file.comment === longComment(file);
  101. });
  102. }
  103. };
  104. // special handlers to add frameworks to the 'Embed Frameworks' build phase, needed for custom frameworks
  105. // see CB-9517. should probably be moved to node-xcode.
  106. var util = require('util');
  107. function pbxBuildPhaseObj (file) {
  108. var obj = Object.create(null);
  109. obj.value = file.uuid;
  110. obj.comment = longComment(file);
  111. return obj;
  112. }
  113. function longComment (file) {
  114. return util.format('%s in %s', file.basename, file.group);
  115. }