Skip to content

Commit c78d781

Browse files
SergeySergey
authored andcommitted
pbxProject addTargetAttribute
1 parent 4cca2f6 commit c78d781

File tree

2 files changed

+27
-8
lines changed

2 files changed

+27
-8
lines changed

lib/pbxProject.js

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ pbxProject.prototype.addResourceFile = function(path, opt, group) {
230230
file = this.addPluginFile(path, opt);
231231
if (!file) return false;
232232
} else {
233-
file = new pbxFile(path, opt);
233+
file = new pbxFile(path, opt);
234234
if (this.hasFile(file.path)) return false;
235235
}
236236

@@ -241,10 +241,10 @@ pbxProject.prototype.addResourceFile = function(path, opt, group) {
241241
correctForResourcesPath(file, this);
242242
file.fileRef = this.generateUuid();
243243
}
244-
244+
245245
this.addToPbxBuildFileSection(file); // PBXBuildFile
246246
this.addToPbxResourcesBuildPhase(file); // PBXResourcesBuildPhase
247-
247+
248248
if (!opt.plugin) {
249249
this.addToPbxFileReferenceSection(file); // PBXFileReference
250250
if (group) {
@@ -253,9 +253,9 @@ pbxProject.prototype.addResourceFile = function(path, opt, group) {
253253
else {
254254
this.addToResourcesPbxGroup(file); // PBXGroup
255255
}
256-
256+
257257
}
258-
258+
259259
return file;
260260
}
261261

@@ -279,7 +279,7 @@ pbxProject.prototype.removeResourceFile = function(path, opt, group) {
279279
}
280280
else {
281281
this.removeFromResourcesPbxGroup(file); // PBXGroup
282-
}
282+
}
283283
this.removeFromPbxResourcesBuildPhase(file); // PBXResourcesBuildPhase
284284

285285
return file;
@@ -1906,5 +1906,16 @@ pbxProject.prototype.addDataModelDocument = function(filePath, group, opt) {
19061906
return file;
19071907
}
19081908

1909+
pbxProject.prototype.addTargetAttribute = function(prop, value, target) {
1910+
var attributes = this.getFirstProject()['firstProject']['attributes'];
1911+
if (attributes['TargetAttributes'] === undefined) {
1912+
attributes['TargetAttributes'] = {};
1913+
}
1914+
target = target || this.getFirstTarget();
1915+
if (attributes['TargetAttributes'][target.uuid] === undefined) {
1916+
attributes['TargetAttributes'][target.uuid] = {};
1917+
}
1918+
attributes['TargetAttributes'][target.uuid][prop] = value;
1919+
}
19091920

19101921
module.exports = pbxProject;

test/group.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ exports.removeHeaderFileFromGroup = {
215215

216216
exports.addResourceFileToGroup = {
217217
'should add resource file (PNG) to the splash group' : function(test) {
218-
218+
219219
var testKey = project.findPBXGroupKey({path:'splash'});
220220
var file = project.addResourceFile('DefaultTest-667h.png', {}, testKey);
221221

@@ -311,7 +311,6 @@ exports.validateHasFile = {
311311
}
312312

313313
exports.testWritingPBXProject = {
314-
315314
'should successfully write to PBXProject TargetAttributes': function(test) {
316315
var pbxProjectObj = project.getPBXObject('PBXProject');
317316
var pbxProject;
@@ -345,6 +344,15 @@ exports.testWritingPBXProject = {
345344

346345
var output = project.writeSync();
347346

347+
test.done();
348+
},
349+
'should successfully add target attribute to PBXProject TargetAttributes': function(test) {
350+
console.log(project.addTargetAttribute);
351+
project.addTargetAttribute('ProvisioningStyle', 'Manual');
352+
353+
var output = project.writeSync();
354+
console.log(output);
355+
test.equal(output.match(/ProvisioningStyle\s*=\s*Manual/g).length, 1);
348356
test.done();
349357
}
350358
}

0 commit comments

Comments
 (0)