Comparing version 0.3.0 to 0.3.1
@@ -6,2 +6,3 @@ var path = require('path'), | ||
XIB_EXTENSION = /[.]xib$/, XIB_FILE = 'file.xib', | ||
FRAMEWORK_EXTENSION = /[.]dylib$/, FRAMEWORK = '"compiled.mach-o.dylib"', | ||
DEFAULT_SOURCE_TREE = 'SOURCE_ROOT', | ||
@@ -23,2 +24,5 @@ DEFAULT_FILE_ENCODING = 4; | ||
if (FRAMEWORK_EXTENSION.test(path)) | ||
return FRAMEWORK; | ||
// dunno | ||
@@ -34,16 +38,38 @@ return 'unknown'; | ||
function defaultSourceTree(file) { | ||
if (file.lastType == FRAMEWORK) { | ||
return 'SDKROOT'; | ||
} else { | ||
return DEFAULT_SOURCE_TREE; | ||
} | ||
} | ||
function correctPath(file, filepath) { | ||
if (file.lastType == FRAMEWORK) { | ||
return 'usr/lib/' + filepath; | ||
} else { | ||
return filepath; | ||
} | ||
} | ||
function correctGroup(file) { | ||
if (file.lastType == SOURCE_FILE) { | ||
return 'Sources'; | ||
} else if (file.lastType == FRAMEWORK) { | ||
return 'Frameworks'; | ||
} else { | ||
return 'Resources'; | ||
} | ||
} | ||
function pbxFile(filepath, opt) { | ||
var opt = opt || {}; | ||
this.path = filepath; | ||
this.lastType = opt.lastType || detectLastType(filepath); | ||
this.path = correctPath(this, filepath); | ||
this.basename = path.basename(filepath); | ||
this.group = correctGroup(this); | ||
if (this.lastType == SOURCE_FILE) { | ||
this.group = 'Sources'; | ||
} else { | ||
this.group = 'Resources'; | ||
} | ||
this.sourceTree = opt.sourceTree || DEFAULT_SOURCE_TREE; | ||
this.sourceTree = opt.sourceTree || defaultSourceTree(this); | ||
this.fileEncoding = opt.fileEncoding || fileEncoding(this); | ||
@@ -50,0 +76,0 @@ } |
@@ -109,6 +109,16 @@ var util = require('util'), | ||
/* | ||
* PBXResourcesBuildPhase | ||
*/ | ||
return file; | ||
} | ||
pbxProject.prototype.addFramework = function (path, opt) { | ||
var file = new pbxFile(path, opt); | ||
file.uuid = this.generateUuid(); | ||
file.fileRef = this.generateUuid(); | ||
this.addToPbxBuildFileSection(file); // PBXBuildFile | ||
this.addToPbxFileReferenceSection(file); // PBXFileReference | ||
this.addToFrameworksPbxGroup(file); // PBXGroup | ||
this.addToPbxFrameworksBuildPhase(file); // PBXFrameworksBuildPhase | ||
return file; | ||
@@ -137,2 +147,7 @@ } | ||
pbxProject.prototype.addToFrameworksPbxGroup = function (file) { | ||
var pluginsGroup = this.pbxGroupByName('Frameworks'); | ||
pluginsGroup.children.push(pbxGroupChild(file)); | ||
} | ||
pbxProject.prototype.addToPbxSourcesBuildPhase = function (file) { | ||
@@ -148,2 +163,7 @@ var sources = this.pbxSourcesBuildPhaseObj(); | ||
pbxProject.prototype.addToPbxFrameworksBuildPhase = function (file) { | ||
var sources = this.pbxFrameworksBuildPhaseObj(); | ||
sources.files.push(pbxBuildPhaseObj(file)); | ||
} | ||
// helper access functions | ||
@@ -175,30 +195,17 @@ pbxProject.prototype.pbxBuildFileSection = function () { | ||
pbxProject.prototype.pbxSourcesBuildPhaseSection = function () { | ||
return this.hash.project.objects['PBXSourcesBuildPhase']; | ||
pbxProject.prototype.pbxSourcesBuildPhaseObj = function () { | ||
return this.buildPhaseObject('PBXSourcesBuildPhase', 'Sources'); | ||
} | ||
pbxProject.prototype.pbxSourcesBuildPhaseObj = function () { | ||
var section = this.pbxSourcesBuildPhaseSection(), | ||
obj, sectionKey; | ||
for (key in section) { | ||
// only look for comments | ||
if (!COMMENT_KEY.test(key)) continue; | ||
if (section[key] == 'Sources') { | ||
sectionKey = key.split(COMMENT_KEY)[0]; | ||
return section[sectionKey]; | ||
} | ||
} | ||
return null; | ||
pbxProject.prototype.pbxResourcesBuildPhaseObj = function () { | ||
return this.buildPhaseObject('PBXResourcesBuildPhase', 'Resources'); | ||
} | ||
pbxProject.prototype.pbxResourcesBuildPhaseSection = function () { | ||
return this.hash.project.objects['PBXResourcesBuildPhase']; | ||
pbxProject.prototype.pbxFrameworksBuildPhaseObj = function () { | ||
return this.buildPhaseObject('PBXResourcesBuildPhase', 'Resources'); | ||
} | ||
pbxProject.prototype.pbxResourcesBuildPhaseObj = function () { | ||
var section = this.pbxResourcesBuildPhaseSection(), | ||
obj, sectionKey; | ||
pbxProject.prototype.buildPhaseObject = function (name, group) { | ||
var section = this.hash.project.objects[name], | ||
obj, sectionKey, key; | ||
@@ -209,3 +216,3 @@ for (key in section) { | ||
if (section[key] == 'Resources') { | ||
if (section[key] == group) { | ||
sectionKey = key.split(COMMENT_KEY)[0]; | ||
@@ -212,0 +219,0 @@ return section[sectionKey]; |
@@ -5,3 +5,3 @@ { | ||
"description": "tools for working with xcode projects", | ||
"version": "0.3.0", | ||
"version": "0.3.1", | ||
"main":"index.js", | ||
@@ -8,0 +8,0 @@ "repository": { |
@@ -32,2 +32,9 @@ var pbxFile = require('../lib/pbxFile'); | ||
'should detect that a .dylib path means "compiled.mach-o.dylib"': function (test) { | ||
var sourceFile = new pbxFile('libsqlite3.dylib'); | ||
test.equal('"compiled.mach-o.dylib"', sourceFile.lastType); | ||
test.done(); | ||
}, | ||
'should allow lastType to be overridden': function (test) { | ||
@@ -56,2 +63,8 @@ var sourceFile = new pbxFile('Plugins/ChildBrowser.m', | ||
}, | ||
'should be Frameworks for frameworks': function (test) { | ||
var framework = new pbxFile('libsqlite3.dylib'); | ||
test.equal('Frameworks', framework.group); | ||
test.done(); | ||
}, | ||
'should be Resources for all other files': function (test) { | ||
@@ -75,1 +88,41 @@ var headerFile = new pbxFile('Plugins/ChildBrowser.h'), | ||
} | ||
exports['sourceTree'] = { | ||
'should be SDKROOT for frameworks': function (test) { | ||
var sourceFile = new pbxFile('libsqlite3.dylib'); | ||
test.equal('SDKROOT', sourceFile.sourceTree); | ||
test.done(); | ||
}, | ||
'should default to SOURCE_ROOT otherwise': function (test) { | ||
var sourceFile = new pbxFile('Plugins/ChildBrowser.m'); | ||
test.equal('SOURCE_ROOT', sourceFile.sourceTree); | ||
test.done(); | ||
}, | ||
'should be overridable either way': function (test) { | ||
var sourceFile = new pbxFile('Plugins/ChildBrowser.m', | ||
{ sourceTree: 'SOMETHING'}); | ||
test.equal('SOMETHING', sourceFile.sourceTree); | ||
test.done(); | ||
} | ||
} | ||
exports['path'] = { | ||
'should be "usr/lib" for frameworks (relative to SDKROOT)': function (test) { | ||
var sourceFile = new pbxFile('libsqlite3.dylib'); | ||
test.equal('usr/lib/libsqlite3.dylib', sourceFile.path); | ||
test.done(); | ||
}, | ||
'should default to the first argument otherwise': function (test) { | ||
var sourceFile = new pbxFile('Plugins/ChildBrowser.m'); | ||
test.equal('Plugins/ChildBrowser.m', sourceFile.path); | ||
test.done(); | ||
} | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
205945
37
3732