1717 under the License.
1818*/
1919
20- var path = require ( 'path' ) ,
21- util = require ( 'util' ) ;
22-
23- var DEFAULT_SOURCETREE = '"<group>"' ,
24- DEFAULT_PRODUCT_SOURCETREE = 'BUILT_PRODUCTS_DIR' ,
25- DEFAULT_FILEENCODING = 4 ,
26- DEFAULT_GROUP = 'Resources' ,
27- DEFAULT_FILETYPE = 'unknown' ;
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- dylib : 'compiled.mach-o.dylib' ,
35- framework : 'wrapper.framework' ,
36- h : 'sourcecode.c.h' ,
37- m : 'sourcecode.c.objc' ,
38- markdown : 'text' ,
39- mdimporter : 'wrapper.cfbundle' ,
40- octest : 'wrapper.cfbundle' ,
41- pch : 'sourcecode.c.h' ,
42- plist : 'text.plist.xml' ,
43- sh : 'text.script.sh' ,
44- swift : 'sourcecode.swift' ,
45- tbd : 'sourcecode.text-based-dylib-definition' ,
46- xcassets : 'folder.assetcatalog' ,
47- xcconfig : 'text.xcconfig' ,
48- xcdatamodel : 'wrapper.xcdatamodel' ,
49- xcodeproj : 'wrapper.pb-project' ,
50- xctest : 'wrapper.cfbundle' ,
51- xib : 'file.xib' ,
52- strings : 'text.plist.strings'
53- } ,
54- GROUP_BY_FILETYPE = {
55- 'archive.ar' : 'Frameworks' ,
56- 'compiled.mach-o.dylib' : 'Frameworks' ,
57- 'sourcecode.text-based-dylib-definition' : 'Frameworks' ,
58- 'wrapper.framework' : 'Frameworks' ,
59- 'embedded.framework' : 'Embed Frameworks' ,
60- 'sourcecode.c.h' : 'Resources' ,
61- 'sourcecode.c.objc' : 'Sources' ,
62- 'sourcecode.swift' : 'Sources'
63- } ,
64- PATH_BY_FILETYPE = {
65- 'compiled.mach-o.dylib' : 'usr/lib/' ,
66- 'sourcecode.text-based-dylib-definition' : 'usr/lib/' ,
67- 'wrapper.framework' : 'System/Library/Frameworks/'
68- } ,
69- SOURCETREE_BY_FILETYPE = {
70- 'compiled.mach-o.dylib' : 'SDKROOT' ,
71- 'sourcecode.text-based-dylib-definition' : 'SDKROOT' ,
72- 'wrapper.framework' : 'SDKROOT'
73- } ,
74- ENCODING_BY_FILETYPE = {
75- 'sourcecode.c.h' : 4 ,
76- 'sourcecode.c.h' : 4 ,
77- 'sourcecode.c.objc' : 4 ,
78- 'sourcecode.swift' : 4 ,
79- 'text' : 4 ,
80- 'text.plist.xml' : 4 ,
81- 'text.script.sh' : 4 ,
82- 'text.xcconfig' : 4 ,
83- 'text.plist.strings' : 4
84- } ;
85-
86-
87- function unquoted ( text ) {
88- return text == null ? '' : text . replace ( / ( ^ " ) | ( " $ ) / g, '' )
20+ const path = require ( 'path' ) ;
21+ const util = require ( 'util' ) ;
22+
23+ const DEFAULT_SOURCETREE = '"<group>"' ;
24+ const DEFAULT_PRODUCT_SOURCETREE = 'BUILT_PRODUCTS_DIR' ;
25+ const DEFAULT_GROUP = 'Resources' ;
26+ const DEFAULT_FILETYPE = 'unknown' ;
27+
28+ const FILETYPE_BY_EXTENSION = {
29+ a : 'archive.ar' ,
30+ app : 'wrapper.application' ,
31+ appex : 'wrapper.app-extension' ,
32+ bundle : 'wrapper.plug-in' ,
33+ dylib : 'compiled.mach-o.dylib' ,
34+ framework : 'wrapper.framework' ,
35+ h : 'sourcecode.c.h' ,
36+ m : 'sourcecode.c.objc' ,
37+ markdown : 'text' ,
38+ mdimporter : 'wrapper.cfbundle' ,
39+ octest : 'wrapper.cfbundle' ,
40+ pch : 'sourcecode.c.h' ,
41+ plist : 'text.plist.xml' ,
42+ sh : 'text.script.sh' ,
43+ swift : 'sourcecode.swift' ,
44+ tbd : 'sourcecode.text-based-dylib-definition' ,
45+ xcassets : 'folder.assetcatalog' ,
46+ xcconfig : 'text.xcconfig' ,
47+ xcdatamodel : 'wrapper.xcdatamodel' ,
48+ xcodeproj : 'wrapper.pb-project' ,
49+ xctest : 'wrapper.cfbundle' ,
50+ xib : 'file.xib' ,
51+ strings : 'text.plist.strings'
52+ } ;
53+ const GROUP_BY_FILETYPE = {
54+ 'archive.ar' : 'Frameworks' ,
55+ 'compiled.mach-o.dylib' : 'Frameworks' ,
56+ 'sourcecode.text-based-dylib-definition' : 'Frameworks' ,
57+ 'wrapper.framework' : 'Frameworks' ,
58+ 'embedded.framework' : 'Embed Frameworks' ,
59+ 'sourcecode.c.h' : 'Resources' ,
60+ 'sourcecode.c.objc' : 'Sources' ,
61+ 'sourcecode.swift' : 'Sources'
62+ } ;
63+ const PATH_BY_FILETYPE = {
64+ 'compiled.mach-o.dylib' : 'usr/lib/' ,
65+ 'sourcecode.text-based-dylib-definition' : 'usr/lib/' ,
66+ 'wrapper.framework' : 'System/Library/Frameworks/'
67+ } ;
68+ const SOURCETREE_BY_FILETYPE = {
69+ 'compiled.mach-o.dylib' : 'SDKROOT' ,
70+ 'sourcecode.text-based-dylib-definition' : 'SDKROOT' ,
71+ 'wrapper.framework' : 'SDKROOT'
72+ } ;
73+ const ENCODING_BY_FILETYPE = {
74+ 'sourcecode.c.h' : 4 ,
75+ 'sourcecode.c.objc' : 4 ,
76+ 'sourcecode.swift' : 4 ,
77+ text : 4 ,
78+ 'text.plist.xml' : 4 ,
79+ 'text.script.sh' : 4 ,
80+ 'text.xcconfig' : 4 ,
81+ 'text.plist.strings' : 4
82+ } ;
83+
84+ function unquoted ( text ) {
85+ return text == null ? '' : text . replace ( / ( ^ " ) | ( " $ ) / g, '' ) ;
8986}
9087
91- function detectType ( filePath ) {
92- var extension = path . extname ( filePath ) . substring ( 1 ) ,
93- filetype = FILETYPE_BY_EXTENSION [ unquoted ( extension ) ] ;
88+ function detectType ( filePath ) {
89+ const extension = path . extname ( filePath ) . substring ( 1 ) ;
90+ const filetype = FILETYPE_BY_EXTENSION [ unquoted ( extension ) ] ;
9491
9592 if ( ! filetype ) {
9693 return DEFAULT_FILETYPE ;
@@ -99,31 +96,31 @@ function detectType(filePath) {
9996 return filetype ;
10097}
10198
102- function defaultExtension ( fileRef ) {
103- var filetype = fileRef . lastKnownFileType && fileRef . lastKnownFileType != DEFAULT_FILETYPE ?
104- fileRef . lastKnownFileType : fileRef . explicitFileType ;
99+ function defaultExtension ( fileRef ) {
100+ const filetype = fileRef . lastKnownFileType && fileRef . lastKnownFileType !== DEFAULT_FILETYPE
101+ ? fileRef . lastKnownFileType
102+ : fileRef . explicitFileType ;
105103
106- for ( var extension in FILETYPE_BY_EXTENSION ) {
107- if ( FILETYPE_BY_EXTENSION . hasOwnProperty ( unquoted ( extension ) ) ) {
108- if ( FILETYPE_BY_EXTENSION [ unquoted ( extension ) ] === unquoted ( filetype ) )
109- return extension ;
104+ for ( const extension in FILETYPE_BY_EXTENSION ) {
105+ if ( Object . prototype . hasOwnProperty . call ( FILETYPE_BY_EXTENSION , unquoted ( extension ) ) ) {
106+ if ( FILETYPE_BY_EXTENSION [ unquoted ( extension ) ] === unquoted ( filetype ) ) { return extension ; }
110107 }
111108 }
112109}
113110
114- function defaultEncoding ( fileRef ) {
115- var filetype = fileRef . lastKnownFileType || fileRef . explicitFileType ,
116- encoding = ENCODING_BY_FILETYPE [ unquoted ( filetype ) ] ;
111+ function defaultEncoding ( fileRef ) {
112+ const filetype = fileRef . lastKnownFileType || fileRef . explicitFileType ;
113+ const encoding = ENCODING_BY_FILETYPE [ unquoted ( filetype ) ] ;
117114
118115 if ( encoding ) {
119116 return encoding ;
120117 }
121118}
122119
123- function detectGroup ( fileRef , opt ) {
124- var extension = path . extname ( fileRef . basename ) . substring ( 1 ) ,
125- filetype = fileRef . lastKnownFileType || fileRef . explicitFileType ,
126- groupName = GROUP_BY_FILETYPE [ unquoted ( filetype ) ] ;
120+ function detectGroup ( fileRef , opt ) {
121+ const extension = path . extname ( fileRef . basename ) . substring ( 1 ) ;
122+ const filetype = fileRef . lastKnownFileType || fileRef . explicitFileType ;
123+ const groupName = GROUP_BY_FILETYPE [ unquoted ( filetype ) ] ;
127124
128125 if ( extension === 'xcdatamodeld' ) {
129126 return 'Sources' ;
@@ -140,10 +137,9 @@ function detectGroup(fileRef, opt) {
140137 return groupName ;
141138}
142139
143- function detectSourcetree ( fileRef ) {
144-
145- var filetype = fileRef . lastKnownFileType || fileRef . explicitFileType ,
146- sourcetree = SOURCETREE_BY_FILETYPE [ unquoted ( filetype ) ] ;
140+ function detectSourcetree ( fileRef ) {
141+ const filetype = fileRef . lastKnownFileType || fileRef . explicitFileType ;
142+ const sourcetree = SOURCETREE_BY_FILETYPE [ unquoted ( filetype ) ] ;
147143
148144 if ( fileRef . explicitFileType ) {
149145 return DEFAULT_PRODUCT_SOURCETREE ;
@@ -160,9 +156,9 @@ function detectSourcetree(fileRef) {
160156 return sourcetree ;
161157}
162158
163- function defaultPath ( fileRef , filePath ) {
164- var filetype = fileRef . lastKnownFileType || fileRef . explicitFileType ,
165- defaultPath = PATH_BY_FILETYPE [ unquoted ( filetype ) ] ;
159+ function defaultPath ( fileRef , filePath ) {
160+ const filetype = fileRef . lastKnownFileType || fileRef . explicitFileType ;
161+ const defaultPath = PATH_BY_FILETYPE [ unquoted ( filetype ) ] ;
166162
167163 if ( fileRef . customFramework ) {
168164 return filePath ;
@@ -175,25 +171,15 @@ function defaultPath(fileRef, filePath) {
175171 return filePath ;
176172}
177173
178- function defaultGroup ( fileRef ) {
179- var groupName = GROUP_BY_FILETYPE [ fileRef . lastKnownFileType ] ;
180-
181- if ( ! groupName ) {
182- return DEFAULT_GROUP ;
183- }
184-
185- return defaultGroup ;
186- }
187-
188- function pbxFile ( filepath , opt ) {
189- var opt = opt || { } ;
174+ function pbxFile ( filepath , opt ) {
175+ opt = opt || { } ;
190176
191177 this . basename = path . basename ( filepath ) ;
192178 this . lastKnownFileType = opt . lastKnownFileType || detectType ( filepath ) ;
193179 this . group = detectGroup ( this , opt ) ;
194180
195181 // for custom frameworks
196- if ( opt . customFramework == true ) {
182+ if ( opt . customFramework === true ) {
197183 this . customFramework = true ;
198184 this . dirname = path . dirname ( filepath ) . replace ( / \\ / g, '/' ) ;
199185 }
@@ -214,21 +200,17 @@ function pbxFile(filepath, opt) {
214200 this . sourceTree = opt . sourceTree || detectSourcetree ( this ) ;
215201 this . includeInIndex = 0 ;
216202
217- if ( opt . weak && opt . weak === true )
218- this . settings = { ATTRIBUTES : [ 'Weak' ] } ;
203+ if ( opt . weak && opt . weak === true ) { this . settings = { ATTRIBUTES : [ 'Weak' ] } ; }
219204
220205 if ( opt . compilerFlags ) {
221- if ( ! this . settings )
222- this . settings = { } ;
206+ if ( ! this . settings ) { this . settings = { } ; }
223207 this . settings . COMPILER_FLAGS = util . format ( '"%s"' , opt . compilerFlags ) ;
224208 }
225209
226210 if ( opt . embed && opt . sign ) {
227- if ( ! this . settings )
228- this . settings = { } ;
229- if ( ! this . settings . ATTRIBUTES )
230- this . settings . ATTRIBUTES = [ ] ;
231- this . settings . ATTRIBUTES . push ( 'CodeSignOnCopy' ) ;
211+ if ( ! this . settings ) { this . settings = { } ; }
212+ if ( ! this . settings . ATTRIBUTES ) { this . settings . ATTRIBUTES = [ ] ; }
213+ this . settings . ATTRIBUTES . push ( 'CodeSignOnCopy' ) ;
232214 }
233215}
234216
0 commit comments