@@ -5,7 +5,8 @@ var util = require('util'),
5
5
uuid = require ( 'node-uuid' ) ,
6
6
fork = require ( 'child_process' ) . fork ,
7
7
pbxWriter = require ( './pbxWriter' ) ,
8
- pbxFile = require ( './pbxFile' ) ,
8
+ pbxFile = require ( './pbxFile' ) . pbxFile ,
9
+ pbxFileTypes = require ( './pbxFile' ) . fileTypes ,
9
10
fs = require ( 'fs' ) ,
10
11
parser = require ( './parser/pbxproj' ) ,
11
12
COMMENT_KEY = / _ c o m m e n t $ / ,
@@ -286,6 +287,21 @@ pbxProject.prototype.removeFromPbxBuildFileSection = function (file) {
286
287
}
287
288
}
288
289
290
+ pbxProject . prototype . findMainPbxGroup = function ( ) {
291
+ var groups = this . hash . project . objects [ 'PBXGroup' ] ;
292
+ var candidates = [ ] ;
293
+ for ( var key in groups ) {
294
+ if ( groups [ key ] . path == undefined && groups [ key ] . name == undefined && groups [ key ] . isa ) {
295
+ candidates . push ( groups [ key ] ) ;
296
+ }
297
+ }
298
+ if ( candidates . length == 1 ) {
299
+ return candidates [ 0 ] ;
300
+ }
301
+
302
+ return null ;
303
+ }
304
+
289
305
pbxProject . prototype . addPbxGroup = function ( filePathsArray , name , path , sourceTree ) {
290
306
var groups = this . hash . project . objects [ 'PBXGroup' ] ,
291
307
pbxGroupUuid = this . generateUuid ( ) ,
@@ -320,20 +336,39 @@ pbxProject.prototype.addPbxGroup = function (filePathsArray, name, path, sourceT
320
336
pbxGroup . children . push ( pbxGroupChild ( filePathToReference [ filePathQuoted ] ) ) ;
321
337
continue ;
322
338
}
323
-
339
+
324
340
var file = new pbxFile ( filePath ) ;
325
- file . uuid = this . generateUuid ( ) ;
326
- file . fileRef = this . generateUuid ( ) ;
327
- this . addToPbxFileReferenceSection ( file ) ; // PBXFileReference
328
- this . addToPbxBuildFileSection ( file ) ; // PBXBuildFile
329
- pbxGroup . children . push ( pbxGroupChild ( file ) ) ;
341
+ if ( file . lastType == pbxFileTypes ( ) . SOURCE_FILE || file . lastType == pbxFileTypes ( ) . HEADER_FILE || fs . lstatSync ( file . path ) . isDirectory ( ) ) {
342
+ file . uuid = this . generateUuid ( ) ;
343
+ file . fileRef = this . generateUuid ( ) ;
344
+ this . addToPbxFileReferenceSection ( file ) ; // PBXFileReference
345
+ this . addToPbxBuildFileSection ( file ) ; // PBXBuildFile
346
+ if ( file . lastType == pbxFileTypes ( ) . SOURCE_FILE ) {
347
+ this . addToPbxSourcesBuildPhase ( file ) ;
348
+ }
349
+ pbxGroup . children . push ( pbxGroupChild ( file ) ) ;
350
+ }
351
+
330
352
}
331
353
332
354
if ( groups ) {
333
355
groups [ pbxGroupUuid ] = pbxGroup ;
334
356
groups [ commentKey ] = name ;
335
357
}
336
-
358
+
359
+ let mainGroup = this . findMainPbxGroup ( ) ;
360
+ if ( mainGroup ) {
361
+ var file = new pbxFile ( pbxGroup . path ) ;
362
+ file . fileRef = pbxGroupUuid ;
363
+ // Following check is just for readability. 'file.basename' will be the comment for the child group in the main/meta PBXGroup.
364
+ //'basename' is set by pbxFile to path's basename. Because we search for 'src' folder in plugins for source code, without this check
365
+ // all root groups will have the same 'src' comment in the .pbxproject.x
366
+ if ( file . basename !== name ) {
367
+ file . basename = name ;
368
+ }
369
+ mainGroup . children . push ( pbxGroupChild ( file ) ) ;
370
+ }
371
+
337
372
return { uuid : pbxGroupUuid , pbxGroup : pbxGroup } ;
338
373
}
339
374
0 commit comments