Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit cd937af

Browse files
committedOct 31, 2012
[pbxProject] first pass at #hasFile method
1 parent ef21e54 commit cd937af

File tree

3 files changed

+42
-1
lines changed

3 files changed

+42
-1
lines changed
 

‎AUTHORS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ Anis Kadri (@imhotep)
33
Mike Reinstein (@mreinstein)
44
Filip Maj (@filmaj)
55
Brett Rudd (@goya)
6+
Bob Easterday (@bobeast)

‎lib/pbxProject.js

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,13 @@ pbxProject.prototype.addPluginFile = function (path, opt) {
8585
var file = new pbxFile(path, opt);
8686

8787
file.plugin = true; // durr
88-
8988
correctForPluginsPath(file, this);
89+
90+
// null is better for early errors
91+
if (this.hasFile(file.path)) {
92+
return null;
93+
}
94+
9095
file.fileRef = this.generateUuid();
9196

9297
this.addToPbxFileReferenceSection(file); // PBXFileReference
@@ -465,6 +470,22 @@ pbxProject.prototype.__defineGetter__("productName", function () {
465470
}
466471
});
467472

473+
// check if file is present
474+
pbxProject.prototype.hasFile = function (filePath) {
475+
var files = nonComments(this.pbxFileReferenceSection()),
476+
file, id;
477+
478+
for (id in files) {
479+
file = files[id];
480+
481+
if (file.path == filePath) {
482+
return true;
483+
}
484+
}
485+
486+
return false;
487+
}
488+
468489
// helper recursive prop search+replace
469490
function propReplace(obj, prop, value) {
470491
for (var p in obj) {

‎test/pbxProject.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,3 +164,22 @@ exports['productName field'] = {
164164
test.done();
165165
}
166166
}
167+
168+
exports['hasFile'] = {
169+
'should return true if the file is in the project': function (test) {
170+
var newProj = new pbx('.');
171+
newProj.hash = jsonProject;
172+
173+
// sourceTree: '"<group>"'
174+
test.ok(newProj.hasFile('AppDelegate.m'))
175+
test.done()
176+
},
177+
'should return false if the file is not in the project': function (test) {
178+
var newProj = new pbx('.');
179+
newProj.hash = jsonProject;
180+
181+
// sourceTree: '"<group>"'
182+
test.ok(!newProj.hasFile('NotTheAppDelegate.m'))
183+
test.done()
184+
}
185+
}

0 commit comments

Comments
 (0)
Please sign in to comment.