Skip to content

Add removeBuildPhase method to pbxProject #14

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 17, 2021
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: 18 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "pwa-node",
"request": "launch",
"name": "Launch Program",
"skipFiles": [
"<node_internals>/**"
],
"runtimeExecutable": "nodeunit",
"runtimeArgs": ["test/parser", "test"]
}
]
}
33 changes: 31 additions & 2 deletions lib/pbxProject.js
Original file line number Diff line number Diff line change
Expand Up @@ -702,7 +702,7 @@ pbxProject.prototype.removePbxGroupByKey = function(groupKey, path) {
if (!group) {
return;
}

path = path || "";
var children = group.children;

Expand Down Expand Up @@ -1064,7 +1064,7 @@ pbxProject.prototype.addTargetDependency = function(target, dependencyTargets) {
containerPortal: this.hash.project['rootObject'],
containerPortal_comment: this.hash.project['rootObject_comment'],
proxyType: 1,
remoteGlobalIDString: dependencyTargetUuid,
remoteGlobalIDString: dependencyTargetUuid,
remoteInfo: nativeTargets[dependencyTargetUuid].name
},
targetDependency = {
Expand All @@ -1087,6 +1087,35 @@ pbxProject.prototype.addTargetDependency = function(target, dependencyTargets) {
return { uuid: target, target: nativeTargets[target] };
}

pbxProject.prototype.removeBuildPhase = function(comment, target) { // Build phase files should be removed separately
var buildPhaseUuid = undefined,
buildPhaseTargetUuid = target || this.getFirstTarget().uuid

if (this.hash.project.objects['PBXNativeTarget'][buildPhaseTargetUuid]['buildPhases']) {
let phases = this.hash.project.objects['PBXNativeTarget'][buildPhaseTargetUuid]['buildPhases'];
for (let i = 0; i < phases.length; i++) {
const phase = phases[i];
if (phase.comment === comment) {
buildPhaseUuid = phase.value;
let commentKey = f("%s_comment", buildPhaseUuid)
if (this.hash.project.objects['PBXCopyFilesBuildPhase']) {
let phase = this.hash.project.objects['PBXCopyFilesBuildPhase'][commentKey]
delete phase
}

if (this.hash.project.objects['PBXShellScriptBuildPhase']) {
let phase = this.hash.project.objects['PBXShellScriptBuildPhase'][commentKey]
delete phase
}

phases.splice(i, 1);
}
}

}

}

pbxProject.prototype.addBuildPhase = function(filePathsArray, buildPhaseType, comment, target, optionsOrFolderType, subfolderPath) {
var buildPhaseSection,
fileReferenceSection = this.pbxFileReferenceSection(),
Expand Down
43 changes: 43 additions & 0 deletions test/removeBuildPhase.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/**
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
'License'); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
'AS IS' BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
*/

var fullProject = require('./fixtures/full-project')
fullProjectStr = JSON.stringify(fullProject),
pbx = require('../lib/pbxProject'),
proj = new pbx('.');

function cleanHash() {
return JSON.parse(fullProjectStr);
}

exports.setUp = function (callback) {
proj.hash = cleanHash();
callback();
}

exports.removeBuildPhase = {

'should remove a pbxBuildPhase': function (test) {
const comment = 'My build phase';
var buildPhase = proj.addBuildPhase([], 'PBXSourcesBuildPhase', comment);
proj.removeBuildPhase(comment)
let phases = proj.hash.project.objects['PBXNativeTarget'][proj.getFirstTarget().uuid]['buildPhases'];

test.ok(phases.map(p => p.comment).indexOf(comment) === -1);
test.done()
},
}