Skip to content

Commit 111392a

Browse files
committed
[project] accessor for productName
javascript getter. HM!
1 parent aeb25d7 commit 111392a

File tree

2 files changed

+43
-1
lines changed

2 files changed

+43
-1
lines changed

lib/pbxProject.js

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,21 @@ pbxProject.prototype.buildPhaseObject = function (name, group) {
403403
pbxProject.prototype.updateProductName = function(name) {
404404
var config = this.pbxXCBuildConfigurationSection();
405405
propReplace(config, 'PRODUCT_NAME', '"' + name + '"');
406-
};
406+
}
407+
408+
// a JS getter. hmmm
409+
pbxProject.prototype.__defineGetter__("productName", function () {
410+
var configurations = nonComments(this.pbxXCBuildConfigurationSection()),
411+
config, productName;
412+
413+
for (config in configurations) {
414+
productName = configurations[config].buildSettings['PRODUCT_NAME'];
415+
416+
if (productName) {
417+
return stripSurroundingQuotes(productName);
418+
}
419+
}
420+
});
407421

408422
// helper recursive prop search+replace
409423
function propReplace(obj, prop, value) {
@@ -493,4 +507,21 @@ function correctForResourcesPath(file, project) {
493507
return file;
494508
}
495509

510+
function nonComments(obj) {
511+
var keys = Object.keys(obj),
512+
newObj = {}, i = 0;
513+
514+
for (i; i < keys.length; i++) {
515+
if (!COMMENT_KEY.test(keys[i])) {
516+
newObj[keys[i]] = obj[keys[i]];
517+
}
518+
}
519+
520+
return newObj;
521+
}
522+
523+
function stripSurroundingQuotes(str) {
524+
return str.replace(/^"(.*)"$/, "$1");
525+
}
526+
496527
module.exports = pbxProject;

test/pbxProject.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
var pbx = require('../lib/pbxProject'),
22
buildConfig = require('./fixtures/buildFiles'),
3+
jsonProject = require('./fixtures/full-project'),
34
fs = require('fs'),
45
project;
56

@@ -153,3 +154,13 @@ exports['updateProductName function'] = {
153154
});
154155
}
155156
}
157+
158+
exports['productName field'] = {
159+
'should return the product name': function (test) {
160+
var newProj = new pbx('.');
161+
newProj.hash = jsonProject;
162+
163+
test.equal(newProj.productName, 'KitchenSinktablet');
164+
test.done();
165+
}
166+
}

0 commit comments

Comments
 (0)