From f7dd2692f10123c9a17ee26796b09903ab17bdb3 Mon Sep 17 00:00:00 2001 From: tdermendjiev Date: Tue, 16 Feb 2021 13:49:19 +0200 Subject: [PATCH] feat: Add removeBuildPhase method to pbxProject --- .vscode/launch.json | 18 +++++++++++++++++ lib/pbxProject.js | 33 ++++++++++++++++++++++++++++-- test/removeBuildPhase.js | 43 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 92 insertions(+), 2 deletions(-) create mode 100644 .vscode/launch.json create mode 100644 test/removeBuildPhase.js diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..6e228a3 --- /dev/null +++ b/.vscode/launch.json @@ -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": [ + "/**" + ], + "runtimeExecutable": "nodeunit", + "runtimeArgs": ["test/parser", "test"] + } + ] +} \ No newline at end of file diff --git a/lib/pbxProject.js b/lib/pbxProject.js index 5d770bf..ed2e8c8 100644 --- a/lib/pbxProject.js +++ b/lib/pbxProject.js @@ -702,7 +702,7 @@ pbxProject.prototype.removePbxGroupByKey = function(groupKey, path) { if (!group) { return; } - + path = path || ""; var children = group.children; @@ -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 = { @@ -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(), diff --git a/test/removeBuildPhase.js b/test/removeBuildPhase.js new file mode 100644 index 0000000..bd35c24 --- /dev/null +++ b/test/removeBuildPhase.js @@ -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() + }, +}