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- ENTITLEMENTS_FILE_TYPE_SUFFIX = ".entitlements" ,
28- SOURCE_CODE_FILE_TYPE_PREFIX = "sourcecode." ;
29-
30- var FILETYPE_BY_EXTENSION = {
31- a : 'archive.ar' ,
32- app : 'wrapper.application' ,
33- appex : 'wrapper.app-extension' ,
34- bundle : 'wrapper.plug-in' ,
35- c : 'sourcecode.c.c' ,
36- cc : 'sourcecode.cpp.cpp' ,
37- cpp : 'sourcecode.cpp.cpp' ,
38- cxx : 'sourcecode.cpp.cpp' ,
39- 'c++' : 'sourcecode.cpp.cpp' ,
40- dylib : 'compiled.mach-o.dylib' ,
41- framework : 'wrapper.framework' ,
42- h : 'sourcecode.c.h' ,
43- hh : 'sourcecode.cpp.h' ,
44- hpp : 'sourcecode.cpp.h' ,
45- hxx : 'sourcecode.cpp.h' ,
46- 'h++' : 'sourcecode.cpp.h' ,
47- m : 'sourcecode.c.objc' ,
48- mm : 'sourcecode.cpp.objcpp' ,
49- markdown : 'text' ,
50- mdimporter : 'wrapper.cfbundle' ,
51- octest : 'wrapper.cfbundle' ,
52- pch : 'sourcecode.c.h' ,
53- plist : 'text.plist.xml' ,
54- entitlements : 'text.plist.entitlements' ,
55- png : "image.png" ,
56- sh : 'text.script.sh' ,
57- swift : 'sourcecode.swift' ,
58- tbd : 'sourcecode.text-based-dylib-definition' ,
59- xcassets : 'folder.assetcatalog' ,
60- xcconfig : 'text.xcconfig' ,
61- xcdatamodel : 'wrapper.xcdatamodel' ,
62- xcodeproj : 'wrapper.pb-project' ,
63- xctest : 'wrapper.cfbundle' ,
64- xib : 'file.xib' ,
65- strings : 'text.plist.strings'
66- } ,
67- GROUP_BY_FILETYPE = {
68- 'archive.ar' : 'Frameworks' ,
69- 'compiled.mach-o.dylib' : 'Frameworks' ,
70- 'sourcecode.text-based-dylib-definition' : 'Frameworks' ,
71- 'wrapper.framework' : 'Frameworks' ,
72- 'embedded.framework' : 'Embed Frameworks' ,
73- 'sourcecode.c.h' : 'Resources' ,
74- 'sourcecode.c.c' : 'Sources' ,
75- 'sourcecode.c.objc' : 'Sources' ,
76- 'sourcecode.swift' : 'Sources' ,
77- 'sourcecode.cpp.cpp' : 'Sources' ,
78- 'sourcecode.cpp.objcpp' : 'Sources'
79- } ,
80- PATH_BY_FILETYPE = {
81- 'compiled.mach-o.dylib' : 'usr/lib/' ,
82- 'sourcecode.text-based-dylib-definition' : 'usr/lib/' ,
83- 'wrapper.framework' : 'System/Library/Frameworks/'
84- } ,
85- SOURCETREE_BY_FILETYPE = {
86- 'compiled.mach-o.dylib' : 'SDKROOT' ,
87- 'sourcecode.text-based-dylib-definition' : 'SDKROOT' ,
88- 'wrapper.framework' : 'SDKROOT'
89- } ,
90- ENCODING_BY_FILETYPE = {
91- 'sourcecode.c.h' : 4 ,
92- 'sourcecode.c.h' : 4 ,
93- 'sourcecode.cpp.h' : 4 ,
94- 'sourcecode.c.c' : 4 ,
95- 'sourcecode.c.objc' : 4 ,
96- 'sourcecode.cpp.cpp' : 4 ,
97- 'sourcecode.cpp.objcpp' : 4 ,
98- 'sourcecode.swift' : 4 ,
99- 'text' : 4 ,
100- 'text.plist.xml' : 4 ,
101- 'text.script.sh' : 4 ,
102- 'text.xcconfig' : 4 ,
103- 'text.plist.strings' : 4
104- } ;
105-
106- function isHeaderFileType ( fileType ) {
107- return fileType . endsWith ( HEADER_FILE_TYPE_SUFFIX ) ;
108- }
109-
110- function isSourceFileType ( fileType ) {
111- return fileType . startsWith ( SOURCE_CODE_FILE_TYPE_PREFIX ) && ! isHeaderFileType ( fileType ) ;
112- }
113-
114- function isAssetFileType ( fileType ) {
115- return fileType === FILETYPE_BY_EXTENSION . xcassets ;
116- }
117-
118- function isResource ( group ) {
119- return group === "Resources" ;
120- }
121-
122- function isEntitlement ( fileType ) {
123- return fileType . endsWith ( ENTITLEMENTS_FILE_TYPE_SUFFIX ) ;
124- }
125-
126- function isPlist ( fileType ) {
127- return fileType === FILETYPE_BY_EXTENSION . plist ;
128- }
129-
130- function unquoted ( text ) {
131- return text == null ? '' : text . replace ( / ( ^ " ) | ( " $ ) / g, '' )
132- }
19+ util = require ( 'util' ) ,
20+ constants = require ( './constants' ) ,
21+ unquoted = constants . unquoted ,
22+ FILETYPE_BY_EXTENSION = constants . FILETYPE_BY_EXTENSION ;
13323
13424function detectType ( filePath ) {
13525 var extension = path . extname ( filePath ) . substring ( 1 ) ,
13626 filetype = FILETYPE_BY_EXTENSION [ unquoted ( extension ) ] ;
13727
13828 if ( ! filetype ) {
139- return DEFAULT_FILETYPE ;
29+ return constants . DEFAULT_FILETYPE ;
14030 }
14131
14232 return filetype ;
14333}
14434
14535function defaultExtension ( fileRef ) {
146- var filetype = fileRef . lastKnownFileType && fileRef . lastKnownFileType != DEFAULT_FILETYPE ?
36+ var filetype = fileRef . lastKnownFileType && fileRef . lastKnownFileType != constants . DEFAULT_FILETYPE ?
14737 fileRef . lastKnownFileType : fileRef . explicitFileType ;
14838
14939 for ( var extension in FILETYPE_BY_EXTENSION ) {
@@ -156,7 +46,7 @@ function defaultExtension(fileRef) {
15646
15747function defaultEncoding ( fileRef ) {
15848 var filetype = fileRef . lastKnownFileType || fileRef . explicitFileType ,
159- encoding = ENCODING_BY_FILETYPE [ unquoted ( filetype ) ] ;
49+ encoding = constants . ENCODING_BY_FILETYPE [ unquoted ( filetype ) ] ;
16050
16151 if ( encoding ) {
16252 return encoding ;
@@ -166,18 +56,18 @@ function defaultEncoding(fileRef) {
16656function detectGroup ( fileRef , opt ) {
16757 var extension = path . extname ( fileRef . basename ) . substring ( 1 ) ,
16858 filetype = fileRef . lastKnownFileType || fileRef . explicitFileType ,
169- groupName = GROUP_BY_FILETYPE [ unquoted ( filetype ) ] ;
59+ groupName = constants . GROUP_BY_FILETYPE [ unquoted ( filetype ) ] ;
17060
17161 if ( extension === 'xcdatamodeld' ) {
17262 return 'Sources' ;
17363 }
17464
17565 if ( opt . customFramework && opt . embed ) {
176- return GROUP_BY_FILETYPE [ 'embedded.framework' ] ;
66+ return constants . GROUP_BY_FILETYPE [ 'embedded.framework' ] ;
17767 }
17868
17969 if ( ! groupName ) {
180- return DEFAULT_GROUP ;
70+ return constants . DEFAULT_GROUP ;
18171 }
18272
18373 return groupName ;
@@ -186,26 +76,26 @@ function detectGroup(fileRef, opt) {
18676function detectSourcetree ( fileRef ) {
18777
18878 var filetype = fileRef . lastKnownFileType || fileRef . explicitFileType ,
189- sourcetree = SOURCETREE_BY_FILETYPE [ unquoted ( filetype ) ] ;
79+ sourcetree = constants . SOURCETREE_BY_FILETYPE [ unquoted ( filetype ) ] ;
19080
19181 if ( fileRef . explicitFileType ) {
192- return DEFAULT_PRODUCT_SOURCETREE ;
82+ return constants . DEFAULT_PRODUCT_SOURCETREE ;
19383 }
19484
19585 if ( fileRef . customFramework ) {
196- return DEFAULT_SOURCETREE ;
86+ return constants . DEFAULT_SOURCETREE ;
19787 }
19888
19989 if ( ! sourcetree ) {
200- return DEFAULT_SOURCETREE ;
90+ return constants . DEFAULT_SOURCETREE ;
20191 }
20292
20393 return sourcetree ;
20494}
20595
20696function defaultPath ( fileRef , filePath ) {
20797 var filetype = fileRef . lastKnownFileType || fileRef . explicitFileType ,
208- defaultPath = PATH_BY_FILETYPE [ unquoted ( filetype ) ] ;
98+ defaultPath = constants . PATH_BY_FILETYPE [ unquoted ( filetype ) ] ;
20999
210100 if ( fileRef . customFramework ) {
211101 return filePath ;
@@ -218,18 +108,8 @@ function defaultPath(fileRef, filePath) {
218108 return filePath ;
219109}
220110
221- function defaultGroup ( fileRef ) {
222- var groupName = GROUP_BY_FILETYPE [ fileRef . lastKnownFileType ] ;
223-
224- if ( ! groupName ) {
225- return DEFAULT_GROUP ;
226- }
227-
228- return defaultGroup ;
229- }
230-
231111function pbxFile ( filepath , opt ) {
232- var opt = opt || { } ;
112+ opt = opt || { } ;
233113
234114 this . basename = opt . basename || path . basename ( filepath ) ;
235115 this . lastKnownFileType = opt . lastKnownFileType || detectType ( filepath ) ;
@@ -275,12 +155,4 @@ function pbxFile(filepath, opt) {
275155 }
276156}
277157
278- module . exports = {
279- pbxFile : pbxFile ,
280- isSourceFileType,
281- isHeaderFileType,
282- isResource,
283- isEntitlement,
284- isAssetFileType,
285- isPlist
286- }
158+ module . exports = pbxFile ;
0 commit comments