Skip to content

Commit 0ed5a5d

Browse files
authored
Merge pull request #7 from NativeScript/kddimitrov/fix-framework-add
Kddimitrov/fix framework add
2 parents fcb7376 + 173c323 commit 0ed5a5d

File tree

1 file changed

+50
-24
lines changed

1 file changed

+50
-24
lines changed

lib/pbxProject.js

+50-24
Original file line numberDiff line numberDiff line change
@@ -641,22 +641,22 @@ function handleLocalization(files, pbxGroup, srcRootPath, opt) {
641641
if(parsedRegionFilePath.ext === ".storyboard") {
642642
storyboardNames[parsedRegionFilePath.name] = true;
643643
}
644-
fileRegions = allNames[parsedRegionFilePath.name] = allNames[parsedRegionFilePath.name] || [];
644+
var fileRegions = allNames[parsedRegionFilePath.name] = allNames[parsedRegionFilePath.name] || [];
645645
fileRegions.push(regionName);
646646
region[regionFileName] = $path.join(filePath, regionFilePath);
647647
}
648648
}
649649
}
650650

651651
for (var name in allNames) {
652-
fileRegions = allNames[name]
652+
var fileRegionsForName = allNames[name]
653653
var variantGroupName = storyboardNames[name] ? name + ".storyboard" : name + ".strings";
654654

655655
var variantGroup = this.addLocalizationVariantGroup(variantGroupName, { target: opt.target, skipAddToResourcesGroup: true });
656656
pbxGroup.children.push(pbxGroupChild(variantGroup));
657-
for (let k = 0; k < fileRegions.length; k++) {
658-
var file = regions[fileRegions[k]][name];
659-
var refFile = new pbxFile($path.relative(srcRootPath, file), {basename: fileRegions[k]});
657+
for (let k = 0; k < fileRegionsForName.length; k++) {
658+
var file = regions[fileRegionsForName[k]][name];
659+
var refFile = new pbxFile($path.relative(srcRootPath, file), {basename: fileRegionsForName[k]});
660660
refFile.fileRef = this.generateUuid();
661661
this.addToPbxFileReferenceSection(refFile);
662662
this.addToPbxVariantGroup(refFile, variantGroup.fileRef);
@@ -669,27 +669,35 @@ pbxProject.prototype.removePbxGroup = function(groupName, path) {
669669
if (!groupKey) {
670670
return;
671671
}
672+
673+
this.removePbxGroupByKey(groupKey, path);
674+
}
675+
676+
pbxProject.prototype.removePbxGroupByKey = function(groupKey, path) {
672677
var group = this.getPBXGroupByKey(groupKey) || this.getPBXVariantGroupByKey(groupKey)
678+
679+
if (!group) {
680+
return;
681+
}
673682

674683
path = path || "";
675-
676684
var children = group.children;
677685

678686
for(i in children) {
679687
var file = new pbxFile($path.join(path, children[i].comment));
680688
file.fileRef = children[i].value;
681689
file.uuid = file.fileRef;
682-
this.removePbxGroup(children[i].comment, $path.join(path, children[i].comment));
683-
this.removeFromPbxFileReferenceSection(file);
690+
this.removePbxGroupByKey(children[i].value, $path.join(path, children[i].comment));
691+
this.removeFromPbxFileReferenceSectionByUuid(children[i].value);
684692
this.removeFromPbxBuildFileSection(file);
685693
this.removeFromPbxSourcesBuildPhase(file);
686694
}
687695

688696
var mainGroup = this.findMainPbxGroup();
689697
if(mainGroup) {
690-
var mainGroupChildren = this.findMainPbxGroup().children, i;
698+
var mainGroupChildren = mainGroup.children, i;
691699
for(i in mainGroupChildren) {
692-
if (mainGroupChildren[i].comment == groupName) {
700+
if (mainGroupChildren[i].value == groupKey) {
693701
mainGroupChildren.splice(i, 1);
694702
}
695703
}
@@ -702,15 +710,7 @@ pbxProject.prototype.removePbxGroup = function(groupName, path) {
702710
section = this.hash.project.objects['PBXGroup'];
703711
}
704712

705-
for (key in section) {
706-
// only look for comments
707-
if (!COMMENT_KEY.test(key)) continue;
708-
709-
if (section[key] == groupName) {
710-
itemKey = key.split(COMMENT_KEY)[0];
711-
delete section[itemKey];
712-
}
713-
}
713+
removeItemAndCommentFromSectionByUuid(section, groupKey);
714714
}
715715

716716
pbxProject.prototype.addToPbxProjectSection = function(target) {
@@ -759,6 +759,12 @@ pbxProject.prototype.removeFromPbxFileReferenceSection = function(file) {
759759
return file;
760760
}
761761

762+
pbxProject.prototype.removeFromPbxFileReferenceSectionByUuid = function(fileUuid) {
763+
var section = this.pbxFileReferenceSection();
764+
765+
removeItemAndCommentFromSectionByUuid(section, fileUuid);
766+
}
767+
762768
pbxProject.prototype.addToXcVersionGroupSection = function(file) {
763769
if (!file.models || !file.currentModel) {
764770
throw new Error("Cannot create a XCVersionGroup section from not a data model document file");
@@ -1677,10 +1683,13 @@ pbxProject.prototype.removeTargetsByProductType = function(targetProductType) {
16771683

16781684
pbxProject.prototype.removeTarget = function(target, targetKey) {
16791685
let files = [];
1686+
var pbxBuildFileSection = this.pbxBuildFileSection();
1687+
var fileReferenceSection = this.pbxFileReferenceSection();
16801688

16811689
// iterate all buildPhases and collect all files that should be removed
16821690
// remove the phase from the appropriate section
16831691
var buildPhases = target["buildPhases"];
1692+
16841693
for (let i = 0; i < buildPhases.length; i++) {
16851694
var buildPhase = buildPhases[i];
16861695
var sectionUuid = buildPhase.value;
@@ -1693,7 +1702,27 @@ pbxProject.prototype.removeTarget = function(target, targetKey) {
16931702
files = files.concat(section[sectionUuid].files);
16941703
} else if (buildPhase.comment === buildPhaseNameForIsa("PBXFrameworksBuildPhase")) {
16951704
section = this.hash.project.objects["PBXFrameworksBuildPhase"];
1696-
files = files.concat(section[sectionUuid].files);
1705+
var frameworkFiles = section[sectionUuid].files;
1706+
for (let currentBuildFile of frameworkFiles) {
1707+
var currentBuildFileUuid = currentBuildFile.value;
1708+
var fileRef = pbxBuildFileSection[currentBuildFileUuid].fileRef;
1709+
var stillReferenced = false;
1710+
for (var buildFileUuid in nonComments(pbxBuildFileSection)) {
1711+
if(pbxBuildFileSection[buildFileUuid].fileRef === fileRef && buildFileUuid !== currentBuildFileUuid){
1712+
stillReferenced = true;
1713+
break;
1714+
}
1715+
}
1716+
1717+
if(!stillReferenced) {
1718+
var frameworkFileRef = fileReferenceSection[fileRef];
1719+
var fileToRemove = new pbxFile(unquote(frameworkFileRef.path), {basename: frameworkFileRef.name});
1720+
fileToRemove.fileRef = fileRef;
1721+
this.removeFromFrameworksPbxGroup(fileToRemove);
1722+
removeItemAndCommentFromSectionByUuid(fileReferenceSection, fileRef);
1723+
}
1724+
}
1725+
files = files.concat(frameworkFiles);
16971726
}
16981727

16991728
removeItemAndCommentFromSectionByUuid(section, sectionUuid);
@@ -1734,12 +1763,10 @@ pbxProject.prototype.removeTarget = function(target, targetKey) {
17341763
var productUuid = "";
17351764

17361765
var productReferenceUuid = target.productReference;
1737-
var pbxBuildFileSection = this.pbxBuildFileSection();
1738-
var pbxBuildFileSectionNoComments = nonComments(pbxBuildFileSection);
17391766

17401767
// the productReference is the uuid from the PBXFileReference Section, but we need the one in PBXBuildFile section
17411768
// check the fileRef of all records until we find the product
1742-
for (var uuid in pbxBuildFileSectionNoComments) {
1769+
for (var uuid in nonComments(pbxBuildFileSection)) {
17431770
if (this.pbxBuildFileSection()[uuid].fileRef == productReferenceUuid) {
17441771
productUuid = uuid;
17451772
}
@@ -1787,7 +1814,6 @@ pbxProject.prototype.removeTarget = function(target, targetKey) {
17871814

17881815

17891816
//remove the product from the Products PBXGroup
1790-
var fileReferenceSection = this.pbxFileReferenceSection();
17911817
var productReference = fileReferenceSection[productReferenceUuid];
17921818
var productFile = new pbxFile(productReference.path);
17931819
productFile.fileRef = productReferenceUuid;

0 commit comments

Comments
 (0)