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
- 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 ;
115
23
116
24
function detectType ( filePath ) {
117
25
var extension = path . extname ( filePath ) . substring ( 1 ) ,
118
26
filetype = FILETYPE_BY_EXTENSION [ unquoted ( extension ) ] ;
119
27
120
28
if ( ! filetype ) {
121
- return DEFAULT_FILETYPE ;
29
+ return constants . DEFAULT_FILETYPE ;
122
30
}
123
31
124
32
return filetype ;
125
33
}
126
34
127
35
function defaultExtension ( fileRef ) {
128
- var filetype = fileRef . lastKnownFileType && fileRef . lastKnownFileType != DEFAULT_FILETYPE ?
36
+ var filetype = fileRef . lastKnownFileType && fileRef . lastKnownFileType != constants . DEFAULT_FILETYPE ?
129
37
fileRef . lastKnownFileType : fileRef . explicitFileType ;
130
38
131
39
for ( var extension in FILETYPE_BY_EXTENSION ) {
@@ -138,7 +46,7 @@ function defaultExtension(fileRef) {
138
46
139
47
function defaultEncoding ( fileRef ) {
140
48
var filetype = fileRef . lastKnownFileType || fileRef . explicitFileType ,
141
- encoding = ENCODING_BY_FILETYPE [ unquoted ( filetype ) ] ;
49
+ encoding = constants . ENCODING_BY_FILETYPE [ unquoted ( filetype ) ] ;
142
50
143
51
if ( encoding ) {
144
52
return encoding ;
@@ -148,18 +56,18 @@ function defaultEncoding(fileRef) {
148
56
function detectGroup ( fileRef , opt ) {
149
57
var extension = path . extname ( fileRef . basename ) . substring ( 1 ) ,
150
58
filetype = fileRef . lastKnownFileType || fileRef . explicitFileType ,
151
- groupName = GROUP_BY_FILETYPE [ unquoted ( filetype ) ] ;
59
+ groupName = constants . GROUP_BY_FILETYPE [ unquoted ( filetype ) ] ;
152
60
153
61
if ( extension === 'xcdatamodeld' ) {
154
62
return 'Sources' ;
155
63
}
156
64
157
65
if ( opt . customFramework && opt . embed ) {
158
- return GROUP_BY_FILETYPE [ 'embedded.framework' ] ;
66
+ return constants . GROUP_BY_FILETYPE [ 'embedded.framework' ] ;
159
67
}
160
68
161
69
if ( ! groupName ) {
162
- return DEFAULT_GROUP ;
70
+ return constants . DEFAULT_GROUP ;
163
71
}
164
72
165
73
return groupName ;
@@ -168,26 +76,26 @@ function detectGroup(fileRef, opt) {
168
76
function detectSourcetree ( fileRef ) {
169
77
170
78
var filetype = fileRef . lastKnownFileType || fileRef . explicitFileType ,
171
- sourcetree = SOURCETREE_BY_FILETYPE [ unquoted ( filetype ) ] ;
79
+ sourcetree = constants . SOURCETREE_BY_FILETYPE [ unquoted ( filetype ) ] ;
172
80
173
81
if ( fileRef . explicitFileType ) {
174
- return DEFAULT_PRODUCT_SOURCETREE ;
82
+ return constants . DEFAULT_PRODUCT_SOURCETREE ;
175
83
}
176
84
177
85
if ( fileRef . customFramework ) {
178
- return DEFAULT_SOURCETREE ;
86
+ return constants . DEFAULT_SOURCETREE ;
179
87
}
180
88
181
89
if ( ! sourcetree ) {
182
- return DEFAULT_SOURCETREE ;
90
+ return constants . DEFAULT_SOURCETREE ;
183
91
}
184
92
185
93
return sourcetree ;
186
94
}
187
95
188
96
function defaultPath ( fileRef , filePath ) {
189
97
var filetype = fileRef . lastKnownFileType || fileRef . explicitFileType ,
190
- defaultPath = PATH_BY_FILETYPE [ unquoted ( filetype ) ] ;
98
+ defaultPath = constants . PATH_BY_FILETYPE [ unquoted ( filetype ) ] ;
191
99
192
100
if ( fileRef . customFramework ) {
193
101
return filePath ;
@@ -200,18 +108,8 @@ function defaultPath(fileRef, filePath) {
200
108
return filePath ;
201
109
}
202
110
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
-
213
111
function pbxFile ( filepath , opt ) {
214
- var opt = opt || { } ;
112
+ opt = opt || { } ;
215
113
216
114
this . basename = opt . basename || path . basename ( filepath ) ;
217
115
this . lastKnownFileType = opt . lastKnownFileType || detectType ( filepath ) ;
@@ -257,8 +155,4 @@ function pbxFile(filepath, opt) {
257
155
}
258
156
}
259
157
260
- module . exports = {
261
- pbxFile : pbxFile ,
262
- isSourceOrHeaderFileType,
263
- isHeaderFileType
264
- }
158
+ module . exports = pbxFile ;
0 commit comments