1
1
var util = require ( 'util' ) ,
2
2
f = util . format ,
3
3
EventEmitter = require ( 'events' ) . EventEmitter ,
4
- path = require ( 'path' ) ,
4
+ $ path = require ( 'path' ) ,
5
5
uuid = require ( 'node-uuid' ) ,
6
6
fork = require ( 'child_process' ) . fork ,
7
7
pbxWriter = require ( './pbxWriter' ) ,
@@ -16,7 +16,7 @@ function pbxProject(filename) {
16
16
if ( ! ( this instanceof pbxProject ) )
17
17
return new pbxProject ( filename ) ;
18
18
19
- this . filepath = path . resolve ( filename )
19
+ this . filepath = $ path. resolve ( filename )
20
20
}
21
21
22
22
util . inherits ( pbxProject , EventEmitter )
@@ -302,9 +302,9 @@ pbxProject.prototype.findMainPbxGroup = function () {
302
302
return null ;
303
303
}
304
304
305
- pbxProject . prototype . addPbxGroup = function ( filePathsArray , name , path , sourceTree ) {
305
+ pbxProject . prototype . addPbxGroup = function ( filePathsArray , name , path , sourceTree , opt ) {
306
306
var groups = this . hash . project . objects [ 'PBXGroup' ] ,
307
- pbxGroupUuid = this . generateUuid ( ) ,
307
+ pbxGroupUuid = opt . uuid ? opt . uuid : this . generateUuid ( ) ,
308
308
commentKey = f ( "%s_comment" , pbxGroupUuid ) ,
309
309
pbxGroup = {
310
310
isa : 'PBXGroup' ,
@@ -338,7 +338,15 @@ pbxProject.prototype.addPbxGroup = function (filePathsArray, name, path, sourceT
338
338
}
339
339
340
340
var file = new pbxFile ( filePath ) ;
341
- if ( file . lastType == pbxFileTypes ( ) . SOURCE_FILE || file . lastType == pbxFileTypes ( ) . HEADER_FILE || fs . lstatSync ( file . path ) . isDirectory ( ) ) {
341
+ if ( fs . lstatSync ( filePath ) . isDirectory ( ) ) {
342
+ file . uuid = this . generateUuid ( ) ;
343
+ file . fileRef = this . generateUuid ( ) ;
344
+ this . addToPbxFileReferenceSection ( file ) ; // PBXFileReference
345
+ this . addToPbxBuildFileSection ( file ) ;
346
+ pbxGroup . children . push ( pbxGroupChild ( file ) ) ;
347
+ var files = fs . readdirSync ( filePath ) . map ( p => $path . join ( filePath , p ) ) ;
348
+ this . addPbxGroup ( files , $path . basename ( filePath ) , filePath , null , { uuid : file . uuid } ) ;
349
+ } else if ( file . lastType == pbxFileTypes ( ) . SOURCE_FILE || file . lastType == pbxFileTypes ( ) . HEADER_FILE ) {
342
350
file . uuid = this . generateUuid ( ) ;
343
351
file . fileRef = this . generateUuid ( ) ;
344
352
this . addToPbxFileReferenceSection ( file ) ; // PBXFileReference
@@ -356,11 +364,13 @@ pbxProject.prototype.addPbxGroup = function (filePathsArray, name, path, sourceT
356
364
groups [ commentKey ] = name ;
357
365
}
358
366
359
- let mainGroup = this . findMainPbxGroup ( ) ;
360
- if ( mainGroup ) {
361
- var file = new pbxFile ( pbxGroup . path ) ;
362
- file . fileRef = pbxGroupUuid ;
363
- mainGroup . children . push ( pbxGroupChild ( file ) ) ;
367
+ if ( opt . isMain ) {
368
+ let mainGroup = this . findMainPbxGroup ( ) ;
369
+ if ( mainGroup ) {
370
+ var file = new pbxFile ( pbxGroup . path ) ;
371
+ file . fileRef = pbxGroupUuid ;
372
+ mainGroup . children . push ( pbxGroupChild ( file ) ) ;
373
+ }
364
374
}
365
375
366
376
return { uuid : pbxGroupUuid , pbxGroup : pbxGroup } ;
@@ -1077,7 +1087,7 @@ function searchPathForFile(file, proj) {
1077
1087
1078
1088
var plugins = proj . pbxGroupByName ( 'Plugins' ) ,
1079
1089
pluginsPath = plugins ? plugins . path : null ,
1080
- fileDir = path . dirname ( file . path ) ;
1090
+ fileDir = $ path. dirname ( file . path ) ;
1081
1091
1082
1092
if ( fileDir == '.' ) {
1083
1093
fileDir = '' ;
0 commit comments