16
16
*/
17
17
18
18
var 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 ;
133
23
134
24
function detectType ( filePath ) {
135
25
var extension = path . extname ( filePath ) . substring ( 1 ) ,
136
26
filetype = FILETYPE_BY_EXTENSION [ unquoted ( extension ) ] ;
137
27
138
28
if ( ! filetype ) {
139
- return DEFAULT_FILETYPE ;
29
+ return constants . DEFAULT_FILETYPE ;
140
30
}
141
31
142
32
return filetype ;
143
33
}
144
34
145
35
function defaultExtension ( fileRef ) {
146
- var filetype = fileRef . lastKnownFileType && fileRef . lastKnownFileType != DEFAULT_FILETYPE ?
36
+ var filetype = fileRef . lastKnownFileType && fileRef . lastKnownFileType != constants . DEFAULT_FILETYPE ?
147
37
fileRef . lastKnownFileType : fileRef . explicitFileType ;
148
38
149
39
for ( var extension in FILETYPE_BY_EXTENSION ) {
@@ -156,7 +46,7 @@ function defaultExtension(fileRef) {
156
46
157
47
function defaultEncoding ( fileRef ) {
158
48
var filetype = fileRef . lastKnownFileType || fileRef . explicitFileType ,
159
- encoding = ENCODING_BY_FILETYPE [ unquoted ( filetype ) ] ;
49
+ encoding = constants . ENCODING_BY_FILETYPE [ unquoted ( filetype ) ] ;
160
50
161
51
if ( encoding ) {
162
52
return encoding ;
@@ -166,18 +56,18 @@ function defaultEncoding(fileRef) {
166
56
function detectGroup ( fileRef , opt ) {
167
57
var extension = path . extname ( fileRef . basename ) . substring ( 1 ) ,
168
58
filetype = fileRef . lastKnownFileType || fileRef . explicitFileType ,
169
- groupName = GROUP_BY_FILETYPE [ unquoted ( filetype ) ] ;
59
+ groupName = constants . GROUP_BY_FILETYPE [ unquoted ( filetype ) ] ;
170
60
171
61
if ( extension === 'xcdatamodeld' ) {
172
62
return 'Sources' ;
173
63
}
174
64
175
65
if ( opt . customFramework && opt . embed ) {
176
- return GROUP_BY_FILETYPE [ 'embedded.framework' ] ;
66
+ return constants . GROUP_BY_FILETYPE [ 'embedded.framework' ] ;
177
67
}
178
68
179
69
if ( ! groupName ) {
180
- return DEFAULT_GROUP ;
70
+ return constants . DEFAULT_GROUP ;
181
71
}
182
72
183
73
return groupName ;
@@ -186,26 +76,26 @@ function detectGroup(fileRef, opt) {
186
76
function detectSourcetree ( fileRef ) {
187
77
188
78
var filetype = fileRef . lastKnownFileType || fileRef . explicitFileType ,
189
- sourcetree = SOURCETREE_BY_FILETYPE [ unquoted ( filetype ) ] ;
79
+ sourcetree = constants . SOURCETREE_BY_FILETYPE [ unquoted ( filetype ) ] ;
190
80
191
81
if ( fileRef . explicitFileType ) {
192
- return DEFAULT_PRODUCT_SOURCETREE ;
82
+ return constants . DEFAULT_PRODUCT_SOURCETREE ;
193
83
}
194
84
195
85
if ( fileRef . customFramework ) {
196
- return DEFAULT_SOURCETREE ;
86
+ return constants . DEFAULT_SOURCETREE ;
197
87
}
198
88
199
89
if ( ! sourcetree ) {
200
- return DEFAULT_SOURCETREE ;
90
+ return constants . DEFAULT_SOURCETREE ;
201
91
}
202
92
203
93
return sourcetree ;
204
94
}
205
95
206
96
function defaultPath ( fileRef , filePath ) {
207
97
var filetype = fileRef . lastKnownFileType || fileRef . explicitFileType ,
208
- defaultPath = PATH_BY_FILETYPE [ unquoted ( filetype ) ] ;
98
+ defaultPath = constants . PATH_BY_FILETYPE [ unquoted ( filetype ) ] ;
209
99
210
100
if ( fileRef . customFramework ) {
211
101
return filePath ;
@@ -218,18 +108,8 @@ function defaultPath(fileRef, filePath) {
218
108
return filePath ;
219
109
}
220
110
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
-
231
111
function pbxFile ( filepath , opt ) {
232
- var opt = opt || { } ;
112
+ opt = opt || { } ;
233
113
234
114
this . basename = opt . basename || path . basename ( filepath ) ;
235
115
this . lastKnownFileType = opt . lastKnownFileType || detectType ( filepath ) ;
@@ -275,12 +155,4 @@ function pbxFile(filepath, opt) {
275
155
}
276
156
}
277
157
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