@@ -242,13 +242,20 @@ pbxProject.prototype.addResourceFile = function(path, opt, group) {
242242 file . fileRef = this . generateUuid ( ) ;
243243 }
244244
245- this . addToPbxBuildFileSection ( file ) ; // PBXBuildFile
246- this . addToPbxResourcesBuildPhase ( file ) ; // PBXResourcesBuildPhase
245+ if ( ! opt . variantGroup ) {
246+ this . addToPbxBuildFileSection ( file ) ; // PBXBuildFile
247+ this . addToPbxResourcesBuildPhase ( file ) ; // PBXResourcesBuildPhase
248+ }
247249
248250 if ( ! opt . plugin ) {
249251 this . addToPbxFileReferenceSection ( file ) ; // PBXFileReference
250252 if ( group ) {
251- this . addToPbxGroup ( file , group ) ; //Group other than Resources (i.e. 'splash')
253+ if ( this . getPBXGroupByKey ( group ) ) {
254+ this . addToPbxGroup ( file , group ) ; //Group other than Resources (i.e. 'splash')
255+ }
256+ else if ( this . getPBXVariantGroupByKey ( group ) ) {
257+ this . addToPbxVariantGroup ( file , group ) ; // PBXVariantGroup
258+ }
252259 }
253260 else {
254261 this . addToResourcesPbxGroup ( file ) ; // PBXGroup
@@ -275,7 +282,12 @@ pbxProject.prototype.removeResourceFile = function(path, opt, group) {
275282 this . removeFromPbxBuildFileSection ( file ) ; // PBXBuildFile
276283 this . removeFromPbxFileReferenceSection ( file ) ; // PBXFileReference
277284 if ( group ) {
278- this . removeFromPbxGroup ( file , group ) ; //Group other than Resources (i.e. 'splash')
285+ if ( this . getPBXGroupByKey ( group ) ) {
286+ this . removeFromPbxGroup ( file , group ) ; //Group other than Resources (i.e. 'splash')
287+ }
288+ else if ( this . getPBXVariantGroupByKey ( group ) ) {
289+ this . removeFromPbxVariantGroup ( file , group ) ; // PBXVariantGroup
290+ }
279291 }
280292 else {
281293 this . removeFromResourcesPbxGroup ( file ) ; // PBXGroup
@@ -1696,15 +1708,20 @@ pbxProject.prototype.getFirstTarget = function() {
16961708
16971709/*** NEW ***/
16981710
1699- pbxProject . prototype . addToPbxGroup = function ( file , groupKey ) {
1700- var group = this . getPBXGroupByKey ( groupKey ) ;
1711+ pbxProject . prototype . addToPbxGroupType = function ( file , groupKey , groupType ) {
1712+ var group = this . getPBXGroupByKeyAndType ( groupKey , groupType ) ;
17011713 if ( group && group . children !== undefined ) {
17021714 if ( typeof file === 'string' ) {
17031715 //Group Key
17041716 var childGroup = {
17051717 value :file ,
1706- comment : this . getPBXGroupByKey ( file ) . name
17071718 } ;
1719+ if ( this . getPBXGroupByKey ( file ) ) {
1720+ childGroup . comment = this . getPBXGroupByKey ( file ) . name ;
1721+ }
1722+ else if ( this . getPBXVariantGroupByKey ( file ) ) {
1723+ childGroup . comment = this . getPBXVariantGroupByKey ( file ) . name ;
1724+ }
17081725
17091726 group . children . push ( childGroup ) ;
17101727 }
@@ -1715,8 +1732,53 @@ pbxProject.prototype.addToPbxGroup = function (file, groupKey) {
17151732 }
17161733}
17171734
1718- pbxProject . prototype . removeFromPbxGroup = function ( file , groupKey ) {
1719- var group = this . getPBXGroupByKey ( groupKey ) ;
1735+ pbxProject . prototype . addToPbxVariantGroup = function ( file , groupKey ) {
1736+ this . addToPbxGroupType ( file , groupKey , 'PBXVariantGroup' ) ;
1737+ }
1738+
1739+ pbxProject . prototype . addToPbxGroup = function ( file , groupKey ) {
1740+ this . addToPbxGroupType ( file , groupKey , 'PBXGroup' ) ;
1741+ }
1742+
1743+
1744+
1745+ pbxProject . prototype . pbxCreateGroupWithType = function ( name , pathName , groupType ) {
1746+ //Create object
1747+ var model = {
1748+ isa : '"' + groupType + '"' ,
1749+ children : [ ] ,
1750+ name : name ,
1751+ sourceTree : '"<group>"'
1752+ } ;
1753+ if ( pathName ) model . path = pathName ;
1754+ var key = this . generateUuid ( ) ;
1755+
1756+ //Create comment
1757+ var commendId = key + '_comment' ;
1758+
1759+ //add obj and commentObj to groups;
1760+ var groups = this . hash . project . objects [ groupType ] ;
1761+ if ( ! groups ) {
1762+ groups = this . hash . project . objects [ groupType ] = new Object ( ) ;
1763+ }
1764+ groups [ commendId ] = name ;
1765+ groups [ key ] = model ;
1766+
1767+ return key ;
1768+ }
1769+
1770+ pbxProject . prototype . pbxCreateVariantGroup = function ( name ) {
1771+ return this . pbxCreateGroupWithType ( name , undefined , 'PBXVariantGroup' )
1772+ }
1773+
1774+ pbxProject . prototype . pbxCreateGroup = function ( name , pathName ) {
1775+ return this . pbxCreateGroupWithType ( name , pathName , 'PBXGroup' ) ;
1776+ }
1777+
1778+
1779+
1780+ pbxProject . prototype . removeFromPbxGroupAndType = function ( file , groupKey , groupType ) {
1781+ var group = this . getPBXGroupByKeyAndType ( groupKey , groupType ) ;
17201782 if ( group ) {
17211783 var groupChildren = group . children , i ;
17221784 for ( i in groupChildren ) {
@@ -1729,12 +1791,32 @@ pbxProject.prototype.removeFromPbxGroup = function (file, groupKey) {
17291791 }
17301792}
17311793
1794+ pbxProject . prototype . removeFromPbxGroup = function ( file , groupKey ) {
1795+ this . removeFromPbxGroupAndType ( file , groupKey , 'PBXGroup' ) ;
1796+ }
1797+
1798+ pbxProject . prototype . removeFromPbxVariantGroup = function ( file , groupKey ) {
1799+ this . removeFromPbxGroupAndType ( file , groupKey , 'PBXVariantGroup' ) ;
1800+ }
1801+
1802+
1803+
1804+ pbxProject . prototype . getPBXGroupByKeyAndType = function ( key , groupType ) {
1805+ return this . hash . project . objects [ groupType ] [ key ] ;
1806+ } ;
1807+
17321808pbxProject . prototype . getPBXGroupByKey = function ( key ) {
17331809 return this . hash . project . objects [ 'PBXGroup' ] [ key ] ;
17341810} ;
17351811
1736- pbxProject . prototype . findPBXGroupKey = function ( criteria ) {
1737- var groups = this . hash . project . objects [ 'PBXGroup' ] ;
1812+ pbxProject . prototype . getPBXVariantGroupByKey = function ( key ) {
1813+ return this . hash . project . objects [ 'PBXVariantGroup' ] [ key ] ;
1814+ } ;
1815+
1816+
1817+
1818+ pbxProject . prototype . findPBXGroupKeyAndType = function ( criteria , groupType ) {
1819+ var groups = this . hash . project . objects [ groupType ] ;
17381820 var target ;
17391821
17401822 for ( var key in groups ) {
@@ -1765,28 +1847,30 @@ pbxProject.prototype.findPBXGroupKey = function(criteria) {
17651847 return target ;
17661848}
17671849
1768- pbxProject . prototype . pbxCreateGroup = function ( name , pathName ) {
1850+ pbxProject . prototype . findPBXGroupKey = function ( criteria ) {
1851+ return this . findPBXGroupKeyAndType ( criteria , 'PBXGroup' ) ;
1852+ }
17691853
1770- //Create object
1771- var model = {
1772- isa :"PBXGroup" ,
1773- children : [ ] ,
1774- name : name ,
1775- path : pathName ,
1776- sourceTree : '"<group>"'
1777- } ;
1778- var key = this . generateUuid ( ) ;
1854+ pbxProject . prototype . findPBXVariantGroupKey = function ( criteria ) {
1855+ return this . findPBXGroupKeyAndType ( criteria , 'PBXVariantGroup' ) ;
1856+ }
17791857
1780- //Create comment
1781- var commendId = key + '_comment' ;
1858+ pbxProject . prototype . addLocalizationVariantGroup = function ( name ) {
1859+ var groupKey = this . pbxCreateVariantGroup ( name ) ;
17821860
1783- //add obj and commentObj to groups;
1784- var groups = this . hash . project . objects [ 'PBXGroup' ] ;
1785- groups [ commendId ] = name ;
1786- groups [ key ] = model ;
1861+ var resourceGroupKey = this . findPBXGroupKey ( { name : 'Resources' } ) ;
1862+ this . addToPbxGroup ( groupKey , resourceGroupKey ) ;
17871863
1788- return key ;
1789- }
1864+ var localizationVariantGroup = {
1865+ uuid : this . generateUuid ( ) ,
1866+ fileRef : groupKey ,
1867+ basename : name
1868+ }
1869+ this . addToPbxBuildFileSection ( localizationVariantGroup ) ; // PBXBuildFile
1870+ this . addToPbxResourcesBuildPhase ( localizationVariantGroup ) ; //PBXResourcesBuildPhase
1871+
1872+ return localizationVariantGroup ;
1873+ } ;
17901874
17911875
17921876pbxProject . prototype . getPBXObject = function ( name ) {
@@ -1804,7 +1888,13 @@ pbxProject.prototype.addFile = function (path, group, opt) {
18041888 file . fileRef = this . generateUuid ( ) ;
18051889
18061890 this . addToPbxFileReferenceSection ( file ) ; // PBXFileReference
1807- this . addToPbxGroup ( file , group ) ; // PBXGroup
1891+
1892+ if ( this . getPBXGroupByKey ( group ) ) {
1893+ this . addToPbxGroup ( file , group ) ; // PBXGroup
1894+ }
1895+ else if ( this . getPBXVariantGroupByKey ( group ) ) {
1896+ this . addToPbxVariantGroup ( file , group ) ; // PBXVariantGroup
1897+ }
18081898
18091899 return file ;
18101900}
@@ -1813,7 +1903,13 @@ pbxProject.prototype.removeFile = function (path, group, opt) {
18131903 var file = new pbxFile ( path , opt ) ;
18141904
18151905 this . removeFromPbxFileReferenceSection ( file ) ; // PBXFileReference
1816- this . removeFromPbxGroup ( file , group ) ; // PBXGroup
1906+
1907+ if ( this . getPBXGroupByKey ( group ) ) {
1908+ this . removeFromPbxGroup ( file , group ) ; // PBXGroup
1909+ }
1910+ else if ( this . getPBXVariantGroupByKey ( group ) ) {
1911+ this . removeFromPbxVariantGroup ( file , group ) ; // PBXVariantGroup
1912+ }
18171913
18181914 return file ;
18191915}
0 commit comments