diff --git a/lib/pbxFile.js b/lib/pbxFile.js index 9553bfb..fa0fb68 100644 --- a/lib/pbxFile.js +++ b/lib/pbxFile.js @@ -22,22 +22,35 @@ 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', 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', pch: 'sourcecode.c.h', plist: 'text.plist.xml', + png: "image.png", sh: 'text.script.sh', swift: 'sourcecode.swift', tbd: 'sourcecode.text-based-dylib-definition', @@ -56,8 +69,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/', @@ -72,7 +88,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, @@ -81,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, '') @@ -186,7 +213,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); @@ -230,4 +257,8 @@ function pbxFile(filepath, opt) { } } -module.exports = pbxFile; +module.exports = { + pbxFile: pbxFile, + isSourceOrHeaderFileType, + isHeaderFileType +} diff --git a/lib/pbxProject.js b/lib/pbxProject.js index 0e0f8f9..793c01c 100644 --- a/lib/pbxProject.js +++ b/lib/pbxProject.js @@ -18,21 +18,24 @@ 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, + isSourceOrHeaderFileType = require('./pbxFile').isSourceOrHeaderFileType, + isHeaderFileType = require('./pbxFile').isHeaderFileType, 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)) return new pbxProject(filename); - this.filepath = path.resolve(filename) + this.filepath = $path.resolve(filename) } util.inherits(pbxProject, EventEmitter) @@ -491,20 +494,45 @@ 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) { + opt = 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 : '""' }, 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; @@ -526,12 +554,34 @@ 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 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; + 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, filesRelativeToProject: opt.filesRelativeToProject}); + } else if (isSourceOrHeaderFileType(file.lastKnownFileType)) { + file.uuid = this.generateUuid(); + file.fileRef = this.generateUuid(); + this.addToPbxFileReferenceSection(file); // PBXFileReference + this.addToPbxBuildFileSection(file); // PBXBuildFile + 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)); + } + } if (groups) { @@ -539,10 +589,48 @@ 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), {basename: name}); + 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; + } + + path = path || ""; + + 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 mainGroup = this.findMainPbxGroup(); + if(mainGroup) { + var mainGroupChildren = this.findMainPbxGroup().children, i; + for(i in mainGroupChildren) { + if (mainGroupChildren[i].comment == groupName) { + mainGroupChildren.splice(i, 1); + } + } + } + var section = this.hash.project.objects['PBXGroup'], key, itemKey; @@ -615,12 +703,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); } } @@ -1232,11 +1320,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)); } } @@ -1245,7 +1329,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 = searchPathForFile(file, this); for (config in configurations) { buildSettings = configurations[config].buildSettings; @@ -1280,11 +1364,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)); } } @@ -1415,7 +1495,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' @@ -1425,7 +1505,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' @@ -1520,8 +1600,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 +1609,19 @@ function pbxFileReferenceObj(file) { includeInIndex: file.includeInIndex }; + if(fileObject.name && fileObject.name.indexOf("\"") !== -1) { + fileObject.name = fileObject.name.replace(/\"/g, "\\\""); + fileObject.path = fileObject.path.replace(/\"/g, "\\\""); + } + + if(file.basename && !file.basename.match(NO_SPECIAL_SYMBOLS)) { + fileObject.name = "\"" + fileObject.name + "\""; + } + + if(!file.path.match(NO_SPECIAL_SYMBOLS)) { + fileObject.path = "\"" + fileObject.path + "\""; + } + return fileObject; } @@ -1602,7 +1695,7 @@ function pbxBuildFileComment(file) { } function pbxFileReferenceComment(file) { - return file.basename || path.basename(file.path); + return file.basename || $path.basename(file.path); } function pbxNativeTargetComment(target) { @@ -1636,9 +1729,32 @@ 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') { + let 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 getRelativePathString(file.relativePath); + } + var plugins = proj.pbxGroupByName('Plugins'), pluginsPath = plugins ? plugins.path : null, - fileDir = path.dirname(file.path); + fileDir = $path.dirname(file.path); if (fileDir == '.') { fileDir = ''; @@ -1647,11 +1763,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); } } @@ -2053,7 +2169,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; diff --git a/package.json b/package.json index b25fa48..2398b84 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.2-NativeScript", "repository": { "url": "https://github.com/apache/cordova-node-xcode.git" }, 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/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 */ 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 c076b96..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'); @@ -328,3 +333,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 = getCleanHash(), + 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 = getCleanHash(), + 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 = getCleanHash(), + 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 = getCleanHash(), + 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 = getCleanHash(), + 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(); + } +} + 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' };