Skip to content

Commit 8b3c7f6

Browse files
committed
addBuildPhase(): Add ad-hoc creation of "CopyFiles" build phase, as it is not available in empty (Cordova) projects
1 parent 96e1d71 commit 8b3c7f6

File tree

1 file changed

+32
-6
lines changed

1 file changed

+32
-6
lines changed

lib/pbxProject.js

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -589,20 +589,46 @@ pbxProject.prototype.addTargetDependency = function(target, dependencyTargets) {
589589
return { uuid: target, target: nativeTargets[target] };
590590
}
591591

592-
pbxProject.prototype.addBuildPhase = function (filePathsArray, isa, comment) {
593-
var section = this.hash.project.objects[isa],
592+
pbxProject.prototype.addBuildPhase = function(filePathsArray, buildPhaseType, comment, target, folderType, subfolderPath) {
593+
var buildPhaseSection,
594594
fileReferenceSection = this.pbxFileReferenceSection(),
595595
buildFileSection = this.pbxBuildFileSection(),
596596
buildPhaseUuid = this.generateUuid(),
597+
buildPhaseTargetUuid = target || this.getFirstTarget().uuid,
597598
commentKey = f("%s_comment", buildPhaseUuid),
598599
buildPhase = {
599-
isa: isa,
600+
isa: buildPhaseType,
600601
buildActionMask: 2147483647,
601602
files: [],
602603
runOnlyForDeploymentPostprocessing: 0
603604
},
604605
filePathToBuildFile = {};
605606

607+
608+
if (buildPhaseType === 'PBXCopyFilesBuildPhase') {
609+
buildPhase = pbxCopyFilesBuildPhaseObj(buildPhase, folderType, subfolderPath, comment);
610+
buildPhase.name = comment;
611+
}
612+
613+
if (!this.hash.project.objects[buildPhaseType]) {
614+
this.hash.project.objects[buildPhaseType] = new Object();
615+
this.hash.project.objects[buildPhaseType][buildPhaseUuid] = buildPhase;
616+
this.hash.project.objects[buildPhaseType][commentKey] = comment;
617+
618+
619+
this.hash.project.objects['PBXNativeTarget'][buildPhaseTargetUuid]['buildPhases'].push({
620+
value: buildPhaseUuid,
621+
comment: comment
622+
})
623+
624+
console.log(util.inspect(this.hash.project.objects['PBXNativeTarget'], true, null));
625+
626+
}
627+
628+
629+
buildPhase = this.hash.project.objects[buildPhaseType];
630+
631+
606632
for (var key in buildFileSection) {
607633
// only look for comments
608634
if (!COMMENT_KEY.test(key)) continue;
@@ -638,9 +664,9 @@ pbxProject.prototype.addBuildPhase = function (filePathsArray, isa, comment) {
638664
buildPhase.files.push(pbxBuildPhaseObj(file));
639665
}
640666

641-
if (section) {
642-
section[buildPhaseUuid] = buildPhase;
643-
section[commentKey] = comment;
667+
if (buildPhaseSection) {
668+
buildPhaseSection[buildPhaseUuid] = buildPhase;
669+
buildPhaseSection[commentKey] = comment;
644670
}
645671

646672
return { uuid: buildPhaseUuid, buildPhase: buildPhase };

0 commit comments

Comments
 (0)