Skip to content

Commit 5f2ccff

Browse files
author
Anis Kadri
committed
Merge branch 'mcgrews3-master'
2 parents dadf03c + 3131b93 commit 5f2ccff

File tree

3 files changed

+1140
-13
lines changed

3 files changed

+1140
-13
lines changed

lib/pbxProject.js

Lines changed: 245 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -132,9 +132,22 @@ pbxProject.prototype.removeProductFile = function(path, opt) {
132132
return file;
133133
}
134134

135-
pbxProject.prototype.addSourceFile = function(path, opt) {
135+
/**
136+
*
137+
* @param path {String}
138+
* @param opt {Object} see pbxFile for avail options
139+
* @param group {String} group key
140+
* @returns {Object} file; see pbxFile
141+
*/
142+
pbxProject.prototype.addSourceFile = function (path, opt, group) {
143+
var file;
144+
if (group) {
145+
file = this.addFile(path, group, opt);
146+
}
147+
else {
148+
file = this.addPluginFile(path, opt);
149+
}
136150

137-
var file = this.addPluginFile(path, opt);
138151
if (!file) return false;
139152

140153
file.target = opt ? opt.target : undefined;
@@ -146,22 +159,58 @@ pbxProject.prototype.addSourceFile = function(path, opt) {
146159
return file;
147160
}
148161

149-
150-
pbxProject.prototype.removeSourceFile = function(path, opt) {
151-
var file = this.removePluginFile(path, opt)
162+
/**
163+
*
164+
* @param path {String}
165+
* @param opt {Object} see pbxFile for avail options
166+
* @param group {String} group key
167+
* @returns {Object} file; see pbxFile
168+
*/
169+
pbxProject.prototype.removeSourceFile = function (path, opt, group) {
170+
var file;
171+
if (group) {
172+
file = this.removeFile(path, group, opt);
173+
}
174+
else {
175+
file = this.removePluginFile(path, opt);
176+
}
152177
file.target = opt ? opt.target : undefined;
153178
this.removeFromPbxBuildFileSection(file); // PBXBuildFile
154179
this.removeFromPbxSourcesBuildPhase(file); // PBXSourcesBuildPhase
155180

156181
return file;
157182
}
158183

159-
pbxProject.prototype.addHeaderFile = function(path, opt) {
160-
return this.addPluginFile(path, opt)
184+
/**
185+
*
186+
* @param path {String}
187+
* @param opt {Object} see pbxFile for avail options
188+
* @param group {String} group key
189+
* @returns {Object} file; see pbxFile
190+
*/
191+
pbxProject.prototype.addHeaderFile = function (path, opt, group) {
192+
if (group) {
193+
return this.addFile(path, group, opt);
194+
}
195+
else {
196+
return this.addPluginFile(path, opt);
197+
}
161198
}
162199

163-
pbxProject.prototype.removeHeaderFile = function(path, opt) {
164-
return this.removePluginFile(path, opt)
200+
/**
201+
*
202+
* @param path {String}
203+
* @param opt {Object} see pbxFile for avail options
204+
* @param group {String} group key
205+
* @returns {Object} file; see pbxFile
206+
*/
207+
pbxProject.prototype.removeHeaderFile = function (path, opt, group) {
208+
if (group) {
209+
return this.removeFile(path, group, opt);
210+
}
211+
else {
212+
return this.removePluginFile(path, opt);
213+
}
165214
}
166215

167216
pbxProject.prototype.addResourceFile = function(path, opt) {
@@ -746,7 +795,20 @@ pbxProject.prototype.pbxXCConfigurationList = function() {
746795
}
747796

748797
pbxProject.prototype.pbxGroupByName = function(name) {
749-
return this.pbxItemByComment(name, 'PBXGroup');
798+
var groups = this.hash.project.objects['PBXGroup'],
799+
key, groupKey;
800+
801+
for (key in groups) {
802+
// only look for comments
803+
if (!COMMENT_KEY.test(key)) continue;
804+
805+
if (groups[key] == name) {
806+
groupKey = key.split(COMMENT_KEY)[0];
807+
return groups[groupKey];
808+
}
809+
}
810+
811+
return null;
750812
}
751813

752814
pbxProject.prototype.pbxTargetByName = function(name) {
@@ -824,9 +886,22 @@ pbxProject.prototype.buildPhaseObject = function(name, group, target) {
824886
}
825887

826888

827-
pbxProject.prototype.updateBuildProperty = function(prop, value) {
828-
var config = this.pbxXCBuildConfigurationSection();
829-
propReplace(config, prop, value);
889+
/**
890+
*
891+
* @param prop {String}
892+
* @param value {String|Array|Object|Number|Boolean}
893+
* @param build {String} Release or Debug
894+
*/
895+
pbxProject.prototype.updateBuildProperty = function(prop, value, build) {
896+
var configs = this.pbxXCBuildConfigurationSection();
897+
for (var configName in configs) {
898+
if (!COMMENT_KEY.test(configName)) {
899+
var config = configs[configName];
900+
if ( (build && config.name === build) || (!build) ) {
901+
config.buildSettings[prop] = value;
902+
}
903+
}
904+
}
830905
}
831906

832907
pbxProject.prototype.updateProductName = function(name) {
@@ -1364,4 +1439,161 @@ pbxProject.prototype.getFirstTarget = function() {
13641439
}
13651440
}
13661441

1442+
/*** NEW ***/
1443+
1444+
pbxProject.prototype.addToPbxGroup = function (file, groupKey) {
1445+
var group = this.getPBXGroupByKey(groupKey);
1446+
if (group && group.children !== undefined) {
1447+
if (typeof file === 'string') {
1448+
//Group Key
1449+
var childGroup = {
1450+
value:file,
1451+
comment: this.getPBXGroupByKey(file).name
1452+
};
1453+
1454+
group.children.push(childGroup);
1455+
}
1456+
else {
1457+
//File Object
1458+
group.children.push(pbxGroupChild(file));
1459+
}
1460+
}
1461+
}
1462+
1463+
pbxProject.prototype.removeFromPbxGroup = function (file, groupKey) {
1464+
var group = this.getPBXGroupByKey(groupKey);
1465+
if (group) {
1466+
var groupChildren = group.children, i;
1467+
for(i in groupChildren) {
1468+
if(pbxGroupChild(file).value == groupChildren[i].value &&
1469+
pbxGroupChild(file).comment == groupChildren[i].comment) {
1470+
groupChildren.splice(i, 1);
1471+
break;
1472+
}
1473+
}
1474+
}
1475+
}
1476+
1477+
pbxProject.prototype.getPBXGroupByKey = function(key) {
1478+
return this.hash.project.objects['PBXGroup'][key];
1479+
};
1480+
1481+
pbxProject.prototype.findPBXGroupKey = function(criteria) {
1482+
var groups = this.hash.project.objects['PBXGroup'];
1483+
var target;
1484+
1485+
for (var key in groups) {
1486+
// only look for comments
1487+
if (COMMENT_KEY.test(key)) continue;
1488+
1489+
var group = groups[key];
1490+
if (criteria && criteria.path && criteria.name) {
1491+
if (criteria.path === group.path && criteria.name === group.name) {
1492+
target = key;
1493+
break
1494+
}
1495+
}
1496+
else if (criteria && criteria.path) {
1497+
if (criteria.path === group.path) {
1498+
target = key;
1499+
break
1500+
}
1501+
}
1502+
else if (criteria && criteria.name) {
1503+
if (criteria.name === group.name) {
1504+
target = key;
1505+
break
1506+
}
1507+
}
1508+
}
1509+
1510+
return target;
1511+
}
1512+
1513+
pbxProject.prototype.pbxCreateGroup = function(name, pathName) {
1514+
1515+
//Create object
1516+
var model = {
1517+
isa:"PBXGroup",
1518+
children: [],
1519+
name: name,
1520+
path: pathName,
1521+
sourceTree: '"<group>"'
1522+
};
1523+
var key = this.generateUuid();
1524+
1525+
//Create comment
1526+
var commendId = key + '_comment';
1527+
1528+
//add obj and commentObj to groups;
1529+
var groups = this.hash.project.objects['PBXGroup'];
1530+
groups[commendId] = name;
1531+
groups[key] = model;
1532+
1533+
return key;
1534+
}
1535+
1536+
1537+
pbxProject.prototype.getPBXObject = function(name) {
1538+
return this.hash.project.objects[name];
1539+
}
1540+
1541+
1542+
1543+
pbxProject.prototype.addFile = function (path, group, opt) {
1544+
var file = new pbxFile(path, opt);
1545+
1546+
// null is better for early errors
1547+
if (this.hasFile(file.path)) return null;
1548+
1549+
file.fileRef = this.generateUuid();
1550+
1551+
this.addToPbxFileReferenceSection(file); // PBXFileReference
1552+
this.addToPbxGroup(file, group); // PBXGroup
1553+
1554+
return file;
1555+
}
1556+
1557+
pbxProject.prototype.removeFile = function (path, group, opt) {
1558+
var file = new pbxFile(path, opt);
1559+
1560+
this.removeFromPbxFileReferenceSection(file); // PBXFileReference
1561+
this.removeFromPbxGroup(file, group); // PBXGroup
1562+
1563+
return file;
1564+
}
1565+
1566+
1567+
1568+
pbxProject.prototype.getBuildProperty = function(prop, build) {
1569+
var target;
1570+
var configs = this.pbxXCBuildConfigurationSection();
1571+
for (var configName in configs) {
1572+
if (!COMMENT_KEY.test(configName)) {
1573+
var config = configs[configName];
1574+
if ( (build && config.name === build) || (build === undefined) ) {
1575+
if (config.buildSettings[prop] !== undefined) {
1576+
target = config.buildSettings[prop];
1577+
}
1578+
}
1579+
}
1580+
}
1581+
return target;
1582+
}
1583+
1584+
pbxProject.prototype.getBuildConfigByName = function(name) {
1585+
var target = {};
1586+
var configs = this.pbxXCBuildConfigurationSection();
1587+
for (var configName in configs) {
1588+
if (!COMMENT_KEY.test(configName)) {
1589+
var config = configs[configName];
1590+
if (config.name === name) {
1591+
target[configName] = config;
1592+
}
1593+
}
1594+
}
1595+
return target;
1596+
}
1597+
1598+
13671599
module.exports = pbxProject;

0 commit comments

Comments
 (0)