From d61c312a0817d0d5fc1e0f93679f71941377a484 Mon Sep 17 00:00:00 2001 From: Fatme Havaluova Date: Wed, 24 Jun 2015 18:18:42 +0300 Subject: [PATCH 01/16] Fix unknown lastKnownFileType Fix quotes --- lib/pbxFile.js | 1 + lib/pbxProject.js | 14 ++++++++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/lib/pbxFile.js b/lib/pbxFile.js index 9553bfb..98206a5 100644 --- a/lib/pbxFile.js +++ b/lib/pbxFile.js @@ -38,6 +38,7 @@ var FILETYPE_BY_EXTENSION = { octest: 'wrapper.cfbundle', pch: 'sourcecode.c.h', plist: 'text.plist.xml', + png: "image.png", sh: 'text.script.sh', swift: 'sourcecode.swift', tbd: 'sourcecode.text-based-dylib-definition', diff --git a/lib/pbxProject.js b/lib/pbxProject.js index 0e0f8f9..11e790c 100644 --- a/lib/pbxProject.js +++ b/lib/pbxProject.js @@ -1520,8 +1520,8 @@ function pbxBuildFileObj(file) { function pbxFileReferenceObj(file) { var fileObject = { isa: "PBXFileReference", - name: "\"" + file.basename + "\"", - path: "\"" + file.path.replace(/\\/g, '/') + "\"", + name: file.basename, + path: file.path, sourceTree: file.sourceTree, fileEncoding: file.fileEncoding, lastKnownFileType: file.lastKnownFileType, @@ -1529,6 +1529,16 @@ function pbxFileReferenceObj(file) { includeInIndex: file.includeInIndex }; + if(fileObject.name.indexOf("\"") !== -1) { + fileObject.name = fileObject.name.replace(/\"/g, "\\\""); + fileObject.path = fileObject.path.replace(/\"/g, "\\\""); + } + + if(!file.basename.match(/^[a-zA-Z0-9_\.\$]+\.[a-zA-Z]+$/)) { + fileObject.name = "\"" + fileObject.name + "\""; + fileObject.path = "\"" + fileObject.path + "\""; + } + return fileObject; } From 053d70c759c948df012d9ae8b34179d4717d99ae Mon Sep 17 00:00:00 2001 From: Dimitar Kerezov Date: Tue, 30 Jun 2015 16:41:24 +0300 Subject: [PATCH 02/16] Fix path/name quotation Those properties should be surrounded by quotation marks based on appearance of special characters in path and basename properties respectively. They are independent of one another. --- lib/pbxProject.js | 8 +++- test/pbxProject.js | 100 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 106 insertions(+), 2 deletions(-) diff --git a/lib/pbxProject.js b/lib/pbxProject.js index 11e790c..cbfd1b8 100644 --- a/lib/pbxProject.js +++ b/lib/pbxProject.js @@ -26,7 +26,8 @@ var util = require('util'), fs = require('fs'), parser = require('./parser/pbxproj'), plist = require('simple-plist'), - COMMENT_KEY = /_comment$/ + COMMENT_KEY = /_comment$/, + NO_SPECIAL_SYMBOLS = /^[a-zA-Z0-9_\.\$]+\.[a-zA-Z]+$/; function pbxProject(filename) { if (!(this instanceof pbxProject)) @@ -1534,8 +1535,11 @@ function pbxFileReferenceObj(file) { fileObject.path = fileObject.path.replace(/\"/g, "\\\""); } - if(!file.basename.match(/^[a-zA-Z0-9_\.\$]+\.[a-zA-Z]+$/)) { + if(!file.basename.match(NO_SPECIAL_SYMBOLS)) { fileObject.name = "\"" + fileObject.name + "\""; + } + + if(!file.path.match(NO_SPECIAL_SYMBOLS)) { fileObject.path = "\"" + fileObject.path + "\""; } diff --git a/test/pbxProject.js b/test/pbxProject.js index c076b96..176f836 100644 --- a/test/pbxProject.js +++ b/test/pbxProject.js @@ -328,3 +328,103 @@ exports['hasFile'] = { test.done() } } + +exports['addToPbxFileReferenceSection'] = { + 'should not quote name when no special characters present in basename': function (test) { + var newProj = new pbx('.'); + newProj.hash = jsonProject, + file = { + uuid: newProj.generateUuid(), + fileRef: newProj.generateUuid(), + isa: 'PBXFileReference', + explicitFileType: 'wrapper.application', + includeInIndex: 0, + basename: "SomeFile.m", + path: "SomePath.m", + sourceTree: 'BUILT_PRODUCTS_DIR' + }, + fileRefSection = newProj.pbxFileReferenceSection(); + + newProj.addToPbxFileReferenceSection(file); + test.equal(fileRefSection[file.fileRef].name, "SomeFile.m"); + test.done(); + }, + 'should quote name when special characters present in basename': function (test) { + var newProj = new pbx('.'); + newProj.hash = jsonProject, + file = { + uuid: newProj.generateUuid(), + fileRef: newProj.generateUuid(), + isa: 'PBXFileReference', + explicitFileType: 'wrapper.application', + includeInIndex: 0, + basename: "Some File.m", + path: "SomePath.m", + sourceTree: 'BUILT_PRODUCTS_DIR' + }, + fileRefSection = newProj.pbxFileReferenceSection(); + + newProj.addToPbxFileReferenceSection(file); + test.equal(fileRefSection[file.fileRef].name, '"Some File.m"'); + test.done(); + }, + 'should not quote path when no special characters present in path': function (test) { + var newProj = new pbx('.'); + newProj.hash = jsonProject, + file = { + uuid: newProj.generateUuid(), + fileRef: newProj.generateUuid(), + isa: 'PBXFileReference', + explicitFileType: 'wrapper.application', + includeInIndex: 0, + basename: "SomeFile.m", + path: "SomePath.m", + sourceTree: 'BUILT_PRODUCTS_DIR' + }, + fileRefSection = newProj.pbxFileReferenceSection(); + + newProj.addToPbxFileReferenceSection(file); + test.equal(fileRefSection[file.fileRef].path, "SomePath.m"); + test.done(); + }, + 'should quote path when special characters present in path': function (test) { + var newProj = new pbx('.'); + newProj.hash = jsonProject, + file = { + uuid: newProj.generateUuid(), + fileRef: newProj.generateUuid(), + isa: 'PBXFileReference', + explicitFileType: 'wrapper.application', + includeInIndex: 0, + basename: "SomeFile.m", + path: "SomeFolder/Some Path.m", + sourceTree: 'BUILT_PRODUCTS_DIR' + }, + fileRefSection = newProj.pbxFileReferenceSection(); + + newProj.addToPbxFileReferenceSection(file); + test.equal(fileRefSection[file.fileRef].path, '"SomeFolder/Some Path.m"'); + test.done(); + }, + 'should quote path and name when special characters present in path and basename': function (test) { + var newProj = new pbx('.'); + newProj.hash = jsonProject, + file = { + uuid: newProj.generateUuid(), + fileRef: newProj.generateUuid(), + isa: 'PBXFileReference', + explicitFileType: 'wrapper.application', + includeInIndex: 0, + basename: "Some File.m", + path: "SomeFolder/Some Path.m", + sourceTree: 'BUILT_PRODUCTS_DIR' + }, + fileRefSection = newProj.pbxFileReferenceSection(); + + newProj.addToPbxFileReferenceSection(file); + test.equal(fileRefSection[file.fileRef].name, '"Some File.m"'); + test.equal(fileRefSection[file.fileRef].path, '"SomeFolder/Some Path.m"'); + test.done(); + } +} + From 1a410c1b1a644f8eb926e4ab718ebe2c4f8da256 Mon Sep 17 00:00:00 2001 From: Toma Popov Date: Mon, 7 Sep 2015 21:16:24 +0300 Subject: [PATCH 03/16] Implement relative to project root search paths. --- lib/pbxProject.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/pbxProject.js b/lib/pbxProject.js index cbfd1b8..28a7718 100644 --- a/lib/pbxProject.js +++ b/lib/pbxProject.js @@ -1650,6 +1650,10 @@ function correctForPath(file, project, group) { } function searchPathForFile(file, proj) { + if (file.relativePath) { + return '"\$(SRCROOT)/' + file.relativePath + '\"'; + } + var plugins = proj.pbxGroupByName('Plugins'), pluginsPath = plugins ? plugins.path : null, fileDir = path.dirname(file.path); From 52fa3f1d7c0c32c8a818d0bde3ca64d8f76b8392 Mon Sep 17 00:00:00 2001 From: Teodor Dermendzhiev Date: Fri, 18 May 2018 18:57:11 +0300 Subject: [PATCH 04/16] feat: Add support various file extensions and export filetypes for pbxFile module --- lib/pbxFile.js | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/lib/pbxFile.js b/lib/pbxFile.js index 98206a5..0a7611b 100644 --- a/lib/pbxFile.js +++ b/lib/pbxFile.js @@ -29,10 +29,20 @@ var FILETYPE_BY_EXTENSION = { app: 'wrapper.application', appex: 'wrapper.app-extension', bundle: 'wrapper.plug-in', + c: 'sourcecode.c.c', + cc: 'sourcecode.cpp.cpp', + cpp: 'sourcecode.cpp.cpp', + cxx: 'sourcecode.cpp.cpp', + 'c++': 'sourcecode.cpp.cpp', dylib: 'compiled.mach-o.dylib', framework: 'wrapper.framework', h: 'sourcecode.c.h', + hh: 'sourcecode.cpp.h', + hpp: 'sourcecode.cpp.h', + hxx: 'sourcecode.cpp.h', + 'h++': 'sourcecode.cpp.h', m: 'sourcecode.c.objc', + mm: 'sourcecode.cpp.objcpp', markdown: 'text', mdimporter: 'wrapper.cfbundle', octest: 'wrapper.cfbundle', @@ -57,8 +67,11 @@ var FILETYPE_BY_EXTENSION = { 'wrapper.framework': 'Frameworks', 'embedded.framework': 'Embed Frameworks', 'sourcecode.c.h': 'Resources', + 'sourcecode.c.c': 'Sources', 'sourcecode.c.objc': 'Sources', - 'sourcecode.swift': 'Sources' + 'sourcecode.swift': 'Sources', + 'sourcecode.cpp.cpp': 'Sources', + 'sourcecode.cpp.objcpp': 'Sources' }, PATH_BY_FILETYPE = { 'compiled.mach-o.dylib': 'usr/lib/', @@ -73,7 +86,11 @@ var FILETYPE_BY_EXTENSION = { ENCODING_BY_FILETYPE = { 'sourcecode.c.h': 4, 'sourcecode.c.h': 4, + 'sourcecode.cpp.h': 4, + 'sourcecode.c.c': 4, 'sourcecode.c.objc': 4, + 'sourcecode.cpp.cpp': 4, + 'sourcecode.cpp.objcpp': 4, 'sourcecode.swift': 4, 'text': 4, 'text.plist.xml': 4, @@ -231,4 +248,7 @@ function pbxFile(filepath, opt) { } } -module.exports = pbxFile; +module.exports = { + pbxFile: pbxFile, + fileTypes: fileTypes +} From 73bb80925643f39b3ed66fd1be9b55efaf77ca29 Mon Sep 17 00:00:00 2001 From: Teodor Dermendzhiev Date: Fri, 18 May 2018 19:06:12 +0300 Subject: [PATCH 05/16] feat: Implement adding and removing of pbx groups *support for c++ files added *recursively add pbxGroup and its children *recursively remove pbxGroup and its children *make sure pbx group name is not duplicated on adding new group --- lib/pbxProject.js | 110 ++++++++++++++++++++++++++++++++++++---------- 1 file changed, 87 insertions(+), 23 deletions(-) diff --git a/lib/pbxProject.js b/lib/pbxProject.js index 28a7718..8e86b55 100644 --- a/lib/pbxProject.js +++ b/lib/pbxProject.js @@ -18,22 +18,25 @@ var util = require('util'), f = util.format, EventEmitter = require('events').EventEmitter, - path = require('path'), + $path = require('path'), uuid = require('uuid'), fork = require('child_process').fork, pbxWriter = require('./pbxWriter'), - pbxFile = require('./pbxFile'), + pbxFile = require('./pbxFile').pbxFile, + pbxFileTypes = require('./pbxFile').fileTypes, fs = require('fs'), parser = require('./parser/pbxproj'), plist = require('simple-plist'), COMMENT_KEY = /_comment$/, - NO_SPECIAL_SYMBOLS = /^[a-zA-Z0-9_\.\$]+\.[a-zA-Z]+$/; + NO_SPECIAL_SYMBOLS = /^[a-zA-Z0-9_\.\$]+\.[a-zA-Z]+$/, + HEADER_FILE_TYPE_SUFFIX = ".h", + SOURCE_CODE_FILE_TYPE_PREFIX = "sourcecode."; function pbxProject(filename) { if (!(this instanceof pbxProject)) return new pbxProject(filename); - this.filepath = path.resolve(filename) + this.filepath = $path.resolve(filename) } util.inherits(pbxProject, EventEmitter) @@ -492,17 +495,37 @@ pbxProject.prototype.removeFromPbxBuildFileSection = function(file) { } } -pbxProject.prototype.addPbxGroup = function(filePathsArray, name, path, sourceTree) { +pbxProject.prototype.findMainPbxGroup = function () { + var groups = this.hash.project.objects['PBXGroup']; + var candidates = []; + for (var key in groups) { + if (!groups[key].path && !groups[key].name && groups[key].isa) { + candidates.push(groups[key]); + } + } + if (candidates.length == 1) { + return candidates[0]; + } + + return null; +} + +pbxProject.prototype.addPbxGroup = function (filePathsArray, name, path, sourceTree, opt) { + + var oldGroup = this.pbxGroupByName(name); + if (oldGroup) { + this.removePbxGroup(name, path); + } + var groups = this.hash.project.objects['PBXGroup'], - pbxGroupUuid = this.generateUuid(), + pbxGroupUuid = opt.uuid || this.generateUuid(), commentKey = f("%s_comment", pbxGroupUuid), pbxGroup = { isa: 'PBXGroup', children: [], name: name, - path: path, sourceTree: sourceTree ? sourceTree : '""' - }, + },//path is mandatory only for the main group fileReferenceSection = this.pbxFileReferenceSection(), filePathToReference = {}; @@ -527,12 +550,27 @@ pbxProject.prototype.addPbxGroup = function(filePathsArray, name, path, sourceTr continue; } - var file = new pbxFile(filePath); - file.uuid = this.generateUuid(); - file.fileRef = this.generateUuid(); - this.addToPbxFileReferenceSection(file); // PBXFileReference - this.addToPbxBuildFileSection(file); // PBXBuildFile - pbxGroup.children.push(pbxGroupChild(file)); + var srcRootPath = $path.dirname($path.dirname(this.filepath)); + var file = new pbxFile($path.relative(srcRootPath, filePath)); + if (fs.lstatSync(filePath).isDirectory()) { + file.uuid = this.generateUuid(); + file.fileRef = file.uuid; + this.addToPbxFileReferenceSection(file); // PBXFileReference + this.addToPbxBuildFileSection(file); + pbxGroup.children.push(pbxGroupChild(file)); + var files = fs.readdirSync(filePath).map(p => $path.join(filePath, p)); + this.addPbxGroup(files, $path.basename(filePath), filePath, null, {uuid: file.uuid}); + }else if (file.lastType.startsWith(SOURCE_CODE_FILE_TYPE_PREFIX)) { + file.uuid = this.generateUuid(); + file.fileRef = this.generateUuid(); + this.addToPbxFileReferenceSection(file); // PBXFileReference + this.addToPbxBuildFileSection(file); // PBXBuildFile + if (!file.lastType.endsWith(HEADER_FILE_TYPE_SUFFIX)) { + this.addToPbxSourcesBuildPhase(file); + } + pbxGroup.children.push(pbxGroupChild(file)); + } + } if (groups) { @@ -540,10 +578,36 @@ pbxProject.prototype.addPbxGroup = function(filePathsArray, name, path, sourceTr groups[commentKey] = name; } - return { uuid: pbxGroupUuid, pbxGroup: pbxGroup }; + if (opt.isMain) { + let mainGroup = this.findMainPbxGroup(); + if (mainGroup) { + var file = new pbxFile($path.relative(this.filepath, path)); + file.fileRef = pbxGroupUuid; + mainGroup.children.push(pbxGroupChild(file)); + } + } + + return {uuid: pbxGroupUuid, pbxGroup: pbxGroup}; } -pbxProject.prototype.removePbxGroup = function (groupName) { +pbxProject.prototype.removePbxGroup = function(groupName, path) { + var group = this.pbxGroupByName(groupName); + if (!group) { + return; + } + + var children = group.children; + + for(i in children) { + var file = new pbxFile($path.join(path, children[i].comment)); + file.fileRef = children[i].value; + file.uuid = file.fileRef; + this.removePbxGroup(children[i].comment, $path.join(path, children[i].comment)); + this.removeFromPbxFileReferenceSection(file); + this.removeFromPbxBuildFileSection(file); + this.removeFromPbxSourcesBuildPhase(file); + } + var section = this.hash.project.objects['PBXGroup'], key, itemKey; @@ -616,12 +680,12 @@ pbxProject.prototype.addToXcVersionGroupSection = function(file) { isa: 'XCVersionGroup', children: file.models.map(function (el) { return el.fileRef; }), currentVersion: file.currentModel.fileRef, - name: path.basename(file.path), + name: $path.basename(file.path), path: file.path, sourceTree: '""', versionGroupType: 'wrapper.xcdatamodel' }; - this.xcVersionGroupSection()[commentKey] = path.basename(file.path); + this.xcVersionGroupSection()[commentKey] = $path.basename(file.path); } } @@ -1416,7 +1480,7 @@ pbxProject.prototype.addTarget = function(name, type, subfolder) { isa: 'XCBuildConfiguration', buildSettings: { GCC_PREPROCESSOR_DEFINITIONS: ['"DEBUG=1"', '"$(inherited)"'], - INFOPLIST_FILE: '"' + path.join(targetSubfolder, targetSubfolder + '-Info.plist' + '"'), + INFOPLIST_FILE: '"' + $path.join(targetSubfolder, targetSubfolder + '-Info.plist' + '"'), LD_RUNPATH_SEARCH_PATHS: '"$(inherited) @executable_path/Frameworks @executable_path/../../Frameworks"', PRODUCT_NAME: '"' + targetName + '"', SKIP_INSTALL: 'YES' @@ -1426,7 +1490,7 @@ pbxProject.prototype.addTarget = function(name, type, subfolder) { name: 'Release', isa: 'XCBuildConfiguration', buildSettings: { - INFOPLIST_FILE: '"' + path.join(targetSubfolder, targetSubfolder + '-Info.plist' + '"'), + INFOPLIST_FILE: '"' + $path.join(targetSubfolder, targetSubfolder + '-Info.plist' + '"'), LD_RUNPATH_SEARCH_PATHS: '"$(inherited) @executable_path/Frameworks @executable_path/../../Frameworks"', PRODUCT_NAME: '"' + targetName + '"', SKIP_INSTALL: 'YES' @@ -1616,7 +1680,7 @@ function pbxBuildFileComment(file) { } function pbxFileReferenceComment(file) { - return file.basename || path.basename(file.path); + return file.basename || $path.basename(file.path); } function pbxNativeTargetComment(target) { @@ -1656,7 +1720,7 @@ function searchPathForFile(file, proj) { var plugins = proj.pbxGroupByName('Plugins'), pluginsPath = plugins ? plugins.path : null, - fileDir = path.dirname(file.path); + fileDir = $path.dirname(file.path); if (fileDir == '.') { fileDir = ''; @@ -2071,7 +2135,7 @@ pbxProject.prototype.addDataModelDocument = function(filePath, group, opt) { var modelFiles = fs.readdirSync(file.path); for (var index in modelFiles) { var modelFileName = modelFiles[index]; - var modelFilePath = path.join(filePath, modelFileName); + var modelFilePath = $path.join(filePath, modelFileName); if (modelFileName == '.xccurrentversion') { currentVersionName = plist.readFileSync(modelFilePath)._XCCurrentVersionName; From 176df7f785ea489adbc7ef7a03b702bb7f5260df Mon Sep 17 00:00:00 2001 From: Teodor Dermendzhiev Date: Tue, 22 May 2018 10:39:53 +0300 Subject: [PATCH 06/16] feat: add support for header search path deletion by string --- lib/pbxProject.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/pbxProject.js b/lib/pbxProject.js index 8e86b55..b3d203f 100644 --- a/lib/pbxProject.js +++ b/lib/pbxProject.js @@ -591,10 +591,10 @@ pbxProject.prototype.addPbxGroup = function (filePathsArray, name, path, sourceT } pbxProject.prototype.removePbxGroup = function(groupName, path) { - var group = this.pbxGroupByName(groupName); - if (!group) { - return; - } + var group = this.pbxGroupByName(groupName); + if (!group) { + return; + } var children = group.children; @@ -1310,7 +1310,7 @@ pbxProject.prototype.removeFromHeaderSearchPaths = function(file) { INHERITED = '"$(inherited)"', SEARCH_PATHS = 'HEADER_SEARCH_PATHS', config, buildSettings, searchPaths; - var new_path = searchPathForFile(file, this); + var new_path = typeof file === 'string' ? file : searchPathForFile(file, this); for (config in configurations) { buildSettings = configurations[config].buildSettings; From bb83017c1adb6d5d7ea778a922714d324a95f14e Mon Sep 17 00:00:00 2001 From: Teodor Dermendzhiev Date: Wed, 23 May 2018 16:05:45 +0300 Subject: [PATCH 07/16] bugfix: Remove group reference from root group after group removal --- lib/pbxFile.js | 2 +- lib/pbxProject.js | 9 ++++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/lib/pbxFile.js b/lib/pbxFile.js index 0a7611b..38ac741 100644 --- a/lib/pbxFile.js +++ b/lib/pbxFile.js @@ -204,7 +204,7 @@ function defaultGroup(fileRef) { function pbxFile(filepath, opt) { var opt = opt || {}; - this.basename = path.basename(filepath); + this.basename = opt.basename || path.basename(filepath); this.lastKnownFileType = opt.lastKnownFileType || detectType(filepath); this.group = detectGroup(this, opt); diff --git a/lib/pbxProject.js b/lib/pbxProject.js index b3d203f..75c7ca0 100644 --- a/lib/pbxProject.js +++ b/lib/pbxProject.js @@ -581,7 +581,7 @@ pbxProject.prototype.addPbxGroup = function (filePathsArray, name, path, sourceT if (opt.isMain) { let mainGroup = this.findMainPbxGroup(); if (mainGroup) { - var file = new pbxFile($path.relative(this.filepath, path)); + var file = new pbxFile($path.relative(this.filepath, path), {basename: name}); file.fileRef = pbxGroupUuid; mainGroup.children.push(pbxGroupChild(file)); } @@ -608,6 +608,13 @@ pbxProject.prototype.removePbxGroup = function(groupName, path) { this.removeFromPbxSourcesBuildPhase(file); } + var mainGroupChildren = this.findMainPbxGroup().children, i; + for(i in mainGroupChildren) { + if (mainGroupChildren[i].comment == name) { + mainGroupChildren.splice(i, 1); + } + } + var section = this.hash.project.objects['PBXGroup'], key, itemKey; From 490024f1f47771b756e3decf8606d53dfd6039dc Mon Sep 17 00:00:00 2001 From: Teodor Dermendzhiev Date: Wed, 23 May 2018 16:45:51 +0300 Subject: [PATCH 08/16] Bump version --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index b25fa48..70c4e53 100644 --- a/package.json +++ b/package.json @@ -2,8 +2,8 @@ "author": "Apache Software Foundation", "name": "xcode", "description": "parser for xcodeproj/project.pbxproj files", - "version": "2.0.1-dev", - "main": "index.js", + "main":"index.js", + "version": "1.5.0-NativeScript", "repository": { "url": "https://github.com/apache/cordova-node-xcode.git" }, From bfbef40b7317110b7cce18de145dd2878ad1b7c3 Mon Sep 17 00:00:00 2001 From: Martin Bektchiev Date: Fri, 25 May 2018 18:21:19 +0300 Subject: [PATCH 09/16] fix: Add C++ Source files to the Sources group They were wrongly being added to Resources. --- lib/pbxFile.js | 14 ++++++++++++-- lib/pbxProject.js | 15 +++++++-------- 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/lib/pbxFile.js b/lib/pbxFile.js index 38ac741..fa0fb68 100644 --- a/lib/pbxFile.js +++ b/lib/pbxFile.js @@ -22,7 +22,9 @@ var DEFAULT_SOURCETREE = '""', DEFAULT_PRODUCT_SOURCETREE = 'BUILT_PRODUCTS_DIR', DEFAULT_FILEENCODING = 4, DEFAULT_GROUP = 'Resources', - DEFAULT_FILETYPE = 'unknown'; + DEFAULT_FILETYPE = 'unknown', + HEADER_FILE_TYPE_SUFFIX = ".h", + SOURCE_CODE_FILE_TYPE_PREFIX = "sourcecode."; var FILETYPE_BY_EXTENSION = { a: 'archive.ar', @@ -99,6 +101,13 @@ var FILETYPE_BY_EXTENSION = { 'text.plist.strings': 4 }; +function isSourceOrHeaderFileType(fileType) { + return fileType.startsWith(SOURCE_CODE_FILE_TYPE_PREFIX); +} + +function isHeaderFileType(fileType) { + return fileType.endsWith(HEADER_FILE_TYPE_SUFFIX); +} function unquoted(text){ return text == null ? '' : text.replace (/(^")|("$)/g, '') @@ -250,5 +259,6 @@ function pbxFile(filepath, opt) { module.exports = { pbxFile: pbxFile, - fileTypes: fileTypes + isSourceOrHeaderFileType, + isHeaderFileType } diff --git a/lib/pbxProject.js b/lib/pbxProject.js index 75c7ca0..0519e31 100644 --- a/lib/pbxProject.js +++ b/lib/pbxProject.js @@ -23,14 +23,13 @@ var util = require('util'), fork = require('child_process').fork, pbxWriter = require('./pbxWriter'), pbxFile = require('./pbxFile').pbxFile, - pbxFileTypes = require('./pbxFile').fileTypes, + isSourceOrHeaderFileType = require('./pbxFile').isSourceOrHeaderFileType, + isHeaderFileType = require('./pbxFile').isHeaderFileType, fs = require('fs'), parser = require('./parser/pbxproj'), plist = require('simple-plist'), COMMENT_KEY = /_comment$/, - NO_SPECIAL_SYMBOLS = /^[a-zA-Z0-9_\.\$]+\.[a-zA-Z]+$/, - HEADER_FILE_TYPE_SUFFIX = ".h", - SOURCE_CODE_FILE_TYPE_PREFIX = "sourcecode."; + NO_SPECIAL_SYMBOLS = /^[a-zA-Z0-9_\.\$]+\.[a-zA-Z]+$/; function pbxProject(filename) { if (!(this instanceof pbxProject)) @@ -560,12 +559,12 @@ pbxProject.prototype.addPbxGroup = function (filePathsArray, name, path, sourceT pbxGroup.children.push(pbxGroupChild(file)); var files = fs.readdirSync(filePath).map(p => $path.join(filePath, p)); this.addPbxGroup(files, $path.basename(filePath), filePath, null, {uuid: file.uuid}); - }else if (file.lastType.startsWith(SOURCE_CODE_FILE_TYPE_PREFIX)) { + }else if (isSourceOrHeaderFileType(file.lastType)) { file.uuid = this.generateUuid(); file.fileRef = this.generateUuid(); this.addToPbxFileReferenceSection(file); // PBXFileReference this.addToPbxBuildFileSection(file); // PBXBuildFile - if (!file.lastType.endsWith(HEADER_FILE_TYPE_SUFFIX)) { + if (!isHeaderFileType(file.lastType)) { this.addToPbxSourcesBuildPhase(file); } pbxGroup.children.push(pbxGroupChild(file)); @@ -1605,11 +1604,11 @@ function pbxFileReferenceObj(file) { fileObject.name = fileObject.name.replace(/\"/g, "\\\""); fileObject.path = fileObject.path.replace(/\"/g, "\\\""); } - + if(!file.basename.match(NO_SPECIAL_SYMBOLS)) { fileObject.name = "\"" + fileObject.name + "\""; } - + if(!file.path.match(NO_SPECIAL_SYMBOLS)) { fileObject.path = "\"" + fileObject.path + "\""; } From 81e03fbea06dede91e224969547968438dc96c63 Mon Sep 17 00:00:00 2001 From: Martin Bektchiev Date: Fri, 25 May 2018 18:21:46 +0300 Subject: [PATCH 10/16] chore: Bump version to 1.5.1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 70c4e53..4fc384d 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,7 @@ "name": "xcode", "description": "parser for xcodeproj/project.pbxproj files", "main":"index.js", - "version": "1.5.0-NativeScript", + "version": "1.5.1-NativeScript", "repository": { "url": "https://github.com/apache/cordova-node-xcode.git" }, From 71f488cbb2a2ea03cfe83a6b0c98e0a427397279 Mon Sep 17 00:00:00 2001 From: fatme Date: Wed, 4 Jul 2018 16:44:31 +0300 Subject: [PATCH 11/16] Fix file references inside .pbxproject --- lib/pbxProject.js | 41 ++++++++++++++++++++++++++--------------- 1 file changed, 26 insertions(+), 15 deletions(-) diff --git a/lib/pbxProject.js b/lib/pbxProject.js index 0519e31..b4afce1 100644 --- a/lib/pbxProject.js +++ b/lib/pbxProject.js @@ -1303,11 +1303,7 @@ pbxProject.prototype.addToLibrarySearchPaths = function(file) { buildSettings['LIBRARY_SEARCH_PATHS'] = [INHERITED]; } - if (typeof file === 'string') { - buildSettings['LIBRARY_SEARCH_PATHS'].push(file); - } else { - buildSettings['LIBRARY_SEARCH_PATHS'].push(searchPathForFile(file, this)); - } + buildSettings['LIBRARY_SEARCH_PATHS'].push(searchPathForFile(file, this)); } } @@ -1316,7 +1312,7 @@ pbxProject.prototype.removeFromHeaderSearchPaths = function(file) { INHERITED = '"$(inherited)"', SEARCH_PATHS = 'HEADER_SEARCH_PATHS', config, buildSettings, searchPaths; - var new_path = typeof file === 'string' ? file : searchPathForFile(file, this); + var new_path = searchPathForFile(file, this); for (config in configurations) { buildSettings = configurations[config].buildSettings; @@ -1351,11 +1347,7 @@ pbxProject.prototype.addToHeaderSearchPaths = function(file) { buildSettings['HEADER_SEARCH_PATHS'] = [INHERITED]; } - if (typeof file === 'string') { - buildSettings['HEADER_SEARCH_PATHS'].push(file); - } else { - buildSettings['HEADER_SEARCH_PATHS'].push(searchPathForFile(file, this)); - } + buildSettings['HEADER_SEARCH_PATHS'].push(searchPathForFile(file, this)); } } @@ -1720,8 +1712,27 @@ function correctForPath(file, project, group) { } function searchPathForFile(file, proj) { + const getPathString = (filePath) => { + return `"\\"${filePath}\\""`; + } + + const getRelativePathString = (filePath) => { + return getPathString(`$(SRCROOT)/${filePath}`); + } + + if (typeof file === 'string') { + const relativeFilePath = file; + + if ($path.isAbsolute(file)) { + const srcRoot = $path.dirname($path.dirname(proj.filepath)); + relativeFilePath = $path.relative(srcRoot, file); + } + + return getRelativePathString(relativeFilePath); + } + if (file.relativePath) { - return '"\$(SRCROOT)/' + file.relativePath + '\"'; + return getRelativePathString(file.relativePath); } var plugins = proj.pbxGroupByName('Plugins'), @@ -1735,11 +1746,11 @@ function searchPathForFile(file, proj) { } if (file.plugin && pluginsPath) { - return '"\\"$(SRCROOT)/' + unquote(pluginsPath) + '\\""'; + return getRelativePathString(unquote(pluginsPath)); } else if (file.customFramework && file.dirname) { - return '"\\"' + file.dirname + '\\""'; + return getPathString(file.dirname); } else { - return '"\\"$(SRCROOT)/' + proj.productName + fileDir + '\\""'; + return getRelativePathString(proj.productName + fileDir); } } From c947e417bc65a2443aec2a9080cce54b602da3f0 Mon Sep 17 00:00:00 2001 From: Fatme Date: Thu, 5 Jul 2018 12:46:35 +0300 Subject: [PATCH 12/16] Update version to 1.5.2 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 4fc384d..2398b84 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,7 @@ "name": "xcode", "description": "parser for xcodeproj/project.pbxproj files", "main":"index.js", - "version": "1.5.1-NativeScript", + "version": "1.5.2-NativeScript", "repository": { "url": "https://github.com/apache/cordova-node-xcode.git" }, From 18fb3908ebf367197210fd970d4a10d9e4d84992 Mon Sep 17 00:00:00 2001 From: Fatme Date: Fri, 6 Jul 2018 09:54:33 +0300 Subject: [PATCH 13/16] Fix "Assignment to constant variable." error --- lib/pbxProject.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/pbxProject.js b/lib/pbxProject.js index b4afce1..255f652 100644 --- a/lib/pbxProject.js +++ b/lib/pbxProject.js @@ -1721,7 +1721,7 @@ function searchPathForFile(file, proj) { } if (typeof file === 'string') { - const relativeFilePath = file; + let relativeFilePath = file; if ($path.isAbsolute(file)) { const srcRoot = $path.dirname($path.dirname(proj.filepath)); From e2a7eee517856185c14af3e923deed6598d4c5db Mon Sep 17 00:00:00 2001 From: "Kristian D. Dimitrov" Date: Thu, 31 Jan 2019 14:27:43 +0200 Subject: [PATCH 14/16] fix: unit tests --- lib/pbxProject.js | 32 +++++++++++++++++++--------- test/BuildSettings.js | 2 +- test/FrameworkSearchPaths.js | 2 +- test/HeaderSearchPaths.js | 2 +- test/LibrarySearchPaths.js | 2 +- test/OtherLinkerFlags.js | 2 +- test/addFramework.js | 4 ++-- test/addHeaderFile.js | 6 +++--- test/addRemovePbxGroup.js | 1 - test/addResourceFile.js | 6 +++--- test/addSourceFile.js | 6 +++--- test/addStaticLibrary.js | 6 +++--- test/addToPbxFileReferenceSection.js | 6 +++--- test/dataModelDocument.js | 2 +- test/group.js | 2 +- test/multipleTargets.js | 2 +- test/pbxFile.js | 2 +- test/pbxProject.js | 15 ++++++++----- test/removeFramework.js | 2 +- test/removeHeaderFile.js | 6 +++--- test/removeResourceFile.js | 4 ++-- test/removeSourceFile.js | 3 ++- test/xcode5searchPaths.js | 2 +- 23 files changed, 67 insertions(+), 50 deletions(-) diff --git a/lib/pbxProject.js b/lib/pbxProject.js index 255f652..deed2d0 100644 --- a/lib/pbxProject.js +++ b/lib/pbxProject.js @@ -510,7 +510,7 @@ pbxProject.prototype.findMainPbxGroup = function () { } pbxProject.prototype.addPbxGroup = function (filePathsArray, name, path, sourceTree, opt) { - + opt = opt || {}; var oldGroup = this.pbxGroupByName(name); if (oldGroup) { this.removePbxGroup(name, path); @@ -523,6 +523,7 @@ pbxProject.prototype.addPbxGroup = function (filePathsArray, name, path, sourceT isa: 'PBXGroup', children: [], name: name, + path: path, sourceTree: sourceTree ? sourceTree : '""' },//path is mandatory only for the main group fileReferenceSection = this.pbxFileReferenceSection(), @@ -551,7 +552,7 @@ pbxProject.prototype.addPbxGroup = function (filePathsArray, name, path, sourceT var srcRootPath = $path.dirname($path.dirname(this.filepath)); var file = new pbxFile($path.relative(srcRootPath, filePath)); - if (fs.lstatSync(filePath).isDirectory()) { + if (fs.existsSync(filePath) && fs.lstatSync(filePath).isDirectory()) { file.uuid = this.generateUuid(); file.fileRef = file.uuid; this.addToPbxFileReferenceSection(file); // PBXFileReference @@ -559,15 +560,21 @@ pbxProject.prototype.addPbxGroup = function (filePathsArray, name, path, sourceT pbxGroup.children.push(pbxGroupChild(file)); var files = fs.readdirSync(filePath).map(p => $path.join(filePath, p)); this.addPbxGroup(files, $path.basename(filePath), filePath, null, {uuid: file.uuid}); - }else if (isSourceOrHeaderFileType(file.lastType)) { + } else if (isSourceOrHeaderFileType(file.lastKnownFileType)) { file.uuid = this.generateUuid(); file.fileRef = this.generateUuid(); this.addToPbxFileReferenceSection(file); // PBXFileReference this.addToPbxBuildFileSection(file); // PBXBuildFile - if (!isHeaderFileType(file.lastType)) { + if (!isHeaderFileType(file.lastKnownFileType)) { this.addToPbxSourcesBuildPhase(file); } pbxGroup.children.push(pbxGroupChild(file)); + } else { + file.uuid = this.generateUuid(); + file.fileRef = this.generateUuid(); + this.addToPbxFileReferenceSection(file); // PBXFileReference + this.addToPbxBuildFileSection(file); + pbxGroup.children.push(pbxGroupChild(file)); } } @@ -594,6 +601,8 @@ pbxProject.prototype.removePbxGroup = function(groupName, path) { if (!group) { return; } + + path = path || $path.dirname(this.filepath); var children = group.children; @@ -607,10 +616,13 @@ pbxProject.prototype.removePbxGroup = function(groupName, path) { this.removeFromPbxSourcesBuildPhase(file); } - var mainGroupChildren = this.findMainPbxGroup().children, i; - for(i in mainGroupChildren) { - if (mainGroupChildren[i].comment == name) { - mainGroupChildren.splice(i, 1); + var mainGroup = this.findMainPbxGroup(); + if(mainGroup) { + var mainGroupChildren = this.findMainPbxGroup().children, i; + for(i in mainGroupChildren) { + if (mainGroupChildren[i].comment == name) { + mainGroupChildren.splice(i, 1); + } } } @@ -1592,12 +1604,12 @@ function pbxFileReferenceObj(file) { includeInIndex: file.includeInIndex }; - if(fileObject.name.indexOf("\"") !== -1) { + if(fileObject.name && fileObject.name.indexOf("\"") !== -1) { fileObject.name = fileObject.name.replace(/\"/g, "\\\""); fileObject.path = fileObject.path.replace(/\"/g, "\\\""); } - if(!file.basename.match(NO_SPECIAL_SYMBOLS)) { + if(file.basename && !file.basename.match(NO_SPECIAL_SYMBOLS)) { fileObject.name = "\"" + fileObject.name + "\""; } diff --git a/test/BuildSettings.js b/test/BuildSettings.js index 213f575..698ce06 100644 --- a/test/BuildSettings.js +++ b/test/BuildSettings.js @@ -18,7 +18,7 @@ var fullProject = require('./fixtures/full-project') fullProjectStr = JSON.stringify(fullProject), pbx = require('../lib/pbxProject'), - pbxFile = require('../lib/pbxFile'), + pbxFile = require('../lib/pbxFile').pbxFile, proj = new pbx('.'); function cleanHash() { diff --git a/test/FrameworkSearchPaths.js b/test/FrameworkSearchPaths.js index b709f3a..d6fb0ce 100644 --- a/test/FrameworkSearchPaths.js +++ b/test/FrameworkSearchPaths.js @@ -18,7 +18,7 @@ var fullProject = require('./fixtures/full-project') fullProjectStr = JSON.stringify(fullProject), pbx = require('../lib/pbxProject'), - pbxFile = require('../lib/pbxFile'), + pbxFile = require('../lib/pbxFile').pbxFile, proj = new pbx('.'); var pbxFile = { diff --git a/test/HeaderSearchPaths.js b/test/HeaderSearchPaths.js index 998fd8b..1377384 100644 --- a/test/HeaderSearchPaths.js +++ b/test/HeaderSearchPaths.js @@ -18,7 +18,7 @@ var fullProject = require('./fixtures/full-project') fullProjectStr = JSON.stringify(fullProject), pbx = require('../lib/pbxProject'), - pbxFile = require('../lib/pbxFile'), + pbxFile = require('../lib/pbxFile').pbxFile, proj = new pbx('.'); function cleanHash() { diff --git a/test/LibrarySearchPaths.js b/test/LibrarySearchPaths.js index 6788e10..5b1461b 100644 --- a/test/LibrarySearchPaths.js +++ b/test/LibrarySearchPaths.js @@ -18,7 +18,7 @@ var fullProject = require('./fixtures/full-project') fullProjectStr = JSON.stringify(fullProject), pbx = require('../lib/pbxProject'), - pbxFile = require('../lib/pbxFile'), + pbxFile = require('../lib/pbxFile').pbxFile, proj = new pbx('.'); function cleanHash() { diff --git a/test/OtherLinkerFlags.js b/test/OtherLinkerFlags.js index de59f4c..f77ea8f 100644 --- a/test/OtherLinkerFlags.js +++ b/test/OtherLinkerFlags.js @@ -18,7 +18,7 @@ var fullProject = require('./fixtures/full-project') fullProjectStr = JSON.stringify(fullProject), pbx = require('../lib/pbxProject'), - pbxFile = require('../lib/pbxFile'), + pbxFile = require('../lib/pbxFile').pbxFile, proj = new pbx('.'); function cleanHash() { diff --git a/test/addFramework.js b/test/addFramework.js index c3c3200..11358ef 100644 --- a/test/addFramework.js +++ b/test/addFramework.js @@ -18,7 +18,7 @@ var fullProject = require('./fixtures/full-project') fullProjectStr = JSON.stringify(fullProject), pbx = require('../lib/pbxProject'), - pbxFile = require('../lib/pbxFile'), + pbxFile = require('../lib/pbxFile').pbxFile, proj = new pbx('.'); function cleanHash() { @@ -98,7 +98,7 @@ exports.addFramework = { test.equal(fileRefEntry.isa, 'PBXFileReference'); test.equal(fileRefEntry.lastKnownFileType, 'compiled.mach-o.dylib'); - test.equal(fileRefEntry.name, '"libsqlite3.dylib"'); + test.equal(fileRefEntry.name, 'libsqlite3.dylib'); test.equal(fileRefEntry.path, '"usr/lib/libsqlite3.dylib"'); test.equal(fileRefEntry.sourceTree, 'SDKROOT'); diff --git a/test/addHeaderFile.js b/test/addHeaderFile.js index f9bd71a..f96a736 100644 --- a/test/addHeaderFile.js +++ b/test/addHeaderFile.js @@ -18,7 +18,7 @@ var fullProject = require('./fixtures/full-project') fullProjectStr = JSON.stringify(fullProject), pbx = require('../lib/pbxProject'), - pbxFile = require('../lib/pbxFile'), + pbxFile = require('../lib/pbxFile').pbxFile, proj = new pbx('.'); function cleanHash() { @@ -70,8 +70,8 @@ exports.addHeaderFile = { test.equal(fileRefEntry.isa, 'PBXFileReference'); test.equal(fileRefEntry.fileEncoding, 4); test.equal(fileRefEntry.lastKnownFileType, 'sourcecode.c.h'); - test.equal(fileRefEntry.name, '"file.h"'); - test.equal(fileRefEntry.path, '"file.h"'); + test.equal(fileRefEntry.name, 'file.h'); + test.equal(fileRefEntry.path, 'file.h'); test.equal(fileRefEntry.sourceTree, '""'); test.done(); diff --git a/test/addRemovePbxGroup.js b/test/addRemovePbxGroup.js index 8212f91..74006da 100644 --- a/test/addRemovePbxGroup.js +++ b/test/addRemovePbxGroup.js @@ -169,7 +169,6 @@ exports.addRemovePbxGroup = { proj.removePbxGroup(groupName); var pbxGroupInPbx = proj.pbxGroupByName(groupName); - console.log(pbxGroupInPbx); test.ok(!pbxGroupInPbx); test.done() diff --git a/test/addResourceFile.js b/test/addResourceFile.js index 36afdb2..04b6013 100644 --- a/test/addResourceFile.js +++ b/test/addResourceFile.js @@ -18,7 +18,7 @@ var fullProject = require('./fixtures/full-project') fullProjectStr = JSON.stringify(fullProject), pbx = require('../lib/pbxProject'), - pbxFile = require('../lib/pbxFile'), + pbxFile = require('../lib/pbxFile').pbxFile, proj = new pbx('.'); function cleanHash() { @@ -108,7 +108,7 @@ exports.addResourceFile = { test.equal(fileRefEntry.isa, 'PBXFileReference'); test.equal(fileRefEntry.fileEncoding, undefined); test.equal(fileRefEntry.lastKnownFileType, 'wrapper.plug-in'); - test.equal(fileRefEntry.name, '"assets.bundle"'); + test.equal(fileRefEntry.name, 'assets.bundle'); test.equal(fileRefEntry.path, '"Resources/assets.bundle"'); test.equal(fileRefEntry.sourceTree, '""'); @@ -169,7 +169,7 @@ exports.addResourceFile = { test.equal(fileRefEntry.isa, 'PBXFileReference'); test.equal(fileRefEntry.fileEncoding, undefined); test.equal(fileRefEntry.lastKnownFileType, 'wrapper.plug-in'); - test.equal(fileRefEntry.name, '"assets.bundle"'); + test.equal(fileRefEntry.name, 'assets.bundle'); test.equal(fileRefEntry.path, '"Plugins/assets.bundle"'); test.equal(fileRefEntry.sourceTree, '""'); test.done(); diff --git a/test/addSourceFile.js b/test/addSourceFile.js index d614d62..fd5352b 100644 --- a/test/addSourceFile.js +++ b/test/addSourceFile.js @@ -18,7 +18,7 @@ var fullProject = require('./fixtures/full-project') fullProjectStr = JSON.stringify(fullProject), pbx = require('../lib/pbxProject'), - pbxFile = require('../lib/pbxFile'), + pbxFile = require('../lib/pbxFile').pbxFile, proj = new pbx('.'); function cleanHash() { @@ -106,8 +106,8 @@ exports.addSourceFile = { test.equal(fileRefEntry.isa, 'PBXFileReference'); test.equal(fileRefEntry.fileEncoding, 4); test.equal(fileRefEntry.lastKnownFileType, 'sourcecode.c.objc'); - test.equal(fileRefEntry.name, '"file.m"'); - test.equal(fileRefEntry.path, '"file.m"'); + test.equal(fileRefEntry.name, 'file.m'); + test.equal(fileRefEntry.path, 'file.m'); test.equal(fileRefEntry.sourceTree, '""'); test.done(); diff --git a/test/addStaticLibrary.js b/test/addStaticLibrary.js index d1b0ec6..9b48546 100644 --- a/test/addStaticLibrary.js +++ b/test/addStaticLibrary.js @@ -18,7 +18,7 @@ var fullProject = require('./fixtures/full-project') fullProjectStr = JSON.stringify(fullProject), pbx = require('../lib/pbxProject'), - pbxFile = require('../lib/pbxFile'), + pbxFile = require('../lib/pbxFile').pbxFile, proj = new pbx('.'); function cleanHash() { @@ -140,8 +140,8 @@ exports.addStaticLibrary = { test.equal(fileRefEntry.isa, 'PBXFileReference'); test.equal(fileRefEntry.lastKnownFileType, 'archive.ar'); - test.equal(fileRefEntry.name, '"libGoogleAnalytics.a"'); - test.equal(fileRefEntry.path, '"libGoogleAnalytics.a"'); + test.equal(fileRefEntry.name, 'libGoogleAnalytics.a'); + test.equal(fileRefEntry.path, 'libGoogleAnalytics.a'); test.equal(fileRefEntry.sourceTree, '""'); test.done(); diff --git a/test/addToPbxFileReferenceSection.js b/test/addToPbxFileReferenceSection.js index d69abbc..da5f440 100644 --- a/test/addToPbxFileReferenceSection.js +++ b/test/addToPbxFileReferenceSection.js @@ -18,7 +18,7 @@ var jsonProject = require('./fixtures/full-project') fullProjectStr = JSON.stringify(jsonProject), pbx = require('../lib/pbxProject'), - pbxFile = require('../lib/pbxFile'), + pbxFile = require('../lib/pbxFile').pbxFile, myProj = new pbx('.'); function cleanHash() { @@ -39,8 +39,8 @@ exports['addToPbxFileReferenceSection function'] = { test.equal(myProj.pbxFileReferenceSection()[file.fileRef].isa, 'PBXFileReference'); test.equal(myProj.pbxFileReferenceSection()[file.fileRef].lastKnownFileType, 'sourcecode.c.objc'); - test.equal(myProj.pbxFileReferenceSection()[file.fileRef].name, '"file.m"'); - test.equal(myProj.pbxFileReferenceSection()[file.fileRef].path, '"file.m"'); + test.equal(myProj.pbxFileReferenceSection()[file.fileRef].name, 'file.m'); + test.equal(myProj.pbxFileReferenceSection()[file.fileRef].path, 'file.m'); test.equal(myProj.pbxFileReferenceSection()[file.fileRef].sourceTree, '""'); test.equal(myProj.pbxFileReferenceSection()[file.fileRef].fileEncoding, 4); test.equal(myProj.pbxFileReferenceSection()[file.fileRef + "_comment"], 'file.m'); diff --git a/test/dataModelDocument.js b/test/dataModelDocument.js index 76477ed..c809d62 100644 --- a/test/dataModelDocument.js +++ b/test/dataModelDocument.js @@ -19,7 +19,7 @@ var jsonProject = require('./fixtures/full-project') fullProjectStr = JSON.stringify(jsonProject), path = require('path'), pbx = require('../lib/pbxProject'), - pbxFile = require('../lib/pbxFile'), + pbxFile = require('../lib/pbxFile').pbxFile, proj = new pbx('.'), singleDataModelFilePath = __dirname + '/fixtures/single-data-model.xcdatamodeld', multipleDataModelFilePath = __dirname + '/fixtures/multiple-data-model.xcdatamodeld'; diff --git a/test/group.js b/test/group.js index af2454e..5072aa1 100644 --- a/test/group.js +++ b/test/group.js @@ -16,7 +16,7 @@ */ var pbx = require('../lib/pbxProject'), - pbxFile = require('../lib/pbxFile'), + pbxFile = require('../lib/pbxFile').pbxFile, project, projectHash; diff --git a/test/multipleTargets.js b/test/multipleTargets.js index dbb945f..dc4c419 100644 --- a/test/multipleTargets.js +++ b/test/multipleTargets.js @@ -18,7 +18,7 @@ var fullProject = require('./fixtures/multiple-targets') fullProjectStr = JSON.stringify(fullProject), pbx = require('../lib/pbxProject'), - pbxFile = require('../lib/pbxFile'), + pbxFile = require('../lib/pbxFile').pbxFile, proj = new pbx('.'); function cleanHash() { diff --git a/test/pbxFile.js b/test/pbxFile.js index 4f0d1a2..f096120 100644 --- a/test/pbxFile.js +++ b/test/pbxFile.js @@ -15,7 +15,7 @@ under the License. */ -var pbxFile = require('../lib/pbxFile'); +var pbxFile = require('../lib/pbxFile').pbxFile; exports['lastKnownFileType'] = { 'should detect that a .m path means sourcecode.c.objc': function (test) { diff --git a/test/pbxProject.js b/test/pbxProject.js index 176f836..e846294 100644 --- a/test/pbxProject.js +++ b/test/pbxProject.js @@ -18,9 +18,14 @@ var pbx = require('../lib/pbxProject'), buildConfig = require('./fixtures/buildFiles'), jsonProject = require('./fixtures/full-project'), + fullProjectStr = JSON.stringify(jsonProject), fs = require('fs'), project; + function getCleanHash() { + return JSON.parse(fullProjectStr); + } + exports['creation'] = { 'should create a pbxProject with the new operator': function (test) { var myProj = new pbx('test/parser/projects/hash.pbxproj'); @@ -332,7 +337,7 @@ exports['hasFile'] = { exports['addToPbxFileReferenceSection'] = { 'should not quote name when no special characters present in basename': function (test) { var newProj = new pbx('.'); - newProj.hash = jsonProject, + newProj.hash = getCleanHash(), file = { uuid: newProj.generateUuid(), fileRef: newProj.generateUuid(), @@ -351,7 +356,7 @@ exports['addToPbxFileReferenceSection'] = { }, 'should quote name when special characters present in basename': function (test) { var newProj = new pbx('.'); - newProj.hash = jsonProject, + newProj.hash = getCleanHash(), file = { uuid: newProj.generateUuid(), fileRef: newProj.generateUuid(), @@ -370,7 +375,7 @@ exports['addToPbxFileReferenceSection'] = { }, 'should not quote path when no special characters present in path': function (test) { var newProj = new pbx('.'); - newProj.hash = jsonProject, + newProj.hash = getCleanHash(), file = { uuid: newProj.generateUuid(), fileRef: newProj.generateUuid(), @@ -389,7 +394,7 @@ exports['addToPbxFileReferenceSection'] = { }, 'should quote path when special characters present in path': function (test) { var newProj = new pbx('.'); - newProj.hash = jsonProject, + newProj.hash = getCleanHash(), file = { uuid: newProj.generateUuid(), fileRef: newProj.generateUuid(), @@ -408,7 +413,7 @@ exports['addToPbxFileReferenceSection'] = { }, 'should quote path and name when special characters present in path and basename': function (test) { var newProj = new pbx('.'); - newProj.hash = jsonProject, + newProj.hash = getCleanHash(), file = { uuid: newProj.generateUuid(), fileRef: newProj.generateUuid(), diff --git a/test/removeFramework.js b/test/removeFramework.js index 20cdbde..15312d4 100644 --- a/test/removeFramework.js +++ b/test/removeFramework.js @@ -18,7 +18,7 @@ var fullProject = require('./fixtures/full-project'), fullProjectStr = JSON.stringify(fullProject), pbx = require('../lib/pbxProject'), - pbxFile = require('../lib/pbxFile'), + pbxFile = require('../lib/pbxFile').pbxFile, proj = new pbx('.'); function cleanHash() { diff --git a/test/removeHeaderFile.js b/test/removeHeaderFile.js index acda161..973533a 100644 --- a/test/removeHeaderFile.js +++ b/test/removeHeaderFile.js @@ -18,7 +18,7 @@ var fullProject = require('./fixtures/full-project') fullProjectStr = JSON.stringify(fullProject), pbx = require('../lib/pbxProject'), - pbxFile = require('../lib/pbxFile'), + pbxFile = require('../lib/pbxFile').pbxFile, proj = new pbx('.'); function cleanHash() { @@ -94,8 +94,8 @@ exports.removeHeaderFile = { test.equal(fileRefEntry.isa, 'PBXFileReference'); test.equal(fileRefEntry.fileEncoding, 4); test.equal(fileRefEntry.lastKnownFileType, 'sourcecode.c.h'); - test.equal(fileRefEntry.name, '"file.h"'); - test.equal(fileRefEntry.path, '"file.h"'); + test.equal(fileRefEntry.name, 'file.h'); + test.equal(fileRefEntry.path, 'file.h'); test.equal(fileRefEntry.sourceTree, '""'); var deletedFile = proj.removeHeaderFile('Plugins/file.h'), diff --git a/test/removeResourceFile.js b/test/removeResourceFile.js index bda48f9..ca7bb94 100644 --- a/test/removeResourceFile.js +++ b/test/removeResourceFile.js @@ -18,7 +18,7 @@ var fullProject = require('./fixtures/full-project') fullProjectStr = JSON.stringify(fullProject), pbx = require('../lib/pbxProject'), - pbxFile = require('../lib/pbxFile'), + pbxFile = require('../lib/pbxFile').pbxFile, proj = new pbx('.'); function cleanHash() { @@ -158,7 +158,7 @@ exports.removeResourceFile = { test.equal(fileRefEntry.isa, 'PBXFileReference'); test.equal(fileRefEntry.fileEncoding, undefined); test.equal(fileRefEntry.lastKnownFileType, 'wrapper.plug-in'); - test.equal(fileRefEntry.name, '"assets.bundle"'); + test.equal(fileRefEntry.name, 'assets.bundle'); test.equal(fileRefEntry.path, '"Resources/assets.bundle"'); test.equal(fileRefEntry.sourceTree, '""'); diff --git a/test/removeSourceFile.js b/test/removeSourceFile.js index de7895e..df9f2e7 100644 --- a/test/removeSourceFile.js +++ b/test/removeSourceFile.js @@ -18,7 +18,7 @@ var fullProject = require('./fixtures/full-project') fullProjectStr = JSON.stringify(fullProject), pbx = require('../lib/pbxProject'), - pbxFile = require('../lib/pbxFile'), + pbxFile = require('../lib/pbxFile').pbxFile, proj = new pbx('.'); function cleanHash() { @@ -83,6 +83,7 @@ exports.removeSourceFile = { test.done(); }, 'should remove 2 fields from the PBXFileReference section': function (test) { + debugger proj.addSourceFile('file.m'); var newFile = proj.removeSourceFile('file.m'), fileRefSection = proj.pbxFileReferenceSection(), diff --git a/test/xcode5searchPaths.js b/test/xcode5searchPaths.js index 7cdf46c..61014cb 100644 --- a/test/xcode5searchPaths.js +++ b/test/xcode5searchPaths.js @@ -18,7 +18,7 @@ var xcode5proj = require('./fixtures/library-search-paths') xcode5projStr = JSON.stringify(xcode5proj), pbx = require('../lib/pbxProject'), - pbxFile = require('../lib/pbxFile'), + pbxFile = require('../lib/pbxFile').pbxFile, proj = new pbx('.'), libPoop = { path: 'some/path/poop.a' }; From d607e87e1cef91dbce0e6f3f06a0e076aeaa16d6 Mon Sep 17 00:00:00 2001 From: "Kristian D. Dimitrov" Date: Wed, 27 Feb 2019 17:54:41 +0200 Subject: [PATCH 15/16] fix: add and remove pbxGroup --- lib/pbxProject.js | 12 ++++++++---- .../with_omit_empty_values_disabled_expected.pbxproj | 2 +- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/lib/pbxProject.js b/lib/pbxProject.js index deed2d0..d854289 100644 --- a/lib/pbxProject.js +++ b/lib/pbxProject.js @@ -523,12 +523,16 @@ pbxProject.prototype.addPbxGroup = function (filePathsArray, name, path, sourceT isa: 'PBXGroup', children: [], name: name, - path: path, sourceTree: sourceTree ? sourceTree : '""' - },//path is mandatory only for the main group + }, fileReferenceSection = this.pbxFileReferenceSection(), filePathToReference = {}; + //path is mandatory only for the main group + if(!opt.filesRelativeToProject) { + pbxGroup.path = path; + } + for (var key in fileReferenceSection) { // only look for comments if (!COMMENT_KEY.test(key)) continue; @@ -602,7 +606,7 @@ pbxProject.prototype.removePbxGroup = function(groupName, path) { return; } - path = path || $path.dirname(this.filepath); + path = path || ""; var children = group.children; @@ -620,7 +624,7 @@ pbxProject.prototype.removePbxGroup = function(groupName, path) { if(mainGroup) { var mainGroupChildren = this.findMainPbxGroup().children, i; for(i in mainGroupChildren) { - if (mainGroupChildren[i].comment == name) { + if (mainGroupChildren[i].comment == groupName) { mainGroupChildren.splice(i, 1); } } diff --git a/test/parser/projects/expected/with_omit_empty_values_disabled_expected.pbxproj b/test/parser/projects/expected/with_omit_empty_values_disabled_expected.pbxproj index da46b23..b143630 100644 --- a/test/parser/projects/expected/with_omit_empty_values_disabled_expected.pbxproj +++ b/test/parser/projects/expected/with_omit_empty_values_disabled_expected.pbxproj @@ -260,8 +260,8 @@ children = ( ); name = CustomGroup; - path = undefined; sourceTree = ""; + path = undefined; }; /* End PBXGroup section */ From f85f635fa5579e21efb31d06d102d3cff9d4398c Mon Sep 17 00:00:00 2001 From: "Kristian D. Dimitrov" Date: Thu, 28 Feb 2019 16:49:44 +0200 Subject: [PATCH 16/16] fix: addPbxGroup nested folders with relative path --- lib/pbxProject.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/pbxProject.js b/lib/pbxProject.js index d854289..793c01c 100644 --- a/lib/pbxProject.js +++ b/lib/pbxProject.js @@ -555,7 +555,8 @@ pbxProject.prototype.addPbxGroup = function (filePathsArray, name, path, sourceT } var srcRootPath = $path.dirname($path.dirname(this.filepath)); - var file = new pbxFile($path.relative(srcRootPath, filePath)); + var relativePath = $path.relative(srcRootPath, filePath); + var file = new pbxFile(opt.filesRelativeToProject ? relativePath : filePath); if (fs.existsSync(filePath) && fs.lstatSync(filePath).isDirectory()) { file.uuid = this.generateUuid(); file.fileRef = file.uuid; @@ -563,7 +564,7 @@ pbxProject.prototype.addPbxGroup = function (filePathsArray, name, path, sourceT this.addToPbxBuildFileSection(file); pbxGroup.children.push(pbxGroupChild(file)); var files = fs.readdirSync(filePath).map(p => $path.join(filePath, p)); - this.addPbxGroup(files, $path.basename(filePath), filePath, null, {uuid: file.uuid}); + this.addPbxGroup(files, $path.basename(filePath), filePath, null, {uuid: file.uuid, filesRelativeToProject: opt.filesRelativeToProject}); } else if (isSourceOrHeaderFileType(file.lastKnownFileType)) { file.uuid = this.generateUuid(); file.fileRef = this.generateUuid();