Comparing version 0.6.2 to 0.6.3
@@ -39,3 +39,3 @@ var path = require('path'), | ||
function fileEncoding(file) { | ||
if (file.lastType != BUNDLE) { | ||
if (file.lastType != BUNDLE && !file.customFramework) { | ||
return DEFAULT_FILE_ENCODING; | ||
@@ -46,3 +46,3 @@ } | ||
function defaultSourceTree(file) { | ||
if (file.lastType == DYLIB || file.lastType == FRAMEWORK) { | ||
if (( file.lastType == DYLIB || file.lastType == FRAMEWORK ) && !file.customFramework) { | ||
return 'SDKROOT'; | ||
@@ -55,6 +55,8 @@ } else { | ||
function correctPath(file, filepath) { | ||
if (file.lastType == FRAMEWORK) { | ||
if (file.lastType == FRAMEWORK && !file.customFramework) { | ||
return 'System/Library/Frameworks/' + filepath; | ||
} else if (file.lastType == DYLIB) { | ||
return 'usr/lib/' + filepath; | ||
} else if (file.customFramework == true) { | ||
return file.basename; | ||
} else { | ||
@@ -68,3 +70,3 @@ return filepath; | ||
return 'Sources'; | ||
} else if (file.lastType == DYLIB || file.lastType == ARCHIVE) { | ||
} else if (file.lastType == DYLIB || file.lastType == ARCHIVE || file.lastType == FRAMEWORK) { | ||
return 'Frameworks'; | ||
@@ -81,4 +83,10 @@ } else { | ||
// for custom frameworks | ||
if(opt.customFramework == true) { | ||
this.customFramework = true; | ||
this.dirname = path.dirname(filepath); | ||
} | ||
this.basename = path.basename(filepath); | ||
this.path = correctPath(this, filepath); | ||
this.basename = path.basename(filepath); | ||
this.group = correctGroup(this); | ||
@@ -85,0 +93,0 @@ |
@@ -184,5 +184,4 @@ var util = require('util'), | ||
pbxProject.prototype.addFramework = function (path, opt) { | ||
var file = new pbxFile(path, opt); | ||
pbxProject.prototype.addFramework = function (fpath, opt) { | ||
var file = new pbxFile(fpath, opt); | ||
// catch duplicates | ||
@@ -198,2 +197,6 @@ if (this.hasFile(file.path)) return false; | ||
this.addToPbxFrameworksBuildPhase(file); // PBXFrameworksBuildPhase | ||
if(opt && opt.customFramework == true) { | ||
this.addToFrameworkSearchPaths(file); | ||
} | ||
@@ -203,4 +206,4 @@ return file; | ||
pbxProject.prototype.removeFramework = function (path, opt) { | ||
var file = new pbxFile(path, opt); | ||
pbxProject.prototype.removeFramework = function (fpath, opt) { | ||
var file = new pbxFile(fpath, opt); | ||
@@ -211,2 +214,6 @@ this.removeFromPbxBuildFileSection(file); // PBXBuildFile | ||
this.removeFromPbxFrameworksBuildPhase(file); // PBXFrameworksBuildPhase | ||
if(opt && opt.customFramework) { | ||
this.removeFromFrameworkSearchPaths(path.dirname(fpath)); | ||
} | ||
@@ -450,2 +457,50 @@ return file; | ||
pbxProject.prototype.removeFromFrameworkSearchPaths = function (file) { | ||
var configurations = nonComments(this.pbxXCBuildConfigurationSection()), | ||
INHERITED = '"$(inherited)"', | ||
SEARCH_PATHS = 'FRAMEWORK_SEARCH_PATHS', | ||
config, buildSettings, searchPaths; | ||
var new_path = searchPathForFile(file, this); | ||
for (config in configurations) { | ||
buildSettings = configurations[config].buildSettings; | ||
if (unquote(buildSettings['PRODUCT_NAME']) != this.productName) | ||
continue; | ||
searchPaths = buildSettings[SEARCH_PATHS]; | ||
if (searchPaths) { | ||
var matches = searchPaths.filter(function(p) { | ||
return p.indexOf(new_path) > -1; | ||
}); | ||
matches.forEach(function(m) { | ||
var idx = searchPaths.indexOf(m); | ||
searchPaths.splice(idx, 1); | ||
}); | ||
} | ||
} | ||
} | ||
pbxProject.prototype.addToFrameworkSearchPaths = function (file) { | ||
var configurations = nonComments(this.pbxXCBuildConfigurationSection()), | ||
INHERITED = '"$(inherited)"', | ||
config, buildSettings, searchPaths; | ||
for (config in configurations) { | ||
buildSettings = configurations[config].buildSettings; | ||
if (unquote(buildSettings['PRODUCT_NAME']) != this.productName) | ||
continue; | ||
if (!buildSettings['FRAMEWORK_SEARCH_PATHS'] | ||
|| buildSettings['FRAMEWORK_SEARCH_PATHS'] === INHERITED) { | ||
buildSettings['FRAMEWORK_SEARCH_PATHS'] = [INHERITED]; | ||
} | ||
buildSettings['FRAMEWORK_SEARCH_PATHS'].push(searchPathForFile(file, this)); | ||
} | ||
} | ||
pbxProject.prototype.removeFromLibrarySearchPaths = function (file) { | ||
@@ -560,6 +615,4 @@ var configurations = nonComments(this.pbxXCBuildConfigurationSection()), | ||
file, id; | ||
for (id in files) { | ||
file = files[id]; | ||
if (file.path == filePath || file.path == ('"' + filePath + '"')) { | ||
@@ -664,2 +717,11 @@ return true; | ||
function correctForFrameworksPath(file, project) { | ||
var r_resources_dir = /^Frameworks\//; | ||
if (project.pbxGroupByName('Frameworks').path) | ||
file.path = file.path.replace(r_resources_dir, ''); | ||
return file; | ||
} | ||
function searchPathForFile(file, proj) { | ||
@@ -678,2 +740,4 @@ var plugins = proj.pbxGroupByName('Plugins') | ||
return '"\\"$(SRCROOT)/' + unquote(pluginsPath) + '\\""'; | ||
} else if (file.customFramework && file.dirname) { | ||
return '"' + file.dirname + '"' | ||
} else { | ||
@@ -680,0 +744,0 @@ return '"\\"$(SRCROOT)/' + proj.productName + fileDir + '\\""'; |
@@ -5,3 +5,3 @@ { | ||
"description": "parser for xcodeproj/project.pbxproj files", | ||
"version": "0.6.2", | ||
"version": "0.6.3", | ||
"main":"index.js", | ||
@@ -8,0 +8,0 @@ "repository": { |
@@ -16,5 +16,35 @@ var fullProject = require('./fixtures/full-project') | ||
function nonComments(obj) { | ||
var keys = Object.keys(obj), | ||
newObj = {}, i = 0; | ||
for (i; i < keys.length; i++) { | ||
if (!/_comment$/.test(keys[i])) { | ||
newObj[keys[i]] = obj[keys[i]]; | ||
} | ||
} | ||
return newObj; | ||
} | ||
function frameworkSearchPaths(proj) { | ||
var configs = nonComments(proj.pbxXCBuildConfigurationSection()), | ||
allPaths = [], | ||
ids = Object.keys(configs), i, buildSettings; | ||
for (i = 0; i< ids.length; i++) { | ||
buildSettings = configs[ids[i]].buildSettings; | ||
if (buildSettings['FRAMEWORK_SEARCH_PATHS']) { | ||
allPaths.push(buildSettings['FRAMEWORK_SEARCH_PATHS']); | ||
} | ||
} | ||
return allPaths; | ||
} | ||
exports.addFramework = { | ||
'should return a pbxFile': function (test) { | ||
var newFile = proj.addFramework('libsqlite3.dylib'); | ||
console.log(newFile); | ||
@@ -145,3 +175,27 @@ test.equal(newFile.constructor, pbxFile); | ||
} | ||
}, | ||
'should pbxFile correctly for custom frameworks': function (test) { | ||
var newFile = proj.addFramework('/path/to/Custom.framework', {customFramework: true}); | ||
test.ok(newFile.customFramework); | ||
test.ok(!newFile.fileEncoding); | ||
test.equal(newFile.sourceTree, '"<group>"'); | ||
test.equal(newFile.group, 'Frameworks'); | ||
test.equal(newFile.basename, 'Custom.framework'); | ||
test.equal(newFile.dirname, '/path/to'); | ||
// XXX framework has to be copied over to PROJECT root. That is what XCode does when you drag&drop | ||
test.equal(newFile.path, 'Custom.framework'); | ||
// should add path to framework search path | ||
var frameworkPaths = frameworkSearchPaths(proj); | ||
expectedPath = '"/path/to"'; | ||
for (i = 0; i < frameworkPaths.length; i++) { | ||
var current = frameworkPaths[i]; | ||
test.ok(current.indexOf('"$(inherited)"') >= 0); | ||
test.ok(current.indexOf(expectedPath) >= 0); | ||
} | ||
test.done(); | ||
} | ||
} |
@@ -16,2 +16,31 @@ var fullProject = require('./fixtures/full-project') | ||
function nonComments(obj) { | ||
var keys = Object.keys(obj), | ||
newObj = {}, i = 0; | ||
for (i; i < keys.length; i++) { | ||
if (!/_comment$/.test(keys[i])) { | ||
newObj[keys[i]] = obj[keys[i]]; | ||
} | ||
} | ||
return newObj; | ||
} | ||
function frameworkSearchPaths(proj) { | ||
var configs = nonComments(proj.pbxXCBuildConfigurationSection()), | ||
allPaths = [], | ||
ids = Object.keys(configs), i, buildSettings; | ||
for (i = 0; i< ids.length; i++) { | ||
buildSettings = configs[ids[i]].buildSettings; | ||
if (buildSettings['FRAMEWORK_SEARCH_PATHS']) { | ||
allPaths.push(buildSettings['FRAMEWORK_SEARCH_PATHS']); | ||
} | ||
} | ||
return allPaths; | ||
} | ||
exports.removeFramework = { | ||
@@ -103,3 +132,25 @@ 'should return a pbxFile': function (test) { | ||
test.done(); | ||
}, | ||
'should remove custom frameworks': function (test) { | ||
var newFile = proj.addFramework('/path/to/Custom.framework'), | ||
frameworks = proj.pbxFrameworksBuildPhaseObj(); | ||
test.equal(frameworks.files.length, 16); | ||
var deletedFile = proj.removeFramework('/path/to/Custom.framework'), | ||
frameworks = proj.pbxFrameworksBuildPhaseObj(); | ||
test.equal(frameworks.files.length, 15); | ||
var frameworkPaths = frameworkSearchPaths(proj); | ||
expectedPath = '"/path/to"'; | ||
for (i = 0; i < frameworkPaths.length; i++) { | ||
var current = frameworkPaths[i]; | ||
test.ok(current.indexOf('"$(inherited)"') == -1); | ||
test.ok(current.indexOf(expectedPath) == -1); | ||
} | ||
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
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
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
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
326207
58
5486
16