Skip to content

Commit 04563e2

Browse files
authored
feat: Add removeBuildPhase method to pbxProject (#14)
1 parent b80d21b commit 04563e2

File tree

3 files changed

+92
-2
lines changed

3 files changed

+92
-2
lines changed

.vscode/launch.json

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
// Use IntelliSense to learn about possible attributes.
3+
// Hover to view descriptions of existing attributes.
4+
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5+
"version": "0.2.0",
6+
"configurations": [
7+
{
8+
"type": "pwa-node",
9+
"request": "launch",
10+
"name": "Launch Program",
11+
"skipFiles": [
12+
"<node_internals>/**"
13+
],
14+
"runtimeExecutable": "nodeunit",
15+
"runtimeArgs": ["test/parser", "test"]
16+
}
17+
]
18+
}

lib/pbxProject.js

+31-2
Original file line numberDiff line numberDiff line change
@@ -702,7 +702,7 @@ pbxProject.prototype.removePbxGroupByKey = function(groupKey, path) {
702702
if (!group) {
703703
return;
704704
}
705-
705+
706706
path = path || "";
707707
var children = group.children;
708708

@@ -1064,7 +1064,7 @@ pbxProject.prototype.addTargetDependency = function(target, dependencyTargets) {
10641064
containerPortal: this.hash.project['rootObject'],
10651065
containerPortal_comment: this.hash.project['rootObject_comment'],
10661066
proxyType: 1,
1067-
remoteGlobalIDString: dependencyTargetUuid,
1067+
remoteGlobalIDString: dependencyTargetUuid,
10681068
remoteInfo: nativeTargets[dependencyTargetUuid].name
10691069
},
10701070
targetDependency = {
@@ -1087,6 +1087,35 @@ pbxProject.prototype.addTargetDependency = function(target, dependencyTargets) {
10871087
return { uuid: target, target: nativeTargets[target] };
10881088
}
10891089

1090+
pbxProject.prototype.removeBuildPhase = function(comment, target) { // Build phase files should be removed separately
1091+
var buildPhaseUuid = undefined,
1092+
buildPhaseTargetUuid = target || this.getFirstTarget().uuid
1093+
1094+
if (this.hash.project.objects['PBXNativeTarget'][buildPhaseTargetUuid]['buildPhases']) {
1095+
let phases = this.hash.project.objects['PBXNativeTarget'][buildPhaseTargetUuid]['buildPhases'];
1096+
for (let i = 0; i < phases.length; i++) {
1097+
const phase = phases[i];
1098+
if (phase.comment === comment) {
1099+
buildPhaseUuid = phase.value;
1100+
let commentKey = f("%s_comment", buildPhaseUuid)
1101+
if (this.hash.project.objects['PBXCopyFilesBuildPhase']) {
1102+
let phase = this.hash.project.objects['PBXCopyFilesBuildPhase'][commentKey]
1103+
delete phase
1104+
}
1105+
1106+
if (this.hash.project.objects['PBXShellScriptBuildPhase']) {
1107+
let phase = this.hash.project.objects['PBXShellScriptBuildPhase'][commentKey]
1108+
delete phase
1109+
}
1110+
1111+
phases.splice(i, 1);
1112+
}
1113+
}
1114+
1115+
}
1116+
1117+
}
1118+
10901119
pbxProject.prototype.addBuildPhase = function(filePathsArray, buildPhaseType, comment, target, optionsOrFolderType, subfolderPath) {
10911120
var buildPhaseSection,
10921121
fileReferenceSection = this.pbxFileReferenceSection(),

test/removeBuildPhase.js

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/**
2+
Licensed to the Apache Software Foundation (ASF) under one
3+
or more contributor license agreements. See the NOTICE file
4+
distributed with this work for additional information
5+
regarding copyright ownership. The ASF licenses this file
6+
to you under the Apache License, Version 2.0 (the
7+
'License'); you may not use this file except in compliance
8+
with the License. You may obtain a copy of the License at
9+
http://www.apache.org/licenses/LICENSE-2.0
10+
Unless required by applicable law or agreed to in writing,
11+
software distributed under the License is distributed on an
12+
'AS IS' BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
13+
KIND, either express or implied. See the License for the
14+
specific language governing permissions and limitations
15+
under the License.
16+
*/
17+
18+
var fullProject = require('./fixtures/full-project')
19+
fullProjectStr = JSON.stringify(fullProject),
20+
pbx = require('../lib/pbxProject'),
21+
proj = new pbx('.');
22+
23+
function cleanHash() {
24+
return JSON.parse(fullProjectStr);
25+
}
26+
27+
exports.setUp = function (callback) {
28+
proj.hash = cleanHash();
29+
callback();
30+
}
31+
32+
exports.removeBuildPhase = {
33+
34+
'should remove a pbxBuildPhase': function (test) {
35+
const comment = 'My build phase';
36+
var buildPhase = proj.addBuildPhase([], 'PBXSourcesBuildPhase', comment);
37+
proj.removeBuildPhase(comment)
38+
let phases = proj.hash.project.objects['PBXNativeTarget'][proj.getFirstTarget().uuid]['buildPhases'];
39+
40+
test.ok(phases.map(p => p.comment).indexOf(comment) === -1);
41+
test.done()
42+
},
43+
}

0 commit comments

Comments
 (0)