Repositorio del curso CCOM4030 el semestre B91 del proyecto kilometro0

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  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 path = require('path'),
  18. util = require('util');
  19. var DEFAULT_SOURCETREE = '"<group>"',
  20. DEFAULT_PRODUCT_SOURCETREE = 'BUILT_PRODUCTS_DIR',
  21. DEFAULT_FILEENCODING = 4,
  22. DEFAULT_GROUP = 'Resources',
  23. DEFAULT_FILETYPE = 'unknown';
  24. var FILETYPE_BY_EXTENSION = {
  25. a: 'archive.ar',
  26. app: 'wrapper.application',
  27. appex: 'wrapper.app-extension',
  28. bundle: 'wrapper.plug-in',
  29. dylib: 'compiled.mach-o.dylib',
  30. framework: 'wrapper.framework',
  31. h: 'sourcecode.c.h',
  32. m: 'sourcecode.c.objc',
  33. markdown: 'text',
  34. mdimporter: 'wrapper.cfbundle',
  35. octest: 'wrapper.cfbundle',
  36. pch: 'sourcecode.c.h',
  37. plist: 'text.plist.xml',
  38. sh: 'text.script.sh',
  39. swift: 'sourcecode.swift',
  40. tbd: 'sourcecode.text-based-dylib-definition',
  41. xcassets: 'folder.assetcatalog',
  42. xcconfig: 'text.xcconfig',
  43. xcdatamodel: 'wrapper.xcdatamodel',
  44. xcodeproj: 'wrapper.pb-project',
  45. xctest: 'wrapper.cfbundle',
  46. xib: 'file.xib',
  47. strings: 'text.plist.strings'
  48. },
  49. GROUP_BY_FILETYPE = {
  50. 'archive.ar': 'Frameworks',
  51. 'compiled.mach-o.dylib': 'Frameworks',
  52. 'sourcecode.text-based-dylib-definition': 'Frameworks',
  53. 'wrapper.framework': 'Frameworks',
  54. 'embedded.framework': 'Embed Frameworks',
  55. 'sourcecode.c.h': 'Resources',
  56. 'sourcecode.c.objc': 'Sources',
  57. 'sourcecode.swift': 'Sources'
  58. },
  59. PATH_BY_FILETYPE = {
  60. 'compiled.mach-o.dylib': 'usr/lib/',
  61. 'sourcecode.text-based-dylib-definition': 'usr/lib/',
  62. 'wrapper.framework': 'System/Library/Frameworks/'
  63. },
  64. SOURCETREE_BY_FILETYPE = {
  65. 'compiled.mach-o.dylib': 'SDKROOT',
  66. 'sourcecode.text-based-dylib-definition': 'SDKROOT',
  67. 'wrapper.framework': 'SDKROOT'
  68. },
  69. ENCODING_BY_FILETYPE = {
  70. 'sourcecode.c.h': 4,
  71. 'sourcecode.c.h': 4,
  72. 'sourcecode.c.objc': 4,
  73. 'sourcecode.swift': 4,
  74. 'text': 4,
  75. 'text.plist.xml': 4,
  76. 'text.script.sh': 4,
  77. 'text.xcconfig': 4,
  78. 'text.plist.strings': 4
  79. };
  80. function unquoted(text){
  81. return text == null ? '' : text.replace (/(^")|("$)/g, '')
  82. }
  83. function detectType(filePath) {
  84. var extension = path.extname(filePath).substring(1),
  85. filetype = FILETYPE_BY_EXTENSION[unquoted(extension)];
  86. if (!filetype) {
  87. return DEFAULT_FILETYPE;
  88. }
  89. return filetype;
  90. }
  91. function defaultExtension(fileRef) {
  92. var filetype = fileRef.lastKnownFileType && fileRef.lastKnownFileType != DEFAULT_FILETYPE ?
  93. fileRef.lastKnownFileType : fileRef.explicitFileType;
  94. for(var extension in FILETYPE_BY_EXTENSION) {
  95. if(FILETYPE_BY_EXTENSION.hasOwnProperty(unquoted(extension)) ) {
  96. if(FILETYPE_BY_EXTENSION[unquoted(extension)] === unquoted(filetype) )
  97. return extension;
  98. }
  99. }
  100. }
  101. function defaultEncoding(fileRef) {
  102. var filetype = fileRef.lastKnownFileType || fileRef.explicitFileType,
  103. encoding = ENCODING_BY_FILETYPE[unquoted(filetype)];
  104. if (encoding) {
  105. return encoding;
  106. }
  107. }
  108. function detectGroup(fileRef, opt) {
  109. var extension = path.extname(fileRef.basename).substring(1),
  110. filetype = fileRef.lastKnownFileType || fileRef.explicitFileType,
  111. groupName = GROUP_BY_FILETYPE[unquoted(filetype)];
  112. if (extension === 'xcdatamodeld') {
  113. return 'Sources';
  114. }
  115. if (opt.customFramework && opt.embed) {
  116. return GROUP_BY_FILETYPE['embedded.framework'];
  117. }
  118. if (!groupName) {
  119. return DEFAULT_GROUP;
  120. }
  121. return groupName;
  122. }
  123. function detectSourcetree(fileRef) {
  124. var filetype = fileRef.lastKnownFileType || fileRef.explicitFileType,
  125. sourcetree = SOURCETREE_BY_FILETYPE[unquoted(filetype)];
  126. if (fileRef.explicitFileType) {
  127. return DEFAULT_PRODUCT_SOURCETREE;
  128. }
  129. if (fileRef.customFramework) {
  130. return DEFAULT_SOURCETREE;
  131. }
  132. if (!sourcetree) {
  133. return DEFAULT_SOURCETREE;
  134. }
  135. return sourcetree;
  136. }
  137. function defaultPath(fileRef, filePath) {
  138. var filetype = fileRef.lastKnownFileType || fileRef.explicitFileType,
  139. defaultPath = PATH_BY_FILETYPE[unquoted(filetype)];
  140. if (fileRef.customFramework) {
  141. return filePath;
  142. }
  143. if (defaultPath) {
  144. return path.join(defaultPath, path.basename(filePath));
  145. }
  146. return filePath;
  147. }
  148. function defaultGroup(fileRef) {
  149. var groupName = GROUP_BY_FILETYPE[fileRef.lastKnownFileType];
  150. if (!groupName) {
  151. return DEFAULT_GROUP;
  152. }
  153. return defaultGroup;
  154. }
  155. function pbxFile(filepath, opt) {
  156. var opt = opt || {};
  157. this.basename = path.basename(filepath);
  158. this.lastKnownFileType = opt.lastKnownFileType || detectType(filepath);
  159. this.group = detectGroup(this, opt);
  160. // for custom frameworks
  161. if (opt.customFramework == true) {
  162. this.customFramework = true;
  163. this.dirname = path.dirname(filepath).replace(/\\/g, '/');
  164. }
  165. this.path = defaultPath(this, filepath).replace(/\\/g, '/');
  166. this.fileEncoding = this.defaultEncoding = opt.defaultEncoding || defaultEncoding(this);
  167. // When referencing products / build output files
  168. if (opt.explicitFileType) {
  169. this.explicitFileType = opt.explicitFileType;
  170. this.basename = this.basename + '.' + defaultExtension(this);
  171. delete this.path;
  172. delete this.lastKnownFileType;
  173. delete this.group;
  174. delete this.defaultEncoding;
  175. }
  176. this.sourceTree = opt.sourceTree || detectSourcetree(this);
  177. this.includeInIndex = 0;
  178. if (opt.weak && opt.weak === true)
  179. this.settings = { ATTRIBUTES: ['Weak'] };
  180. if (opt.compilerFlags) {
  181. if (!this.settings)
  182. this.settings = {};
  183. this.settings.COMPILER_FLAGS = util.format('"%s"', opt.compilerFlags);
  184. }
  185. if (opt.embed && opt.sign) {
  186. if (!this.settings)
  187. this.settings = {};
  188. if (!this.settings.ATTRIBUTES)
  189. this.settings.ATTRIBUTES = [];
  190. this.settings.ATTRIBUTES.push('CodeSignOnCopy');
  191. }
  192. }
  193. module.exports = pbxFile;