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

projectFile.js 5.1KB

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