Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions lib/pbxProject.js
Original file line number Diff line number Diff line change
Expand Up @@ -811,7 +811,7 @@ pbxProject.prototype.addTargetDependency = function(target, dependencyTargets) {
return { uuid: target, target: nativeTargets[target] };
}

pbxProject.prototype.addBuildPhase = function(filePathsArray, buildPhaseType, comment, target, folderType, subfolderPath) {
pbxProject.prototype.addBuildPhase = function(filePathsArray, buildPhaseType, comment, target, optionsOrFolderType, subfolderPath) {
var buildPhaseSection,
fileReferenceSection = this.pbxFileReferenceSection(),
buildFileSection = this.pbxBuildFileSection(),
Expand All @@ -827,7 +827,9 @@ pbxProject.prototype.addBuildPhase = function(filePathsArray, buildPhaseType, co
filePathToBuildFile = {};

if (buildPhaseType === 'PBXCopyFilesBuildPhase') {
buildPhase = pbxCopyFilesBuildPhaseObj(buildPhase, folderType, subfolderPath, comment);
buildPhase = pbxCopyFilesBuildPhaseObj(buildPhase, optionsOrFolderType, subfolderPath, comment);
} else if (buildPhaseType === 'PBXShellScriptBuildPhase') {
buildPhase = pbxShellScriptBuildPhaseObj(buildPhase, optionsOrFolderType, comment)
}

if (!this.hash.project.objects[buildPhaseType]) {
Expand Down Expand Up @@ -1490,7 +1492,7 @@ function pbxBuildPhaseObj(file) {
return obj;
}

function pbxCopyFilesBuildPhaseObj(obj, folderType, subfolderPath, phaseName){
function pbxCopyFilesBuildPhaseObj(obj, folderType, subfolderPath, phaseName) {

// Add additional properties for 'CopyFiles' build phase
var DESTINATION_BY_TARGETTYPE = {
Expand Down Expand Up @@ -1527,6 +1529,16 @@ function pbxCopyFilesBuildPhaseObj(obj, folderType, subfolderPath, phaseName){
return obj;
}

function pbxShellScriptBuildPhaseObj(obj, options, phaseName) {
obj.name = '"' + phaseName + '"';
obj.inputPaths = options.inputPaths || [];
obj.outputPaths = options.outputPaths || [];
obj.shellPath = options.shellPath;
obj.shellScript = '"' + options.shellScript.replace(/"/g, '\\"') + '"';

return obj;
}

function pbxBuildFileComment(file) {
return longComment(file);
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"author": "Andrew Lunny <[email protected]>",
"name": "xcode",
"description": "parser for xcodeproj/project.pbxproj files",
"version": "0.8.9",
"version": "0.9.0",
"main": "index.js",
"repository": {
"url": "https://github.com/alunny/node-xcode.git"
Expand Down
7 changes: 7 additions & 0 deletions test/addBuildPhase.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,4 +110,11 @@ exports.addBuildPhase = {
test.equal(buildPhase.dstSubfolderSpec, 10);
test.done();
},
'should add a script build phase to echo "hello world!"': function(test) {
var options = {shellPath: '/bin/sh', shellScript: 'echo "hello world!"'};
var buildPhase = proj.addBuildPhase([], 'PBXShellScriptBuildPhase', 'Run a script', proj.getFirstTarget().uuid, options).buildPhase;
test.equal(buildPhase.shellPath, '/bin/sh');
test.equal(buildPhase.shellScript, '"echo \\"hello world!\\""');
test.done();
},
}