1616 */
1717
1818var path = require ( 'path' ) ,
19- util = require ( 'util' ) ;
20-
21- var DEFAULT_SOURCETREE = '"<group>"' ,
22- DEFAULT_PRODUCT_SOURCETREE = 'BUILT_PRODUCTS_DIR' ,
23- DEFAULT_FILEENCODING = 4 ,
24- DEFAULT_GROUP = 'Resources' ,
25- DEFAULT_FILETYPE = 'unknown' ,
26- HEADER_FILE_TYPE_SUFFIX = ".h" ,
27- SOURCE_CODE_FILE_TYPE_PREFIX = "sourcecode." ;
28-
29- var FILETYPE_BY_EXTENSION = {
30- a : 'archive.ar' ,
31- app : 'wrapper.application' ,
32- appex : 'wrapper.app-extension' ,
33- bundle : 'wrapper.plug-in' ,
34- c : 'sourcecode.c.c' ,
35- cc : 'sourcecode.cpp.cpp' ,
36- cpp : 'sourcecode.cpp.cpp' ,
37- cxx : 'sourcecode.cpp.cpp' ,
38- 'c++' : 'sourcecode.cpp.cpp' ,
39- dylib : 'compiled.mach-o.dylib' ,
40- framework : 'wrapper.framework' ,
41- h : 'sourcecode.c.h' ,
42- hh : 'sourcecode.cpp.h' ,
43- hpp : 'sourcecode.cpp.h' ,
44- hxx : 'sourcecode.cpp.h' ,
45- 'h++' : 'sourcecode.cpp.h' ,
46- m : 'sourcecode.c.objc' ,
47- mm : 'sourcecode.cpp.objcpp' ,
48- markdown : 'text' ,
49- mdimporter : 'wrapper.cfbundle' ,
50- octest : 'wrapper.cfbundle' ,
51- pch : 'sourcecode.c.h' ,
52- plist : 'text.plist.xml' ,
53- png : "image.png" ,
54- sh : 'text.script.sh' ,
55- swift : 'sourcecode.swift' ,
56- tbd : 'sourcecode.text-based-dylib-definition' ,
57- xcassets : 'folder.assetcatalog' ,
58- xcconfig : 'text.xcconfig' ,
59- xcdatamodel : 'wrapper.xcdatamodel' ,
60- xcodeproj : 'wrapper.pb-project' ,
61- xctest : 'wrapper.cfbundle' ,
62- xib : 'file.xib' ,
63- strings : 'text.plist.strings'
64- } ,
65- GROUP_BY_FILETYPE = {
66- 'archive.ar' : 'Frameworks' ,
67- 'compiled.mach-o.dylib' : 'Frameworks' ,
68- 'sourcecode.text-based-dylib-definition' : 'Frameworks' ,
69- 'wrapper.framework' : 'Frameworks' ,
70- 'embedded.framework' : 'Embed Frameworks' ,
71- 'sourcecode.c.h' : 'Resources' ,
72- 'sourcecode.c.c' : 'Sources' ,
73- 'sourcecode.c.objc' : 'Sources' ,
74- 'sourcecode.swift' : 'Sources' ,
75- 'sourcecode.cpp.cpp' : 'Sources' ,
76- 'sourcecode.cpp.objcpp' : 'Sources'
77- } ,
78- PATH_BY_FILETYPE = {
79- 'compiled.mach-o.dylib' : 'usr/lib/' ,
80- 'sourcecode.text-based-dylib-definition' : 'usr/lib/' ,
81- 'wrapper.framework' : 'System/Library/Frameworks/'
82- } ,
83- SOURCETREE_BY_FILETYPE = {
84- 'compiled.mach-o.dylib' : 'SDKROOT' ,
85- 'sourcecode.text-based-dylib-definition' : 'SDKROOT' ,
86- 'wrapper.framework' : 'SDKROOT'
87- } ,
88- ENCODING_BY_FILETYPE = {
89- 'sourcecode.c.h' : 4 ,
90- 'sourcecode.c.h' : 4 ,
91- 'sourcecode.cpp.h' : 4 ,
92- 'sourcecode.c.c' : 4 ,
93- 'sourcecode.c.objc' : 4 ,
94- 'sourcecode.cpp.cpp' : 4 ,
95- 'sourcecode.cpp.objcpp' : 4 ,
96- 'sourcecode.swift' : 4 ,
97- 'text' : 4 ,
98- 'text.plist.xml' : 4 ,
99- 'text.script.sh' : 4 ,
100- 'text.xcconfig' : 4 ,
101- 'text.plist.strings' : 4
102- } ;
103-
104- function isSourceOrHeaderFileType ( fileType ) {
105- return fileType . startsWith ( SOURCE_CODE_FILE_TYPE_PREFIX ) ;
106- }
107-
108- function isHeaderFileType ( fileType ) {
109- return fileType . endsWith ( HEADER_FILE_TYPE_SUFFIX ) ;
110- }
111-
112- function unquoted ( text ) {
113- return text == null ? '' : text . replace ( / ( ^ " ) | ( " $ ) / g, '' )
114- }
19+ util = require ( 'util' ) ,
20+ constants = require ( './constants' ) ,
21+ unquoted = constants . unquoted ,
22+ FILETYPE_BY_EXTENSION = constants . FILETYPE_BY_EXTENSION ;
11523
11624function detectType ( filePath ) {
11725 var extension = path . extname ( filePath ) . substring ( 1 ) ,
11826 filetype = FILETYPE_BY_EXTENSION [ unquoted ( extension ) ] ;
11927
12028 if ( ! filetype ) {
121- return DEFAULT_FILETYPE ;
29+ return constants . DEFAULT_FILETYPE ;
12230 }
12331
12432 return filetype ;
12533}
12634
12735function defaultExtension ( fileRef ) {
128- var filetype = fileRef . lastKnownFileType && fileRef . lastKnownFileType != DEFAULT_FILETYPE ?
36+ var filetype = fileRef . lastKnownFileType && fileRef . lastKnownFileType != constants . DEFAULT_FILETYPE ?
12937 fileRef . lastKnownFileType : fileRef . explicitFileType ;
13038
13139 for ( var extension in FILETYPE_BY_EXTENSION ) {
@@ -138,7 +46,7 @@ function defaultExtension(fileRef) {
13846
13947function defaultEncoding ( fileRef ) {
14048 var filetype = fileRef . lastKnownFileType || fileRef . explicitFileType ,
141- encoding = ENCODING_BY_FILETYPE [ unquoted ( filetype ) ] ;
49+ encoding = constants . ENCODING_BY_FILETYPE [ unquoted ( filetype ) ] ;
14250
14351 if ( encoding ) {
14452 return encoding ;
@@ -148,18 +56,18 @@ function defaultEncoding(fileRef) {
14856function detectGroup ( fileRef , opt ) {
14957 var extension = path . extname ( fileRef . basename ) . substring ( 1 ) ,
15058 filetype = fileRef . lastKnownFileType || fileRef . explicitFileType ,
151- groupName = GROUP_BY_FILETYPE [ unquoted ( filetype ) ] ;
59+ groupName = constants . GROUP_BY_FILETYPE [ unquoted ( filetype ) ] ;
15260
15361 if ( extension === 'xcdatamodeld' ) {
15462 return 'Sources' ;
15563 }
15664
15765 if ( opt . customFramework && opt . embed ) {
158- return GROUP_BY_FILETYPE [ 'embedded.framework' ] ;
66+ return constants . GROUP_BY_FILETYPE [ 'embedded.framework' ] ;
15967 }
16068
16169 if ( ! groupName ) {
162- return DEFAULT_GROUP ;
70+ return constants . DEFAULT_GROUP ;
16371 }
16472
16573 return groupName ;
@@ -168,26 +76,26 @@ function detectGroup(fileRef, opt) {
16876function detectSourcetree ( fileRef ) {
16977
17078 var filetype = fileRef . lastKnownFileType || fileRef . explicitFileType ,
171- sourcetree = SOURCETREE_BY_FILETYPE [ unquoted ( filetype ) ] ;
79+ sourcetree = constants . SOURCETREE_BY_FILETYPE [ unquoted ( filetype ) ] ;
17280
17381 if ( fileRef . explicitFileType ) {
174- return DEFAULT_PRODUCT_SOURCETREE ;
82+ return constants . DEFAULT_PRODUCT_SOURCETREE ;
17583 }
17684
17785 if ( fileRef . customFramework ) {
178- return DEFAULT_SOURCETREE ;
86+ return constants . DEFAULT_SOURCETREE ;
17987 }
18088
18189 if ( ! sourcetree ) {
182- return DEFAULT_SOURCETREE ;
90+ return constants . DEFAULT_SOURCETREE ;
18391 }
18492
18593 return sourcetree ;
18694}
18795
18896function defaultPath ( fileRef , filePath ) {
18997 var filetype = fileRef . lastKnownFileType || fileRef . explicitFileType ,
190- defaultPath = PATH_BY_FILETYPE [ unquoted ( filetype ) ] ;
98+ defaultPath = constants . PATH_BY_FILETYPE [ unquoted ( filetype ) ] ;
19199
192100 if ( fileRef . customFramework ) {
193101 return filePath ;
@@ -200,18 +108,8 @@ function defaultPath(fileRef, filePath) {
200108 return filePath ;
201109}
202110
203- function defaultGroup ( fileRef ) {
204- var groupName = GROUP_BY_FILETYPE [ fileRef . lastKnownFileType ] ;
205-
206- if ( ! groupName ) {
207- return DEFAULT_GROUP ;
208- }
209-
210- return defaultGroup ;
211- }
212-
213111function pbxFile ( filepath , opt ) {
214- var opt = opt || { } ;
112+ opt = opt || { } ;
215113
216114 this . basename = opt . basename || path . basename ( filepath ) ;
217115 this . lastKnownFileType = opt . lastKnownFileType || detectType ( filepath ) ;
@@ -257,8 +155,4 @@ function pbxFile(filepath, opt) {
257155 }
258156}
259157
260- module . exports = {
261- pbxFile : pbxFile ,
262- isSourceOrHeaderFileType,
263- isHeaderFileType
264- }
158+ module . exports = pbxFile ;
0 commit comments