diff --git a/.eslintrc.yml b/.eslintrc.yml new file mode 100644 index 0000000..469f6b2 --- /dev/null +++ b/.eslintrc.yml @@ -0,0 +1,30 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +root: true +extends: '@cordova/eslint-config/node' + +# This will ignore the parser that is generated by pegjs +ignorePatterns: ['lib/parser/'] + +rules: + new-cap: off + +overrides: + - files: [test/**/*.js] + rules: + handle-callback-err: off diff --git a/index.js b/index.js index 4fe8416..a590364 100644 --- a/index.js +++ b/index.js @@ -15,4 +15,4 @@ under the License. */ -exports.project = require('./lib/pbxProject') +exports.project = require('./lib/pbxProject'); diff --git a/lib/parseJob.js b/lib/parseJob.js index 4e34eb2..e3d9260 100644 --- a/lib/parseJob.js +++ b/lib/parseJob.js @@ -17,10 +17,12 @@ // parsing is slow and blocking right now // so we do it in a separate process -var fs = require('fs'), - parser = require('./parser/pbxproj'), - path = process.argv[2], - fileContents, obj; +var fs = require('fs'); + +var parser = require('./parser/pbxproj'); +var path = process.argv[2]; +var fileContents; +var obj; try { fileContents = fs.readFileSync(path, 'utf-8'); diff --git a/lib/pbxFile.js b/lib/pbxFile.js index 9553bfb..d926be2 100644 --- a/lib/pbxFile.js +++ b/lib/pbxFile.js @@ -15,80 +15,81 @@ under the License. */ -var path = require('path'), - util = require('util'); +var path = require('path'); -var DEFAULT_SOURCETREE = '""', - DEFAULT_PRODUCT_SOURCETREE = 'BUILT_PRODUCTS_DIR', - DEFAULT_FILEENCODING = 4, - DEFAULT_GROUP = 'Resources', - DEFAULT_FILETYPE = 'unknown'; +var util = require('util'); +var DEFAULT_SOURCETREE = '""'; +var DEFAULT_PRODUCT_SOURCETREE = 'BUILT_PRODUCTS_DIR'; +var DEFAULT_GROUP = 'Resources'; +var DEFAULT_FILETYPE = 'unknown'; var FILETYPE_BY_EXTENSION = { - a: 'archive.ar', - app: 'wrapper.application', - appex: 'wrapper.app-extension', - bundle: 'wrapper.plug-in', - dylib: 'compiled.mach-o.dylib', - framework: 'wrapper.framework', - h: 'sourcecode.c.h', - m: 'sourcecode.c.objc', - markdown: 'text', - mdimporter: 'wrapper.cfbundle', - octest: 'wrapper.cfbundle', - pch: 'sourcecode.c.h', - plist: 'text.plist.xml', - sh: 'text.script.sh', - swift: 'sourcecode.swift', - tbd: 'sourcecode.text-based-dylib-definition', - xcassets: 'folder.assetcatalog', - xcconfig: 'text.xcconfig', - xcdatamodel: 'wrapper.xcdatamodel', - xcodeproj: 'wrapper.pb-project', - xctest: 'wrapper.cfbundle', - xib: 'file.xib', - strings: 'text.plist.strings' - }, - GROUP_BY_FILETYPE = { - 'archive.ar': 'Frameworks', - 'compiled.mach-o.dylib': 'Frameworks', - 'sourcecode.text-based-dylib-definition': 'Frameworks', - 'wrapper.framework': 'Frameworks', - 'embedded.framework': 'Embed Frameworks', - 'sourcecode.c.h': 'Resources', - 'sourcecode.c.objc': 'Sources', - 'sourcecode.swift': 'Sources' - }, - PATH_BY_FILETYPE = { - 'compiled.mach-o.dylib': 'usr/lib/', - 'sourcecode.text-based-dylib-definition': 'usr/lib/', - 'wrapper.framework': 'System/Library/Frameworks/' - }, - SOURCETREE_BY_FILETYPE = { - 'compiled.mach-o.dylib': 'SDKROOT', - 'sourcecode.text-based-dylib-definition': 'SDKROOT', - 'wrapper.framework': 'SDKROOT' - }, - ENCODING_BY_FILETYPE = { - 'sourcecode.c.h': 4, - 'sourcecode.c.h': 4, - 'sourcecode.c.objc': 4, - 'sourcecode.swift': 4, - 'text': 4, - 'text.plist.xml': 4, - 'text.script.sh': 4, - 'text.xcconfig': 4, - 'text.plist.strings': 4 - }; - - -function unquoted(text){ - return text == null ? '' : text.replace (/(^")|("$)/g, '') + a: 'archive.ar', + app: 'wrapper.application', + appex: 'wrapper.app-extension', + bundle: 'wrapper.plug-in', + dylib: 'compiled.mach-o.dylib', + framework: 'wrapper.framework', + h: 'sourcecode.c.h', + m: 'sourcecode.c.objc', + markdown: 'text', + mdimporter: 'wrapper.cfbundle', + octest: 'wrapper.cfbundle', + pch: 'sourcecode.c.h', + plist: 'text.plist.xml', + sh: 'text.script.sh', + swift: 'sourcecode.swift', + tbd: 'sourcecode.text-based-dylib-definition', + xcassets: 'folder.assetcatalog', + xcconfig: 'text.xcconfig', + xcdatamodel: 'wrapper.xcdatamodel', + xcodeproj: 'wrapper.pb-project', + xctest: 'wrapper.cfbundle', + xib: 'file.xib', + strings: 'text.plist.strings' +}; + +var GROUP_BY_FILETYPE = { + 'archive.ar': 'Frameworks', + 'compiled.mach-o.dylib': 'Frameworks', + 'sourcecode.text-based-dylib-definition': 'Frameworks', + 'wrapper.framework': 'Frameworks', + 'embedded.framework': 'Embed Frameworks', + 'sourcecode.c.h': 'Resources', + 'sourcecode.c.objc': 'Sources', + 'sourcecode.swift': 'Sources' +}; + +var PATH_BY_FILETYPE = { + 'compiled.mach-o.dylib': 'usr/lib/', + 'sourcecode.text-based-dylib-definition': 'usr/lib/', + 'wrapper.framework': 'System/Library/Frameworks/' +}; + +var SOURCETREE_BY_FILETYPE = { + 'compiled.mach-o.dylib': 'SDKROOT', + 'sourcecode.text-based-dylib-definition': 'SDKROOT', + 'wrapper.framework': 'SDKROOT' +}; + +var ENCODING_BY_FILETYPE = { + 'sourcecode.c.h': 4, + 'sourcecode.c.objc': 4, + 'sourcecode.swift': 4, + text: 4, + 'text.plist.xml': 4, + 'text.script.sh': 4, + 'text.xcconfig': 4, + 'text.plist.strings': 4 +}; + +function unquoted (text) { + return text === null ? '' : text.replace(/(^")|("$)/g, ''); } -function detectType(filePath) { - var extension = path.extname(filePath).substring(1), - filetype = FILETYPE_BY_EXTENSION[unquoted(extension)]; +function detectType (filePath) { + var extension = path.extname(filePath).substring(1); + var filetype = FILETYPE_BY_EXTENSION[unquoted(extension)]; if (!filetype) { return DEFAULT_FILETYPE; @@ -97,31 +98,30 @@ function detectType(filePath) { return filetype; } -function defaultExtension(fileRef) { - var filetype = fileRef.lastKnownFileType && fileRef.lastKnownFileType != DEFAULT_FILETYPE ? - fileRef.lastKnownFileType : fileRef.explicitFileType; +function defaultExtension (fileRef) { + var filetype = fileRef.lastKnownFileType && fileRef.lastKnownFileType !== DEFAULT_FILETYPE + ? fileRef.lastKnownFileType : fileRef.explicitFileType; - for(var extension in FILETYPE_BY_EXTENSION) { - if(FILETYPE_BY_EXTENSION.hasOwnProperty(unquoted(extension)) ) { - if(FILETYPE_BY_EXTENSION[unquoted(extension)] === unquoted(filetype) ) - return extension; + for (var extension in FILETYPE_BY_EXTENSION) { + if (Object.prototype.hasOwnProperty.call(FILETYPE_BY_EXTENSION, unquoted(extension))) { + if (FILETYPE_BY_EXTENSION[unquoted(extension)] === unquoted(filetype)) { return extension; } } } } -function defaultEncoding(fileRef) { - var filetype = fileRef.lastKnownFileType || fileRef.explicitFileType, - encoding = ENCODING_BY_FILETYPE[unquoted(filetype)]; +function defaultEncoding (fileRef) { + var filetype = fileRef.lastKnownFileType || fileRef.explicitFileType; + var encoding = ENCODING_BY_FILETYPE[unquoted(filetype)]; if (encoding) { return encoding; } } -function detectGroup(fileRef, opt) { - var extension = path.extname(fileRef.basename).substring(1), - filetype = fileRef.lastKnownFileType || fileRef.explicitFileType, - groupName = GROUP_BY_FILETYPE[unquoted(filetype)]; +function detectGroup (fileRef, opt) { + var extension = path.extname(fileRef.basename).substring(1); + var filetype = fileRef.lastKnownFileType || fileRef.explicitFileType; + var groupName = GROUP_BY_FILETYPE[unquoted(filetype)]; if (extension === 'xcdatamodeld') { return 'Sources'; @@ -138,10 +138,9 @@ function detectGroup(fileRef, opt) { return groupName; } -function detectSourcetree(fileRef) { - - var filetype = fileRef.lastKnownFileType || fileRef.explicitFileType, - sourcetree = SOURCETREE_BY_FILETYPE[unquoted(filetype)]; +function detectSourcetree (fileRef) { + var filetype = fileRef.lastKnownFileType || fileRef.explicitFileType; + var sourcetree = SOURCETREE_BY_FILETYPE[unquoted(filetype)]; if (fileRef.explicitFileType) { return DEFAULT_PRODUCT_SOURCETREE; @@ -158,9 +157,9 @@ function detectSourcetree(fileRef) { return sourcetree; } -function defaultPath(fileRef, filePath) { - var filetype = fileRef.lastKnownFileType || fileRef.explicitFileType, - defaultPath = PATH_BY_FILETYPE[unquoted(filetype)]; +function defaultPath (fileRef, filePath) { + var filetype = fileRef.lastKnownFileType || fileRef.explicitFileType; + var defaultPath = PATH_BY_FILETYPE[unquoted(filetype)]; if (fileRef.customFramework) { return filePath; @@ -173,25 +172,15 @@ function defaultPath(fileRef, filePath) { return filePath; } -function defaultGroup(fileRef) { - var groupName = GROUP_BY_FILETYPE[fileRef.lastKnownFileType]; - - if (!groupName) { - return DEFAULT_GROUP; - } - - return defaultGroup; -} - -function pbxFile(filepath, opt) { - var opt = opt || {}; +function pbxFile (filepath, opt) { + opt = opt || {}; this.basename = path.basename(filepath); this.lastKnownFileType = opt.lastKnownFileType || detectType(filepath); this.group = detectGroup(this, opt); // for custom frameworks - if (opt.customFramework == true) { + if (opt.customFramework === true) { this.customFramework = true; this.dirname = path.dirname(filepath).replace(/\\/g, '/'); } @@ -212,21 +201,17 @@ function pbxFile(filepath, opt) { this.sourceTree = opt.sourceTree || detectSourcetree(this); this.includeInIndex = 0; - if (opt.weak && opt.weak === true) - this.settings = { ATTRIBUTES: ['Weak'] }; + if (opt.weak && opt.weak === true) { this.settings = { ATTRIBUTES: ['Weak'] }; } if (opt.compilerFlags) { - if (!this.settings) - this.settings = {}; + if (!this.settings) { this.settings = {}; } this.settings.COMPILER_FLAGS = util.format('"%s"', opt.compilerFlags); } if (opt.embed && opt.sign) { - if (!this.settings) - this.settings = {}; - if (!this.settings.ATTRIBUTES) - this.settings.ATTRIBUTES = []; - this.settings.ATTRIBUTES.push('CodeSignOnCopy'); + if (!this.settings) { this.settings = {}; } + if (!this.settings.ATTRIBUTES) { this.settings.ATTRIBUTES = []; } + this.settings.ATTRIBUTES.push('CodeSignOnCopy'); } } diff --git a/lib/pbxProject.js b/lib/pbxProject.js index 3097678..5913e04 100644 --- a/lib/pbxProject.js +++ b/lib/pbxProject.js @@ -15,37 +15,37 @@ under the License. */ -var util = require('util'), - f = util.format, - EventEmitter = require('events').EventEmitter, - path = require('path'), - uuid = require('uuid'), - fork = require('child_process').fork, - pbxWriter = require('./pbxWriter'), - pbxFile = require('./pbxFile'), - fs = require('fs'), - parser = require('./parser/pbxproj'), - plist = require('simple-plist'), - COMMENT_KEY = /_comment$/ - -function pbxProject(filename) { - if (!(this instanceof pbxProject)) - return new pbxProject(filename); - - this.filepath = path.resolve(filename) +var util = require('util'); + +var f = util.format; +var EventEmitter = require('events').EventEmitter; +var path = require('path'); +var uuid = require('uuid'); +var fork = require('child_process').fork; +var pbxWriter = require('./pbxWriter'); +var pbxFile = require('./pbxFile'); +var fs = require('fs'); +var parser = require('./parser/pbxproj'); +var plist = require('simple-plist'); +var COMMENT_KEY = /_comment$/; + +function pbxProject (filename) { + if (!(this instanceof pbxProject)) { return new pbxProject(filename); } + + this.filepath = path.resolve(filename); } -util.inherits(pbxProject, EventEmitter) +util.inherits(pbxProject, EventEmitter); -pbxProject.prototype.parse = function(cb) { - var worker = fork(__dirname + '/parseJob.js', [this.filepath]) +pbxProject.prototype.parse = function (cb) { + var worker = fork(path.join(`${__dirname}/parseJob.js`), [this.filepath]); - worker.on('message', function(msg) { - if (msg.name == 'SyntaxError' || msg.code) { + worker.on('message', function (msg) { + if (msg.name === 'SyntaxError' || msg.code) { this.emit('error', msg); } else { this.hash = msg; - this.emit('end', null, msg) + this.emit('end', null, msg); } }.bind(this)); @@ -55,51 +55,51 @@ pbxProject.prototype.parse = function(cb) { } return this; -} +}; -pbxProject.prototype.parseSync = function() { +pbxProject.prototype.parseSync = function () { var file_contents = fs.readFileSync(this.filepath, 'utf-8'); this.hash = parser.parse(file_contents); return this; -} +}; -pbxProject.prototype.writeSync = function(options) { +pbxProject.prototype.writeSync = function (options) { this.writer = new pbxWriter(this.hash, options); return this.writer.writeSync(); -} +}; -pbxProject.prototype.allUuids = function() { - var sections = this.hash.project.objects, - uuids = [], - section; +pbxProject.prototype.allUuids = function () { + var sections = this.hash.project.objects; + var uuids = []; + var section; - for (key in sections) { - section = sections[key] - uuids = uuids.concat(Object.keys(section)) + for (var key in sections) { + section = sections[key]; + uuids = uuids.concat(Object.keys(section)); } - uuids = uuids.filter(function(str) { - return !COMMENT_KEY.test(str) && str.length == 24; + uuids = uuids.filter(function (str) { + return !COMMENT_KEY.test(str) && str.length === 24; }); return uuids; -} +}; -pbxProject.prototype.generateUuid = function() { +pbxProject.prototype.generateUuid = function () { var id = uuid.v4() .replace(/-/g, '') .substr(0, 24) - .toUpperCase() + .toUpperCase(); if (this.allUuids().indexOf(id) >= 0) { return this.generateUuid(); } else { return id; } -} +}; -pbxProject.prototype.addPluginFile = function(path, opt) { +pbxProject.prototype.addPluginFile = function (path, opt) { var file = new pbxFile(path, opt); file.plugin = true; // durr @@ -110,23 +110,23 @@ pbxProject.prototype.addPluginFile = function(path, opt) { file.fileRef = this.generateUuid(); - this.addToPbxFileReferenceSection(file); // PBXFileReference - this.addToPluginsPbxGroup(file); // PBXGroup + this.addToPbxFileReferenceSection(file); // PBXFileReference + this.addToPluginsPbxGroup(file); // PBXGroup return file; -} +}; -pbxProject.prototype.removePluginFile = function(path, opt) { +pbxProject.prototype.removePluginFile = function (path, opt) { var file = new pbxFile(path, opt); correctForPluginsPath(file, this); - this.removeFromPbxFileReferenceSection(file); // PBXFileReference - this.removeFromPluginsPbxGroup(file); // PBXGroup + this.removeFromPbxFileReferenceSection(file); // PBXFileReference + this.removeFromPluginsPbxGroup(file); // PBXGroup return file; -} +}; -pbxProject.prototype.addProductFile = function(targetPath, opt) { +pbxProject.prototype.addProductFile = function (targetPath, opt) { var file = new pbxFile(targetPath, opt); file.includeInIndex = 0; @@ -137,18 +137,18 @@ pbxProject.prototype.addProductFile = function(targetPath, opt) { file.path = file.basename; this.addToPbxFileReferenceSection(file); - this.addToProductsPbxGroup(file); // PBXGroup + this.addToProductsPbxGroup(file); // PBXGroup return file; -} +}; -pbxProject.prototype.removeProductFile = function(path, opt) { +pbxProject.prototype.removeProductFile = function (path, opt) { var file = new pbxFile(path, opt); - this.removeFromProductsPbxGroup(file); // PBXGroup + this.removeFromProductsPbxGroup(file); // PBXGroup return file; -} +}; /** * @@ -161,8 +161,7 @@ pbxProject.prototype.addSourceFile = function (path, opt, group) { var file; if (group) { file = this.addFile(path, group, opt); - } - else { + } else { file = this.addPluginFile(path, opt); } @@ -171,11 +170,11 @@ pbxProject.prototype.addSourceFile = function (path, opt, group) { file.target = opt ? opt.target : undefined; file.uuid = this.generateUuid(); - this.addToPbxBuildFileSection(file); // PBXBuildFile - this.addToPbxSourcesBuildPhase(file); // PBXSourcesBuildPhase + this.addToPbxBuildFileSection(file); // PBXBuildFile + this.addToPbxSourcesBuildPhase(file); // PBXSourcesBuildPhase return file; -} +}; /** * @@ -188,16 +187,15 @@ pbxProject.prototype.removeSourceFile = function (path, opt, group) { var file; if (group) { file = this.removeFile(path, group, opt); - } - else { + } else { file = this.removePluginFile(path, opt); } file.target = opt ? opt.target : undefined; - this.removeFromPbxBuildFileSection(file); // PBXBuildFile - this.removeFromPbxSourcesBuildPhase(file); // PBXSourcesBuildPhase + this.removeFromPbxBuildFileSection(file); // PBXBuildFile + this.removeFromPbxSourcesBuildPhase(file); // PBXSourcesBuildPhase return file; -} +}; /** * @@ -209,11 +207,10 @@ pbxProject.prototype.removeSourceFile = function (path, opt, group) { pbxProject.prototype.addHeaderFile = function (path, opt, group) { if (group) { return this.addFile(path, group, opt); - } - else { + } else { return this.addPluginFile(path, opt); } -} +}; /** * @@ -225,11 +222,10 @@ pbxProject.prototype.addHeaderFile = function (path, opt, group) { pbxProject.prototype.removeHeaderFile = function (path, opt, group) { if (group) { return this.removeFile(path, group, opt); - } - else { + } else { return this.removePluginFile(path, opt); } -} +}; /** * @@ -238,7 +234,7 @@ pbxProject.prototype.removeHeaderFile = function (path, opt, group) { * @param group {String} group key * @returns {Object} file; see pbxFile */ -pbxProject.prototype.addResourceFile = function(path, opt, group) { +pbxProject.prototype.addResourceFile = function (path, opt, group) { opt = opt || {}; var file; @@ -260,28 +256,25 @@ pbxProject.prototype.addResourceFile = function(path, opt, group) { } if (!opt.variantGroup) { - this.addToPbxBuildFileSection(file); // PBXBuildFile - this.addToPbxResourcesBuildPhase(file); // PBXResourcesBuildPhase + this.addToPbxBuildFileSection(file); // PBXBuildFile + this.addToPbxResourcesBuildPhase(file); // PBXResourcesBuildPhase } if (!opt.plugin) { - this.addToPbxFileReferenceSection(file); // PBXFileReference + this.addToPbxFileReferenceSection(file); // PBXFileReference if (group) { if (this.getPBXGroupByKey(group)) { - this.addToPbxGroup(file, group); //Group other than Resources (i.e. 'splash') - } - else if (this.getPBXVariantGroupByKey(group)) { - this.addToPbxVariantGroup(file, group); // PBXVariantGroup + this.addToPbxGroup(file, group); // Group other than Resources (i.e. 'splash') + } else if (this.getPBXVariantGroupByKey(group)) { + this.addToPbxVariantGroup(file, group); // PBXVariantGroup } + } else { + this.addToResourcesPbxGroup(file); // PBXGroup } - else { - this.addToResourcesPbxGroup(file); // PBXGroup - } - } return file; -} +}; /** * @@ -290,37 +283,35 @@ pbxProject.prototype.addResourceFile = function(path, opt, group) { * @param group {String} group key * @returns {Object} file; see pbxFile */ -pbxProject.prototype.removeResourceFile = function(path, opt, group) { +pbxProject.prototype.removeResourceFile = function (path, opt, group) { var file = new pbxFile(path, opt); file.target = opt ? opt.target : undefined; correctForResourcesPath(file, this); - this.removeFromPbxBuildFileSection(file); // PBXBuildFile - this.removeFromPbxFileReferenceSection(file); // PBXFileReference + this.removeFromPbxBuildFileSection(file); // PBXBuildFile + this.removeFromPbxFileReferenceSection(file); // PBXFileReference if (group) { if (this.getPBXGroupByKey(group)) { - this.removeFromPbxGroup(file, group); //Group other than Resources (i.e. 'splash') - } - else if (this.getPBXVariantGroupByKey(group)) { - this.removeFromPbxVariantGroup(file, group); // PBXVariantGroup + this.removeFromPbxGroup(file, group); // Group other than Resources (i.e. 'splash') + } else if (this.getPBXVariantGroupByKey(group)) { + this.removeFromPbxVariantGroup(file, group); // PBXVariantGroup } + } else { + this.removeFromResourcesPbxGroup(file); // PBXGroup } - else { - this.removeFromResourcesPbxGroup(file); // PBXGroup - } - this.removeFromPbxResourcesBuildPhase(file); // PBXResourcesBuildPhase + this.removeFromPbxResourcesBuildPhase(file); // PBXResourcesBuildPhase return file; -} +}; -pbxProject.prototype.addFramework = function(fpath, opt) { - var customFramework = opt && opt.customFramework == true; - var link = !opt || (opt.link == undefined || opt.link); //defaults to true if not specified - var embed = opt && opt.embed; //defaults to false if not specified +pbxProject.prototype.addFramework = function (fpath, opt) { + var customFramework = opt && opt.customFramework === true; + var link = !opt || (opt.link === undefined || opt.link); // defaults to true if not specified + var embed = opt && opt.embed; // defaults to false if not specified if (opt) { - delete opt.embed; + delete opt.embed; } var file = new pbxFile(fpath, opt); @@ -331,50 +322,48 @@ pbxProject.prototype.addFramework = function(fpath, opt) { if (this.hasFile(file.path)) return false; - this.addToPbxBuildFileSection(file); // PBXBuildFile - this.addToPbxFileReferenceSection(file); // PBXFileReference - this.addToFrameworksPbxGroup(file); // PBXGroup + this.addToPbxBuildFileSection(file); // PBXBuildFile + this.addToPbxFileReferenceSection(file); // PBXFileReference + this.addToFrameworksPbxGroup(file); // PBXGroup if (link) { - this.addToPbxFrameworksBuildPhase(file); // PBXFrameworksBuildPhase + this.addToPbxFrameworksBuildPhase(file); // PBXFrameworksBuildPhase } if (customFramework) { this.addToFrameworkSearchPaths(file); if (embed) { - opt.embed = embed; - var embeddedFile = new pbxFile(fpath, opt); + opt.embed = embed; + var embeddedFile = new pbxFile(fpath, opt); - embeddedFile.uuid = this.generateUuid(); - embeddedFile.fileRef = file.fileRef; + embeddedFile.uuid = this.generateUuid(); + embeddedFile.fileRef = file.fileRef; - //keeping a separate PBXBuildFile entry for Embed Frameworks - this.addToPbxBuildFileSection(embeddedFile); // PBXBuildFile + // keeping a separate PBXBuildFile entry for Embed Frameworks + this.addToPbxBuildFileSection(embeddedFile); // PBXBuildFile - this.addToPbxEmbedFrameworksBuildPhase(embeddedFile); // PBXCopyFilesBuildPhase + this.addToPbxEmbedFrameworksBuildPhase(embeddedFile); // PBXCopyFilesBuildPhase - return embeddedFile; + return embeddedFile; } } return file; -} - -pbxProject.prototype.removeFramework = function(fpath, opt) { - var embed = opt && opt.embed; +}; +pbxProject.prototype.removeFramework = function (fpath, opt) { if (opt) { - delete opt.embed; + delete opt.embed; } var file = new pbxFile(fpath, opt); file.target = opt ? opt.target : undefined; - this.removeFromPbxBuildFileSection(file); // PBXBuildFile - this.removeFromPbxFileReferenceSection(file); // PBXFileReference - this.removeFromFrameworksPbxGroup(file); // PBXGroup - this.removeFromPbxFrameworksBuildPhase(file); // PBXFrameworksBuildPhase + this.removeFromPbxBuildFileSection(file); // PBXBuildFile + this.removeFromPbxFileReferenceSection(file); // PBXFileReference + this.removeFromFrameworksPbxGroup(file); // PBXGroup + this.removeFromPbxFrameworksBuildPhase(file); // PBXFrameworksBuildPhase if (opt && opt.customFramework) { this.removeFromFrameworkSearchPaths(file); @@ -386,14 +375,13 @@ pbxProject.prototype.removeFramework = function(fpath, opt) { embeddedFile.fileRef = file.fileRef; - this.removeFromPbxBuildFileSection(embeddedFile); // PBXBuildFile + this.removeFromPbxBuildFileSection(embeddedFile); // PBXBuildFile this.removeFromPbxEmbedFrameworksBuildPhase(embeddedFile); // PBXCopyFilesBuildPhase return file; -} - +}; -pbxProject.prototype.addCopyfile = function(fpath, opt) { +pbxProject.prototype.addCopyfile = function (fpath, opt) { var file = new pbxFile(fpath, opt); // catch duplicates @@ -404,44 +392,44 @@ pbxProject.prototype.addCopyfile = function(fpath, opt) { file.fileRef = file.uuid = this.generateUuid(); file.target = opt ? opt.target : undefined; - this.addToPbxBuildFileSection(file); // PBXBuildFile - this.addToPbxFileReferenceSection(file); // PBXFileReference - this.addToPbxCopyfilesBuildPhase(file); // PBXCopyFilesBuildPhase + this.addToPbxBuildFileSection(file); // PBXBuildFile + this.addToPbxFileReferenceSection(file); // PBXFileReference + this.addToPbxCopyfilesBuildPhase(file); // PBXCopyFilesBuildPhase return file; -} +}; -pbxProject.prototype.pbxCopyfilesBuildPhaseObj = function(target) { +pbxProject.prototype.pbxCopyfilesBuildPhaseObj = function (target) { return this.buildPhaseObject('PBXCopyFilesBuildPhase', 'Copy Files', target); -} +}; -pbxProject.prototype.addToPbxCopyfilesBuildPhase = function(file) { +pbxProject.prototype.addToPbxCopyfilesBuildPhase = function (file) { var sources = this.buildPhaseObject('PBXCopyFilesBuildPhase', 'Copy Files', file.target); sources.files.push(pbxBuildPhaseObj(file)); -} +}; -pbxProject.prototype.removeCopyfile = function(fpath, opt) { +pbxProject.prototype.removeCopyfile = function (fpath, opt) { var file = new pbxFile(fpath, opt); file.target = opt ? opt.target : undefined; - this.removeFromPbxBuildFileSection(file); // PBXBuildFile - this.removeFromPbxFileReferenceSection(file); // PBXFileReference - this.removeFromPbxCopyfilesBuildPhase(file); // PBXFrameworksBuildPhase + this.removeFromPbxBuildFileSection(file); // PBXBuildFile + this.removeFromPbxFileReferenceSection(file); // PBXFileReference + this.removeFromPbxCopyfilesBuildPhase(file); // PBXFrameworksBuildPhase return file; -} +}; -pbxProject.prototype.removeFromPbxCopyfilesBuildPhase = function(file) { +pbxProject.prototype.removeFromPbxCopyfilesBuildPhase = function (file) { var sources = this.pbxCopyfilesBuildPhaseObj(file.target); - for (i in sources.files) { - if (sources.files[i].comment == longComment(file)) { + for (var i in sources.files) { + if (sources.files[i].comment === longComment(file)) { sources.files.splice(i, 1); break; } } -} +}; -pbxProject.prototype.addStaticLibrary = function(path, opt) { +pbxProject.prototype.addStaticLibrary = function (path, opt) { opt = opt || {}; var file; @@ -459,65 +447,67 @@ pbxProject.prototype.addStaticLibrary = function(path, opt) { if (!opt.plugin) { file.fileRef = this.generateUuid(); - this.addToPbxFileReferenceSection(file); // PBXFileReference + this.addToPbxFileReferenceSection(file); // PBXFileReference } - this.addToPbxBuildFileSection(file); // PBXBuildFile - this.addToPbxFrameworksBuildPhase(file); // PBXFrameworksBuildPhase - this.addToLibrarySearchPaths(file); // make sure it gets built! + this.addToPbxBuildFileSection(file); // PBXBuildFile + this.addToPbxFrameworksBuildPhase(file); // PBXFrameworksBuildPhase + this.addToLibrarySearchPaths(file); // make sure it gets built! return file; -} +}; // helper addition functions -pbxProject.prototype.addToPbxBuildFileSection = function(file) { - var commentKey = f("%s_comment", file.uuid); +pbxProject.prototype.addToPbxBuildFileSection = function (file) { + var commentKey = f('%s_comment', file.uuid); this.pbxBuildFileSection()[file.uuid] = pbxBuildFileObj(file); this.pbxBuildFileSection()[commentKey] = pbxBuildFileComment(file); -} +}; -pbxProject.prototype.removeFromPbxBuildFileSection = function(file) { +pbxProject.prototype.removeFromPbxBuildFileSection = function (file) { var uuid; for (uuid in this.pbxBuildFileSection()) { - if (this.pbxBuildFileSection()[uuid].fileRef_comment == file.basename) { + if (this.pbxBuildFileSection()[uuid].fileRef_comment === file.basename) { file.uuid = uuid; delete this.pbxBuildFileSection()[uuid]; - var commentKey = f("%s_comment", uuid); + var commentKey = f('%s_comment', uuid); delete this.pbxBuildFileSection()[commentKey]; } } -} +}; -pbxProject.prototype.addPbxGroup = function(filePathsArray, name, path, sourceTree) { - var groups = this.hash.project.objects['PBXGroup'], - pbxGroupUuid = this.generateUuid(), - commentKey = f("%s_comment", pbxGroupUuid), - pbxGroup = { - isa: 'PBXGroup', - children: [], - name: name, - path: path, - sourceTree: sourceTree ? sourceTree : '""' - }, - fileReferenceSection = this.pbxFileReferenceSection(), - filePathToReference = {}; +pbxProject.prototype.addPbxGroup = function (filePathsArray, name, path, sourceTree) { + var groups = this.hash.project.objects.PBXGroup; + var pbxGroupUuid = this.generateUuid(); + var commentKey = f('%s_comment', pbxGroupUuid); + + var pbxGroup = { + isa: 'PBXGroup', + children: [], + name: name, + path: path, + sourceTree: sourceTree || '""' + }; + + var fileReferenceSection = this.pbxFileReferenceSection(); + var filePathToReference = {}; for (var key in fileReferenceSection) { // only look for comments if (!COMMENT_KEY.test(key)) continue; - var fileReferenceKey = key.split(COMMENT_KEY)[0], - fileReference = fileReferenceSection[fileReferenceKey]; + var fileReferenceKey = key.split(COMMENT_KEY)[0]; + var fileReference = fileReferenceSection[fileReferenceKey]; filePathToReference[fileReference.path] = { fileRef: fileReferenceKey, basename: fileReferenceSection[key] }; } for (var index = 0; index < filePathsArray.length; index++) { - var filePath = filePathsArray[index], - filePathQuoted = "\"" + filePath + "\""; + var filePath = filePathsArray[index]; + var filePathQuoted = '"' + filePath + '"'; if (filePathToReference[filePath]) { pbxGroup.children.push(pbxGroupChild(filePathToReference[filePath])); continue; @@ -529,8 +519,8 @@ pbxProject.prototype.addPbxGroup = function(filePathsArray, name, path, sourceTr var file = new pbxFile(filePath); file.uuid = this.generateUuid(); file.fileRef = this.generateUuid(); - this.addToPbxFileReferenceSection(file); // PBXFileReference - this.addToPbxBuildFileSection(file); // PBXBuildFile + this.addToPbxFileReferenceSection(file); // PBXFileReference + this.addToPbxBuildFileSection(file); // PBXBuildFile pbxGroup.children.push(pbxGroupChild(file)); } @@ -540,75 +530,73 @@ pbxProject.prototype.addPbxGroup = function(filePathsArray, name, path, sourceTr } return { uuid: pbxGroupUuid, pbxGroup: pbxGroup }; -} +}; pbxProject.prototype.removePbxGroup = function (groupName) { - var section = this.hash.project.objects['PBXGroup'], - key, itemKey; + var section = this.hash.project.objects.PBXGroup; + var key; + var itemKey; for (key in section) { // only look for comments if (!COMMENT_KEY.test(key)) continue; - if (section[key] == groupName) { + if (section[key] === groupName) { itemKey = key.split(COMMENT_KEY)[0]; delete section[itemKey]; } } -} - -pbxProject.prototype.addToPbxProjectSection = function(target) { +}; +pbxProject.prototype.addToPbxProjectSection = function (target) { var newTarget = { - value: target.uuid, - comment: pbxNativeTargetComment(target.pbxNativeTarget) - }; + value: target.uuid, + comment: pbxNativeTargetComment(target.pbxNativeTarget) + }; - this.pbxProjectSection()[this.getFirstProject()['uuid']]['targets'].push(newTarget); -} + this.pbxProjectSection()[this.getFirstProject().uuid].targets.push(newTarget); +}; -pbxProject.prototype.addToPbxNativeTargetSection = function(target) { - var commentKey = f("%s_comment", target.uuid); +pbxProject.prototype.addToPbxNativeTargetSection = function (target) { + var commentKey = f('%s_comment', target.uuid); this.pbxNativeTargetSection()[target.uuid] = target.pbxNativeTarget; this.pbxNativeTargetSection()[commentKey] = target.pbxNativeTarget.name; -} +}; -pbxProject.prototype.addToPbxFileReferenceSection = function(file) { - var commentKey = f("%s_comment", file.fileRef); +pbxProject.prototype.addToPbxFileReferenceSection = function (file) { + var commentKey = f('%s_comment', file.fileRef); this.pbxFileReferenceSection()[file.fileRef] = pbxFileReferenceObj(file); this.pbxFileReferenceSection()[commentKey] = pbxFileReferenceComment(file); -} - -pbxProject.prototype.removeFromPbxFileReferenceSection = function(file) { +}; - var i; +pbxProject.prototype.removeFromPbxFileReferenceSection = function (file) { var refObj = pbxFileReferenceObj(file); - for (i in this.pbxFileReferenceSection()) { - if (this.pbxFileReferenceSection()[i].name == refObj.name || - ('"' + this.pbxFileReferenceSection()[i].name + '"') == refObj.name || - this.pbxFileReferenceSection()[i].path == refObj.path || - ('"' + this.pbxFileReferenceSection()[i].path + '"') == refObj.path) { + for (var i in this.pbxFileReferenceSection()) { + if (this.pbxFileReferenceSection()[i].name === refObj.name || + ('"' + this.pbxFileReferenceSection()[i].name + '"') === refObj.name || + this.pbxFileReferenceSection()[i].path === refObj.path || + ('"' + this.pbxFileReferenceSection()[i].path + '"') === refObj.path) { file.fileRef = file.uuid = i; delete this.pbxFileReferenceSection()[i]; break; } } - var commentKey = f("%s_comment", file.fileRef); - if (this.pbxFileReferenceSection()[commentKey] != undefined) { + var commentKey = f('%s_comment', file.fileRef); + if (this.pbxFileReferenceSection()[commentKey] !== undefined) { delete this.pbxFileReferenceSection()[commentKey]; } return file; -} +}; -pbxProject.prototype.addToXcVersionGroupSection = function(file) { +pbxProject.prototype.addToXcVersionGroupSection = function (file) { if (!file.models || !file.currentModel) { - throw new Error("Cannot create a XCVersionGroup section from not a data model document file"); + throw new Error('Cannot create a XCVersionGroup section from not a data model document file'); } - var commentKey = f("%s_comment", file.fileRef); + var commentKey = f('%s_comment', file.fileRef); if (!this.xcVersionGroupSection()[file.fileRef]) { this.xcVersionGroupSection()[file.fileRef] = { @@ -622,184 +610,184 @@ pbxProject.prototype.addToXcVersionGroupSection = function(file) { }; this.xcVersionGroupSection()[commentKey] = path.basename(file.path); } -} +}; -pbxProject.prototype.addToPluginsPbxGroup = function(file) { +pbxProject.prototype.addToPluginsPbxGroup = function (file) { var pluginsGroup = this.pbxGroupByName('Plugins'); if (!pluginsGroup) { this.addPbxGroup([file.path], 'Plugins'); } else { pluginsGroup.children.push(pbxGroupChild(file)); } -} +}; -pbxProject.prototype.removeFromPluginsPbxGroup = function(file) { +pbxProject.prototype.removeFromPluginsPbxGroup = function (file) { if (!this.pbxGroupByName('Plugins')) { return null; } - var pluginsGroupChildren = this.pbxGroupByName('Plugins').children, i; - for (i in pluginsGroupChildren) { - if (pbxGroupChild(file).value == pluginsGroupChildren[i].value && - pbxGroupChild(file).comment == pluginsGroupChildren[i].comment) { + var pluginsGroupChildren = this.pbxGroupByName('Plugins').children; + for (var i in pluginsGroupChildren) { + if (pbxGroupChild(file).value === pluginsGroupChildren[i].value && + pbxGroupChild(file).comment === pluginsGroupChildren[i].comment) { pluginsGroupChildren.splice(i, 1); break; } } -} +}; -pbxProject.prototype.addToResourcesPbxGroup = function(file) { +pbxProject.prototype.addToResourcesPbxGroup = function (file) { var pluginsGroup = this.pbxGroupByName('Resources'); if (!pluginsGroup) { this.addPbxGroup([file.path], 'Resources'); } else { pluginsGroup.children.push(pbxGroupChild(file)); } -} +}; -pbxProject.prototype.removeFromResourcesPbxGroup = function(file) { +pbxProject.prototype.removeFromResourcesPbxGroup = function (file) { if (!this.pbxGroupByName('Resources')) { return null; } - var pluginsGroupChildren = this.pbxGroupByName('Resources').children, i; - for (i in pluginsGroupChildren) { - if (pbxGroupChild(file).value == pluginsGroupChildren[i].value && - pbxGroupChild(file).comment == pluginsGroupChildren[i].comment) { + var pluginsGroupChildren = this.pbxGroupByName('Resources').children; + for (var i in pluginsGroupChildren) { + if (pbxGroupChild(file).value === pluginsGroupChildren[i].value && + pbxGroupChild(file).comment === pluginsGroupChildren[i].comment) { pluginsGroupChildren.splice(i, 1); break; } } -} +}; -pbxProject.prototype.addToFrameworksPbxGroup = function(file) { +pbxProject.prototype.addToFrameworksPbxGroup = function (file) { var pluginsGroup = this.pbxGroupByName('Frameworks'); if (!pluginsGroup) { this.addPbxGroup([file.path], 'Frameworks'); } else { pluginsGroup.children.push(pbxGroupChild(file)); } -} +}; -pbxProject.prototype.removeFromFrameworksPbxGroup = function(file) { +pbxProject.prototype.removeFromFrameworksPbxGroup = function (file) { if (!this.pbxGroupByName('Frameworks')) { return null; } var pluginsGroupChildren = this.pbxGroupByName('Frameworks').children; - for (i in pluginsGroupChildren) { - if (pbxGroupChild(file).value == pluginsGroupChildren[i].value && - pbxGroupChild(file).comment == pluginsGroupChildren[i].comment) { + for (var i in pluginsGroupChildren) { + if (pbxGroupChild(file).value === pluginsGroupChildren[i].value && + pbxGroupChild(file).comment === pluginsGroupChildren[i].comment) { pluginsGroupChildren.splice(i, 1); break; } } -} +}; pbxProject.prototype.addToPbxEmbedFrameworksBuildPhase = function (file) { var sources = this.pbxEmbedFrameworksBuildPhaseObj(file.target); if (sources) { sources.files.push(pbxBuildPhaseObj(file)); } -} +}; pbxProject.prototype.removeFromPbxEmbedFrameworksBuildPhase = function (file) { var sources = this.pbxEmbedFrameworksBuildPhaseObj(file.target); if (sources) { var files = []; - for (i in sources.files) { - if (sources.files[i].comment != longComment(file)) { + for (var i in sources.files) { + if (sources.files[i].comment !== longComment(file)) { files.push(sources.files[i]); } } sources.files = files; } -} +}; -pbxProject.prototype.addToProductsPbxGroup = function(file) { +pbxProject.prototype.addToProductsPbxGroup = function (file) { var productsGroup = this.pbxGroupByName('Products'); if (!productsGroup) { this.addPbxGroup([file.path], 'Products'); } else { productsGroup.children.push(pbxGroupChild(file)); } -} +}; -pbxProject.prototype.removeFromProductsPbxGroup = function(file) { +pbxProject.prototype.removeFromProductsPbxGroup = function (file) { if (!this.pbxGroupByName('Products')) { return null; } - var productsGroupChildren = this.pbxGroupByName('Products').children, i; - for (i in productsGroupChildren) { - if (pbxGroupChild(file).value == productsGroupChildren[i].value && - pbxGroupChild(file).comment == productsGroupChildren[i].comment) { + var productsGroupChildren = this.pbxGroupByName('Products').children; + for (var i in productsGroupChildren) { + if (pbxGroupChild(file).value === productsGroupChildren[i].value && + pbxGroupChild(file).comment === productsGroupChildren[i].comment) { productsGroupChildren.splice(i, 1); break; } } -} +}; -pbxProject.prototype.addToPbxSourcesBuildPhase = function(file) { +pbxProject.prototype.addToPbxSourcesBuildPhase = function (file) { var sources = this.pbxSourcesBuildPhaseObj(file.target); sources.files.push(pbxBuildPhaseObj(file)); -} - -pbxProject.prototype.removeFromPbxSourcesBuildPhase = function(file) { +}; - var sources = this.pbxSourcesBuildPhaseObj(file.target), i; - for (i in sources.files) { - if (sources.files[i].comment == longComment(file)) { +pbxProject.prototype.removeFromPbxSourcesBuildPhase = function (file) { + var sources = this.pbxSourcesBuildPhaseObj(file.target); + for (var i in sources.files) { + if (sources.files[i].comment === longComment(file)) { sources.files.splice(i, 1); break; } } -} +}; -pbxProject.prototype.addToPbxResourcesBuildPhase = function(file) { +pbxProject.prototype.addToPbxResourcesBuildPhase = function (file) { var sources = this.pbxResourcesBuildPhaseObj(file.target); sources.files.push(pbxBuildPhaseObj(file)); -} +}; -pbxProject.prototype.removeFromPbxResourcesBuildPhase = function(file) { - var sources = this.pbxResourcesBuildPhaseObj(file.target), i; +pbxProject.prototype.removeFromPbxResourcesBuildPhase = function (file) { + var sources = this.pbxResourcesBuildPhaseObj(file.target); - for (i in sources.files) { - if (sources.files[i].comment == longComment(file)) { + for (var i in sources.files) { + if (sources.files[i].comment === longComment(file)) { sources.files.splice(i, 1); break; } } -} +}; -pbxProject.prototype.addToPbxFrameworksBuildPhase = function(file) { +pbxProject.prototype.addToPbxFrameworksBuildPhase = function (file) { var sources = this.pbxFrameworksBuildPhaseObj(file.target); sources.files.push(pbxBuildPhaseObj(file)); -} +}; -pbxProject.prototype.removeFromPbxFrameworksBuildPhase = function(file) { +pbxProject.prototype.removeFromPbxFrameworksBuildPhase = function (file) { var sources = this.pbxFrameworksBuildPhaseObj(file.target); - for (i in sources.files) { - if (sources.files[i].comment == longComment(file)) { + for (var i in sources.files) { + if (sources.files[i].comment === longComment(file)) { sources.files.splice(i, 1); break; } } -} +}; -pbxProject.prototype.addXCConfigurationList = function(configurationObjectsArray, defaultConfigurationName, comment) { - var pbxBuildConfigurationSection = this.pbxXCBuildConfigurationSection(), - pbxXCConfigurationListSection = this.pbxXCConfigurationList(), - xcConfigurationListUuid = this.generateUuid(), - commentKey = f("%s_comment", xcConfigurationListUuid), - xcConfigurationList = { - isa: 'XCConfigurationList', - buildConfigurations: [], - defaultConfigurationIsVisible: 0, - defaultConfigurationName: defaultConfigurationName - }; +pbxProject.prototype.addXCConfigurationList = function (configurationObjectsArray, defaultConfigurationName, comment) { + var pbxBuildConfigurationSection = this.pbxXCBuildConfigurationSection(); + var pbxXCConfigurationListSection = this.pbxXCConfigurationList(); + var xcConfigurationListUuid = this.generateUuid(); + var commentKey = f('%s_comment', xcConfigurationListUuid); + + var xcConfigurationList = { + isa: 'XCConfigurationList', + buildConfigurations: [], + defaultConfigurationIsVisible: 0, + defaultConfigurationName: defaultConfigurationName + }; for (var index = 0; index < configurationObjectsArray.length; index++) { - var configuration = configurationObjectsArray[index], - configurationUuid = this.generateUuid(), - configurationCommentKey = f("%s_comment", configurationUuid); + var configuration = configurationObjectsArray[index]; + var configurationUuid = this.generateUuid(); + var configurationCommentKey = f('%s_comment', configurationUuid); pbxBuildConfigurationSection[configurationUuid] = configuration; pbxBuildConfigurationSection[configurationCommentKey] = configuration.name; @@ -812,86 +800,87 @@ pbxProject.prototype.addXCConfigurationList = function(configurationObjectsArray } return { uuid: xcConfigurationListUuid, xcConfigurationList: xcConfigurationList }; -} +}; -pbxProject.prototype.addTargetDependency = function(target, dependencyTargets) { - if (!target) - return undefined; +pbxProject.prototype.addTargetDependency = function (target, dependencyTargets) { + if (!target) { return undefined; } var nativeTargets = this.pbxNativeTargetSection(); - if (typeof nativeTargets[target] == "undefined") - throw new Error("Invalid target: " + target); + if (typeof nativeTargets[target] === 'undefined') { throw new Error('Invalid target: ' + target); } for (var index = 0; index < dependencyTargets.length; index++) { var dependencyTarget = dependencyTargets[index]; - if (typeof nativeTargets[dependencyTarget] == "undefined") - throw new Error("Invalid target: " + dependencyTarget); - } - - var pbxTargetDependency = 'PBXTargetDependency', - pbxContainerItemProxy = 'PBXContainerItemProxy', - pbxTargetDependencySection = this.hash.project.objects[pbxTargetDependency], - pbxContainerItemProxySection = this.hash.project.objects[pbxContainerItemProxy]; + if (typeof nativeTargets[dependencyTarget] === 'undefined') { throw new Error('Invalid target: ' + dependencyTarget); } + } + + var pbxTargetDependency = 'PBXTargetDependency'; + var pbxContainerItemProxy = 'PBXContainerItemProxy'; + var pbxTargetDependencySection = this.hash.project.objects[pbxTargetDependency]; + var pbxContainerItemProxySection = this.hash.project.objects[pbxContainerItemProxy]; + + for (var index2 = 0; index2 < dependencyTargets.length; index2++) { + var dependencyTargetUuid = dependencyTargets[index2]; + var dependencyTargetCommentKey = f('%s_comment', dependencyTargetUuid); + var targetDependencyUuid = this.generateUuid(); + var targetDependencyCommentKey = f('%s_comment', targetDependencyUuid); + var itemProxyUuid = this.generateUuid(); + var itemProxyCommentKey = f('%s_comment', itemProxyUuid); + + var itemProxy = { + isa: pbxContainerItemProxy, + containerPortal: this.hash.project.rootObject, + containerPortal_comment: this.hash.project.rootObject_comment, + proxyType: 1, + remoteGlobalIDString: dependencyTargetUuid, + remoteInfo: nativeTargets[dependencyTargetUuid].name + }; - for (var index = 0; index < dependencyTargets.length; index++) { - var dependencyTargetUuid = dependencyTargets[index], - dependencyTargetCommentKey = f("%s_comment", dependencyTargetUuid), - targetDependencyUuid = this.generateUuid(), - targetDependencyCommentKey = f("%s_comment", targetDependencyUuid), - itemProxyUuid = this.generateUuid(), - itemProxyCommentKey = f("%s_comment", itemProxyUuid), - itemProxy = { - isa: pbxContainerItemProxy, - containerPortal: this.hash.project['rootObject'], - containerPortal_comment: this.hash.project['rootObject_comment'], - proxyType: 1, - remoteGlobalIDString: dependencyTargetUuid, - remoteInfo: nativeTargets[dependencyTargetUuid].name - }, - targetDependency = { - isa: pbxTargetDependency, - target: dependencyTargetUuid, - target_comment: nativeTargets[dependencyTargetCommentKey], - targetProxy: itemProxyUuid, - targetProxy_comment: pbxContainerItemProxy - }; + var targetDependency = { + isa: pbxTargetDependency, + target: dependencyTargetUuid, + target_comment: nativeTargets[dependencyTargetCommentKey], + targetProxy: itemProxyUuid, + targetProxy_comment: pbxContainerItemProxy + }; if (pbxContainerItemProxySection && pbxTargetDependencySection) { pbxContainerItemProxySection[itemProxyUuid] = itemProxy; pbxContainerItemProxySection[itemProxyCommentKey] = pbxContainerItemProxy; pbxTargetDependencySection[targetDependencyUuid] = targetDependency; pbxTargetDependencySection[targetDependencyCommentKey] = pbxTargetDependency; - nativeTargets[target].dependencies.push({ value: targetDependencyUuid, comment: pbxTargetDependency }) + nativeTargets[target].dependencies.push({ value: targetDependencyUuid, comment: pbxTargetDependency }); } } return { uuid: target, target: nativeTargets[target] }; -} +}; -pbxProject.prototype.addBuildPhase = function(filePathsArray, buildPhaseType, comment, target, optionsOrFolderType, subfolderPath) { - var buildPhaseSection, - fileReferenceSection = this.pbxFileReferenceSection(), - buildFileSection = this.pbxBuildFileSection(), - buildPhaseUuid = this.generateUuid(), - buildPhaseTargetUuid = target || this.getFirstTarget().uuid, - commentKey = f("%s_comment", buildPhaseUuid), - buildPhase = { - isa: buildPhaseType, - buildActionMask: 2147483647, - files: [], - runOnlyForDeploymentPostprocessing: 0 - }, - filePathToBuildFile = {}; +pbxProject.prototype.addBuildPhase = function (filePathsArray, buildPhaseType, comment, target, optionsOrFolderType, subfolderPath) { + var buildPhaseSection; + var fileReferenceSection = this.pbxFileReferenceSection(); + var buildFileSection = this.pbxBuildFileSection(); + var buildPhaseUuid = this.generateUuid(); + var buildPhaseTargetUuid = target || this.getFirstTarget().uuid; + var commentKey = f('%s_comment', buildPhaseUuid); + + var buildPhase = { + isa: buildPhaseType, + buildActionMask: 2147483647, + files: [], + runOnlyForDeploymentPostprocessing: 0 + }; + + var filePathToBuildFile = {}; if (buildPhaseType === 'PBXCopyFilesBuildPhase') { buildPhase = pbxCopyFilesBuildPhaseObj(buildPhase, optionsOrFolderType, subfolderPath, comment); } else if (buildPhaseType === 'PBXShellScriptBuildPhase') { - buildPhase = pbxShellScriptBuildPhaseObj(buildPhase, optionsOrFolderType, comment) + buildPhase = pbxShellScriptBuildPhaseObj(buildPhase, optionsOrFolderType, comment); } if (!this.hash.project.objects[buildPhaseType]) { - this.hash.project.objects[buildPhaseType] = new Object(); + this.hash.project.objects[buildPhaseType] = {}; } if (!this.hash.project.objects[buildPhaseType][buildPhaseUuid]) { @@ -899,22 +888,20 @@ pbxProject.prototype.addBuildPhase = function(filePathsArray, buildPhaseType, co this.hash.project.objects[buildPhaseType][commentKey] = comment; } - if (this.hash.project.objects['PBXNativeTarget'][buildPhaseTargetUuid]['buildPhases']) { - this.hash.project.objects['PBXNativeTarget'][buildPhaseTargetUuid]['buildPhases'].push({ + if (this.hash.project.objects.PBXNativeTarget[buildPhaseTargetUuid].buildPhases) { + this.hash.project.objects.PBXNativeTarget[buildPhaseTargetUuid].buildPhases.push({ value: buildPhaseUuid, comment: comment - }) - + }); } - for (var key in buildFileSection) { // only look for comments if (!COMMENT_KEY.test(key)) continue; - var buildFileKey = key.split(COMMENT_KEY)[0], - buildFile = buildFileSection[buildFileKey]; - fileReference = fileReferenceSection[buildFile.fileRef]; + var buildFileKey = key.split(COMMENT_KEY)[0]; + var buildFile = buildFileSection[buildFileKey]; + var fileReference = fileReferenceSection[buildFile.fileRef]; if (!fileReference) continue; @@ -924,9 +911,9 @@ pbxProject.prototype.addBuildPhase = function(filePathsArray, buildPhaseType, co } for (var index = 0; index < filePathsArray.length; index++) { - var filePath = filePathsArray[index], - filePathQuoted = "\"" + filePath + "\"", - file = new pbxFile(filePath); + var filePath = filePathsArray[index]; + var filePathQuoted = '"' + filePath + '"'; + var file = new pbxFile(filePath); if (filePathToBuildFile[filePath]) { buildPhase.files.push(pbxBuildPhaseObj(filePathToBuildFile[filePath])); @@ -938,8 +925,8 @@ pbxProject.prototype.addBuildPhase = function(filePathsArray, buildPhaseType, co file.uuid = this.generateUuid(); file.fileRef = this.generateUuid(); - this.addToPbxFileReferenceSection(file); // PBXFileReference - this.addToPbxBuildFileSection(file); // PBXBuildFile + this.addToPbxFileReferenceSection(file); // PBXFileReference + this.addToPbxBuildFileSection(file); // PBXBuildFile buildPhase.files.push(pbxBuildPhaseObj(file)); } @@ -949,63 +936,64 @@ pbxProject.prototype.addBuildPhase = function(filePathsArray, buildPhaseType, co } return { uuid: buildPhaseUuid, buildPhase: buildPhase }; -} +}; // helper access functions -pbxProject.prototype.pbxProjectSection = function() { - return this.hash.project.objects['PBXProject']; -} -pbxProject.prototype.pbxBuildFileSection = function() { - return this.hash.project.objects['PBXBuildFile']; -} +pbxProject.prototype.pbxProjectSection = function () { + return this.hash.project.objects.PBXProject; +}; +pbxProject.prototype.pbxBuildFileSection = function () { + return this.hash.project.objects.PBXBuildFile; +}; -pbxProject.prototype.pbxXCBuildConfigurationSection = function() { - return this.hash.project.objects['XCBuildConfiguration']; -} +pbxProject.prototype.pbxXCBuildConfigurationSection = function () { + return this.hash.project.objects.XCBuildConfiguration; +}; -pbxProject.prototype.pbxFileReferenceSection = function() { - return this.hash.project.objects['PBXFileReference']; -} +pbxProject.prototype.pbxFileReferenceSection = function () { + return this.hash.project.objects.PBXFileReference; +}; -pbxProject.prototype.pbxNativeTargetSection = function() { - return this.hash.project.objects['PBXNativeTarget']; -} +pbxProject.prototype.pbxNativeTargetSection = function () { + return this.hash.project.objects.PBXNativeTarget; +}; pbxProject.prototype.xcVersionGroupSection = function () { - if (typeof this.hash.project.objects['XCVersionGroup'] !== 'object') { - this.hash.project.objects['XCVersionGroup'] = {}; + if (typeof this.hash.project.objects.XCVersionGroup !== 'object') { + this.hash.project.objects.XCVersionGroup = {}; } - return this.hash.project.objects['XCVersionGroup']; -} + return this.hash.project.objects.XCVersionGroup; +}; -pbxProject.prototype.pbxXCConfigurationList = function() { - return this.hash.project.objects['XCConfigurationList']; -} +pbxProject.prototype.pbxXCConfigurationList = function () { + return this.hash.project.objects.XCConfigurationList; +}; -pbxProject.prototype.pbxGroupByName = function(name) { - var groups = this.hash.project.objects['PBXGroup'], - key, groupKey; +pbxProject.prototype.pbxGroupByName = function (name) { + var groups = this.hash.project.objects.PBXGroup; + var key; + var groupKey; for (key in groups) { // only look for comments if (!COMMENT_KEY.test(key)) continue; - if (groups[key] == name) { + if (groups[key] === name) { groupKey = key.split(COMMENT_KEY)[0]; return groups[groupKey]; } } return null; -} +}; -pbxProject.prototype.pbxTargetByName = function(name) { +pbxProject.prototype.pbxTargetByName = function (name) { return this.pbxItemByComment(name, 'PBXNativeTarget'); -} +}; -pbxProject.prototype.findTargetKey = function(name) { - var targets = this.hash.project.objects['PBXNativeTarget']; +pbxProject.prototype.findTargetKey = function (name) { + var targets = this.hash.project.objects.PBXNativeTarget; for (var key in targets) { // only look for comments @@ -1018,106 +1006,102 @@ pbxProject.prototype.findTargetKey = function(name) { } return null; -} +}; -pbxProject.prototype.pbxItemByComment = function(name, pbxSectionName) { - var section = this.hash.project.objects[pbxSectionName], - key, itemKey; +pbxProject.prototype.pbxItemByComment = function (name, pbxSectionName) { + var section = this.hash.project.objects[pbxSectionName]; + var key; + var itemKey; for (key in section) { // only look for comments if (!COMMENT_KEY.test(key)) continue; - if (section[key] == name) { + if (section[key] === name) { itemKey = key.split(COMMENT_KEY)[0]; return section[itemKey]; } } return null; -} +}; -pbxProject.prototype.pbxSourcesBuildPhaseObj = function(target) { +pbxProject.prototype.pbxSourcesBuildPhaseObj = function (target) { return this.buildPhaseObject('PBXSourcesBuildPhase', 'Sources', target); -} +}; -pbxProject.prototype.pbxResourcesBuildPhaseObj = function(target) { +pbxProject.prototype.pbxResourcesBuildPhaseObj = function (target) { return this.buildPhaseObject('PBXResourcesBuildPhase', 'Resources', target); -} +}; -pbxProject.prototype.pbxFrameworksBuildPhaseObj = function(target) { +pbxProject.prototype.pbxFrameworksBuildPhaseObj = function (target) { return this.buildPhaseObject('PBXFrameworksBuildPhase', 'Frameworks', target); -} +}; pbxProject.prototype.pbxEmbedFrameworksBuildPhaseObj = function (target) { return this.buildPhaseObject('PBXCopyFilesBuildPhase', 'Embed Frameworks', target); }; // Find Build Phase from group/target -pbxProject.prototype.buildPhase = function(group, target) { - - if (!target) - return undefined; +pbxProject.prototype.buildPhase = function (group, target) { + if (!target) { return undefined; } var nativeTargets = this.pbxNativeTargetSection(); - if (typeof nativeTargets[target] == "undefined") - throw new Error("Invalid target: " + target); + if (typeof nativeTargets[target] === 'undefined') { throw new Error('Invalid target: ' + target); } var nativeTarget = nativeTargets[target]; var buildPhases = nativeTarget.buildPhases; - for(var i in buildPhases) - { + for (var i in buildPhases) { var buildPhase = buildPhases[i]; - if (buildPhase.comment==group) - return buildPhase.value + "_comment"; - } + if (buildPhase.comment === group) { return buildPhase.value + '_comment'; } } +}; -pbxProject.prototype.buildPhaseObject = function(name, group, target) { - var section = this.hash.project.objects[name], - obj, sectionKey, key; +pbxProject.prototype.buildPhaseObject = function (name, group, target) { + var section = this.hash.project.objects[name]; + var sectionKey; + var key; var buildPhase = this.buildPhase(group, target); for (key in section) { - // only look for comments if (!COMMENT_KEY.test(key)) continue; // select the proper buildPhase - if (buildPhase && buildPhase!=key) - continue; - if (section[key] == group) { + if (buildPhase && buildPhase !== key) { continue; } + if (section[key] === group) { sectionKey = key.split(COMMENT_KEY)[0]; return section[sectionKey]; } } return null; -} +}; -pbxProject.prototype.addBuildProperty = function(prop, value, build_name) { - var configurations = nonComments(this.pbxXCBuildConfigurationSection()), - key, configuration; +pbxProject.prototype.addBuildProperty = function (prop, value, build_name) { + var configurations = nonComments(this.pbxXCBuildConfigurationSection()); + var key; + var configuration; - for (key in configurations){ + for (key in configurations) { configuration = configurations[key]; - if (!build_name || configuration.name === build_name){ + if (!build_name || configuration.name === build_name) { configuration.buildSettings[prop] = value; } } -} +}; -pbxProject.prototype.removeBuildProperty = function(prop, build_name) { - var configurations = nonComments(this.pbxXCBuildConfigurationSection()), - key, configuration; +pbxProject.prototype.removeBuildProperty = function (prop, build_name) { + var configurations = nonComments(this.pbxXCBuildConfigurationSection()); + var key; + var configuration; - for (key in configurations){ + for (key in configurations) { configuration = configurations[key]; - if (configuration.buildSettings[prop] && - !build_name || configuration.name === build_name){ + if ((configuration.buildSettings[prop] && !build_name) || configuration.name === build_name) { delete configuration.buildSettings[prop]; } } -} +}; /** * @@ -1125,199 +1109,197 @@ pbxProject.prototype.removeBuildProperty = function(prop, build_name) { * @param value {String|Array|Object|Number|Boolean} * @param build {String} Release or Debug */ -pbxProject.prototype.updateBuildProperty = function(prop, value, build) { +pbxProject.prototype.updateBuildProperty = function (prop, value, build) { var configs = this.pbxXCBuildConfigurationSection(); for (var configName in configs) { if (!COMMENT_KEY.test(configName)) { var config = configs[configName]; - if ( (build && config.name === build) || (!build) ) { + if ((build && config.name === build) || (!build)) { config.buildSettings[prop] = value; } } } -} +}; -pbxProject.prototype.updateProductName = function(name) { +pbxProject.prototype.updateProductName = function (name) { this.updateBuildProperty('PRODUCT_NAME', '"' + name + '"'); -} +}; -pbxProject.prototype.removeFromFrameworkSearchPaths = function(file) { - var configurations = nonComments(this.pbxXCBuildConfigurationSection()), - INHERITED = '"$(inherited)"', - SEARCH_PATHS = 'FRAMEWORK_SEARCH_PATHS', - config, buildSettings, searchPaths; +pbxProject.prototype.removeFromFrameworkSearchPaths = function (file) { + var configurations = nonComments(this.pbxXCBuildConfigurationSection()); + var SEARCH_PATHS = 'FRAMEWORK_SEARCH_PATHS'; + var config; + var buildSettings; + var searchPaths; var new_path = searchPathForFile(file, this); for (config in configurations) { buildSettings = configurations[config].buildSettings; - if (unquote(buildSettings['PRODUCT_NAME']) != this.productName) - continue; + if (unquote(buildSettings.PRODUCT_NAME) !== this.productName) { continue; } searchPaths = buildSettings[SEARCH_PATHS]; if (searchPaths && Array.isArray(searchPaths)) { - var matches = searchPaths.filter(function(p) { + var matches = searchPaths.filter(function (p) { return p.indexOf(new_path) > -1; }); - matches.forEach(function(m) { + matches.forEach(function (m) { var idx = searchPaths.indexOf(m); searchPaths.splice(idx, 1); }); } } -} +}; -pbxProject.prototype.addToFrameworkSearchPaths = function(file) { - var configurations = nonComments(this.pbxXCBuildConfigurationSection()), - INHERITED = '"$(inherited)"', - config, buildSettings, searchPaths; +pbxProject.prototype.addToFrameworkSearchPaths = function (file) { + var configurations = nonComments(this.pbxXCBuildConfigurationSection()); + var INHERITED = '"$(inherited)"'; + var config; + var buildSettings; for (config in configurations) { buildSettings = configurations[config].buildSettings; - if (unquote(buildSettings['PRODUCT_NAME']) != this.productName) - continue; + if (unquote(buildSettings.PRODUCT_NAME) !== this.productName) { continue; } - if (!buildSettings['FRAMEWORK_SEARCH_PATHS'] - || buildSettings['FRAMEWORK_SEARCH_PATHS'] === INHERITED) { - buildSettings['FRAMEWORK_SEARCH_PATHS'] = [INHERITED]; + if (!buildSettings.FRAMEWORK_SEARCH_PATHS || + buildSettings.FRAMEWORK_SEARCH_PATHS === INHERITED) { + buildSettings.FRAMEWORK_SEARCH_PATHS = [INHERITED]; } - buildSettings['FRAMEWORK_SEARCH_PATHS'].push(searchPathForFile(file, this)); + buildSettings.FRAMEWORK_SEARCH_PATHS.push(searchPathForFile(file, this)); } -} +}; -pbxProject.prototype.removeFromLibrarySearchPaths = function(file) { - var configurations = nonComments(this.pbxXCBuildConfigurationSection()), - INHERITED = '"$(inherited)"', - SEARCH_PATHS = 'LIBRARY_SEARCH_PATHS', - config, buildSettings, searchPaths; +pbxProject.prototype.removeFromLibrarySearchPaths = function (file) { + var configurations = nonComments(this.pbxXCBuildConfigurationSection()); + var SEARCH_PATHS = 'LIBRARY_SEARCH_PATHS'; + var config; + var buildSettings; + var searchPaths; var new_path = searchPathForFile(file, this); for (config in configurations) { buildSettings = configurations[config].buildSettings; - if (unquote(buildSettings['PRODUCT_NAME']) != this.productName) - continue; + if (unquote(buildSettings.PRODUCT_NAME) !== this.productName) { continue; } searchPaths = buildSettings[SEARCH_PATHS]; if (searchPaths && Array.isArray(searchPaths)) { - var matches = searchPaths.filter(function(p) { + var matches = searchPaths.filter(function (p) { return p.indexOf(new_path) > -1; }); - matches.forEach(function(m) { + matches.forEach(function (m) { var idx = searchPaths.indexOf(m); searchPaths.splice(idx, 1); }); } - } -} +}; -pbxProject.prototype.addToLibrarySearchPaths = function(file) { - var configurations = nonComments(this.pbxXCBuildConfigurationSection()), - INHERITED = '"$(inherited)"', - config, buildSettings, searchPaths; +pbxProject.prototype.addToLibrarySearchPaths = function (file) { + var configurations = nonComments(this.pbxXCBuildConfigurationSection()); + var INHERITED = '"$(inherited)"'; + var config; + var buildSettings; for (config in configurations) { buildSettings = configurations[config].buildSettings; - if (unquote(buildSettings['PRODUCT_NAME']) != this.productName) - continue; + if (unquote(buildSettings.PRODUCT_NAME) !== this.productName) { continue; } - if (!buildSettings['LIBRARY_SEARCH_PATHS'] - || buildSettings['LIBRARY_SEARCH_PATHS'] === INHERITED) { - buildSettings['LIBRARY_SEARCH_PATHS'] = [INHERITED]; + if (!buildSettings.LIBRARY_SEARCH_PATHS || + buildSettings.LIBRARY_SEARCH_PATHS === INHERITED) { + buildSettings.LIBRARY_SEARCH_PATHS = [INHERITED]; } if (typeof file === 'string') { - buildSettings['LIBRARY_SEARCH_PATHS'].push(file); + buildSettings.LIBRARY_SEARCH_PATHS.push(file); } else { - buildSettings['LIBRARY_SEARCH_PATHS'].push(searchPathForFile(file, this)); + buildSettings.LIBRARY_SEARCH_PATHS.push(searchPathForFile(file, this)); } } -} +}; -pbxProject.prototype.removeFromHeaderSearchPaths = function(file) { - var configurations = nonComments(this.pbxXCBuildConfigurationSection()), - INHERITED = '"$(inherited)"', - SEARCH_PATHS = 'HEADER_SEARCH_PATHS', - config, buildSettings, searchPaths; +pbxProject.prototype.removeFromHeaderSearchPaths = function (file) { + var configurations = nonComments(this.pbxXCBuildConfigurationSection()); + var SEARCH_PATHS = 'HEADER_SEARCH_PATHS'; + var config; + var buildSettings; var new_path = searchPathForFile(file, this); for (config in configurations) { buildSettings = configurations[config].buildSettings; - if (unquote(buildSettings['PRODUCT_NAME']) != this.productName) - continue; + if (unquote(buildSettings.PRODUCT_NAME) !== this.productName) { continue; } if (buildSettings[SEARCH_PATHS]) { - var matches = buildSettings[SEARCH_PATHS].filter(function(p) { + var matches = buildSettings[SEARCH_PATHS].filter(function (p) { return p.indexOf(new_path) > -1; }); - matches.forEach(function(m) { + matches.forEach(function (m) { var idx = buildSettings[SEARCH_PATHS].indexOf(m); buildSettings[SEARCH_PATHS].splice(idx, 1); }); } - } -} -pbxProject.prototype.addToHeaderSearchPaths = function(file) { - var configurations = nonComments(this.pbxXCBuildConfigurationSection()), - INHERITED = '"$(inherited)"', - config, buildSettings, searchPaths; +}; +pbxProject.prototype.addToHeaderSearchPaths = function (file) { + var configurations = nonComments(this.pbxXCBuildConfigurationSection()); + var INHERITED = '"$(inherited)"'; + var config; + var buildSettings; for (config in configurations) { buildSettings = configurations[config].buildSettings; - if (unquote(buildSettings['PRODUCT_NAME']) != this.productName) - continue; + if (unquote(buildSettings.PRODUCT_NAME) !== this.productName) { continue; } - if (!buildSettings['HEADER_SEARCH_PATHS']) { - buildSettings['HEADER_SEARCH_PATHS'] = [INHERITED]; + if (!buildSettings.HEADER_SEARCH_PATHS) { + buildSettings.HEADER_SEARCH_PATHS = [INHERITED]; } if (typeof file === 'string') { - buildSettings['HEADER_SEARCH_PATHS'].push(file); + buildSettings.HEADER_SEARCH_PATHS.push(file); } else { - buildSettings['HEADER_SEARCH_PATHS'].push(searchPathForFile(file, this)); + buildSettings.HEADER_SEARCH_PATHS.push(searchPathForFile(file, this)); } } -} +}; pbxProject.prototype.addToOtherLinkerFlags = function (flag) { - var configurations = nonComments(this.pbxXCBuildConfigurationSection()), - INHERITED = '"$(inherited)"', - OTHER_LDFLAGS = 'OTHER_LDFLAGS', - config, buildSettings; + var configurations = nonComments(this.pbxXCBuildConfigurationSection()); + var INHERITED = '"$(inherited)"'; + var OTHER_LDFLAGS = 'OTHER_LDFLAGS'; + var config; + var buildSettings; for (config in configurations) { buildSettings = configurations[config].buildSettings; - if (unquote(buildSettings['PRODUCT_NAME']) != this.productName) - continue; + if (unquote(buildSettings.PRODUCT_NAME) !== this.productName) { continue; } - if (!buildSettings[OTHER_LDFLAGS] - || buildSettings[OTHER_LDFLAGS] === INHERITED) { + if (!buildSettings[OTHER_LDFLAGS] || + buildSettings[OTHER_LDFLAGS] === INHERITED) { buildSettings[OTHER_LDFLAGS] = [INHERITED]; } buildSettings[OTHER_LDFLAGS].push(flag); } -} +}; pbxProject.prototype.removeFromOtherLinkerFlags = function (flag) { - var configurations = nonComments(this.pbxXCBuildConfigurationSection()), - OTHER_LDFLAGS = 'OTHER_LDFLAGS', - config, buildSettings; + var configurations = nonComments(this.pbxXCBuildConfigurationSection()); + var OTHER_LDFLAGS = 'OTHER_LDFLAGS'; + var config; + var buildSettings; for (config in configurations) { buildSettings = configurations[config].buildSettings; - if (unquote(buildSettings['PRODUCT_NAME']) != this.productName) { + if (unquote(buildSettings.PRODUCT_NAME) !== this.productName) { continue; } @@ -1331,22 +1313,24 @@ pbxProject.prototype.removeFromOtherLinkerFlags = function (flag) { }); } } -} +}; pbxProject.prototype.addToBuildSettings = function (buildSetting, value) { - var configurations = nonComments(this.pbxXCBuildConfigurationSection()), - config, buildSettings; + var configurations = nonComments(this.pbxXCBuildConfigurationSection()); + var config; + var buildSettings; for (config in configurations) { buildSettings = configurations[config].buildSettings; buildSettings[buildSetting] = value; } -} +}; pbxProject.prototype.removeFromBuildSettings = function (buildSetting) { - var configurations = nonComments(this.pbxXCBuildConfigurationSection()), - config, buildSettings; + var configurations = nonComments(this.pbxXCBuildConfigurationSection()); + var config; + var buildSettings; for (config in configurations) { buildSettings = configurations[config].buildSettings; @@ -1355,15 +1339,16 @@ pbxProject.prototype.removeFromBuildSettings = function (buildSetting) { delete buildSettings[buildSetting]; } } -} +}; // a JS getter. hmmm -pbxProject.prototype.__defineGetter__("productName", function() { - var configurations = nonComments(this.pbxXCBuildConfigurationSection()), - config, productName; +pbxProject.prototype.__defineGetter__('productName', function () { + var configurations = nonComments(this.pbxXCBuildConfigurationSection()); + var config; + var productName; for (config in configurations) { - productName = configurations[config].buildSettings['PRODUCT_NAME']; + productName = configurations[config].buildSettings.PRODUCT_NAME; if (productName) { return unquote(productName); @@ -1372,40 +1357,41 @@ pbxProject.prototype.__defineGetter__("productName", function() { }); // check if file is present -pbxProject.prototype.hasFile = function(filePath) { - var files = nonComments(this.pbxFileReferenceSection()), - file, id; - for (id in files) { +pbxProject.prototype.hasFile = function (filePath) { + var files = nonComments(this.pbxFileReferenceSection()); + var file; + + for (var id in files) { file = files[id]; - if (file.path == filePath || file.path == ('"' + filePath + '"')) { + if (file.path === filePath || file.path === ('"' + filePath + '"')) { return file; } } return false; -} - -pbxProject.prototype.addTarget = function(name, type, subfolder) { +}; +pbxProject.prototype.addTarget = function (name, type, subfolder) { // Setup uuid and name of new target - var targetUuid = this.generateUuid(), - targetType = type, - targetSubfolder = subfolder || name, - targetName = name.trim(); + var targetUuid = this.generateUuid(); + + var targetType = type; + var targetSubfolder = subfolder || name; + var targetName = name.trim(); // Check type against list of allowed target types if (!targetName) { - throw new Error("Target name missing."); + throw new Error('Target name missing.'); } // Check type against list of allowed target types if (!targetType) { - throw new Error("Target type missing."); + throw new Error('Target type missing.'); } // Check type against list of allowed target types if (!producttypeForTargettype(targetType)) { - throw new Error("Target type invalid: " + targetType); + throw new Error('Target type invalid: ' + targetType); } // Build Configuration: Create @@ -1434,48 +1420,46 @@ pbxProject.prototype.addTarget = function(name, type, subfolder) { ]; // Build Configuration: Add - var buildConfigurations = this.addXCConfigurationList(buildConfigurationsList, 'Release', 'Build configuration list for PBXNativeTarget "' + targetName +'"'); + var buildConfigurations = this.addXCConfigurationList(buildConfigurationsList, 'Release', 'Build configuration list for PBXNativeTarget "' + targetName + '"'); // Product: Create - var productName = targetName, - productType = producttypeForTargettype(targetType), - productFileType = filetypeForProducttype(productType), - productFile = this.addProductFile(productName, { group: 'Copy Files', 'target': targetUuid, 'explicitFileType': productFileType}), - productFileName = productFile.basename; + var productName = targetName; + var productType = producttypeForTargettype(targetType); + var productFileType = filetypeForProducttype(productType); + var productFile = this.addProductFile(productName, { group: 'Copy Files', target: targetUuid, explicitFileType: productFileType }); // Product: Add to build file list this.addToPbxBuildFileSection(productFile); // Target: Create var target = { - uuid: targetUuid, - pbxNativeTarget: { - isa: 'PBXNativeTarget', - name: '"' + targetName + '"', - productName: '"' + targetName + '"', - productReference: productFile.fileRef, - productType: '"' + producttypeForTargettype(targetType) + '"', - buildConfigurationList: buildConfigurations.uuid, - buildPhases: [], - buildRules: [], - dependencies: [] - } + uuid: targetUuid, + pbxNativeTarget: { + isa: 'PBXNativeTarget', + name: '"' + targetName + '"', + productName: '"' + targetName + '"', + productReference: productFile.fileRef, + productType: '"' + producttypeForTargettype(targetType) + '"', + buildConfigurationList: buildConfigurations.uuid, + buildPhases: [], + buildRules: [], + dependencies: [] + } }; // Target: Add to PBXNativeTarget section - this.addToPbxNativeTargetSection(target) + this.addToPbxNativeTargetSection(target); // Product: Embed (only for "extension"-type targets) if (targetType === 'app_extension') { - // Create CopyFiles phase in first target - this.addBuildPhase([], 'PBXCopyFilesBuildPhase', 'Copy Files', this.getFirstTarget().uuid, targetType) + this.addBuildPhase([], 'PBXCopyFilesBuildPhase', 'Copy Files', this.getFirstTarget().uuid, targetType); // Add product to CopyFiles phase - this.addToPbxCopyfilesBuildPhase(productFile) + this.addToPbxCopyfilesBuildPhase(productFile); - // this.addBuildPhaseToTarget(newPhase.buildPhase, this.getFirstTarget().uuid) + // this.addBuildPhaseToTarget(newPhase.buildPhase, this.getFirstTarget().uuid) } else if (targetType === 'watch2_app') { // Create CopyFiles phase in first target this.addBuildPhase( @@ -1488,13 +1472,13 @@ pbxProject.prototype.addTarget = function(name, type, subfolder) { ); } else if (targetType === 'watch2_extension') { // Create CopyFiles phase in watch target (if exists) - var watch2Target = this.getTarget(producttypeForTargettype('watch2_app')); - if (watch2Target) { + var watch2AppTarget = this.getTarget(producttypeForTargettype('watch2_app')); + if (watch2AppTarget) { this.addBuildPhase( [targetName + '.appex'], 'PBXCopyFilesBuildPhase', 'Embed App Extensions', - watch2Target.uuid, + watch2AppTarget.uuid, targetType ); } @@ -1505,22 +1489,20 @@ pbxProject.prototype.addTarget = function(name, type, subfolder) { // Target: Add dependency for this target to other targets if (targetType === 'watch2_extension') { - var watch2Target = this.getTarget(producttypeForTargettype('watch2_app')); - if (watch2Target) { - this.addTargetDependency(watch2Target.uuid, [target.uuid]); + var watch2ExtensionTarget = this.getTarget(producttypeForTargettype('watch2_app')); + if (watch2ExtensionTarget) { + this.addTargetDependency(watch2ExtensionTarget.uuid, [target.uuid]); } } else { this.addTargetDependency(this.getFirstTarget().uuid, [target.uuid]); } - // Return target on success return target; - }; // helper object creation functions -function pbxBuildFileObj(file) { +function pbxBuildFileObj (file) { var obj = Object.create(null); obj.isa = 'PBXBuildFile'; @@ -1531,11 +1513,11 @@ function pbxBuildFileObj(file) { return obj; } -function pbxFileReferenceObj(file) { +function pbxFileReferenceObj (file) { var fileObject = { - isa: "PBXFileReference", - name: "\"" + file.basename + "\"", - path: "\"" + file.path.replace(/\\/g, '/') + "\"", + isa: 'PBXFileReference', + name: '"' + file.basename + '"', + path: '"' + file.path.replace(/\\/g, '/') + '"', sourceTree: file.sourceTree, fileEncoding: file.fileEncoding, lastKnownFileType: file.lastKnownFileType, @@ -1546,7 +1528,7 @@ function pbxFileReferenceObj(file) { return fileObject; } -function pbxGroupChild(file) { +function pbxGroupChild (file) { var obj = Object.create(null); obj.value = file.fileRef; @@ -1555,7 +1537,7 @@ function pbxGroupChild(file) { return obj; } -function pbxBuildPhaseObj(file) { +function pbxBuildPhaseObj (file) { var obj = Object.create(null); obj.value = file.uuid; @@ -1564,9 +1546,8 @@ function pbxBuildPhaseObj(file) { return obj; } -function pbxCopyFilesBuildPhaseObj(obj, folderType, subfolderPath, phaseName) { - - // Add additional properties for 'CopyFiles' build phase +function pbxCopyFilesBuildPhaseObj (obj, folderType, subfolderPath, phaseName) { + // Add additional properties for 'CopyFiles' build phase var DESTINATION_BY_TARGETTYPE = { application: 'wrapper', app_extension: 'plugins', @@ -1581,7 +1562,7 @@ function pbxCopyFilesBuildPhaseObj(obj, folderType, subfolderPath, phaseName) { watch2_app: 'products_directory', watch_extension: 'plugins', watch2_extension: 'plugins' - } + }; var SUBFOLDERSPEC_BY_DESTINATION = { absolute_path: 0, executables: 6, @@ -1594,7 +1575,7 @@ function pbxCopyFilesBuildPhaseObj(obj, folderType, subfolderPath, phaseName) { shared_support: 12, wrapper: 1, xpc_services: 0 - } + }; obj.name = '"' + phaseName + '"'; obj.dstPath = subfolderPath || '""'; @@ -1603,7 +1584,7 @@ function pbxCopyFilesBuildPhaseObj(obj, folderType, subfolderPath, phaseName) { return obj; } -function pbxShellScriptBuildPhaseObj(obj, options, phaseName) { +function pbxShellScriptBuildPhaseObj (obj, options, phaseName) { obj.name = '"' + phaseName + '"'; obj.inputPaths = options.inputPaths || []; obj.outputPaths = options.outputPaths || []; @@ -1613,50 +1594,45 @@ function pbxShellScriptBuildPhaseObj(obj, options, phaseName) { return obj; } -function pbxBuildFileComment(file) { +function pbxBuildFileComment (file) { return longComment(file); } -function pbxFileReferenceComment(file) { +function pbxFileReferenceComment (file) { return file.basename || path.basename(file.path); } -function pbxNativeTargetComment(target) { +function pbxNativeTargetComment (target) { return target.name; } -function longComment(file) { - return f("%s in %s", file.basename, file.group); +function longComment (file) { + return f('%s in %s', file.basename, file.group); } // respect path -function correctForPluginsPath(file, project) { +function correctForPluginsPath (file, project) { return correctForPath(file, project, 'Plugins'); } -function correctForResourcesPath(file, project) { +function correctForResourcesPath (file, project) { return correctForPath(file, project, 'Resources'); } -function correctForFrameworksPath(file, project) { - return correctForPath(file, project, 'Frameworks'); -} - -function correctForPath(file, project, group) { +function correctForPath (file, project, group) { var r_group_dir = new RegExp('^' + group + '[\\\\/]'); - if (project.pbxGroupByName(group).path) - file.path = file.path.replace(r_group_dir, ''); + if (project.pbxGroupByName(group).path) { file.path = file.path.replace(r_group_dir, ''); } return file; } -function searchPathForFile(file, proj) { - var plugins = proj.pbxGroupByName('Plugins'), - pluginsPath = plugins ? plugins.path : null, - fileDir = path.dirname(file.path); +function searchPathForFile (file, proj) { + var plugins = proj.pbxGroupByName('Plugins'); + var pluginsPath = plugins ? plugins.path : null; + var fileDir = path.dirname(file.path); - if (fileDir == '.') { + if (fileDir === '.') { fileDir = ''; } else { fileDir = '/' + fileDir; @@ -1671,11 +1647,11 @@ function searchPathForFile(file, proj) { } } -function nonComments(obj) { - var keys = Object.keys(obj), - newObj = {}, i = 0; +function nonComments (obj) { + var keys = Object.keys(obj); + var newObj = {}; - for (i; i < keys.length; i++) { + for (var i = 0; i < keys.length; i++) { if (!COMMENT_KEY.test(keys[i])) { newObj[keys[i]] = obj[keys[i]]; } @@ -1684,65 +1660,49 @@ function nonComments(obj) { return newObj; } -function unquote(str) { - if (str) return str.replace(/^"(.*)"$/, "$1"); -} - - -function buildPhaseNameForIsa (isa) { - - BUILDPHASENAME_BY_ISA = { - PBXCopyFilesBuildPhase: 'Copy Files', - PBXResourcesBuildPhase: 'Resources', - PBXSourcesBuildPhase: 'Sources', - PBXFrameworksBuildPhase: 'Frameworks' - } - - return BUILDPHASENAME_BY_ISA[isa] +function unquote (str) { + if (str) return str.replace(/^"(.*)"$/, '$1'); } function producttypeForTargettype (targetType) { + var PRODUCTTYPE_BY_TARGETTYPE = { + application: 'com.apple.product-type.application', + app_extension: 'com.apple.product-type.app-extension', + bundle: 'com.apple.product-type.bundle', + command_line_tool: 'com.apple.product-type.tool', + dynamic_library: 'com.apple.product-type.library.dynamic', + framework: 'com.apple.product-type.framework', + static_library: 'com.apple.product-type.library.static', + unit_test_bundle: 'com.apple.product-type.bundle.unit-test', + watch_app: 'com.apple.product-type.application.watchapp', + watch2_app: 'com.apple.product-type.application.watchapp2', + watch_extension: 'com.apple.product-type.watchkit-extension', + watch2_extension: 'com.apple.product-type.watchkit2-extension' + }; - PRODUCTTYPE_BY_TARGETTYPE = { - application: 'com.apple.product-type.application', - app_extension: 'com.apple.product-type.app-extension', - bundle: 'com.apple.product-type.bundle', - command_line_tool: 'com.apple.product-type.tool', - dynamic_library: 'com.apple.product-type.library.dynamic', - framework: 'com.apple.product-type.framework', - static_library: 'com.apple.product-type.library.static', - unit_test_bundle: 'com.apple.product-type.bundle.unit-test', - watch_app: 'com.apple.product-type.application.watchapp', - watch2_app: 'com.apple.product-type.application.watchapp2', - watch_extension: 'com.apple.product-type.watchkit-extension', - watch2_extension: 'com.apple.product-type.watchkit2-extension' - }; - - return PRODUCTTYPE_BY_TARGETTYPE[targetType] + return PRODUCTTYPE_BY_TARGETTYPE[targetType]; } function filetypeForProducttype (productType) { + var FILETYPE_BY_PRODUCTTYPE = { + 'com.apple.product-type.application': '"wrapper.application"', + 'com.apple.product-type.app-extension': '"wrapper.app-extension"', + 'com.apple.product-type.bundle': '"wrapper.plug-in"', + 'com.apple.product-type.tool': '"compiled.mach-o.dylib"', + 'com.apple.product-type.library.dynamic': '"compiled.mach-o.dylib"', + 'com.apple.product-type.framework': '"wrapper.framework"', + 'com.apple.product-type.library.static': '"archive.ar"', + 'com.apple.product-type.bundle.unit-test': '"wrapper.cfbundle"', + 'com.apple.product-type.application.watchapp': '"wrapper.application"', + 'com.apple.product-type.application.watchapp2': '"wrapper.application"', + 'com.apple.product-type.watchkit-extension': '"wrapper.app-extension"', + 'com.apple.product-type.watchkit2-extension': '"wrapper.app-extension"' + }; - FILETYPE_BY_PRODUCTTYPE = { - 'com.apple.product-type.application': '"wrapper.application"', - 'com.apple.product-type.app-extension': '"wrapper.app-extension"', - 'com.apple.product-type.bundle': '"wrapper.plug-in"', - 'com.apple.product-type.tool': '"compiled.mach-o.dylib"', - 'com.apple.product-type.library.dynamic': '"compiled.mach-o.dylib"', - 'com.apple.product-type.framework': '"wrapper.framework"', - 'com.apple.product-type.library.static': '"archive.ar"', - 'com.apple.product-type.bundle.unit-test': '"wrapper.cfbundle"', - 'com.apple.product-type.application.watchapp': '"wrapper.application"', - 'com.apple.product-type.application.watchapp2': '"wrapper.application"', - 'com.apple.product-type.watchkit-extension': '"wrapper.app-extension"', - 'com.apple.product-type.watchkit2-extension': '"wrapper.app-extension"' - }; - - return FILETYPE_BY_PRODUCTTYPE[productType] + return FILETYPE_BY_PRODUCTTYPE[productType]; } -pbxProject.prototype.getFirstProject = function() { - +pbxProject.prototype.getFirstProject = function () { // Get pbxProject container var pbxProjectContainer = this.pbxProjectSection(); @@ -1752,15 +1712,15 @@ pbxProject.prototype.getFirstProject = function() { // Get first pbxProject var firstProject = pbxProjectContainer[firstProjectUuid]; - return { + return { uuid: firstProjectUuid, firstProject: firstProject - } -} + }; +}; -pbxProject.prototype.getFirstTarget = function() { +pbxProject.prototype.getFirstTarget = function () { // Get first target's UUID - var firstTargetUuid = this.getFirstProject()['firstProject']['targets'][0].value; + var firstTargetUuid = this.getFirstProject().firstProject.targets[0].value; // Get first pbxNativeTarget var firstTarget = this.pbxNativeTargetSection()[firstTargetUuid]; @@ -1768,17 +1728,17 @@ pbxProject.prototype.getFirstTarget = function() { return { uuid: firstTargetUuid, firstTarget: firstTarget - } -} + }; +}; -pbxProject.prototype.getTarget = function(productType) { +pbxProject.prototype.getTarget = function (productType) { // Find target by product type - var targets = this.getFirstProject()['firstProject']['targets']; + var targets = this.getFirstProject().firstProject.targets; var nativeTargets = this.pbxNativeTargetSection(); for (var i = 0; i < targets.length; i++) { var target = targets[i]; var targetUuid = target.value; - if (nativeTargets[targetUuid]['productType'] === '"' + productType + '"') { + if (nativeTargets[targetUuid].productType === '"' + productType + '"') { // Get pbxNativeTarget var nativeTarget = this.pbxNativeTargetSection()[targetUuid]; return { @@ -1789,46 +1749,42 @@ pbxProject.prototype.getTarget = function(productType) { } return null; -} +}; -/*** NEW ***/ +/** * NEW ***/ pbxProject.prototype.addToPbxGroupType = function (file, groupKey, groupType) { var group = this.getPBXGroupByKeyAndType(groupKey, groupType); if (group && group.children !== undefined) { if (typeof file === 'string') { - //Group Key + // Group Key var childGroup = { - value:file, + value: file }; if (this.getPBXGroupByKey(file)) { childGroup.comment = this.getPBXGroupByKey(file).name; - } - else if (this.getPBXVariantGroupByKey(file)) { + } else if (this.getPBXVariantGroupByKey(file)) { childGroup.comment = this.getPBXVariantGroupByKey(file).name; } group.children.push(childGroup); - } - else { - //File Object + } else { + // File Object group.children.push(pbxGroupChild(file)); } } -} +}; pbxProject.prototype.addToPbxVariantGroup = function (file, groupKey) { this.addToPbxGroupType(file, groupKey, 'PBXVariantGroup'); -} +}; pbxProject.prototype.addToPbxGroup = function (file, groupKey) { this.addToPbxGroupType(file, groupKey, 'PBXGroup'); -} - - +}; -pbxProject.prototype.pbxCreateGroupWithType = function(name, pathName, groupType) { - //Create object +pbxProject.prototype.pbxCreateGroupWithType = function (name, pathName, groupType) { + // Create object var model = { isa: '"' + groupType + '"', children: [], @@ -1838,69 +1794,63 @@ pbxProject.prototype.pbxCreateGroupWithType = function(name, pathName, groupType if (pathName) model.path = pathName; var key = this.generateUuid(); - //Create comment + // Create comment var commendId = key + '_comment'; - //add obj and commentObj to groups; + // add obj and commentObj to groups; var groups = this.hash.project.objects[groupType]; if (!groups) { - groups = this.hash.project.objects[groupType] = new Object(); + groups = this.hash.project.objects[groupType] = {}; } groups[commendId] = name; groups[key] = model; return key; -} +}; -pbxProject.prototype.pbxCreateVariantGroup = function(name) { - return this.pbxCreateGroupWithType(name, undefined, 'PBXVariantGroup') -} +pbxProject.prototype.pbxCreateVariantGroup = function (name) { + return this.pbxCreateGroupWithType(name, undefined, 'PBXVariantGroup'); +}; -pbxProject.prototype.pbxCreateGroup = function(name, pathName) { +pbxProject.prototype.pbxCreateGroup = function (name, pathName) { return this.pbxCreateGroupWithType(name, pathName, 'PBXGroup'); -} - - +}; pbxProject.prototype.removeFromPbxGroupAndType = function (file, groupKey, groupType) { var group = this.getPBXGroupByKeyAndType(groupKey, groupType); if (group) { - var groupChildren = group.children, i; - for(i in groupChildren) { - if(pbxGroupChild(file).value == groupChildren[i].value && - pbxGroupChild(file).comment == groupChildren[i].comment) { + var groupChildren = group.children; + for (var i in groupChildren) { + if (pbxGroupChild(file).value === groupChildren[i].value && + pbxGroupChild(file).comment === groupChildren[i].comment) { groupChildren.splice(i, 1); break; } } } -} +}; pbxProject.prototype.removeFromPbxGroup = function (file, groupKey) { this.removeFromPbxGroupAndType(file, groupKey, 'PBXGroup'); -} +}; pbxProject.prototype.removeFromPbxVariantGroup = function (file, groupKey) { this.removeFromPbxGroupAndType(file, groupKey, 'PBXVariantGroup'); -} - - +}; -pbxProject.prototype.getPBXGroupByKeyAndType = function(key, groupType) { +pbxProject.prototype.getPBXGroupByKeyAndType = function (key, groupType) { return this.hash.project.objects[groupType][key]; }; -pbxProject.prototype.getPBXGroupByKey = function(key) { - return this.hash.project.objects['PBXGroup'][key]; +pbxProject.prototype.getPBXGroupByKey = function (key) { + return this.hash.project.objects.PBXGroup[key]; }; -pbxProject.prototype.getPBXVariantGroupByKey = function(key) { - return this.hash.project.objects['PBXVariantGroup'][key]; +pbxProject.prototype.getPBXVariantGroupByKey = function (key) { + return this.hash.project.objects.PBXVariantGroup[key]; }; - - -pbxProject.prototype.findPBXGroupKeyAndType = function(criteria, groupType) { +pbxProject.prototype.findPBXGroupKeyAndType = function (criteria, groupType) { var groups = this.hash.project.objects[groupType]; var target; @@ -1912,90 +1862,86 @@ pbxProject.prototype.findPBXGroupKeyAndType = function(criteria, groupType) { if (criteria && criteria.path && criteria.name) { if (criteria.path === group.path && criteria.name === group.name) { target = key; - break + break; } - } - else if (criteria && criteria.path) { + } else if (criteria && criteria.path) { if (criteria.path === group.path) { target = key; - break + break; } - } - else if (criteria && criteria.name) { + } else if (criteria && criteria.name) { if (criteria.name === group.name) { target = key; - break + break; } } } return target; -} +}; -pbxProject.prototype.findPBXGroupKey = function(criteria) { +pbxProject.prototype.findPBXGroupKey = function (criteria) { return this.findPBXGroupKeyAndType(criteria, 'PBXGroup'); -} +}; -pbxProject.prototype.findPBXVariantGroupKey = function(criteria) { +pbxProject.prototype.findPBXVariantGroupKey = function (criteria) { return this.findPBXGroupKeyAndType(criteria, 'PBXVariantGroup'); -} +}; -pbxProject.prototype.addLocalizationVariantGroup = function(name) { +pbxProject.prototype.addLocalizationVariantGroup = function (name) { var groupKey = this.pbxCreateVariantGroup(name); - var resourceGroupKey = this.findPBXGroupKey({name: 'Resources'}); + var resourceGroupKey = this.findPBXGroupKey({ name: 'Resources' }); this.addToPbxGroup(groupKey, resourceGroupKey); var localizationVariantGroup = { uuid: this.generateUuid(), fileRef: groupKey, basename: name - } - this.addToPbxBuildFileSection(localizationVariantGroup); // PBXBuildFile - this.addToPbxResourcesBuildPhase(localizationVariantGroup); //PBXResourcesBuildPhase + }; + this.addToPbxBuildFileSection(localizationVariantGroup); // PBXBuildFile + this.addToPbxResourcesBuildPhase(localizationVariantGroup); // PBXResourcesBuildPhase return localizationVariantGroup; }; pbxProject.prototype.addKnownRegion = function (name) { - if (!this.pbxProjectSection()[this.getFirstProject()['uuid']]['knownRegions']) { - this.pbxProjectSection()[this.getFirstProject()['uuid']]['knownRegions'] = []; - } - if (!this.hasKnownRegion(name)) { - this.pbxProjectSection()[this.getFirstProject()['uuid']]['knownRegions'].push(name); - } -} + if (!this.pbxProjectSection()[this.getFirstProject().uuid].knownRegions) { + this.pbxProjectSection()[this.getFirstProject().uuid].knownRegions = []; + } + if (!this.hasKnownRegion(name)) { + this.pbxProjectSection()[this.getFirstProject().uuid].knownRegions.push(name); + } +}; pbxProject.prototype.removeKnownRegion = function (name) { - var regions = this.pbxProjectSection()[this.getFirstProject()['uuid']]['knownRegions']; - if (regions) { - for (var i = 0; i < regions.length; i++) { - if (regions[i] === name) { - regions.splice(i, 1); - break; - } - } - this.pbxProjectSection()[this.getFirstProject()['uuid']]['knownRegions'] = regions; - } -} + var regions = this.pbxProjectSection()[this.getFirstProject().uuid].knownRegions; + if (regions) { + for (var i = 0; i < regions.length; i++) { + if (regions[i] === name) { + regions.splice(i, 1); + break; + } + } + this.pbxProjectSection()[this.getFirstProject().uuid].knownRegions = regions; + } +}; pbxProject.prototype.hasKnownRegion = function (name) { - var regions = this.pbxProjectSection()[this.getFirstProject()['uuid']]['knownRegions']; - if (regions) { - for (var i in regions) { - if (regions[i] === name) { - return true; - } - } - } - return false; -} + var regions = this.pbxProjectSection()[this.getFirstProject().uuid].knownRegions; + if (regions) { + for (var i in regions) { + if (regions[i] === name) { + return true; + } + } + } + return false; +}; -pbxProject.prototype.getPBXObject = function(name) { +pbxProject.prototype.getPBXObject = function (name) { return this.hash.project.objects[name]; -} - - +}; pbxProject.prototype.addFile = function (path, group, opt) { var file = new pbxFile(path, opt); @@ -2005,42 +1951,38 @@ pbxProject.prototype.addFile = function (path, group, opt) { file.fileRef = this.generateUuid(); - this.addToPbxFileReferenceSection(file); // PBXFileReference + this.addToPbxFileReferenceSection(file); // PBXFileReference if (this.getPBXGroupByKey(group)) { - this.addToPbxGroup(file, group); // PBXGroup - } - else if (this.getPBXVariantGroupByKey(group)) { - this.addToPbxVariantGroup(file, group); // PBXVariantGroup + this.addToPbxGroup(file, group); // PBXGroup + } else if (this.getPBXVariantGroupByKey(group)) { + this.addToPbxVariantGroup(file, group); // PBXVariantGroup } return file; -} +}; pbxProject.prototype.removeFile = function (path, group, opt) { var file = new pbxFile(path, opt); - this.removeFromPbxFileReferenceSection(file); // PBXFileReference + this.removeFromPbxFileReferenceSection(file); // PBXFileReference if (this.getPBXGroupByKey(group)) { - this.removeFromPbxGroup(file, group); // PBXGroup - } - else if (this.getPBXVariantGroupByKey(group)) { - this.removeFromPbxVariantGroup(file, group); // PBXVariantGroup + this.removeFromPbxGroup(file, group); // PBXGroup + } else if (this.getPBXVariantGroupByKey(group)) { + this.removeFromPbxVariantGroup(file, group); // PBXVariantGroup } return file; -} - - +}; -pbxProject.prototype.getBuildProperty = function(prop, build) { +pbxProject.prototype.getBuildProperty = function (prop, build) { var target; var configs = this.pbxXCBuildConfigurationSection(); for (var configName in configs) { if (!COMMENT_KEY.test(configName)) { var config = configs[configName]; - if ( (build && config.name === build) || (build === undefined) ) { + if ((build && config.name === build) || (build === undefined)) { if (config.buildSettings[prop] !== undefined) { target = config.buildSettings[prop]; } @@ -2048,23 +1990,23 @@ pbxProject.prototype.getBuildProperty = function(prop, build) { } } return target; -} +}; -pbxProject.prototype.getBuildConfigByName = function(name) { +pbxProject.prototype.getBuildConfigByName = function (name) { var target = {}; var configs = this.pbxXCBuildConfigurationSection(); for (var configName in configs) { if (!COMMENT_KEY.test(configName)) { var config = configs[configName]; - if (config.name === name) { + if (config.name === name) { target[configName] = config; } } } return target; -} +}; -pbxProject.prototype.addDataModelDocument = function(filePath, group, opt) { +pbxProject.prototype.addDataModelDocument = function (filePath, group, opt) { if (!group) { group = 'Resources'; } @@ -2094,7 +2036,7 @@ pbxProject.prototype.addDataModelDocument = function(filePath, group, opt) { var modelFileName = modelFiles[index]; var modelFilePath = path.join(filePath, modelFileName); - if (modelFileName == '.xccurrentversion') { + if (modelFileName === '.xccurrentversion') { currentVersionName = plist.readFileSync(modelFilePath)._XCCurrentVersionName; continue; } @@ -2118,27 +2060,27 @@ pbxProject.prototype.addDataModelDocument = function(filePath, group, opt) { this.addToXcVersionGroupSection(file); return file; -} +}; -pbxProject.prototype.addTargetAttribute = function(prop, value, target) { - var attributes = this.getFirstProject()['firstProject']['attributes']; - if (attributes['TargetAttributes'] === undefined) { - attributes['TargetAttributes'] = {}; +pbxProject.prototype.addTargetAttribute = function (prop, value, target) { + var attributes = this.getFirstProject().firstProject.attributes; + if (attributes.TargetAttributes === undefined) { + attributes.TargetAttributes = {}; } target = target || this.getFirstTarget(); - if (attributes['TargetAttributes'][target.uuid] === undefined) { - attributes['TargetAttributes'][target.uuid] = {}; + if (attributes.TargetAttributes[target.uuid] === undefined) { + attributes.TargetAttributes[target.uuid] = {}; } - attributes['TargetAttributes'][target.uuid][prop] = value; -} + attributes.TargetAttributes[target.uuid][prop] = value; +}; -pbxProject.prototype.removeTargetAttribute = function(prop, target) { - var attributes = this.getFirstProject()['firstProject']['attributes']; +pbxProject.prototype.removeTargetAttribute = function (prop, target) { + var attributes = this.getFirstProject().firstProject.attributes; target = target || this.getFirstTarget(); - if (attributes['TargetAttributes'] && - attributes['TargetAttributes'][target.uuid]) { - delete attributes['TargetAttributes'][target.uuid][prop]; + if (attributes.TargetAttributes && + attributes.TargetAttributes[target.uuid]) { + delete attributes.TargetAttributes[target.uuid][prop]; } -} +}; module.exports = pbxProject; diff --git a/lib/pbxWriter.js b/lib/pbxWriter.js index d297bc7..a6d918a 100644 --- a/lib/pbxWriter.js +++ b/lib/pbxWriter.js @@ -15,52 +15,44 @@ under the License. */ -var pbxProj = require('./pbxProject'), - util = require('util'), - f = util.format, - INDENT = '\t', - COMMENT_KEY = /_comment$/, - QUOTED = /^"(.*)"$/, - EventEmitter = require('events').EventEmitter +var util = require('util'); +var f = util.format; +var INDENT = '\t'; +var COMMENT_KEY = /_comment$/; +var EventEmitter = require('events').EventEmitter; // indentation -function i(x) { - if (x <=0) - return ''; - else - return INDENT + i(x-1); +function i (x) { + if (x <= 0) { return ''; } else { return INDENT + i(x - 1); } } -function comment(key, parent) { +function comment (key, parent) { var text = parent[key + '_comment']; - if (text) - return text; - else - return null; + if (text) { return text; } else { return null; } } // copied from underscore -function isObject(obj) { - return obj === Object(obj) +function isObject (obj) { + return obj === Object(obj); } -function isArray(obj) { - return Array.isArray(obj) +function isArray (obj) { + return Array.isArray(obj); } -function pbxWriter(contents, options) { +function pbxWriter (contents, options) { if (!options) { - options = {} + options = {}; } if (options.omitEmptyValues === undefined) { - options.omitEmptyValues = false + options.omitEmptyValues = false; } this.contents = contents; this.sync = false; this.indentLevel = 0; - this.omitEmptyValues = options.omitEmptyValues + this.omitEmptyValues = options.omitEmptyValues; } util.inherits(pbxWriter, EventEmitter); @@ -69,43 +61,45 @@ pbxWriter.prototype.write = function (str) { var fmt = f.apply(null, arguments); if (this.sync) { - this.buffer += f("%s%s", i(this.indentLevel), fmt); + this.buffer += f('%s%s', i(this.indentLevel), fmt); } else { // do stream write } -} +}; pbxWriter.prototype.writeFlush = function (str) { var oldIndent = this.indentLevel; this.indentLevel = 0; - this.write.apply(this, arguments) + this.write.apply(this, arguments); this.indentLevel = oldIndent; -} +}; pbxWriter.prototype.writeSync = function () { this.sync = true; - this.buffer = ""; + this.buffer = ''; this.writeHeadComment(); this.writeProject(); return this.buffer; -} +}; pbxWriter.prototype.writeHeadComment = function () { if (this.contents.headComment) { - this.write("// %s\n", this.contents.headComment) + this.write('// %s\n', this.contents.headComment); } -} +}; pbxWriter.prototype.writeProject = function () { - var proj = this.contents.project, - key, cmt, obj; + var proj = this.contents.project; + var key; + var cmt; + var obj; - this.write("{\n") + this.write('{\n'); if (proj) { this.indentLevel++; @@ -118,36 +112,38 @@ pbxWriter.prototype.writeProject = function () { obj = proj[key]; if (isArray(obj)) { - this.writeArray(obj, key) + this.writeArray(obj, key); } else if (isObject(obj)) { - this.write("%s = {\n", key); + this.write('%s = {\n', key); this.indentLevel++; if (key === 'objects') { - this.writeObjectsSections(obj) + this.writeObjectsSections(obj); } else { - this.writeObject(obj) + this.writeObject(obj); } this.indentLevel--; - this.write("};\n"); + this.write('};\n'); } else if (this.omitEmptyValues && (obj === undefined || obj === null)) { continue; } else if (cmt) { - this.write("%s = %s /* %s */;\n", key, obj, cmt) + this.write('%s = %s /* %s */;\n', key, obj, cmt); } else { - this.write("%s = %s;\n", key, obj) + this.write('%s = %s;\n', key, obj); } } this.indentLevel--; } - this.write("}\n") -} + this.write('}\n'); +}; pbxWriter.prototype.writeObject = function (object) { - var key, obj, cmt; + var key; + var obj; + var cmt; for (key in object) { if (COMMENT_KEY.test(key)) continue; @@ -156,32 +152,33 @@ pbxWriter.prototype.writeObject = function (object) { obj = object[key]; if (isArray(obj)) { - this.writeArray(obj, key) + this.writeArray(obj, key); } else if (isObject(obj)) { - this.write("%s = {\n", key); + this.write('%s = {\n', key); this.indentLevel++; - this.writeObject(obj) + this.writeObject(obj); this.indentLevel--; - this.write("};\n"); + this.write('};\n'); } else { if (this.omitEmptyValues && (obj === undefined || obj === null)) { continue; } else if (cmt) { - this.write("%s = %s /* %s */;\n", key, obj, cmt) + this.write('%s = %s /* %s */;\n', key, obj, cmt); } else { - this.write("%s = %s;\n", key, obj) + this.write('%s = %s;\n', key, obj); } } } -} +}; pbxWriter.prototype.writeObjectsSections = function (objects) { - var key, obj; + var key; + var obj; for (key in objects) { - this.writeFlush("\n") + this.writeFlush('\n'); obj = objects[key]; @@ -193,16 +190,17 @@ pbxWriter.prototype.writeObjectsSections = function (objects) { this.writeSectionComment(key, false); } } -} +}; pbxWriter.prototype.writeArray = function (arr, name) { - var i, entry; + var i; + var entry; - this.write("%s = (\n", name); + this.write('%s = (\n', name); this.indentLevel++; - for (i=0; i < arr.length; i++) { - entry = arr[i] + for (i = 0; i < arr.length; i++) { + entry = arr[i]; if (entry.value && entry.comment) { this.write('%s /* %s */,\n', entry.value, entry.comment); @@ -220,57 +218,61 @@ pbxWriter.prototype.writeArray = function (arr, name) { } this.indentLevel--; - this.write(");\n"); -} + this.write(');\n'); +}; pbxWriter.prototype.writeSectionComment = function (name, begin) { if (begin) { - this.writeFlush("/* Begin %s section */\n", name) + this.writeFlush('/* Begin %s section */\n', name); } else { // end - this.writeFlush("/* End %s section */\n", name) + this.writeFlush('/* End %s section */\n', name); } -} +}; pbxWriter.prototype.writeSection = function (section) { - var key, obj, cmt; + var key; + var obj; + var cmt; // section should only contain objects for (key in section) { if (COMMENT_KEY.test(key)) continue; cmt = comment(key, section); - obj = section[key] + obj = section[key]; - if (obj.isa == 'PBXBuildFile' || obj.isa == 'PBXFileReference') { + if (obj.isa === 'PBXBuildFile' || obj.isa === 'PBXFileReference') { this.writeInlineObject(key, cmt, obj); } else { if (cmt) { - this.write("%s /* %s */ = {\n", key, cmt); + this.write('%s /* %s */ = {\n', key, cmt); } else { - this.write("%s = {\n", key); + this.write('%s = {\n', key); } - this.indentLevel++ + this.indentLevel++; - this.writeObject(obj) + this.writeObject(obj); - this.indentLevel-- - this.write("};\n"); + this.indentLevel--; + this.write('};\n'); } } -} +}; pbxWriter.prototype.writeInlineObject = function (n, d, r) { var output = []; - var self = this + var self = this; var inlineObjectHelper = function (name, desc, ref) { - var key, cmt, obj; + var key; + var cmt; + var obj; if (desc) { - output.push(f("%s /* %s */ = {", name, desc)); + output.push(f('%s /* %s */ = {', name, desc)); } else { - output.push(f("%s = {", name)); + output.push(f('%s = {', name)); } for (key in ref) { @@ -280,30 +282,30 @@ pbxWriter.prototype.writeInlineObject = function (n, d, r) { obj = ref[key]; if (isArray(obj)) { - output.push(f("%s = (", key)); + output.push(f('%s = (', key)); - for (var i=0; i < obj.length; i++) { - output.push(f("%s, ", obj[i])) + for (var i = 0; i < obj.length; i++) { + output.push(f('%s, ', obj[i])); } - output.push("); "); + output.push('); '); } else if (isObject(obj)) { - inlineObjectHelper(key, cmt, obj) + inlineObjectHelper(key, cmt, obj); } else if (self.omitEmptyValues && (obj === undefined || obj === null)) { continue; } else if (cmt) { - output.push(f("%s = %s /* %s */; ", key, obj, cmt)) + output.push(f('%s = %s /* %s */; ', key, obj, cmt)); } else { - output.push(f("%s = %s; ", key, obj)) + output.push(f('%s = %s; ', key, obj)); } } - output.push("}; "); - } + output.push('}; '); + }; inlineObjectHelper(n, d, r); - this.write("%s\n", output.join('').trim()); -} + this.write('%s\n', output.join('').trim()); +}; module.exports = pbxWriter; diff --git a/package.json b/package.json index 2493cc5..37246c0 100644 --- a/package.json +++ b/package.json @@ -14,12 +14,14 @@ "uuid": "^7.0.3" }, "devDependencies": { + "@cordova/eslint-config": "^3.0.0", "nodeunit": "^0.11.3", "pegjs": "^0.10.0" }, "scripts": { "pegjs": "node_modules/.bin/pegjs lib/parser/pbxproj.pegjs", - "test": "node_modules/.bin/nodeunit test/parser test" + "test": "npm run lint && node_modules/.bin/nodeunit test/parser test", + "lint": "eslint ." }, "license": "Apache-2.0", "contributors": [ diff --git a/test/BuildSettings.js b/test/BuildSettings.js index 213f575..067d30e 100644 --- a/test/BuildSettings.js +++ b/test/BuildSettings.js @@ -15,44 +15,44 @@ under the License. */ -var fullProject = require('./fixtures/full-project') - fullProjectStr = JSON.stringify(fullProject), - pbx = require('../lib/pbxProject'), - pbxFile = require('../lib/pbxFile'), - proj = new pbx('.'); +var fullProject = require('./fixtures/full-project'); -function cleanHash() { +var fullProjectStr = JSON.stringify(fullProject); +var pbx = require('../lib/pbxProject'); +var proj = new pbx('.'); + +function cleanHash () { return JSON.parse(fullProjectStr); } exports.setUp = function (callback) { proj.hash = cleanHash(); callback(); -} +}; var PRODUCT_NAME = '"KitchenSinktablet"'; exports.addAndRemoveToFromBuildSettings = { - 'add should add the build setting to each configuration section':function(test) { + 'add should add the build setting to each configuration section': function (test) { var buildSetting = 'some/buildSetting'; var value = 'some/buildSetting'; proj.addToBuildSettings(buildSetting, value); var config = proj.pbxXCBuildConfigurationSection(); for (var ref in config) { - if (ref.indexOf('_comment') > -1 || config[ref].buildSettings.PRODUCT_NAME != PRODUCT_NAME) continue; + if (ref.indexOf('_comment') > -1 || config[ref].buildSettings.PRODUCT_NAME !== PRODUCT_NAME) continue; test.ok(config[ref].buildSettings[buildSetting] === value); } test.done(); }, - 'remove should remove from the build settings in each configuration section':function(test) { + 'remove should remove from the build settings in each configuration section': function (test) { var buildSetting = 'some/buildSetting'; proj.addToBuildSettings(buildSetting, 'some/buildSetting'); proj.removeFromBuildSettings(buildSetting); var config = proj.pbxXCBuildConfigurationSection(); for (var ref in config) { - if (ref.indexOf('_comment') > -1 || config[ref].buildSettings.PRODUCT_NAME != PRODUCT_NAME) continue; - test.ok(!config[ref].buildSettings.hasOwnProperty(buildSetting)); + if (ref.indexOf('_comment') > -1 || config[ref].buildSettings.PRODUCT_NAME !== PRODUCT_NAME) continue; + test.ok(!Object.prototype.hasOwnProperty.call(config[ref].buildSettings, buildSetting)); } test.done(); } -} +}; diff --git a/test/FrameworkSearchPaths.js b/test/FrameworkSearchPaths.js index b709f3a..142a4d6 100644 --- a/test/FrameworkSearchPaths.js +++ b/test/FrameworkSearchPaths.js @@ -15,49 +15,49 @@ under the License. */ -var fullProject = require('./fixtures/full-project') - fullProjectStr = JSON.stringify(fullProject), - pbx = require('../lib/pbxProject'), - pbxFile = require('../lib/pbxFile'), - proj = new pbx('.'); +var fullProject = require('./fixtures/full-project'); + +var fullProjectStr = JSON.stringify(fullProject); +var pbx = require('../lib/pbxProject'); +var proj = new pbx('.'); var pbxFile = { - path:'some/path/include', - dirname: 'some/path', - customFramework: true -} -function cleanHash() { + path: 'some/path/include', + dirname: 'some/path', + customFramework: true +}; +function cleanHash () { return JSON.parse(fullProjectStr); } exports.setUp = function (callback) { proj.hash = cleanHash(); callback(); -} +}; var PRODUCT_NAME = '"KitchenSinktablet"'; exports.addAndRemoveToFromFrameworkSearchPaths = { - 'add should add the path to each configuration section':function(test) { + 'add should add the path to each configuration section': function (test) { proj.addToFrameworkSearchPaths(pbxFile); var config = proj.pbxXCBuildConfigurationSection(); for (var ref in config) { - if (ref.indexOf('_comment') > -1 || config[ref].buildSettings.PRODUCT_NAME != PRODUCT_NAME) continue; + if (ref.indexOf('_comment') > -1 || config[ref].buildSettings.PRODUCT_NAME !== PRODUCT_NAME) continue; var lib = config[ref].buildSettings.FRAMEWORK_SEARCH_PATHS; test.ok(lib[1].indexOf('some/path') > -1); } test.done(); }, - 'remove should remove from the path to each configuration section':function(test) { + 'remove should remove from the path to each configuration section': function (test) { proj.addToFrameworkSearchPaths(pbxFile); proj.removeFromFrameworkSearchPaths(pbxFile); var config = proj.pbxXCBuildConfigurationSection(); for (var ref in config) { - if (ref.indexOf('_comment') > -1 || config[ref].buildSettings.PRODUCT_NAME != PRODUCT_NAME) continue; + if (ref.indexOf('_comment') > -1 || config[ref].buildSettings.PRODUCT_NAME !== PRODUCT_NAME) continue; var lib = config[ref].buildSettings.FRAMEWORK_SEARCH_PATHS; test.ok(lib.length === 1); - test.ok(lib[0].indexOf('some/path') == -1); + test.ok(lib[0].indexOf('some/path') === -1); } test.done(); } -} +}; diff --git a/test/HeaderSearchPaths.js b/test/HeaderSearchPaths.js index 998fd8b..816498d 100644 --- a/test/HeaderSearchPaths.js +++ b/test/HeaderSearchPaths.js @@ -15,62 +15,62 @@ under the License. */ -var fullProject = require('./fixtures/full-project') - fullProjectStr = JSON.stringify(fullProject), - pbx = require('../lib/pbxProject'), - pbxFile = require('../lib/pbxFile'), - proj = new pbx('.'); +var fullProject = require('./fixtures/full-project'); -function cleanHash() { +var fullProjectStr = JSON.stringify(fullProject); +var pbx = require('../lib/pbxProject'); +var proj = new pbx('.'); + +function cleanHash () { return JSON.parse(fullProjectStr); } exports.setUp = function (callback) { proj.hash = cleanHash(); callback(); -} +}; var PRODUCT_NAME = '"KitchenSinktablet"'; exports.addAndRemoveToFromHeaderSearchPaths = { - 'add should add the path to each configuration section':function(test) { + 'add should add the path to each configuration section': function (test) { proj.addToHeaderSearchPaths({ - path:'some/path/include' + path: 'some/path/include' }); var config = proj.pbxXCBuildConfigurationSection(); for (var ref in config) { - if (ref.indexOf('_comment') > -1 || config[ref].buildSettings.PRODUCT_NAME != PRODUCT_NAME) continue; + if (ref.indexOf('_comment') > -1 || config[ref].buildSettings.PRODUCT_NAME !== PRODUCT_NAME) continue; var lib = config[ref].buildSettings.HEADER_SEARCH_PATHS; test.ok(lib[1].indexOf('$(SRCROOT)/KitchenSinktablet/some/path') > -1); } test.done(); }, - 'add should not mangle string arguments and add to each config section':function(test) { + 'add should not mangle string arguments and add to each config section': function (test) { var includePath = '../../some/path'; proj.addToHeaderSearchPaths(includePath); var config = proj.pbxXCBuildConfigurationSection(); for (var ref in config) { - if (ref.indexOf('_comment') > -1 || config[ref].buildSettings.PRODUCT_NAME != PRODUCT_NAME) continue; + if (ref.indexOf('_comment') > -1 || config[ref].buildSettings.PRODUCT_NAME !== PRODUCT_NAME) continue; var lib = config[ref].buildSettings.HEADER_SEARCH_PATHS; test.ok(lib[1].indexOf(includePath) > -1); } test.done(); }, - 'remove should remove from the path to each configuration section':function(test) { + 'remove should remove from the path to each configuration section': function (test) { var libPath = 'some/path/include'; proj.addToHeaderSearchPaths({ - path:libPath + path: libPath }); proj.removeFromHeaderSearchPaths({ - path:libPath + path: libPath }); var config = proj.pbxXCBuildConfigurationSection(); for (var ref in config) { - if (ref.indexOf('_comment') > -1 || config[ref].buildSettings.PRODUCT_NAME != PRODUCT_NAME) continue; + if (ref.indexOf('_comment') > -1 || config[ref].buildSettings.PRODUCT_NAME !== PRODUCT_NAME) continue; var lib = config[ref].buildSettings.HEADER_SEARCH_PATHS; test.ok(lib.length === 1); - test.ok(lib[0].indexOf('$(SRCROOT)/KitchenSinktablet/some/path/include') == -1); + test.ok(lib[0].indexOf('$(SRCROOT)/KitchenSinktablet/some/path/include') === -1); } test.done(); } -} +}; diff --git a/test/LibrarySearchPaths.js b/test/LibrarySearchPaths.js index 6788e10..b5d0d94 100644 --- a/test/LibrarySearchPaths.js +++ b/test/LibrarySearchPaths.js @@ -15,62 +15,62 @@ under the License. */ -var fullProject = require('./fixtures/full-project') - fullProjectStr = JSON.stringify(fullProject), - pbx = require('../lib/pbxProject'), - pbxFile = require('../lib/pbxFile'), - proj = new pbx('.'); +var fullProject = require('./fixtures/full-project'); -function cleanHash() { +var fullProjectStr = JSON.stringify(fullProject); +var pbx = require('../lib/pbxProject'); +var proj = new pbx('.'); + +function cleanHash () { return JSON.parse(fullProjectStr); } exports.setUp = function (callback) { proj.hash = cleanHash(); callback(); -} +}; var PRODUCT_NAME = '"KitchenSinktablet"'; exports.addAndRemoveToFromLibrarySearchPaths = { - 'add should add the path to each configuration section':function(test) { + 'add should add the path to each configuration section': function (test) { proj.addToLibrarySearchPaths({ - path:'some/path/poop.a' + path: 'some/path/poop.a' }); var config = proj.pbxXCBuildConfigurationSection(); for (var ref in config) { - if (ref.indexOf('_comment') > -1 || config[ref].buildSettings.PRODUCT_NAME != PRODUCT_NAME) continue; + if (ref.indexOf('_comment') > -1 || config[ref].buildSettings.PRODUCT_NAME !== PRODUCT_NAME) continue; var lib = config[ref].buildSettings.LIBRARY_SEARCH_PATHS; test.ok(lib[1].indexOf('$(SRCROOT)/KitchenSinktablet/some/path') > -1); } test.done(); }, - 'add should not mangle string arguments and add to each config section':function(test) { + 'add should not mangle string arguments and add to each config section': function (test) { var libPath = '../../some/path'; proj.addToLibrarySearchPaths(libPath); var config = proj.pbxXCBuildConfigurationSection(); for (var ref in config) { - if (ref.indexOf('_comment') > -1 || config[ref].buildSettings.PRODUCT_NAME != PRODUCT_NAME) continue; + if (ref.indexOf('_comment') > -1 || config[ref].buildSettings.PRODUCT_NAME !== PRODUCT_NAME) continue; var lib = config[ref].buildSettings.LIBRARY_SEARCH_PATHS; test.ok(lib[1].indexOf(libPath) > -1); } test.done(); }, - 'remove should remove from the path to each configuration section':function(test) { + 'remove should remove from the path to each configuration section': function (test) { var libPath = 'some/path/poop.a'; proj.addToLibrarySearchPaths({ - path:libPath + path: libPath }); proj.removeFromLibrarySearchPaths({ - path:libPath + path: libPath }); var config = proj.pbxXCBuildConfigurationSection(); for (var ref in config) { - if (ref.indexOf('_comment') > -1 || config[ref].buildSettings.PRODUCT_NAME != PRODUCT_NAME) continue; + if (ref.indexOf('_comment') > -1 || config[ref].buildSettings.PRODUCT_NAME !== PRODUCT_NAME) continue; var lib = config[ref].buildSettings.LIBRARY_SEARCH_PATHS; test.ok(lib.length === 1); - test.ok(lib[0].indexOf('$(SRCROOT)/KitchenSinktablet/some/path') == -1); + test.ok(lib[0].indexOf('$(SRCROOT)/KitchenSinktablet/some/path') === -1); } test.done(); } -} +}; diff --git a/test/OtherLinkerFlags.js b/test/OtherLinkerFlags.js index de59f4c..4fe6a1f 100644 --- a/test/OtherLinkerFlags.js +++ b/test/OtherLinkerFlags.js @@ -15,46 +15,46 @@ under the License. */ -var fullProject = require('./fixtures/full-project') - fullProjectStr = JSON.stringify(fullProject), - pbx = require('../lib/pbxProject'), - pbxFile = require('../lib/pbxFile'), - proj = new pbx('.'); +var fullProject = require('./fixtures/full-project'); -function cleanHash() { +var fullProjectStr = JSON.stringify(fullProject); +var pbx = require('../lib/pbxProject'); +var proj = new pbx('.'); + +function cleanHash () { return JSON.parse(fullProjectStr); } exports.setUp = function (callback) { proj.hash = cleanHash(); callback(); -} +}; var PRODUCT_NAME = '"KitchenSinktablet"'; exports.addAndRemoveToFromOtherLinkerFlags = { - 'add should add the flag to each configuration section':function(test) { + 'add should add the flag to each configuration section': function (test) { var flag = 'some/flag'; proj.addToOtherLinkerFlags(flag); var config = proj.pbxXCBuildConfigurationSection(); for (var ref in config) { - if (ref.indexOf('_comment') > -1 || config[ref].buildSettings.PRODUCT_NAME != PRODUCT_NAME) continue; + if (ref.indexOf('_comment') > -1 || config[ref].buildSettings.PRODUCT_NAME !== PRODUCT_NAME) continue; var lib = config[ref].buildSettings.OTHER_LDFLAGS; test.ok(lib[1].indexOf(flag) > -1); } test.done(); }, - 'remove should remove from the path to each configuration section':function(test) { + 'remove should remove from the path to each configuration section': function (test) { var flag = 'some/flag'; proj.addToOtherLinkerFlags(flag); proj.removeFromOtherLinkerFlags(flag); var config = proj.pbxXCBuildConfigurationSection(); for (var ref in config) { - if (ref.indexOf('_comment') > -1 || config[ref].buildSettings.PRODUCT_NAME != PRODUCT_NAME) continue; + if (ref.indexOf('_comment') > -1 || config[ref].buildSettings.PRODUCT_NAME !== PRODUCT_NAME) continue; var lib = config[ref].buildSettings.OTHER_LDFLAGS; test.ok(lib.length === 1); - test.ok(lib[0].indexOf(flag) == -1); + test.ok(lib[0].indexOf(flag) === -1); } test.done(); } -} +}; diff --git a/test/addBuildPhase.js b/test/addBuildPhase.js index eb105f8..c908e07 100644 --- a/test/addBuildPhase.js +++ b/test/addBuildPhase.js @@ -15,32 +15,33 @@ under the License. */ -var fullProject = require('./fixtures/full-project') - fullProjectStr = JSON.stringify(fullProject), - pbx = require('../lib/pbxProject'), - proj = new pbx('.'); +var fullProject = require('./fixtures/full-project'); -function cleanHash() { +var fullProjectStr = JSON.stringify(fullProject); +var pbx = require('../lib/pbxProject'); +var proj = new pbx('.'); + +function cleanHash () { return JSON.parse(fullProjectStr); } exports.setUp = function (callback) { proj.hash = cleanHash(); callback(); -} +}; exports.addBuildPhase = { 'should return a pbxBuildPhase': function (test) { var buildPhase = proj.addBuildPhase(['file.m'], 'PBXSourcesBuildPhase', 'My build phase'); test.ok(typeof buildPhase === 'object'); - test.done() + test.done(); }, 'should set a uuid on the pbxBuildPhase': function (test) { var buildPhase = proj.addBuildPhase(['file.m'], 'PBXSourcesBuildPhase', 'My build phase'); test.ok(buildPhase.uuid); - test.done() + test.done(); }, 'should add all files to build phase': function (test) { var buildPhase = proj.addBuildPhase(['file.m', 'assets.bundle'], 'PBXResourcesBuildPhase', 'My build phase').buildPhase; @@ -49,11 +50,11 @@ exports.addBuildPhase = { test.ok(file.value); } - test.done() + test.done(); }, 'should add the PBXBuildPhase object correctly': function (test) { - var buildPhase = proj.addBuildPhase(['file.m', 'assets.bundle'], 'PBXResourcesBuildPhase', 'My build phase').buildPhase, - buildPhaseInPbx = proj.buildPhaseObject('PBXResourcesBuildPhase', 'My build phase'); + var buildPhase = proj.addBuildPhase(['file.m', 'assets.bundle'], 'PBXResourcesBuildPhase', 'My build phase').buildPhase; + var buildPhaseInPbx = proj.buildPhaseObject('PBXResourcesBuildPhase', 'My build phase'); test.equal(buildPhaseInPbx, buildPhase); test.equal(buildPhaseInPbx.isa, 'PBXResourcesBuildPhase'); @@ -62,8 +63,8 @@ exports.addBuildPhase = { test.done(); }, 'should add each of the files to PBXBuildFile section': function (test) { - var buildPhase = proj.addBuildPhase(['file.m', 'assets.bundle'], 'PBXResourcesBuildPhase', 'My build phase').buildPhase, - buildFileSection = proj.pbxBuildFileSection(); + var buildPhase = proj.addBuildPhase(['file.m', 'assets.bundle'], 'PBXResourcesBuildPhase', 'My build phase').buildPhase; + var buildFileSection = proj.pbxBuildFileSection(); for (var index = 0; index < buildPhase.files.length; index++) { var file = buildPhase.files[index]; @@ -73,14 +74,13 @@ exports.addBuildPhase = { test.done(); }, 'should add each of the files to PBXFileReference section': function (test) { - var buildPhase = proj.addBuildPhase(['file.m', 'assets.bundle'], 'PBXResourcesBuildPhase', 'My build phase').buildPhase, - fileRefSection = proj.pbxFileReferenceSection(), - buildFileSection = proj.pbxBuildFileSection(), - fileRefs = []; + var buildPhase = proj.addBuildPhase(['file.m', 'assets.bundle'], 'PBXResourcesBuildPhase', 'My build phase').buildPhase; + var fileRefSection = proj.pbxFileReferenceSection(); + var buildFileSection = proj.pbxBuildFileSection(); for (var index = 0; index < buildPhase.files.length; index++) { - var file = buildPhase.files[index], - fileRef = buildFileSection[file.value].fileRef; + var file = buildPhase.files[index]; + var fileRef = buildFileSection[file.value].fileRef; test.ok(fileRefSection[fileRef]); } @@ -88,33 +88,33 @@ exports.addBuildPhase = { test.done(); }, 'should not add files to PBXFileReference section if already added': function (test) { - var fileRefSection = proj.pbxFileReferenceSection(), - initialFileReferenceSectionItemsCount = Object.keys(fileRefSection), - buildPhase = proj.addBuildPhase(['AppDelegate.m', 'main.m'], 'PBXResourcesBuildPhase', 'My build phase').buildPhase, - afterAdditionBuildFileSectionItemsCount = Object.keys(fileRefSection); + var fileRefSection = proj.pbxFileReferenceSection(); + var initialFileReferenceSectionItemsCount = Object.keys(fileRefSection); + proj.addBuildPhase(['AppDelegate.m', 'main.m'], 'PBXResourcesBuildPhase', 'My build phase'); + var afterAdditionBuildFileSectionItemsCount = Object.keys(fileRefSection); test.deepEqual(initialFileReferenceSectionItemsCount, afterAdditionBuildFileSectionItemsCount); test.done(); }, 'should not add files to PBXBuildFile section if already added': function (test) { - var buildFileSection = proj.pbxBuildFileSection(), - initialBuildFileSectionItemsCount = Object.keys(buildFileSection), - buildPhase = proj.addBuildPhase(['AppDelegate.m', 'main.m'], 'PBXResourcesBuildPhase', 'My build phase').buildPhase, - afterAdditionBuildFileSectionItemsCount = Object.keys(buildFileSection); + var buildFileSection = proj.pbxBuildFileSection(); + var initialBuildFileSectionItemsCount = Object.keys(buildFileSection); + proj.addBuildPhase(['AppDelegate.m', 'main.m'], 'PBXResourcesBuildPhase', 'My build phase'); + var afterAdditionBuildFileSectionItemsCount = Object.keys(buildFileSection); test.deepEqual(initialBuildFileSectionItemsCount, afterAdditionBuildFileSectionItemsCount); test.done(); }, 'should add only missing files to PBXFileReference section': function (test) { - var fileRefSection = proj.pbxFileReferenceSection(), - buildFileSection = proj.pbxBuildFileSection(), - initialFileReferenceSectionItemsCount = Object.keys(fileRefSection), - buildPhase = proj.addBuildPhase(['file.m', 'AppDelegate.m'], 'PBXResourcesBuildPhase', 'My build phase').buildPhase, - afterAdditionBuildFileSectionItemsCount = Object.keys(fileRefSection); + var fileRefSection = proj.pbxFileReferenceSection(); + var buildFileSection = proj.pbxBuildFileSection(); + var initialFileReferenceSectionItemsCount = Object.keys(fileRefSection); + var buildPhase = proj.addBuildPhase(['file.m', 'AppDelegate.m'], 'PBXResourcesBuildPhase', 'My build phase').buildPhase; + var afterAdditionBuildFileSectionItemsCount = Object.keys(fileRefSection); for (var index = 0; index < buildPhase.files.length; index++) { - var file = buildPhase.files[index], - fileRef = buildFileSection[file.value].fileRef; + var file = buildPhase.files[index]; + var fileRef = buildFileSection[file.value].fileRef; test.ok(fileRefSection[fileRef]); } @@ -187,11 +187,11 @@ exports.addBuildPhase = { test.equal(buildPhase.dstSubfolderSpec, 13); test.done(); }, - 'should add a script build phase to echo "hello world!"': function(test) { - var options = {shellPath: '/bin/sh', shellScript: 'echo "hello world!"'}; + 'should add a script build phase to echo "hello world!"': function (test) { + var options = { shellPath: '/bin/sh', shellScript: 'echo "hello world!"' }; var buildPhase = proj.addBuildPhase([], 'PBXShellScriptBuildPhase', 'Run a script', proj.getFirstTarget().uuid, options).buildPhase; test.equal(buildPhase.shellPath, '/bin/sh'); test.equal(buildPhase.shellScript, '"echo \\"hello world!\\""'); test.done(); - }, -} + } +}; diff --git a/test/addFramework.js b/test/addFramework.js index c3c3200..30e871e 100644 --- a/test/addFramework.js +++ b/test/addFramework.js @@ -15,24 +15,26 @@ under the License. */ -var fullProject = require('./fixtures/full-project') - fullProjectStr = JSON.stringify(fullProject), - pbx = require('../lib/pbxProject'), - pbxFile = require('../lib/pbxFile'), - proj = new pbx('.'); +var fullProject = require('./fixtures/full-project'); -function cleanHash() { +var fullProjectStr = JSON.stringify(fullProject); +var pbx = require('../lib/pbxProject'); +var pbxFile = require('../lib/pbxFile'); +var proj = new pbx('.'); + +function cleanHash () { return JSON.parse(fullProjectStr); } exports.setUp = function (callback) { proj.hash = cleanHash(); callback(); -} +}; -function nonComments(obj) { - var keys = Object.keys(obj), - newObj = {}, i = 0; +function nonComments (obj) { + var keys = Object.keys(obj); + var newObj = {}; + var i = 0; for (i; i < keys.length; i++) { if (!/_comment$/.test(keys[i])) { @@ -43,16 +45,18 @@ function nonComments(obj) { return newObj; } -function frameworkSearchPaths(proj) { - var configs = nonComments(proj.pbxXCBuildConfigurationSection()), - allPaths = [], - ids = Object.keys(configs), i, buildSettings; +function frameworkSearchPaths (proj) { + var configs = nonComments(proj.pbxXCBuildConfigurationSection()); + var allPaths = []; + var ids = Object.keys(configs); + var i; + var buildSettings; - for (i = 0; i< ids.length; i++) { + for (i = 0; i < ids.length; i++) { buildSettings = configs[ids[i]].buildSettings; - if (buildSettings['FRAMEWORK_SEARCH_PATHS']) { - allPaths.push(buildSettings['FRAMEWORK_SEARCH_PATHS']); + if (buildSettings.FRAMEWORK_SEARCH_PATHS) { + allPaths.push(buildSettings.FRAMEWORK_SEARCH_PATHS); } } @@ -64,18 +68,18 @@ exports.addFramework = { var newFile = proj.addFramework('libsqlite3.dylib'); test.equal(newFile.constructor, pbxFile); - test.done() + test.done(); }, 'should set a fileRef on the pbxFile': function (test) { var newFile = proj.addFramework('libsqlite3.dylib'); test.ok(newFile.fileRef); - test.done() + test.done(); }, 'should populate the PBXFileReference section with 2 fields': function (test) { var newFile = proj.addFramework('libsqlite3.dylib'); - fileRefSection = proj.pbxFileReferenceSection(), - frsLength = Object.keys(fileRefSection).length; + var fileRefSection = proj.pbxFileReferenceSection(); + var frsLength = Object.keys(fileRefSection).length; test.equal(68, frsLength); test.ok(fileRefSection[newFile.fileRef]); @@ -85,16 +89,16 @@ exports.addFramework = { }, 'should populate the PBXFileReference comment correctly': function (test) { var newFile = proj.addFramework('libsqlite3.dylib'); - fileRefSection = proj.pbxFileReferenceSection(), - commentKey = newFile.fileRef + '_comment'; + var fileRefSection = proj.pbxFileReferenceSection(); + var commentKey = newFile.fileRef + '_comment'; test.equal(fileRefSection[commentKey], 'libsqlite3.dylib'); test.done(); }, 'should add the PBXFileReference object correctly': function (test) { - var newFile = proj.addFramework('libsqlite3.dylib'), - fileRefSection = proj.pbxFileReferenceSection(), - fileRefEntry = fileRefSection[newFile.fileRef]; + var newFile = proj.addFramework('libsqlite3.dylib'); + var fileRefSection = proj.pbxFileReferenceSection(); + var fileRefEntry = fileRefSection[newFile.fileRef]; test.equal(fileRefEntry.isa, 'PBXFileReference'); test.equal(fileRefEntry.lastKnownFileType, 'compiled.mach-o.dylib'); @@ -105,9 +109,9 @@ exports.addFramework = { test.done(); }, 'should populate the PBXBuildFile section with 2 fields': function (test) { - var newFile = proj.addFramework('libsqlite3.dylib'), - buildFileSection = proj.pbxBuildFileSection(), - bfsLength = Object.keys(buildFileSection).length; + var newFile = proj.addFramework('libsqlite3.dylib'); + var buildFileSection = proj.pbxBuildFileSection(); + var bfsLength = Object.keys(buildFileSection).length; test.equal(60, bfsLength); test.ok(buildFileSection[newFile.uuid]); @@ -116,17 +120,17 @@ exports.addFramework = { test.done(); }, 'should add the PBXBuildFile comment correctly': function (test) { - var newFile = proj.addFramework('libsqlite3.dylib'), - commentKey = newFile.uuid + '_comment', - buildFileSection = proj.pbxBuildFileSection(); + var newFile = proj.addFramework('libsqlite3.dylib'); + var commentKey = newFile.uuid + '_comment'; + var buildFileSection = proj.pbxBuildFileSection(); test.equal(buildFileSection[commentKey], 'libsqlite3.dylib in Frameworks'); test.done(); }, 'should add the PBXBuildFile object correctly': function (test) { - var newFile = proj.addFramework('libsqlite3.dylib'), - buildFileSection = proj.pbxBuildFileSection(), - buildFileEntry = buildFileSection[newFile.uuid]; + var newFile = proj.addFramework('libsqlite3.dylib'); + var buildFileSection = proj.pbxBuildFileSection(); + var buildFileEntry = buildFileSection[newFile.uuid]; test.equal(buildFileEntry.isa, 'PBXBuildFile'); test.equal(buildFileEntry.fileRef, newFile.fileRef); @@ -136,52 +140,52 @@ exports.addFramework = { test.done(); }, 'should add the PBXBuildFile object correctly /w weak linked frameworks': function (test) { - var newFile = proj.addFramework('libsqlite3.dylib', { weak: true }), - buildFileSection = proj.pbxBuildFileSection(), - buildFileEntry = buildFileSection[newFile.uuid]; + var newFile = proj.addFramework('libsqlite3.dylib', { weak: true }); + var buildFileSection = proj.pbxBuildFileSection(); + var buildFileEntry = buildFileSection[newFile.uuid]; test.equal(buildFileEntry.isa, 'PBXBuildFile'); test.equal(buildFileEntry.fileRef, newFile.fileRef); test.equal(buildFileEntry.fileRef_comment, 'libsqlite3.dylib'); - test.deepEqual(buildFileEntry.settings, { ATTRIBUTES: [ 'Weak' ] }); + test.deepEqual(buildFileEntry.settings, { ATTRIBUTES: ['Weak'] }); test.done(); }, 'should add to the Frameworks PBXGroup': function (test) { - var newLength = proj.pbxGroupByName('Frameworks').children.length + 1, - newFile = proj.addFramework('libsqlite3.dylib'), - frameworks = proj.pbxGroupByName('Frameworks'); + var newLength = proj.pbxGroupByName('Frameworks').children.length + 1; + proj.addFramework('libsqlite3.dylib'); + var frameworks = proj.pbxGroupByName('Frameworks'); test.equal(frameworks.children.length, newLength); test.done(); }, 'should have the right values for the PBXGroup entry': function (test) { - var newFile = proj.addFramework('libsqlite3.dylib'), - frameworks = proj.pbxGroupByName('Frameworks').children, - framework = frameworks[frameworks.length - 1]; + var newFile = proj.addFramework('libsqlite3.dylib'); + var frameworks = proj.pbxGroupByName('Frameworks').children; + var framework = frameworks[frameworks.length - 1]; test.equal(framework.comment, 'libsqlite3.dylib'); test.equal(framework.value, newFile.fileRef); test.done(); }, 'should add to the PBXFrameworksBuildPhase': function (test) { - var newFile = proj.addFramework('libsqlite3.dylib'), - frameworks = proj.pbxFrameworksBuildPhaseObj(); + proj.addFramework('libsqlite3.dylib'); + var frameworks = proj.pbxFrameworksBuildPhaseObj(); test.equal(frameworks.files.length, 16); test.done(); }, 'should not add to the PBXFrameworksBuildPhase': function (test) { - var newFile = proj.addFramework('Private.framework', {link: false}), - frameworks = proj.pbxFrameworksBuildPhaseObj(); + proj.addFramework('Private.framework', { link: false }); + var frameworks = proj.pbxFrameworksBuildPhaseObj(); test.equal(frameworks.files.length, 15); test.done(); }, 'should have the right values for the Sources entry': function (test) { - var newFile = proj.addFramework('libsqlite3.dylib'), - frameworks = proj.pbxFrameworksBuildPhaseObj(), - framework = frameworks.files[15]; + var newFile = proj.addFramework('libsqlite3.dylib'); + var frameworks = proj.pbxFrameworksBuildPhaseObj(); + var framework = frameworks.files[15]; test.equal(framework.comment, 'libsqlite3.dylib in Frameworks'); test.equal(framework.value, newFile.uuid); @@ -189,14 +193,14 @@ exports.addFramework = { }, 'duplicate entries': { 'should return false': function (test) { - var newFile = proj.addFramework('libsqlite3.dylib'); + proj.addFramework('libsqlite3.dylib'); test.ok(!proj.addFramework('libsqlite3.dylib')); test.done(); } }, 'should pbxFile correctly for custom frameworks': function (test) { - var newFile = proj.addFramework('/path/to/Custom.framework', {customFramework: true}); + var newFile = proj.addFramework('/path/to/Custom.framework', { customFramework: true }); test.ok(newFile.customFramework); test.ok(!newFile.fileEncoding); @@ -207,12 +211,11 @@ exports.addFramework = { // XXX framework has to be copied over to PROJECT root. That is what XCode does when you drag&drop test.equal(newFile.path, '/path/to/Custom.framework'); - // should add path to framework search path var frameworkPaths = frameworkSearchPaths(proj); - expectedPath = '"\\"/path/to\\""'; + var expectedPath = '"\\"/path/to\\""'; - for (i = 0; i < frameworkPaths.length; i++) { + for (var i = 0; i < frameworkPaths.length; i++) { var current = frameworkPaths[i]; test.ok(current.indexOf('"$(inherited)"') >= 0); test.ok(current.indexOf(expectedPath) >= 0); @@ -220,8 +223,8 @@ exports.addFramework = { test.done(); }, 'should add to the Embed Frameworks PBXCopyFilesBuildPhase': function (test) { - var newFile = proj.addFramework('/path/to/SomeEmbeddableCustom.framework', {customFramework: true, embed: true}), - frameworks = proj.pbxEmbedFrameworksBuildPhaseObj(); + proj.addFramework('/path/to/SomeEmbeddableCustom.framework', { customFramework: true, embed: true }); + var frameworks = proj.pbxEmbedFrameworksBuildPhaseObj(); var buildPhaseInPbx = proj.pbxEmbedFrameworksBuildPhaseObj(); test.equal(buildPhaseInPbx.dstSubfolderSpec, 10); @@ -230,23 +233,23 @@ exports.addFramework = { test.done(); }, 'should not add to the Embed Frameworks PBXCopyFilesBuildPhase by default': function (test) { - var newFile = proj.addFramework('/path/to/Custom.framework', {customFramework: true}), - frameworks = proj.pbxEmbedFrameworksBuildPhaseObj(); + proj.addFramework('/path/to/Custom.framework', { customFramework: true }); + var frameworks = proj.pbxEmbedFrameworksBuildPhaseObj(); test.equal(frameworks.files.length, 0); test.done(); }, 'should add the PBXBuildFile object correctly /w signable frameworks': function (test) { - var newFile = proj.addFramework('/path/to/SomeSignable.framework', { customFramework: true, embed: true, sign: true }), - buildFileSection = proj.pbxBuildFileSection(), - buildFileEntry = buildFileSection[newFile.uuid]; + var newFile = proj.addFramework('/path/to/SomeSignable.framework', { customFramework: true, embed: true, sign: true }); + var buildFileSection = proj.pbxBuildFileSection(); + var buildFileEntry = buildFileSection[newFile.uuid]; test.equal(newFile.group, 'Embed Frameworks'); test.equal(buildFileEntry.isa, 'PBXBuildFile'); test.equal(buildFileEntry.fileRef, newFile.fileRef); test.equal(buildFileEntry.fileRef_comment, 'SomeSignable.framework'); - test.deepEqual(buildFileEntry.settings, { ATTRIBUTES: [ 'CodeSignOnCopy' ] }); + test.deepEqual(buildFileEntry.settings, { ATTRIBUTES: ['CodeSignOnCopy'] }); test.done(); - }, -} + } +}; diff --git a/test/addHeaderFile.js b/test/addHeaderFile.js index f9bd71a..f17a706 100644 --- a/test/addHeaderFile.js +++ b/test/addHeaderFile.js @@ -15,38 +15,39 @@ under the License. */ -var fullProject = require('./fixtures/full-project') - fullProjectStr = JSON.stringify(fullProject), - pbx = require('../lib/pbxProject'), - pbxFile = require('../lib/pbxFile'), - proj = new pbx('.'); +var fullProject = require('./fixtures/full-project'); -function cleanHash() { +var fullProjectStr = JSON.stringify(fullProject); +var pbx = require('../lib/pbxProject'); +var pbxFile = require('../lib/pbxFile'); +var proj = new pbx('.'); + +function cleanHash () { return JSON.parse(fullProjectStr); } exports.setUp = function (callback) { proj.hash = cleanHash(); callback(); -} +}; exports.addHeaderFile = { 'should return a pbxFile': function (test) { var newFile = proj.addHeaderFile('file.h'); test.equal(newFile.constructor, pbxFile); - test.done() + test.done(); }, 'should set a fileRef on the pbxFile': function (test) { var newFile = proj.addHeaderFile('file.h'); test.ok(newFile.fileRef); - test.done() + test.done(); }, 'should populate the PBXFileReference section with 2 fields': function (test) { - var newFile = proj.addHeaderFile('file.h'), - fileRefSection = proj.pbxFileReferenceSection(), - frsLength = Object.keys(fileRefSection).length; + var newFile = proj.addHeaderFile('file.h'); + var fileRefSection = proj.pbxFileReferenceSection(); + var frsLength = Object.keys(fileRefSection).length; test.equal(68, frsLength); test.ok(fileRefSection[newFile.fileRef]); @@ -55,17 +56,17 @@ exports.addHeaderFile = { test.done(); }, 'should populate the PBXFileReference comment correctly': function (test) { - var newFile = proj.addHeaderFile('file.h'), - fileRefSection = proj.pbxFileReferenceSection(), - commentKey = newFile.fileRef + '_comment'; + var newFile = proj.addHeaderFile('file.h'); + var fileRefSection = proj.pbxFileReferenceSection(); + var commentKey = newFile.fileRef + '_comment'; test.equal(fileRefSection[commentKey], 'file.h'); test.done(); }, 'should add the PBXFileReference object correctly': function (test) { - var newFile = proj.addHeaderFile('Plugins/file.h'), - fileRefSection = proj.pbxFileReferenceSection(), - fileRefEntry = fileRefSection[newFile.fileRef]; + var newFile = proj.addHeaderFile('Plugins/file.h'); + var fileRefSection = proj.pbxFileReferenceSection(); + var fileRefEntry = fileRefSection[newFile.fileRef]; test.equal(fileRefEntry.isa, 'PBXFileReference'); test.equal(fileRefEntry.fileEncoding, 4); @@ -77,16 +78,16 @@ exports.addHeaderFile = { test.done(); }, 'should add to the Plugins PBXGroup group': function (test) { - var newFile = proj.addHeaderFile('Plugins/file.h'), - plugins = proj.pbxGroupByName('Plugins'); + proj.addHeaderFile('Plugins/file.h'); + var plugins = proj.pbxGroupByName('Plugins'); test.equal(plugins.children.length, 1); test.done(); }, 'should have the right values for the PBXGroup entry': function (test) { - var newFile = proj.addHeaderFile('Plugins/file.h'), - plugins = proj.pbxGroupByName('Plugins'), - pluginObj = plugins.children[0]; + var newFile = proj.addHeaderFile('Plugins/file.h'); + var plugins = proj.pbxGroupByName('Plugins'); + var pluginObj = plugins.children[0]; test.equal(pluginObj.comment, 'file.h'); test.equal(pluginObj.value, newFile.fileRef); @@ -94,16 +95,16 @@ exports.addHeaderFile = { }, 'duplicate entries': { 'should return false': function (test) { - var newFile = proj.addHeaderFile('Plugins/file.h'); + proj.addHeaderFile('Plugins/file.h'); test.ok(!proj.addHeaderFile('Plugins/file.h')); test.done(); }, 'should not add another entry anywhere': function (test) { - var newFile = proj.addHeaderFile('Plugins/file.h'), - fileRefSection = proj.pbxFileReferenceSection(), - frsLength = Object.keys(fileRefSection).length, - plugins = proj.pbxGroupByName('Plugins'); + proj.addHeaderFile('Plugins/file.h'); + var fileRefSection = proj.pbxFileReferenceSection(); + var frsLength = Object.keys(fileRefSection).length; + var plugins = proj.pbxGroupByName('Plugins'); proj.addHeaderFile('Plugins/file.h'); @@ -112,4 +113,4 @@ exports.addHeaderFile = { test.done(); } } -} +}; diff --git a/test/addRemovePbxGroup.js b/test/addRemovePbxGroup.js index 8212f91..938f4fa 100644 --- a/test/addRemovePbxGroup.js +++ b/test/addRemovePbxGroup.js @@ -15,32 +15,33 @@ under the License. */ -var fullProject = require('./fixtures/full-project') - fullProjectStr = JSON.stringify(fullProject), - pbx = require('../lib/pbxProject'), - proj = new pbx('.'); +var fullProject = require('./fixtures/full-project'); -function cleanHash() { +var fullProjectStr = JSON.stringify(fullProject); +var pbx = require('../lib/pbxProject'); +var proj = new pbx('.'); + +function cleanHash () { return JSON.parse(fullProjectStr); } exports.setUp = function (callback) { proj.hash = cleanHash(); callback(); -} +}; exports.addRemovePbxGroup = { 'should return a pbxGroup': function (test) { var pbxGroup = proj.addPbxGroup(['file.m'], 'MyGroup', 'Application', 'Application', '""'); test.ok(typeof pbxGroup === 'object'); - test.done() + test.done(); }, 'should set a uuid on the pbxGroup': function (test) { var pbxGroup = proj.addPbxGroup(['file.m'], 'MyGroup', 'Application', 'Application', '""'); test.ok(pbxGroup.uuid); - test.done() + test.done(); }, 'should add all files to pbxGroup': function (test) { var pbxGroup = proj.addPbxGroup(['file.m'], 'MyGroup', 'Application', 'Application', '""'); @@ -49,11 +50,11 @@ exports.addRemovePbxGroup = { test.ok(file.value); } - test.done() + test.done(); }, 'should add the PBXGroup object correctly': function (test) { var pbxGroup = proj.addPbxGroup(['file.m'], 'MyGroup', 'Application', '""'); - pbxGroupInPbx = proj.pbxGroupByName('MyGroup'); + var pbxGroupInPbx = proj.pbxGroupByName('MyGroup'); test.equal(pbxGroupInPbx.children, pbxGroup.pbxGroup.children); test.equal(pbxGroupInPbx.isa, 'PBXGroup'); @@ -62,8 +63,8 @@ exports.addRemovePbxGroup = { test.done(); }, 'should add sourceTree if no other specified': function (test) { - var pbxGroup = proj.addPbxGroup(['file.m'], 'MyGroup', 'Application'); - pbxGroupInPbx = proj.pbxGroupByName('MyGroup'); + proj.addPbxGroup(['file.m'], 'MyGroup', 'Application'); + var pbxGroupInPbx = proj.pbxGroupByName('MyGroup'); test.equal(pbxGroupInPbx.sourceTree, '""'); test.done(); @@ -75,28 +76,28 @@ exports.addRemovePbxGroup = { test.notEqual(buildFileSection[key].fileRef_comment, 'assets.bundle'); } - var initialBuildFileSectionItemsCount = Object.keys(buildFileSection), - pbxGroup = proj.addPbxGroup(['file.m', 'assets.bundle'], 'MyGroup', 'Application', '""'), - afterAdditionBuildFileSectionItemsCount = Object.keys(buildFileSection); + var initialBuildFileSectionItemsCount = Object.keys(buildFileSection); + proj.addPbxGroup(['file.m', 'assets.bundle'], 'MyGroup', 'Application', '""'); + var afterAdditionBuildFileSectionItemsCount = Object.keys(buildFileSection); // for each file added in the build file section two keyes are added - one for the object and one for the comment test.equal(initialBuildFileSectionItemsCount.length, afterAdditionBuildFileSectionItemsCount.length - 4); test.done(); }, 'should not add any of the files to PBXBuildFile section if already added': function (test) { - var buildFileSection = proj.pbxBuildFileSection(), - initialBuildFileSectionItemsCount = Object.keys(buildFileSection), - pbxGroup = proj.addPbxGroup(['AppDelegate.m', 'AppDelegate.h'], 'MyGroup', 'Application', '""'), - afterAdditionBuildFileSectionItemsCount = Object.keys(buildFileSection); + var buildFileSection = proj.pbxBuildFileSection(); + var initialBuildFileSectionItemsCount = Object.keys(buildFileSection); + proj.addPbxGroup(['AppDelegate.m', 'AppDelegate.h'], 'MyGroup', 'Application', '""'); + var afterAdditionBuildFileSectionItemsCount = Object.keys(buildFileSection); test.deepEqual(initialBuildFileSectionItemsCount, afterAdditionBuildFileSectionItemsCount); test.done(); }, 'should not add any of the files to PBXBuildFile section when they contain special symbols and are already added': function (test) { - var buildFileSection = proj.pbxBuildFileSection(), - initialBuildFileSectionItemsCount = Object.keys(buildFileSection), - pbxGroup = proj.addPbxGroup(['KitchenSinktablet.app'], 'MyGroup', 'Application', '""'), - afterAdditionBuildFileSectionItemsCount = Object.keys(buildFileSection); + var buildFileSection = proj.pbxBuildFileSection(); + var initialBuildFileSectionItemsCount = Object.keys(buildFileSection); + proj.addPbxGroup(['KitchenSinktablet.app'], 'MyGroup', 'Application', '""'); + var afterAdditionBuildFileSectionItemsCount = Object.keys(buildFileSection); test.deepEqual(initialBuildFileSectionItemsCount, afterAdditionBuildFileSectionItemsCount); test.done(); @@ -108,9 +109,9 @@ exports.addRemovePbxGroup = { test.notEqual(buildFileSection[key].fileRef_comment, 'assets.bundle'); } - var initialBuildFileSectionItemsCount = Object.keys(buildFileSection), - pbxGroup = proj.addPbxGroup(['AppDelegate.m', 'AppDelegate.h', 'file.m', 'assets.bundle'], 'MyGroup', 'Application', '""'), - afterAdditionBuildFileSectionItemsCount = Object.keys(buildFileSection); + var initialBuildFileSectionItemsCount = Object.keys(buildFileSection); + proj.addPbxGroup(['AppDelegate.m', 'AppDelegate.h', 'file.m', 'assets.bundle'], 'MyGroup', 'Application', '""'); + var afterAdditionBuildFileSectionItemsCount = Object.keys(buildFileSection); // for each file added in the build file section two keyes are added - one for the object and one for the comment test.equal(initialBuildFileSectionItemsCount.length, afterAdditionBuildFileSectionItemsCount.length - 4); @@ -131,33 +132,33 @@ exports.addRemovePbxGroup = { test.done(); }, 'should not add any of the files to PBXFileReference section if already added': function (test) { - var fileReference = proj.pbxFileReferenceSection (), - initialBuildFileSectionItemsCount = Object.keys(fileReference), - pbxGroup = proj.addPbxGroup(['AppDelegate.m', 'AppDelegate.h'], 'MyGroup', 'Application', '""'), - afterAdditionBuildFileSectionItemsCount = Object.keys(fileReference); + var fileReference = proj.pbxFileReferenceSection(); + var initialBuildFileSectionItemsCount = Object.keys(fileReference); + proj.addPbxGroup(['AppDelegate.m', 'AppDelegate.h'], 'MyGroup', 'Application', '""'); + var afterAdditionBuildFileSectionItemsCount = Object.keys(fileReference); test.deepEqual(initialBuildFileSectionItemsCount, afterAdditionBuildFileSectionItemsCount); test.done(); }, 'should not add any of the files to PBXFileReference section when they contain special symbols and are already added': function (test) { - var fileReference = proj.pbxFileReferenceSection (), - initialBuildFileSectionItemsCount = Object.keys(fileReference), - pbxGroup = proj.addPbxGroup(['KitchenSinktablet.app'], 'MyGroup', 'Application', '""'), - afterAdditionBuildFileSectionItemsCount = Object.keys(fileReference); + var fileReference = proj.pbxFileReferenceSection(); + var initialBuildFileSectionItemsCount = Object.keys(fileReference); + proj.addPbxGroup(['KitchenSinktablet.app'], 'MyGroup', 'Application', '""'); + var afterAdditionBuildFileSectionItemsCount = Object.keys(fileReference); test.deepEqual(initialBuildFileSectionItemsCount, afterAdditionBuildFileSectionItemsCount); test.done(); }, 'should add all files which are not added and not add files already added to PBXFileReference section': function (test) { - var fileReference = proj.pbxFileReferenceSection (); + var fileReference = proj.pbxFileReferenceSection(); for (var key in fileReference) { test.notEqual(fileReference[key].fileRef_comment, 'file.m'); test.notEqual(fileReference[key].fileRef_comment, 'assets.bundle'); } - var initialBuildFileSectionItemsCount = Object.keys(fileReference), - pbxGroup = proj.addPbxGroup(['AppDelegate.m', 'AppDelegate.h', 'file.m', 'assets.bundle'], 'MyGroup', 'Application', '""'), - afterAdditionBuildFileSectionItemsCount = Object.keys(fileReference); + var initialBuildFileSectionItemsCount = Object.keys(fileReference); + proj.addPbxGroup(['AppDelegate.m', 'AppDelegate.h', 'file.m', 'assets.bundle'], 'MyGroup', 'Application', '""'); + var afterAdditionBuildFileSectionItemsCount = Object.keys(fileReference); // for each file added in the file reference section two keyes are added - one for the object and one for the comment test.equal(initialBuildFileSectionItemsCount.length, afterAdditionBuildFileSectionItemsCount.length - 4); @@ -172,6 +173,6 @@ exports.addRemovePbxGroup = { console.log(pbxGroupInPbx); test.ok(!pbxGroupInPbx); - test.done() + test.done(); } -} +}; diff --git a/test/addResourceFile.js b/test/addResourceFile.js index 36afdb2..fc1b522 100644 --- a/test/addResourceFile.js +++ b/test/addResourceFile.js @@ -15,44 +15,45 @@ under the License. */ -var fullProject = require('./fixtures/full-project') - fullProjectStr = JSON.stringify(fullProject), - pbx = require('../lib/pbxProject'), - pbxFile = require('../lib/pbxFile'), - proj = new pbx('.'); +var fullProject = require('./fixtures/full-project'); -function cleanHash() { +var fullProjectStr = JSON.stringify(fullProject); +var pbx = require('../lib/pbxProject'); +var pbxFile = require('../lib/pbxFile'); +var proj = new pbx('.'); + +function cleanHash () { return JSON.parse(fullProjectStr); } exports.setUp = function (callback) { proj.hash = cleanHash(); callback(); -} +}; exports.addResourceFile = { 'should return a pbxFile': function (test) { var newFile = proj.addResourceFile('assets.bundle'); test.equal(newFile.constructor, pbxFile); - test.done() + test.done(); }, 'should set a uuid on the pbxFile': function (test) { var newFile = proj.addResourceFile('assets.bundle'); test.ok(newFile.uuid); - test.done() + test.done(); }, 'should set a fileRef on the pbxFile': function (test) { var newFile = proj.addResourceFile('assets.bundle'); test.ok(newFile.fileRef); - test.done() + test.done(); }, 'should populate the PBXBuildFile section with 2 fields': function (test) { - var newFile = proj.addResourceFile('assets.bundle'), - buildFileSection = proj.pbxBuildFileSection(), - bfsLength = Object.keys(buildFileSection).length; + var newFile = proj.addResourceFile('assets.bundle'); + var buildFileSection = proj.pbxBuildFileSection(); + var bfsLength = Object.keys(buildFileSection).length; test.equal(60, bfsLength); test.ok(buildFileSection[newFile.uuid]); @@ -61,17 +62,17 @@ exports.addResourceFile = { test.done(); }, 'should add the PBXBuildFile comment correctly': function (test) { - var newFile = proj.addResourceFile('assets.bundle'), - commentKey = newFile.uuid + '_comment', - buildFileSection = proj.pbxBuildFileSection(); + var newFile = proj.addResourceFile('assets.bundle'); + var commentKey = newFile.uuid + '_comment'; + var buildFileSection = proj.pbxBuildFileSection(); test.equal(buildFileSection[commentKey], 'assets.bundle in Resources'); test.done(); }, 'should add the PBXBuildFile object correctly': function (test) { - var newFile = proj.addResourceFile('assets.bundle'), - buildFileSection = proj.pbxBuildFileSection(), - buildFileEntry = buildFileSection[newFile.uuid]; + var newFile = proj.addResourceFile('assets.bundle'); + var buildFileSection = proj.pbxBuildFileSection(); + var buildFileEntry = buildFileSection[newFile.uuid]; test.equal(buildFileEntry.isa, 'PBXBuildFile'); test.equal(buildFileEntry.fileRef, newFile.fileRef); @@ -80,9 +81,9 @@ exports.addResourceFile = { test.done(); }, 'should populate the PBXFileReference section with 2 fields': function (test) { - var newFile = proj.addResourceFile('assets.bundle'), - fileRefSection = proj.pbxFileReferenceSection(), - frsLength = Object.keys(fileRefSection).length; + var newFile = proj.addResourceFile('assets.bundle'); + var fileRefSection = proj.pbxFileReferenceSection(); + var frsLength = Object.keys(fileRefSection).length; test.equal(68, frsLength); test.ok(fileRefSection[newFile.fileRef]); @@ -91,9 +92,9 @@ exports.addResourceFile = { test.done(); }, 'should populate the PBXFileReference comment correctly': function (test) { - var newFile = proj.addResourceFile('assets.bundle'), - fileRefSection = proj.pbxFileReferenceSection(), - commentKey = newFile.fileRef + '_comment'; + var newFile = proj.addResourceFile('assets.bundle'); + var fileRefSection = proj.pbxFileReferenceSection(); + var commentKey = newFile.fileRef + '_comment'; test.equal(fileRefSection[commentKey], 'assets.bundle'); test.done(); @@ -101,9 +102,9 @@ exports.addResourceFile = { 'should add the PBXFileReference object correctly': function (test) { delete proj.pbxGroupByName('Resources').path; - var newFile = proj.addResourceFile('Resources/assets.bundle'), - fileRefSection = proj.pbxFileReferenceSection(), - fileRefEntry = fileRefSection[newFile.fileRef]; + var newFile = proj.addResourceFile('Resources/assets.bundle'); + var fileRefSection = proj.pbxFileReferenceSection(); + var fileRefEntry = fileRefSection[newFile.fileRef]; test.equal(fileRefEntry.isa, 'PBXFileReference'); test.equal(fileRefEntry.fileEncoding, undefined); @@ -115,40 +116,40 @@ exports.addResourceFile = { test.done(); }, 'should add to the Resources PBXGroup group': function (test) { - var newFile = proj.addResourceFile('Resources/assets.bundle'), - resources = proj.pbxGroupByName('Resources'); + proj.addResourceFile('Resources/assets.bundle'); + var resources = proj.pbxGroupByName('Resources'); test.equal(resources.children.length, 10); test.done(); }, 'should have the right values for the PBXGroup entry': function (test) { - var newFile = proj.addResourceFile('Resources/assets.bundle'), - resources = proj.pbxGroupByName('Resources'), - resourceObj = resources.children[9]; + var newFile = proj.addResourceFile('Resources/assets.bundle'); + var resources = proj.pbxGroupByName('Resources'); + var resourceObj = resources.children[9]; test.equal(resourceObj.comment, 'assets.bundle'); test.equal(resourceObj.value, newFile.fileRef); test.done(); }, 'should add to the PBXSourcesBuildPhase': function (test) { - var newFile = proj.addResourceFile('Resources/assets.bundle'), - sources = proj.pbxResourcesBuildPhaseObj(); + proj.addResourceFile('Resources/assets.bundle'); + var sources = proj.pbxResourcesBuildPhaseObj(); test.equal(sources.files.length, 13); test.done(); }, 'should have the right values for the Sources entry': function (test) { - var newFile = proj.addResourceFile('Resources/assets.bundle'), - sources = proj.pbxResourcesBuildPhaseObj(), - sourceObj = sources.files[12]; + var newFile = proj.addResourceFile('Resources/assets.bundle'); + var sources = proj.pbxResourcesBuildPhaseObj(); + var sourceObj = sources.files[12]; test.equal(sourceObj.comment, 'assets.bundle in Resources'); test.equal(sourceObj.value, newFile.uuid); test.done(); }, 'should remove "Resources/" from path if group path is set': function (test) { - var resources = proj.pbxGroupByName('Resources'), - newFile; + var resources = proj.pbxGroupByName('Resources'); + var newFile; resources.path = '"Test200/Resources"'; newFile = proj.addResourceFile('Resources/assets.bundle'); @@ -162,9 +163,10 @@ exports.addResourceFile = { delete proj.pbxGroupByName('Plugins').path; var newFile = proj.addResourceFile('Plugins/assets.bundle', - { plugin: true }), - fileRefSection = proj.pbxFileReferenceSection(), - fileRefEntry = fileRefSection[newFile.fileRef]; + { plugin: true }); + + var fileRefSection = proj.pbxFileReferenceSection(); + var fileRefEntry = fileRefSection[newFile.fileRef]; test.equal(fileRefEntry.isa, 'PBXFileReference'); test.equal(fileRefEntry.fileEncoding, undefined); @@ -176,9 +178,10 @@ exports.addResourceFile = { }, 'should add to the Plugins PBXGroup group': function (test) { - var newFile = proj.addResourceFile('Plugins/assets.bundle', - { plugin: true }), - plugins = proj.pbxGroupByName('Plugins'); + proj.addResourceFile('Plugins/assets.bundle', + { plugin: true }); + + var plugins = proj.pbxGroupByName('Plugins'); test.equal(plugins.children.length, 1); test.done(); @@ -186,9 +189,10 @@ exports.addResourceFile = { 'should have the Plugins values for the PBXGroup entry': function (test) { var newFile = proj.addResourceFile('Plugins/assets.bundle', - { plugin: true }), - plugins = proj.pbxGroupByName('Plugins'), - pluginObj = plugins.children[0]; + { plugin: true }); + + var plugins = proj.pbxGroupByName('Plugins'); + var pluginObj = plugins.children[0]; test.equal(pluginObj.comment, 'assets.bundle'); test.equal(pluginObj.value, newFile.fileRef); @@ -196,9 +200,10 @@ exports.addResourceFile = { }, 'should add to the PBXSourcesBuildPhase': function (test) { - var newFile = proj.addResourceFile('Plugins/assets.bundle', - { plugin: true }), - sources = proj.pbxResourcesBuildPhaseObj(); + proj.addResourceFile('Plugins/assets.bundle', + { plugin: true }); + + var sources = proj.pbxResourcesBuildPhaseObj(); test.equal(sources.files.length, 13); test.done(); @@ -206,9 +211,10 @@ exports.addResourceFile = { 'should have the right values for the Sources entry': function (test) { var newFile = proj.addResourceFile('Plugins/assets.bundle', - { plugin: true }), - sources = proj.pbxResourcesBuildPhaseObj(), - sourceObj = sources.files[12]; + { plugin: true }); + + var sources = proj.pbxResourcesBuildPhaseObj(); + var sourceObj = sources.files[12]; test.equal(sourceObj.comment, 'assets.bundle in Resources'); test.equal(sourceObj.value, newFile.uuid); @@ -216,12 +222,12 @@ exports.addResourceFile = { }, 'should remove "Plugins/" from path if group path is set': function (test) { - var plugins = proj.pbxGroupByName('Plugins'), - newFile; + var plugins = proj.pbxGroupByName('Plugins'); + var newFile; plugins.path = '"Test200/Plugins"'; newFile = proj.addResourceFile('Plugins/assets.bundle', - { plugin: true }); + { plugin: true }); test.equal(newFile.path, 'assets.bundle'); test.done(); @@ -240,32 +246,32 @@ exports.addResourceFile = { test.ok(buildFileSection[newFile.uuid] === undefined); test.done(); - }, + } }, 'duplicate entries': { 'should return false': function (test) { - var newFile = proj.addResourceFile('Plugins/assets.bundle'); + proj.addResourceFile('Plugins/assets.bundle'); test.ok(!proj.addResourceFile('Plugins/assets.bundle')); test.done(); }, 'should return false (plugin entries)': function (test) { - var newFile = proj.addResourceFile('Plugins/assets.bundle', - { plugin: true }); + proj.addResourceFile('Plugins/assets.bundle', + { plugin: true }); test.ok(!proj.addResourceFile('Plugins/assets.bundle', - { plugin: true })); + { plugin: true })); test.done(); }, 'should not add another entry anywhere': function (test) { - var newFile = proj.addResourceFile('Plugins/assets.bundle'), - buildFileSection = proj.pbxBuildFileSection(), - bfsLength = Object.keys(buildFileSection).length, - fileRefSection = proj.pbxFileReferenceSection(), - frsLength = Object.keys(fileRefSection).length, - resources = proj.pbxGroupByName('Resources'), - sources = proj.pbxResourcesBuildPhaseObj(); + proj.addResourceFile('Plugins/assets.bundle'); + var buildFileSection = proj.pbxBuildFileSection(); + var bfsLength = Object.keys(buildFileSection).length; + var fileRefSection = proj.pbxFileReferenceSection(); + var frsLength = Object.keys(fileRefSection).length; + var resources = proj.pbxGroupByName('Resources'); + var sources = proj.pbxResourcesBuildPhaseObj(); proj.addResourceFile('Plugins/assets.bundle'); @@ -281,4 +287,4 @@ exports.addResourceFile = { delete proj.pbxGroupByName('Resources').path; callback(); } -} +}; diff --git a/test/addSourceFile.js b/test/addSourceFile.js index d614d62..cbd3a01 100644 --- a/test/addSourceFile.js +++ b/test/addSourceFile.js @@ -15,44 +15,45 @@ under the License. */ -var fullProject = require('./fixtures/full-project') - fullProjectStr = JSON.stringify(fullProject), - pbx = require('../lib/pbxProject'), - pbxFile = require('../lib/pbxFile'), - proj = new pbx('.'); +var fullProject = require('./fixtures/full-project'); -function cleanHash() { +var fullProjectStr = JSON.stringify(fullProject); +var pbx = require('../lib/pbxProject'); +var pbxFile = require('../lib/pbxFile'); +var proj = new pbx('.'); + +function cleanHash () { return JSON.parse(fullProjectStr); } exports.setUp = function (callback) { proj.hash = cleanHash(); callback(); -} +}; exports.addSourceFile = { 'should return a pbxFile': function (test) { var newFile = proj.addSourceFile('file.m'); test.equal(newFile.constructor, pbxFile); - test.done() + test.done(); }, 'should set a uuid on the pbxFile': function (test) { var newFile = proj.addSourceFile('file.m'); test.ok(newFile.uuid); - test.done() + test.done(); }, 'should set a fileRef on the pbxFile': function (test) { var newFile = proj.addSourceFile('file.m'); test.ok(newFile.fileRef); - test.done() + test.done(); }, 'should populate the PBXBuildFile section with 2 fields': function (test) { - var newFile = proj.addSourceFile('file.m'), - buildFileSection = proj.pbxBuildFileSection(), - bfsLength = Object.keys(buildFileSection).length; + var newFile = proj.addSourceFile('file.m'); + var buildFileSection = proj.pbxBuildFileSection(); + var bfsLength = Object.keys(buildFileSection).length; test.equal(60, bfsLength); test.ok(buildFileSection[newFile.uuid]); @@ -61,17 +62,17 @@ exports.addSourceFile = { test.done(); }, 'should add the PBXBuildFile comment correctly': function (test) { - var newFile = proj.addSourceFile('file.m'), - commentKey = newFile.uuid + '_comment', - buildFileSection = proj.pbxBuildFileSection(); + var newFile = proj.addSourceFile('file.m'); + var commentKey = newFile.uuid + '_comment'; + var buildFileSection = proj.pbxBuildFileSection(); test.equal(buildFileSection[commentKey], 'file.m in Sources'); test.done(); }, 'should add the PBXBuildFile object correctly': function (test) { - var newFile = proj.addSourceFile('file.m'), - buildFileSection = proj.pbxBuildFileSection(), - buildFileEntry = buildFileSection[newFile.uuid]; + var newFile = proj.addSourceFile('file.m'); + var buildFileSection = proj.pbxBuildFileSection(); + var buildFileEntry = buildFileSection[newFile.uuid]; test.equal(buildFileEntry.isa, 'PBXBuildFile'); test.equal(buildFileEntry.fileRef, newFile.fileRef); @@ -80,9 +81,9 @@ exports.addSourceFile = { test.done(); }, 'should populate the PBXFileReference section with 2 fields': function (test) { - var newFile = proj.addSourceFile('file.m'), - fileRefSection = proj.pbxFileReferenceSection(), - frsLength = Object.keys(fileRefSection).length; + var newFile = proj.addSourceFile('file.m'); + var fileRefSection = proj.pbxFileReferenceSection(); + var frsLength = Object.keys(fileRefSection).length; test.equal(68, frsLength); test.ok(fileRefSection[newFile.fileRef]); @@ -91,17 +92,17 @@ exports.addSourceFile = { test.done(); }, 'should populate the PBXFileReference comment correctly': function (test) { - var newFile = proj.addSourceFile('file.m'), - fileRefSection = proj.pbxFileReferenceSection(), - commentKey = newFile.fileRef + '_comment'; + var newFile = proj.addSourceFile('file.m'); + var fileRefSection = proj.pbxFileReferenceSection(); + var commentKey = newFile.fileRef + '_comment'; test.equal(fileRefSection[commentKey], 'file.m'); test.done(); }, 'should add the PBXFileReference object correctly': function (test) { - var newFile = proj.addSourceFile('Plugins/file.m'), - fileRefSection = proj.pbxFileReferenceSection(), - fileRefEntry = fileRefSection[newFile.fileRef]; + var newFile = proj.addSourceFile('Plugins/file.m'); + var fileRefSection = proj.pbxFileReferenceSection(); + var fileRefEntry = fileRefSection[newFile.fileRef]; test.equal(fileRefEntry.isa, 'PBXFileReference'); test.equal(fileRefEntry.fileEncoding, 4); @@ -113,32 +114,32 @@ exports.addSourceFile = { test.done(); }, 'should add to the Plugins PBXGroup group': function (test) { - var newFile = proj.addSourceFile('Plugins/file.m'), - plugins = proj.pbxGroupByName('Plugins'); + proj.addSourceFile('Plugins/file.m'); + var plugins = proj.pbxGroupByName('Plugins'); test.equal(plugins.children.length, 1); test.done(); }, 'should have the right values for the PBXGroup entry': function (test) { - var newFile = proj.addSourceFile('Plugins/file.m'), - plugins = proj.pbxGroupByName('Plugins'), - pluginObj = plugins.children[0]; + var newFile = proj.addSourceFile('Plugins/file.m'); + var plugins = proj.pbxGroupByName('Plugins'); + var pluginObj = plugins.children[0]; test.equal(pluginObj.comment, 'file.m'); test.equal(pluginObj.value, newFile.fileRef); test.done(); }, 'should add to the PBXSourcesBuildPhase': function (test) { - var newFile = proj.addSourceFile('Plugins/file.m'), - sources = proj.pbxSourcesBuildPhaseObj(); + proj.addSourceFile('Plugins/file.m'); + var sources = proj.pbxSourcesBuildPhaseObj(); test.equal(sources.files.length, 3); test.done(); }, 'should have the right values for the Sources entry': function (test) { - var newFile = proj.addSourceFile('Plugins/file.m'), - sources = proj.pbxSourcesBuildPhaseObj(), - sourceObj = sources.files[2]; + var newFile = proj.addSourceFile('Plugins/file.m'); + var sources = proj.pbxSourcesBuildPhaseObj(); + var sourceObj = sources.files[2]; test.equal(sourceObj.comment, 'file.m in Sources'); test.equal(sourceObj.value, newFile.uuid); @@ -146,29 +147,28 @@ exports.addSourceFile = { }, 'duplicate entries': { 'should return false': function (test) { - var newFile = proj.addSourceFile('Plugins/file.m'); + proj.addSourceFile('Plugins/file.m'); test.ok(!proj.addSourceFile('Plugins/file.m')); test.done(); }, 'should not add another entry anywhere': function (test) { - var newFile = proj.addSourceFile('Plugins/file.m'), - buildFileSection = proj.pbxBuildFileSection(), - bfsLength = Object.keys(buildFileSection).length, - fileRefSection = proj.pbxFileReferenceSection(), - frsLength = Object.keys(fileRefSection).length, - plugins = proj.pbxGroupByName('Plugins'), - sources = proj.pbxSourcesBuildPhaseObj(); + proj.addSourceFile('Plugins/file.m'); + var buildFileSection = proj.pbxBuildFileSection(); + var bfsLength = Object.keys(buildFileSection).length; + var fileRefSection = proj.pbxFileReferenceSection(); + var frsLength = Object.keys(fileRefSection).length; + var plugins = proj.pbxGroupByName('Plugins'); + var sources = proj.pbxSourcesBuildPhaseObj(); // duplicate! proj.addSourceFile('Plugins/file.m'); - test.equal(60, bfsLength); // BuildFileSection - test.equal(68, frsLength); // FileReferenceSection + test.equal(60, bfsLength); // BuildFileSection + test.equal(68, frsLength); // FileReferenceSection test.equal(plugins.children.length, 1); // Plugins pbxGroup - test.equal(sources.files.length, 3); // SourcesBuildPhhase + test.equal(sources.files.length, 3); // SourcesBuildPhhase test.done(); } } -} - +}; diff --git a/test/addStaticLibrary.js b/test/addStaticLibrary.js index d1b0ec6..ecda8df 100644 --- a/test/addStaticLibrary.js +++ b/test/addStaticLibrary.js @@ -15,19 +15,21 @@ under the License. */ -var fullProject = require('./fixtures/full-project') - fullProjectStr = JSON.stringify(fullProject), - pbx = require('../lib/pbxProject'), - pbxFile = require('../lib/pbxFile'), - proj = new pbx('.'); +var fullProject = require('./fixtures/full-project'); -function cleanHash() { +var fullProjectStr = JSON.stringify(fullProject); +var pbx = require('../lib/pbxProject'); +var pbxFile = require('../lib/pbxFile'); +var proj = new pbx('.'); + +function cleanHash () { return JSON.parse(fullProjectStr); } -function nonComments(obj) { - var keys = Object.keys(obj), - newObj = {}, i = 0; +function nonComments (obj) { + var keys = Object.keys(obj); + var newObj = {}; + var i = 0; for (i; i < keys.length; i++) { if (!/_comment$/.test(keys[i])) { @@ -38,16 +40,18 @@ function nonComments(obj) { return newObj; } -function librarySearchPaths(proj) { - var configs = nonComments(proj.pbxXCBuildConfigurationSection()), - allPaths = [], - ids = Object.keys(configs), i, buildSettings; +function librarySearchPaths (proj) { + var configs = nonComments(proj.pbxXCBuildConfigurationSection()); + var allPaths = []; + var ids = Object.keys(configs); + var i; + var buildSettings; - for (i = 0; i< ids.length; i++) { + for (i = 0; i < ids.length; i++) { buildSettings = configs[ids[i]].buildSettings; - if (buildSettings['LIBRARY_SEARCH_PATHS']) { - allPaths.push(buildSettings['LIBRARY_SEARCH_PATHS']); + if (buildSettings.LIBRARY_SEARCH_PATHS) { + allPaths.push(buildSettings.LIBRARY_SEARCH_PATHS); } } @@ -57,25 +61,25 @@ function librarySearchPaths(proj) { exports.setUp = function (callback) { proj.hash = cleanHash(); callback(); -} +}; exports.addStaticLibrary = { 'should return a pbxFile': function (test) { var newFile = proj.addStaticLibrary('libGoogleAnalytics.a'); test.equal(newFile.constructor, pbxFile); - test.done() + test.done(); }, 'should set a fileRef on the pbxFile': function (test) { var newFile = proj.addStaticLibrary('libGoogleAnalytics.a'); test.ok(newFile.fileRef); - test.done() + test.done(); }, 'should populate the PBXBuildFile section with 2 fields': function (test) { var newFile = proj.addStaticLibrary('libGoogleAnalytics.a'); - buildFileSection = proj.pbxBuildFileSection(), - bfsLength = Object.keys(buildFileSection).length; + var buildFileSection = proj.pbxBuildFileSection(); + var bfsLength = Object.keys(buildFileSection).length; test.equal(60, bfsLength); test.ok(buildFileSection[newFile.uuid]); @@ -85,9 +89,9 @@ exports.addStaticLibrary = { }, 'should populate the PBXBuildFile section with 2 fields as plugin': function (test) { var newFile = proj.addStaticLibrary('libGoogleAnalytics.a', - { plugin: true }); - buildFileSection = proj.pbxBuildFileSection(), - bfsLength = Object.keys(buildFileSection).length; + { plugin: true }); + var buildFileSection = proj.pbxBuildFileSection(); + var bfsLength = Object.keys(buildFileSection).length; test.equal(60, bfsLength); test.ok(buildFileSection[newFile.uuid]); @@ -97,16 +101,16 @@ exports.addStaticLibrary = { }, 'should add the PBXBuildFile comment correctly': function (test) { var newFile = proj.addStaticLibrary('libGoogleAnalytics.a'); - commentKey = newFile.uuid + '_comment', - buildFileSection = proj.pbxBuildFileSection(); + var commentKey = newFile.uuid + '_comment'; + var buildFileSection = proj.pbxBuildFileSection(); test.equal(buildFileSection[commentKey], 'libGoogleAnalytics.a in Frameworks'); test.done(); }, 'should add the PBXBuildFile object correctly': function (test) { var newFile = proj.addStaticLibrary('libGoogleAnalytics.a'); - buildFileSection = proj.pbxBuildFileSection(), - buildFileEntry = buildFileSection[newFile.uuid]; + var buildFileSection = proj.pbxBuildFileSection(); + var buildFileEntry = buildFileSection[newFile.uuid]; test.equal(buildFileEntry.isa, 'PBXBuildFile'); test.equal(buildFileEntry.fileRef, newFile.fileRef); @@ -116,8 +120,8 @@ exports.addStaticLibrary = { }, 'should populate the PBXFileReference section with 2 fields': function (test) { var newFile = proj.addStaticLibrary('libGoogleAnalytics.a'); - fileRefSection = proj.pbxFileReferenceSection(), - frsLength = Object.keys(fileRefSection).length; + var fileRefSection = proj.pbxFileReferenceSection(); + var frsLength = Object.keys(fileRefSection).length; test.equal(68, frsLength); test.ok(fileRefSection[newFile.fileRef]); @@ -127,16 +131,16 @@ exports.addStaticLibrary = { }, 'should populate the PBXFileReference comment correctly': function (test) { var newFile = proj.addStaticLibrary('libGoogleAnalytics.a'); - fileRefSection = proj.pbxFileReferenceSection(), - commentKey = newFile.fileRef + '_comment'; + var fileRefSection = proj.pbxFileReferenceSection(); + var commentKey = newFile.fileRef + '_comment'; test.equal(fileRefSection[commentKey], 'libGoogleAnalytics.a'); test.done(); }, 'should add the PBXFileReference object correctly': function (test) { - var newFile = proj.addStaticLibrary('libGoogleAnalytics.a'), - fileRefSection = proj.pbxFileReferenceSection(), - fileRefEntry = fileRefSection[newFile.fileRef]; + var newFile = proj.addStaticLibrary('libGoogleAnalytics.a'); + var fileRefSection = proj.pbxFileReferenceSection(); + var fileRefEntry = fileRefSection[newFile.fileRef]; test.equal(fileRefEntry.isa, 'PBXFileReference'); test.equal(fileRefEntry.lastKnownFileType, 'archive.ar'); @@ -147,41 +151,43 @@ exports.addStaticLibrary = { test.done(); }, 'should add to the PBXFrameworksBuildPhase': function (test) { - var newFile = proj.addStaticLibrary('libGoogleAnalytics.a'), - frameworks = proj.pbxFrameworksBuildPhaseObj(); + proj.addStaticLibrary('libGoogleAnalytics.a'); + var frameworks = proj.pbxFrameworksBuildPhaseObj(); test.equal(frameworks.files.length, 16); test.done(); }, 'should have the right values for the Sources entry': function (test) { - var newFile = proj.addStaticLibrary('libGoogleAnalytics.a'), - frameworks = proj.pbxFrameworksBuildPhaseObj(), - framework = frameworks.files[15]; + var newFile = proj.addStaticLibrary('libGoogleAnalytics.a'); + var frameworks = proj.pbxFrameworksBuildPhaseObj(); + var framework = frameworks.files[15]; test.equal(framework.comment, 'libGoogleAnalytics.a in Frameworks'); test.equal(framework.value, newFile.uuid); test.done(); }, 'should set LIBRARY_SEARCH_PATHS for appropriate build configurations': function (test) { - var newFile = proj.addStaticLibrary('libGoogleAnalytics.a'), - configs = nonComments(proj.pbxXCBuildConfigurationSection()), - ids = Object.keys(configs), i, buildSettings; + proj.addStaticLibrary('libGoogleAnalytics.a'); + var configs = nonComments(proj.pbxXCBuildConfigurationSection()); + var ids = Object.keys(configs); + var i; + var buildSettings; - for (i = 0; i< ids.length; i++) { + for (i = 0; i < ids.length; i++) { buildSettings = configs[ids[i]].buildSettings; - if (buildSettings['PRODUCT_NAME'] == '"KitchenSinktablet"') { - test.ok(buildSettings['LIBRARY_SEARCH_PATHS']); + if (buildSettings.PRODUCT_NAME === '"KitchenSinktablet"') { + test.ok(buildSettings.LIBRARY_SEARCH_PATHS); } } test.done(); }, 'should ensure LIBRARY_SEARCH_PATHS inherits defaults correctly': function (test) { - var newFile = proj.addStaticLibrary('libGoogleAnalytics.a'), - libraryPaths = librarySearchPaths(proj), - expectedPath = '"\\"$(SRCROOT)/KitchenSinktablet\\""', - i, current; + proj.addStaticLibrary('libGoogleAnalytics.a'); + var libraryPaths = librarySearchPaths(proj); + var i; + var current; for (i = 0; i < libraryPaths.length; i++) { current = libraryPaths[i]; @@ -191,10 +197,11 @@ exports.addStaticLibrary = { test.done(); }, 'should ensure the new library is in LIBRARY_SEARCH_PATHS': function (test) { - var newFile = proj.addStaticLibrary('libGoogleAnalytics.a'), - libraryPaths = librarySearchPaths(proj), - expectedPath = '"\\"$(SRCROOT)/KitchenSinktablet\\""', - i, current; + proj.addStaticLibrary('libGoogleAnalytics.a'); + var libraryPaths = librarySearchPaths(proj); + var expectedPath = '"\\"$(SRCROOT)/KitchenSinktablet\\""'; + var i; + var current; for (i = 0; i < libraryPaths.length; i++) { current = libraryPaths[i]; @@ -204,46 +211,51 @@ exports.addStaticLibrary = { test.done(); }, 'should add to the Plugins group, optionally': function (test) { - var newFile = proj.addStaticLibrary('libGoogleAnalytics.a', - { plugin: true }), - plugins = proj.pbxGroupByName('Plugins'); + proj.addStaticLibrary('libGoogleAnalytics.a', + { plugin: true }); + + var plugins = proj.pbxGroupByName('Plugins'); test.equal(plugins.children.length, 1); test.done(); }, 'should add the right LIBRARY_SEARCH_PATHS entry for plugins': { 'with group set': function (test) { - plugins = proj.pbxGroupByName('Plugins'); + var plugins = proj.pbxGroupByName('Plugins'); plugins.path = '"Test200/Plugins"'; - var newFile = proj.addStaticLibrary('Plugins/libGoogleAnalytics.a', - { plugin: true }), - libraryPaths = librarySearchPaths(proj), - expectedPath = '"\\"$(SRCROOT)/Test200/Plugins\\""', - i, current; + proj.addStaticLibrary('Plugins/libGoogleAnalytics.a', + { plugin: true }); + + var libraryPaths = librarySearchPaths(proj); + var expectedPath = '"\\"$(SRCROOT)/Test200/Plugins\\""'; + var i; + var current; for (i = 0; i < libraryPaths.length; i++) { current = libraryPaths[i]; test.ok(current.indexOf(expectedPath) >= 0, - expectedPath + ' not found in ' + current); + expectedPath + ' not found in ' + current); } test.done(); }, 'without group set': function (test) { - plugins = proj.pbxGroupByName('Plugins'); + var plugins = proj.pbxGroupByName('Plugins'); delete plugins.path; - var newFile = proj.addStaticLibrary('Plugins/libGoogleAnalytics.a', - { plugin: true }), - libraryPaths = librarySearchPaths(proj), - expectedPath = '"\\"$(SRCROOT)/KitchenSinktablet/Plugins\\""', - i, current; + proj.addStaticLibrary('Plugins/libGoogleAnalytics.a', + { plugin: true }); + + var libraryPaths = librarySearchPaths(proj); + var expectedPath = '"\\"$(SRCROOT)/KitchenSinktablet/Plugins\\""'; + var i; + var current; for (i = 0; i < libraryPaths.length; i++) { current = libraryPaths[i]; test.ok(current.indexOf(expectedPath) >= 0, - expectedPath + ' not found in ' + current); + expectedPath + ' not found in ' + current); } test.done(); @@ -251,18 +263,18 @@ exports.addStaticLibrary = { }, 'duplicate entries': { 'should return false': function (test) { - var newFile = proj.addStaticLibrary('libGoogleAnalytics.a'); + proj.addStaticLibrary('libGoogleAnalytics.a'); test.ok(!proj.addStaticLibrary('libGoogleAnalytics.a')); test.done(); }, 'should return false (plugin entries)': function (test) { - var newFile = proj.addStaticLibrary('Plugins/libGoogleAnalytics.a', - { plugin: true }); + proj.addStaticLibrary('Plugins/libGoogleAnalytics.a', + { plugin: true }); test.ok(!proj.addStaticLibrary('Plugins/libGoogleAnalytics.a', - { plugin: true })); + { plugin: true })); test.done(); - }, + } } -} +}; diff --git a/test/addTarget.js b/test/addTarget.js index 6e44625..78398ca 100644 --- a/test/addTarget.js +++ b/test/addTarget.js @@ -15,41 +15,42 @@ under the License. */ -var fullProject = require('./fixtures/full-project') - fullProjectStr = JSON.stringify(fullProject), - pbx = require('../lib/pbxProject'), - pbxFile = require('../lib/pbxFile'), - proj = new pbx('.'); +var fullProject = require('./fixtures/full-project'); -function cleanHash() { +var fullProjectStr = JSON.stringify(fullProject); +var pbx = require('../lib/pbxProject'); +var pbxFile = require('../lib/pbxFile'); +var proj = new pbx('.'); + +function cleanHash () { return JSON.parse(fullProjectStr); } -var TARGET_NAME = 'TestExtension', - TARGET_TYPE = 'app_extension', - TARGET_SUBFOLDER_NAME = 'TestExtensionFiles'; +var TARGET_NAME = 'TestExtension'; +var TARGET_TYPE = 'app_extension'; +var TARGET_SUBFOLDER_NAME = 'TestExtensionFiles'; exports.setUp = function (callback) { proj.hash = cleanHash(); callback(); -} +}; exports.addTarget = { 'should throw when target name is missing': function (test) { - test.throws(function() { + test.throws(function () { proj.addTarget(null, TARGET_TYPE); }); test.done(); }, 'should throw when provided blank or empty target name': function (test) { - test.throws(function() { + test.throws(function () { proj.addTarget('', TARGET_TYPE); }, function (error) { return (error instanceof Error) && /Target name missing/i.test(error); }); - test.throws(function() { + test.throws(function () { proj.addTarget(' ', TARGET_TYPE); }, function (error) { return (error instanceof Error) && /Target name missing/i.test(error); @@ -58,7 +59,7 @@ exports.addTarget = { test.done(); }, 'should throw when target type missing': function (test) { - test.throws(function() { + test.throws(function () { proj.addTarget(TARGET_NAME, null); }, function (error) { return (error instanceof Error) && /Target type missing/i.test(error); @@ -67,7 +68,7 @@ exports.addTarget = { test.done(); }, 'should throw when invalid target type': function (test) { - test.throws(function() { + test.throws(function () { proj.addTarget(TARGET_NAME, 'invalid_target_type'); }, function (error) { return (error instanceof Error) && /Target type invalid/i.test(error); @@ -78,7 +79,7 @@ exports.addTarget = { 'should create a new target': function (test) { var target = proj.addTarget(TARGET_NAME, TARGET_TYPE, TARGET_SUBFOLDER_NAME); - test.ok(typeof target == 'object'); + test.ok(typeof target === 'object'); test.ok(target.uuid); test.ok(target.pbxNativeTarget); test.ok(target.pbxNativeTarget.isa); @@ -94,9 +95,9 @@ exports.addTarget = { test.done(); }, 'should add debug and release configurations to build configuration list': function (test) { - var pbxXCBuildConfigurationSection = proj.pbxXCBuildConfigurationSection(), - pbxXCConfigurationList = proj.pbxXCConfigurationList(), - target = proj.addTarget(TARGET_NAME, TARGET_TYPE, TARGET_SUBFOLDER_NAME); + var pbxXCBuildConfigurationSection = proj.pbxXCBuildConfigurationSection(); + var pbxXCConfigurationList = proj.pbxXCConfigurationList(); + var target = proj.addTarget(TARGET_NAME, TARGET_TYPE, TARGET_SUBFOLDER_NAME); test.ok(target.pbxNativeTarget.buildConfigurationList); test.ok(pbxXCConfigurationList[target.pbxNativeTarget.buildConfigurationList]); @@ -113,23 +114,23 @@ exports.addTarget = { test.equal(pbxConfig.isa, 'XCBuildConfiguration'); test.ok(pbxConfig.buildSettings); if (index === 0) { - var debugConfig = pbxConfig.buildSettings['GCC_PREPROCESSOR_DEFINITIONS']; + var debugConfig = pbxConfig.buildSettings.GCC_PREPROCESSOR_DEFINITIONS; test.ok(debugConfig); test.equal(debugConfig.length, 2); test.equal(debugConfig[0], '"DEBUG=1"'); test.equal(debugConfig[1], '"$(inherited)"'); } - test.equal(pbxConfig.buildSettings['INFOPLIST_FILE'], '"' + TARGET_SUBFOLDER_NAME + '/' + TARGET_SUBFOLDER_NAME + '-Info.plist"'); - test.equal(pbxConfig.buildSettings['LD_RUNPATH_SEARCH_PATHS'], '"$(inherited) @executable_path/Frameworks @executable_path/../../Frameworks"'); - test.equal(pbxConfig.buildSettings['PRODUCT_NAME'], '"' + TARGET_NAME + '"'); - test.equal(pbxConfig.buildSettings['SKIP_INSTALL'], 'YES'); + test.equal(pbxConfig.buildSettings.INFOPLIST_FILE, '"' + TARGET_SUBFOLDER_NAME + '/' + TARGET_SUBFOLDER_NAME + '-Info.plist"'); + test.equal(pbxConfig.buildSettings.LD_RUNPATH_SEARCH_PATHS, '"$(inherited) @executable_path/Frameworks @executable_path/../../Frameworks"'); + test.equal(pbxConfig.buildSettings.PRODUCT_NAME, '"' + TARGET_NAME + '"'); + test.equal(pbxConfig.buildSettings.SKIP_INSTALL, 'YES'); }); test.done(); }, 'should add to build configuration list with default configuration name': function (test) { - var pbxXCConfigurationList = proj.pbxXCConfigurationList(), - target = proj.addTarget(TARGET_NAME, TARGET_TYPE, TARGET_SUBFOLDER_NAME); + var pbxXCConfigurationList = proj.pbxXCConfigurationList(); + var target = proj.addTarget(TARGET_NAME, TARGET_TYPE, TARGET_SUBFOLDER_NAME); test.ok(target.pbxNativeTarget.buildConfigurationList); test.ok(pbxXCConfigurationList[target.pbxNativeTarget.buildConfigurationList]); @@ -138,8 +139,8 @@ exports.addTarget = { test.done(); }, 'should add to build configuration list with comment': function (test) { - var pbxXCConfigurationList = proj.pbxXCConfigurationList(), - target = proj.addTarget(TARGET_NAME, TARGET_TYPE, TARGET_SUBFOLDER_NAME); + var pbxXCConfigurationList = proj.pbxXCConfigurationList(); + var target = proj.addTarget(TARGET_NAME, TARGET_TYPE, TARGET_SUBFOLDER_NAME); var buildCommentKey = target.pbxNativeTarget.buildConfigurationList + '_comment'; test.ok(pbxXCConfigurationList[buildCommentKey]); @@ -148,16 +149,15 @@ exports.addTarget = { test.done(); }, 'should create a new target and add source, framework, resource and header files and the corresponding build phases': function (test) { - var target = proj.addTarget(TARGET_NAME, TARGET_TYPE, TARGET_SUBFOLDER_NAME), - options = { 'target' : target.uuid }; - - var sourceFile = proj.addSourceFile('Plugins/file.m', options), - sourcePhase = proj.addBuildPhase([], 'PBXSourcesBuildPhase', 'Sources', target.uuid), - resourceFile = proj.addResourceFile('assets.bundle', options), - resourcePhase = proj.addBuildPhase([], 'PBXResourcesBuildPhase', 'Resources', target.uuid), - frameworkFile = proj.addFramework('libsqlite3.dylib', options); - frameworkPhase = proj.addBuildPhase([], 'PBXFrameworkBuildPhase', 'Frameworks', target.uuid), - headerFile = proj.addHeaderFile('file.h', options); + var target = proj.addTarget(TARGET_NAME, TARGET_TYPE, TARGET_SUBFOLDER_NAME); + var options = { target: target.uuid }; + var sourceFile = proj.addSourceFile('Plugins/file.m', options); + var sourcePhase = proj.addBuildPhase([], 'PBXSourcesBuildPhase', 'Sources', target.uuid); + var resourceFile = proj.addResourceFile('assets.bundle', options); + var resourcePhase = proj.addBuildPhase([], 'PBXResourcesBuildPhase', 'Resources', target.uuid); + var frameworkFile = proj.addFramework('libsqlite3.dylib', options); + var frameworkPhase = proj.addBuildPhase([], 'PBXFrameworkBuildPhase', 'Frameworks', target.uuid); + var headerFile = proj.addHeaderFile('file.h', options); test.ok(sourcePhase); test.ok(resourcePhase); @@ -168,7 +168,7 @@ exports.addTarget = { test.equal(frameworkFile.constructor, pbxFile); test.equal(headerFile.constructor, pbxFile); - test.ok(typeof target == 'object'); + test.ok(typeof target === 'object'); test.ok(target.uuid); test.ok(target.pbxNativeTarget); test.ok(target.pbxNativeTarget.isa); @@ -217,9 +217,9 @@ exports.addTarget = { test.ok(target); test.ok(target.uuid); - var pbxTargetDependencySection = proj.hash.project.objects['PBXTargetDependency']; + var pbxTargetDependencySection = proj.hash.project.objects.PBXTargetDependency; - var targetDependencyUuid = Object.keys(pbxTargetDependencySection).find( (key) => pbxTargetDependencySection[key].target === target.uuid); + var targetDependencyUuid = Object.keys(pbxTargetDependencySection).find((key) => pbxTargetDependencySection[key].target === target.uuid); test.ok(targetDependencyUuid); var firstTarget = proj.getFirstTarget(); @@ -227,7 +227,7 @@ exports.addTarget = { test.ok(firstTarget.firstTarget); test.ok(firstTarget.firstTarget.dependencies); - var firstTargetMatchingDependency = firstTarget.firstTarget.dependencies.find( (elem) => elem.value === targetDependencyUuid); + var firstTargetMatchingDependency = firstTarget.firstTarget.dependencies.find((elem) => elem.value === targetDependencyUuid); test.ok(firstTargetMatchingDependency); test.done(); @@ -388,4 +388,4 @@ exports.addTarget = { test.done(); } -} +}; diff --git a/test/addTargetDependency.js b/test/addTargetDependency.js index 37fe829..ad42c8d 100644 --- a/test/addTargetDependency.js +++ b/test/addTargetDependency.js @@ -15,47 +15,48 @@ under the License. */ -var fullProject = require('./fixtures/full-project') - fullProjectStr = JSON.stringify(fullProject), - pbx = require('../lib/pbxProject'), - proj = new pbx('.'); +var fullProject = require('./fixtures/full-project'); -function cleanHash() { +var fullProjectStr = JSON.stringify(fullProject); +var pbx = require('../lib/pbxProject'); +var proj = new pbx('.'); + +function cleanHash () { return JSON.parse(fullProjectStr); } exports.setUp = function (callback) { proj.hash = cleanHash(); callback(); -} +}; exports.addTargetDependency = { 'should return undefined when no target specified': function (test) { var buildPhase = proj.addTargetDependency(); test.ok(typeof buildPhase === 'undefined'); - test.done() + test.done(); }, 'should throw when target not found in nativeTargetsSection': function (test) { - test.throws(function() { + test.throws(function () { proj.addTargetDependency('invalidTarget'); }, function (error) { return (error instanceof Error) && /Invalid target/i.test(error); }); - test.done() + test.done(); }, 'should throw when any dependency target not found in nativeTargetsSection': function (test) { - test.throws(function() { + test.throws(function () { proj.addTargetDependency('1D6058900D05DD3D006BFB54', ['invalidTarget']); }, function (error) { return (error instanceof Error) && /Invalid target/i.test(error); }); - test.done() + test.done(); }, 'should return the pbxTarget': function (test) { var target = proj.addTargetDependency('1D6058900D05DD3D006BFB54', ['1D6058900D05DD3D006BFB54']); - test.ok(typeof target == 'object'); + test.ok(typeof target === 'object'); test.ok(target.uuid); test.ok(target.target); test.done(); @@ -65,11 +66,11 @@ exports.addTargetDependency = { test.deepEqual(targetInPbxProj.dependencies, []); var target = proj.addTargetDependency('1D6058900D05DD3D006BFB55', ['1D6058900D05DD3D006BFB54', '1D6058900D05DD3D006BFB55']).target; - test.deepEqual(targetInPbxProj.dependencies, target.dependencies) - test.done() + test.deepEqual(targetInPbxProj.dependencies, target.dependencies); + test.done(); }, 'should not modify native target dependencies if PBXTargetDependency object does not exist': function (test) { - delete proj.hash.project.objects['PBXTargetDependency']; + delete proj.hash.project.objects.PBXTargetDependency; var numDependenciesBefore = proj.pbxNativeTargetSection()['1D6058900D05DD3D006BFB54'].dependencies.length; proj.addTargetDependency('1D6058900D05DD3D006BFB54', ['1D6058900D05DD3D006BFB54']); @@ -80,7 +81,7 @@ exports.addTargetDependency = { test.done(); }, 'should not modify native target dependencies if PBXContainerItemProxy object does not exist': function (test) { - delete proj.hash.project.objects['PBXContainerItemProxy']; + delete proj.hash.project.objects.PBXContainerItemProxy; var numDependenciesBefore = proj.pbxNativeTargetSection()['1D6058900D05DD3D006BFB54'].dependencies.length; proj.addTargetDependency('1D6058900D05DD3D006BFB54', ['1D6058900D05DD3D006BFB54']); @@ -91,30 +92,30 @@ exports.addTargetDependency = { test.done(); }, 'should create a PBXTargetDependency for each dependency target': function (test) { - var pbxTargetDependencySection = proj.hash.project.objects['PBXTargetDependency'], - target = proj.addTargetDependency('1D6058900D05DD3D006BFB54', ['1D6058900D05DD3D006BFB54', '1D6058900D05DD3D006BFB55']).target; + var pbxTargetDependencySection = proj.hash.project.objects.PBXTargetDependency; + var target = proj.addTargetDependency('1D6058900D05DD3D006BFB54', ['1D6058900D05DD3D006BFB54', '1D6058900D05DD3D006BFB55']).target; for (var index = 0; index < target.dependencies.length; index++) { var dependency = target.dependencies[index].value; test.ok(pbxTargetDependencySection[dependency]); } - test.done() + test.done(); }, 'should set right comment for each target dependency': function (test) { - var pbxTargetDependencySection = proj.hash.project.objects['PBXTargetDependency'], - target = proj.addTargetDependency('1D6058900D05DD3D006BFB54', ['1D6058900D05DD3D006BFB54', '1D6058900D05DD3D006BFB55']).target; + var pbxTargetDependencySection = proj.hash.project.objects.PBXTargetDependency; + var target = proj.addTargetDependency('1D6058900D05DD3D006BFB54', ['1D6058900D05DD3D006BFB54', '1D6058900D05DD3D006BFB55']).target; for (var index = 0; index < target.dependencies.length; index++) { var dependencyCommentKey = target.dependencies[index].value + '_comment'; test.equal(pbxTargetDependencySection[dependencyCommentKey], 'PBXTargetDependency'); } - test.done() + test.done(); }, 'should set right comment for each dependency target': function (test) { - var pbxTargetDependencySection = proj.hash.project.objects['PBXTargetDependency'], - target = proj.addTargetDependency('1D6058900D05DD3D006BFB54', ['1D6058900D05DD3D006BFB54', '1D6058900D05DD3D006BFB55']).target; + var pbxTargetDependencySection = proj.hash.project.objects.PBXTargetDependency; + var target = proj.addTargetDependency('1D6058900D05DD3D006BFB54', ['1D6058900D05DD3D006BFB54', '1D6058900D05DD3D006BFB55']).target; for (var index = 0; index < target.dependencies.length; index++) { var dependencyTargetUuid = target.dependencies[index].value; @@ -129,23 +130,23 @@ exports.addTargetDependency = { test.done(); }, 'should create a PBXContainerItemProxy for each PBXTargetDependency': function (test) { - var pbxTargetDependencySection = proj.hash.project.objects['PBXTargetDependency'], - pbxContainerItemProxySection = proj.hash.project.objects['PBXContainerItemProxy'], - target = proj.addTargetDependency('1D6058900D05DD3D006BFB54', ['1D6058900D05DD3D006BFB54', '1D6058900D05DD3D006BFB55']).target; + var pbxTargetDependencySection = proj.hash.project.objects.PBXTargetDependency; + var pbxContainerItemProxySection = proj.hash.project.objects.PBXContainerItemProxy; + var target = proj.addTargetDependency('1D6058900D05DD3D006BFB54', ['1D6058900D05DD3D006BFB54', '1D6058900D05DD3D006BFB55']).target; for (var index = 0; index < target.dependencies.length; index++) { - var dependency = target.dependencies[index].value, - targetProxy = pbxTargetDependencySection[dependency]['targetProxy']; + var dependency = target.dependencies[index].value; + var targetProxy = pbxTargetDependencySection[dependency].targetProxy; test.ok(pbxContainerItemProxySection[targetProxy]); } - test.done() + test.done(); }, 'should set right comment for each container item proxy': function (test) { - var pbxTargetDependencySection = proj.hash.project.objects['PBXTargetDependency'], - pbxContainerItemProxySection = proj.hash.project.objects['PBXContainerItemProxy'], - target = proj.addTargetDependency('1D6058900D05DD3D006BFB54', ['1D6058900D05DD3D006BFB54', '1D6058900D05DD3D006BFB55']).target; + var pbxTargetDependencySection = proj.hash.project.objects.PBXTargetDependency; + var pbxContainerItemProxySection = proj.hash.project.objects.PBXContainerItemProxy; + var target = proj.addTargetDependency('1D6058900D05DD3D006BFB54', ['1D6058900D05DD3D006BFB54', '1D6058900D05DD3D006BFB55']).target; for (var index = 0; index < target.dependencies.length; index++) { var dependencyTargetUuid = target.dependencies[index].value; @@ -163,77 +164,77 @@ exports.addTargetDependency = { test.done(); }, 'should set each PBXContainerItemProxy`s remoteGlobalIDString correctly': function (test) { - var pbxTargetDependencySection = proj.hash.project.objects['PBXTargetDependency'], - pbxContainerItemProxySection = proj.hash.project.objects['PBXContainerItemProxy'], - target = proj.addTargetDependency('1D6058900D05DD3D006BFB55', ['1D6058900D05DD3D006BFB54', '1D6058900D05DD3D006BFB55']).target, - remoteGlobalIDStrings = []; + var pbxTargetDependencySection = proj.hash.project.objects.PBXTargetDependency; + var pbxContainerItemProxySection = proj.hash.project.objects.PBXContainerItemProxy; + var target = proj.addTargetDependency('1D6058900D05DD3D006BFB55', ['1D6058900D05DD3D006BFB54', '1D6058900D05DD3D006BFB55']).target; + var remoteGlobalIDStrings = []; for (var index = 0; index < target.dependencies.length; index++) { - var dependency = target.dependencies[index].value, - targetProxy = pbxTargetDependencySection[dependency]['targetProxy']; + var dependency = target.dependencies[index].value; + var targetProxy = pbxTargetDependencySection[dependency].targetProxy; - remoteGlobalIDStrings.push(pbxContainerItemProxySection[targetProxy]['remoteGlobalIDString']); + remoteGlobalIDStrings.push(pbxContainerItemProxySection[targetProxy].remoteGlobalIDString); } test.deepEqual(remoteGlobalIDStrings, ['1D6058900D05DD3D006BFB54', '1D6058900D05DD3D006BFB55']); - test.done() + test.done(); }, 'should set each PBXContainerItemProxy`s remoteInfo correctly': function (test) { - var pbxTargetDependencySection = proj.hash.project.objects['PBXTargetDependency'], - pbxContainerItemProxySection = proj.hash.project.objects['PBXContainerItemProxy'], - target = proj.addTargetDependency('1D6058900D05DD3D006BFB55', ['1D6058900D05DD3D006BFB54', '1D6058900D05DD3D006BFB55']).target, - remoteInfoArray = []; + var pbxTargetDependencySection = proj.hash.project.objects.PBXTargetDependency; + var pbxContainerItemProxySection = proj.hash.project.objects.PBXContainerItemProxy; + var target = proj.addTargetDependency('1D6058900D05DD3D006BFB55', ['1D6058900D05DD3D006BFB54', '1D6058900D05DD3D006BFB55']).target; + var remoteInfoArray = []; for (var index = 0; index < target.dependencies.length; index++) { - var dependency = target.dependencies[index].value, - targetProxy = pbxTargetDependencySection[dependency]['targetProxy']; + var dependency = target.dependencies[index].value; + var targetProxy = pbxTargetDependencySection[dependency].targetProxy; - remoteInfoArray.push(pbxContainerItemProxySection[targetProxy]['remoteInfo']); + remoteInfoArray.push(pbxContainerItemProxySection[targetProxy].remoteInfo); } test.deepEqual(remoteInfoArray, ['"KitchenSinktablet"', '"TestApp"']); - test.done() + test.done(); }, 'should set each PBXContainerItemProxy`s containerPortal correctly': function (test) { - var pbxTargetDependencySection = proj.hash.project.objects['PBXTargetDependency'], - pbxContainerItemProxySection = proj.hash.project.objects['PBXContainerItemProxy'], - target = proj.addTargetDependency('1D6058900D05DD3D006BFB55', ['1D6058900D05DD3D006BFB54', '1D6058900D05DD3D006BFB55']).target; + var pbxTargetDependencySection = proj.hash.project.objects.PBXTargetDependency; + var pbxContainerItemProxySection = proj.hash.project.objects.PBXContainerItemProxy; + var target = proj.addTargetDependency('1D6058900D05DD3D006BFB55', ['1D6058900D05DD3D006BFB54', '1D6058900D05DD3D006BFB55']).target; for (var index = 0; index < target.dependencies.length; index++) { - var dependency = target.dependencies[index].value, - targetProxy = pbxTargetDependencySection[dependency]['targetProxy']; + var dependency = target.dependencies[index].value; + var targetProxy = pbxTargetDependencySection[dependency].targetProxy; - test.equal(pbxContainerItemProxySection[targetProxy]['containerPortal'], proj.hash.project['rootObject']); + test.equal(pbxContainerItemProxySection[targetProxy].containerPortal, proj.hash.project.rootObject); } - test.done() + test.done(); }, 'should set each PBXContainerItemProxy`s containerPortal_comment correctly': function (test) { - var pbxTargetDependencySection = proj.hash.project.objects['PBXTargetDependency'], - pbxContainerItemProxySection = proj.hash.project.objects['PBXContainerItemProxy'], - target = proj.addTargetDependency('1D6058900D05DD3D006BFB55', ['1D6058900D05DD3D006BFB54', '1D6058900D05DD3D006BFB55']).target; + var pbxTargetDependencySection = proj.hash.project.objects.PBXTargetDependency; + var pbxContainerItemProxySection = proj.hash.project.objects.PBXContainerItemProxy; + var target = proj.addTargetDependency('1D6058900D05DD3D006BFB55', ['1D6058900D05DD3D006BFB54', '1D6058900D05DD3D006BFB55']).target; for (var index = 0; index < target.dependencies.length; index++) { - var dependency = target.dependencies[index].value, - targetProxy = pbxTargetDependencySection[dependency]['targetProxy']; + var dependency = target.dependencies[index].value; + var targetProxy = pbxTargetDependencySection[dependency].targetProxy; - test.equal(pbxContainerItemProxySection[targetProxy]['containerPortal_comment'], proj.hash.project['rootObject_comment']); + test.equal(pbxContainerItemProxySection[targetProxy].containerPortal_comment, proj.hash.project.rootObject_comment); } - test.done() + test.done(); }, 'should set each PBXContainerItemProxy`s proxyType correctly': function (test) { - var pbxTargetDependencySection = proj.hash.project.objects['PBXTargetDependency'], - pbxContainerItemProxySection = proj.hash.project.objects['PBXContainerItemProxy'], - target = proj.addTargetDependency('1D6058900D05DD3D006BFB55', ['1D6058900D05DD3D006BFB54', '1D6058900D05DD3D006BFB55']).target; + var pbxTargetDependencySection = proj.hash.project.objects.PBXTargetDependency; + var pbxContainerItemProxySection = proj.hash.project.objects.PBXContainerItemProxy; + var target = proj.addTargetDependency('1D6058900D05DD3D006BFB55', ['1D6058900D05DD3D006BFB54', '1D6058900D05DD3D006BFB55']).target; for (var index = 0; index < target.dependencies.length; index++) { - var dependency = target.dependencies[index].value, - targetProxy = pbxTargetDependencySection[dependency]['targetProxy']; + var dependency = target.dependencies[index].value; + var targetProxy = pbxTargetDependencySection[dependency].targetProxy; - test.equal(pbxContainerItemProxySection[targetProxy]['proxyType'], 1); + test.equal(pbxContainerItemProxySection[targetProxy].proxyType, 1); } - test.done() + test.done(); } -} +}; diff --git a/test/addToPbxFileReferenceSection.js b/test/addToPbxFileReferenceSection.js index d69abbc..a040b96 100644 --- a/test/addToPbxFileReferenceSection.js +++ b/test/addToPbxFileReferenceSection.js @@ -15,27 +15,28 @@ under the License. */ -var jsonProject = require('./fixtures/full-project') - fullProjectStr = JSON.stringify(jsonProject), - pbx = require('../lib/pbxProject'), - pbxFile = require('../lib/pbxFile'), - myProj = new pbx('.'); +var jsonProject = require('./fixtures/full-project'); -function cleanHash() { +var fullProjectStr = JSON.stringify(jsonProject); +var pbx = require('../lib/pbxProject'); +var pbxFile = require('../lib/pbxFile'); +var myProj = new pbx('.'); + +function cleanHash () { return JSON.parse(fullProjectStr); } exports.setUp = function (callback) { myProj.hash = cleanHash(); callback(); -} +}; exports['addToPbxFileReferenceSection function'] = { 'should add file and comment to fileReferenceSection': function (test) { var file = new pbxFile('file.m'); file.fileRef = myProj.generateUuid(); - myProj.addToPbxFileReferenceSection(file) + myProj.addToPbxFileReferenceSection(file); test.equal(myProj.pbxFileReferenceSection()[file.fileRef].isa, 'PBXFileReference'); test.equal(myProj.pbxFileReferenceSection()[file.fileRef].lastKnownFileType, 'sourcecode.c.objc'); @@ -43,13 +44,13 @@ exports['addToPbxFileReferenceSection function'] = { 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'); + test.equal(myProj.pbxFileReferenceSection()[file.fileRef + '_comment'], 'file.m'); test.done(); }, 'should add file with preset explicitFileType to fileReferenceSection correctly': function (test) { - var appexFile = { fileRef: myProj.generateUuid(), isa: 'PBXFileReference', explicitFileType: '"wrapper.app-extension"', path: "WatchKit Extension.appex"}; + var appexFile = { fileRef: myProj.generateUuid(), isa: 'PBXFileReference', explicitFileType: '"wrapper.app-extension"', path: 'WatchKit Extension.appex' }; - myProj.addToPbxFileReferenceSection(appexFile) + myProj.addToPbxFileReferenceSection(appexFile); test.equal(myProj.pbxFileReferenceSection()[appexFile.fileRef].isa, 'PBXFileReference'); test.equal(myProj.pbxFileReferenceSection()[appexFile.fileRef].explicitFileType, '"wrapper.app-extension"'); @@ -57,9 +58,9 @@ exports['addToPbxFileReferenceSection function'] = { test.done(); }, 'should add file with preset includeInIndex to fileReferenceSection correctly': function (test) { - var appexFile = { fileRef: myProj.generateUuid(), isa: 'PBXFileReference', includeInIndex: 0, path: "WatchKit Extension.appex"}; + var appexFile = { fileRef: myProj.generateUuid(), isa: 'PBXFileReference', includeInIndex: 0, path: 'WatchKit Extension.appex' }; - myProj.addToPbxFileReferenceSection(appexFile) + myProj.addToPbxFileReferenceSection(appexFile); test.equal(myProj.pbxFileReferenceSection()[appexFile.fileRef].isa, 'PBXFileReference'); test.equal(myProj.pbxFileReferenceSection()[appexFile.fileRef].includeInIndex, 0); @@ -67,13 +68,13 @@ exports['addToPbxFileReferenceSection function'] = { test.done(); }, 'should add file with preset sourceTree to fileReferenceSection correctly': function (test) { - var appexFile = { fileRef: myProj.generateUuid(), isa: 'PBXFileReference', sourceTree: 'BUILT_PRODUCTS_DIR', path: "WatchKit Extension.appex"}; + var appexFile = { fileRef: myProj.generateUuid(), isa: 'PBXFileReference', sourceTree: 'BUILT_PRODUCTS_DIR', path: 'WatchKit Extension.appex' }; - myProj.addToPbxFileReferenceSection(appexFile) + myProj.addToPbxFileReferenceSection(appexFile); test.equal(myProj.pbxFileReferenceSection()[appexFile.fileRef].isa, 'PBXFileReference'); test.equal(myProj.pbxFileReferenceSection()[appexFile.fileRef].sourceTree, 'BUILT_PRODUCTS_DIR'); test.equal(myProj.pbxFileReferenceSection()[appexFile.fileRef].path, '"WatchKit Extension.appex"'); test.done(); } -} +}; diff --git a/test/addWatch2App.js b/test/addWatch2App.js index 2dd72f5..8abd45e 100644 --- a/test/addWatch2App.js +++ b/test/addWatch2App.js @@ -15,30 +15,31 @@ under the License. */ -var fullProject = require('./fixtures/full-project') - fullProjectStr = JSON.stringify(fullProject), - pbx = require('../lib/pbxProject'), - pbxFile = require('../lib/pbxFile'), - proj = new pbx('.'); +var fullProject = require('./fixtures/full-project'); -function cleanHash() { +var fullProjectStr = JSON.stringify(fullProject); +var pbx = require('../lib/pbxProject'); +var pbxFile = require('../lib/pbxFile'); +var proj = new pbx('.'); + +function cleanHash () { return JSON.parse(fullProjectStr); } -var TARGET_NAME = 'TestWatchApp', - TARGET_TYPE = 'watch2_app', - TARGET_SUBFOLDER_NAME = 'TestWatchAppFiles'; +var TARGET_NAME = 'TestWatchApp'; +var TARGET_TYPE = 'watch2_app'; +var TARGET_SUBFOLDER_NAME = 'TestWatchAppFiles'; exports.setUp = function (callback) { proj.hash = cleanHash(); callback(); -} +}; exports.addWatchApp = { 'should create a new watch2 app target with the correct product type': function (test) { var target = proj.addTarget(TARGET_NAME, TARGET_TYPE, TARGET_SUBFOLDER_NAME); - test.ok(typeof target == 'object'); + test.ok(typeof target === 'object'); test.ok(target.uuid); test.ok(target.pbxNativeTarget); test.ok(target.pbxNativeTarget.isa); @@ -58,7 +59,7 @@ exports.addWatchApp = { 'should create a new watch2 app target with the correct product type, without needing a subfolder name': function (test) { var target = proj.addTarget(TARGET_NAME, TARGET_TYPE); - test.ok(typeof target == 'object'); + test.ok(typeof target === 'object'); test.ok(target.uuid); test.ok(target.pbxNativeTarget); test.ok(target.pbxNativeTarget.isa); @@ -76,16 +77,15 @@ exports.addWatchApp = { test.done(); }, 'should create a new watch2 app target and add source, framework, resource and header files and the corresponding build phases': function (test) { - var target = proj.addTarget(TARGET_NAME, TARGET_TYPE, TARGET_SUBFOLDER_NAME), - options = { 'target' : target.uuid }; - - var sourceFile = proj.addSourceFile('Plugins/file.m', options), - sourcePhase = proj.addBuildPhase([], 'PBXSourcesBuildPhase', 'Sources', target.uuid), - resourceFile = proj.addResourceFile('assets.bundle', options), - resourcePhase = proj.addBuildPhase([], 'PBXResourcesBuildPhase', 'Resources', target.uuid), - frameworkFile = proj.addFramework('libsqlite3.dylib', options); - frameworkPhase = proj.addBuildPhase([], 'PBXFrameworkBuildPhase', 'Frameworks', target.uuid), - headerFile = proj.addHeaderFile('file.h', options); + var target = proj.addTarget(TARGET_NAME, TARGET_TYPE, TARGET_SUBFOLDER_NAME); + var options = { target: target.uuid }; + var sourceFile = proj.addSourceFile('Plugins/file.m', options); + var sourcePhase = proj.addBuildPhase([], 'PBXSourcesBuildPhase', 'Sources', target.uuid); + var resourceFile = proj.addResourceFile('assets.bundle', options); + var resourcePhase = proj.addBuildPhase([], 'PBXResourcesBuildPhase', 'Resources', target.uuid); + var frameworkFile = proj.addFramework('libsqlite3.dylib', options); + var frameworkPhase = proj.addBuildPhase([], 'PBXFrameworkBuildPhase', 'Frameworks', target.uuid); + var headerFile = proj.addHeaderFile('file.h', options); test.ok(sourcePhase); test.ok(resourcePhase); @@ -96,7 +96,7 @@ exports.addWatchApp = { test.equal(frameworkFile.constructor, pbxFile); test.equal(headerFile.constructor, pbxFile); - test.ok(typeof target == 'object'); + test.ok(typeof target === 'object'); test.ok(target.uuid); test.ok(target.pbxNativeTarget); test.ok(target.pbxNativeTarget.isa); @@ -114,7 +114,7 @@ exports.addWatchApp = { 'should create a new watch2 app target and add watch build phase': function (test) { var target = proj.addTarget(TARGET_NAME, TARGET_TYPE); - test.ok(typeof target == 'object'); + test.ok(typeof target === 'object'); test.ok(target.uuid); test.ok(target.pbxNativeTarget); test.ok(target.pbxNativeTarget.isa); @@ -143,7 +143,7 @@ exports.addWatchApp = { 'should create a new watch2 app with appropriate target extension': function (test) { var target = proj.addTarget(TARGET_NAME, TARGET_TYPE); - var buildPhase = proj.buildPhaseObject('PBXCopyFilesBuildPhase', 'Embed Watch Content', target.uuid) + var buildPhase = proj.buildPhaseObject('PBXCopyFilesBuildPhase', 'Embed Watch Content', target.uuid); var buildPhaseFile = buildPhase.files[0]; test.ok(buildPhaseFile.value); @@ -156,10 +156,10 @@ exports.addWatchApp = { test.ok(buildPhaseFileRef.name); test.ok(buildPhaseFileRef.path); - var quotedTargetPath = "\"" + TARGET_NAME + ".app\""; + var quotedTargetPath = '"' + TARGET_NAME + '.app"'; test.equal(buildPhaseFileRef.name, quotedTargetPath); test.equal(buildPhaseFileRef.path, quotedTargetPath); test.done(); } -} +}; diff --git a/test/addWatch2Extension.js b/test/addWatch2Extension.js index 302b752..ca383c3 100644 --- a/test/addWatch2Extension.js +++ b/test/addWatch2Extension.js @@ -15,30 +15,31 @@ under the License. */ -var fullProject = require('./fixtures/full-project') - fullProjectStr = JSON.stringify(fullProject), - pbx = require('../lib/pbxProject'), - pbxFile = require('../lib/pbxFile'), - proj = new pbx('.'); +var fullProject = require('./fixtures/full-project'); -function cleanHash() { +var fullProjectStr = JSON.stringify(fullProject); +var pbx = require('../lib/pbxProject'); +var pbxFile = require('../lib/pbxFile'); +var proj = new pbx('.'); + +function cleanHash () { return JSON.parse(fullProjectStr); } -var TARGET_NAME = 'TestWatchExtension', - TARGET_TYPE = 'watch2_extension', - TARGET_SUBFOLDER_NAME = 'TestWatchExtensionFiles'; +var TARGET_NAME = 'TestWatchExtension'; +var TARGET_TYPE = 'watch2_extension'; +var TARGET_SUBFOLDER_NAME = 'TestWatchExtensionFiles'; exports.setUp = function (callback) { proj.hash = cleanHash(); callback(); -} +}; exports.addWatchExtension = { 'should create a new watch2 extension target with the correct product type': function (test) { var target = proj.addTarget(TARGET_NAME, TARGET_TYPE, TARGET_SUBFOLDER_NAME); - test.ok(typeof target == 'object'); + test.ok(typeof target === 'object'); test.ok(target.uuid); test.ok(target.pbxNativeTarget); test.ok(target.pbxNativeTarget.isa); @@ -55,16 +56,15 @@ exports.addWatchExtension = { test.done(); }, 'should create a new watch2 extension target and add source, framework, resource and header files and the corresponding build phases': function (test) { - var target = proj.addTarget(TARGET_NAME, TARGET_TYPE, TARGET_SUBFOLDER_NAME), - options = { 'target' : target.uuid }; - - var sourceFile = proj.addSourceFile('Plugins/file.m', options), - sourcePhase = proj.addBuildPhase([], 'PBXSourcesBuildPhase', 'Sources', target.uuid), - resourceFile = proj.addResourceFile('assets.bundle', options), - resourcePhase = proj.addBuildPhase([], 'PBXResourcesBuildPhase', 'Resources', target.uuid), - frameworkFile = proj.addFramework('libsqlite3.dylib', options); - frameworkPhase = proj.addBuildPhase([], 'PBXFrameworkBuildPhase', 'Frameworks', target.uuid), - headerFile = proj.addHeaderFile('file.h', options); + var target = proj.addTarget(TARGET_NAME, TARGET_TYPE, TARGET_SUBFOLDER_NAME); + var options = { target: target.uuid }; + var sourceFile = proj.addSourceFile('Plugins/file.m', options); + var sourcePhase = proj.addBuildPhase([], 'PBXSourcesBuildPhase', 'Sources', target.uuid); + var resourceFile = proj.addResourceFile('assets.bundle', options); + var resourcePhase = proj.addBuildPhase([], 'PBXResourcesBuildPhase', 'Resources', target.uuid); + var frameworkFile = proj.addFramework('libsqlite3.dylib', options); + var frameworkPhase = proj.addBuildPhase([], 'PBXFrameworkBuildPhase', 'Frameworks', target.uuid); + var headerFile = proj.addHeaderFile('file.h', options); test.ok(sourcePhase); test.ok(resourcePhase); @@ -75,7 +75,7 @@ exports.addWatchExtension = { test.equal(frameworkFile.constructor, pbxFile); test.equal(headerFile.constructor, pbxFile); - test.ok(typeof target == 'object'); + test.ok(typeof target === 'object'); test.ok(target.uuid); test.ok(target.pbxNativeTarget); test.ok(target.pbxNativeTarget.isa); @@ -93,7 +93,7 @@ exports.addWatchExtension = { 'should not create a new watch2 extension build phase if no watch2 app exists': function (test) { var target = proj.addTarget(TARGET_NAME, TARGET_TYPE); - test.ok(typeof target == 'object'); + test.ok(typeof target === 'object'); test.ok(target.uuid); test.ok(target.pbxNativeTarget); test.ok(target.pbxNativeTarget.isa); @@ -106,7 +106,7 @@ exports.addWatchExtension = { test.ok(target.pbxNativeTarget.buildRules); test.ok(target.pbxNativeTarget.dependencies); - var buildPhase = proj.buildPhaseObject('PBXCopyFilesBuildPhase', 'Embed App Extensions', target.uuid) + var buildPhase = proj.buildPhaseObject('PBXCopyFilesBuildPhase', 'Embed App Extensions', target.uuid); test.ok(!buildPhase); @@ -116,7 +116,7 @@ exports.addWatchExtension = { proj.addTarget('TestWatchApp', 'watch2_app'); var target = proj.addTarget(TARGET_NAME, TARGET_TYPE); - var buildPhase = proj.buildPhaseObject('PBXCopyFilesBuildPhase', 'Embed App Extensions', target.uuid) + var buildPhase = proj.buildPhaseObject('PBXCopyFilesBuildPhase', 'Embed App Extensions', target.uuid); test.ok(buildPhase); test.ok(buildPhase.files); @@ -149,12 +149,12 @@ exports.addWatchExtension = { test.equal(nativeTargets[watchApp.uuid].buildPhases.length, 0); test.equal(nativeTargets[watchApp.uuid].dependencies.length, 0); - proj.addTarget(TARGET_NAME, "app_extension"); + proj.addTarget(TARGET_NAME, 'app_extension'); test.equal(nativeTargets[watchApp.uuid].buildPhases.length, 0); test.equal(nativeTargets[watchApp.uuid].dependencies.length, 0); - proj.addTarget(TARGET_NAME, "watch_extension"); + proj.addTarget(TARGET_NAME, 'watch_extension'); test.equal(nativeTargets[watchApp.uuid].buildPhases.length, 0); test.equal(nativeTargets[watchApp.uuid].dependencies.length, 0); @@ -165,7 +165,7 @@ exports.addWatchExtension = { proj.addTarget('TestWatchApp', 'watch2_app'); var target = proj.addTarget(TARGET_NAME, TARGET_TYPE); - var buildPhase = proj.buildPhaseObject('PBXCopyFilesBuildPhase', 'Embed App Extensions', target.uuid) + var buildPhase = proj.buildPhaseObject('PBXCopyFilesBuildPhase', 'Embed App Extensions', target.uuid); var buildPhaseFile = buildPhase.files[0]; test.ok(buildPhaseFile.value); @@ -178,10 +178,10 @@ exports.addWatchExtension = { test.ok(buildPhaseFileRef.name); test.ok(buildPhaseFileRef.path); - var quotedTargetPath = "\"" + TARGET_NAME + ".appex\""; + var quotedTargetPath = '"' + TARGET_NAME + '.appex"'; test.equal(buildPhaseFileRef.name, quotedTargetPath); test.equal(buildPhaseFileRef.path, quotedTargetPath); test.done(); } -} +}; diff --git a/test/addWatchApp.js b/test/addWatchApp.js index b1b603d..853f1b3 100644 --- a/test/addWatchApp.js +++ b/test/addWatchApp.js @@ -15,30 +15,31 @@ under the License. */ -var fullProject = require('./fixtures/full-project') - fullProjectStr = JSON.stringify(fullProject), - pbx = require('../lib/pbxProject'), - pbxFile = require('../lib/pbxFile'), - proj = new pbx('.'); +var fullProject = require('./fixtures/full-project'); -function cleanHash() { +var fullProjectStr = JSON.stringify(fullProject); +var pbx = require('../lib/pbxProject'); +var pbxFile = require('../lib/pbxFile'); +var proj = new pbx('.'); + +function cleanHash () { return JSON.parse(fullProjectStr); } -var TARGET_NAME = 'TestWatchApp', - TARGET_TYPE = 'watch_app', - TARGET_SUBFOLDER_NAME = 'TestWatchAppFiles'; +var TARGET_NAME = 'TestWatchApp'; +var TARGET_TYPE = 'watch_app'; +var TARGET_SUBFOLDER_NAME = 'TestWatchAppFiles'; exports.setUp = function (callback) { proj.hash = cleanHash(); callback(); -} +}; exports.addWatchApp = { 'should create a new watch app target with the correct product type': function (test) { var target = proj.addTarget(TARGET_NAME, TARGET_TYPE, TARGET_SUBFOLDER_NAME); - test.ok(typeof target == 'object'); + test.ok(typeof target === 'object'); test.ok(target.uuid); test.ok(target.pbxNativeTarget); test.ok(target.pbxNativeTarget.isa); @@ -58,7 +59,7 @@ exports.addWatchApp = { 'should create a new watch app target with the correct product type, without needing a subfolder name': function (test) { var target = proj.addTarget(TARGET_NAME, TARGET_TYPE); - test.ok(typeof target == 'object'); + test.ok(typeof target === 'object'); test.ok(target.uuid); test.ok(target.pbxNativeTarget); test.ok(target.pbxNativeTarget.isa); @@ -76,16 +77,15 @@ exports.addWatchApp = { test.done(); }, 'should create a new watch app target and add source, framework, resource and header files and the corresponding build phases': function (test) { - var target = proj.addTarget(TARGET_NAME, TARGET_TYPE, TARGET_SUBFOLDER_NAME), - options = { 'target' : target.uuid }; - - var sourceFile = proj.addSourceFile('Plugins/file.m', options), - sourcePhase = proj.addBuildPhase([], 'PBXSourcesBuildPhase', 'Sources', target.uuid), - resourceFile = proj.addResourceFile('assets.bundle', options), - resourcePhase = proj.addBuildPhase([], 'PBXResourcesBuildPhase', 'Resources', target.uuid), - frameworkFile = proj.addFramework('libsqlite3.dylib', options); - frameworkPhase = proj.addBuildPhase([], 'PBXFrameworkBuildPhase', 'Frameworks', target.uuid), - headerFile = proj.addHeaderFile('file.h', options); + var target = proj.addTarget(TARGET_NAME, TARGET_TYPE, TARGET_SUBFOLDER_NAME); + var options = { target: target.uuid }; + var sourceFile = proj.addSourceFile('Plugins/file.m', options); + var sourcePhase = proj.addBuildPhase([], 'PBXSourcesBuildPhase', 'Sources', target.uuid); + var resourceFile = proj.addResourceFile('assets.bundle', options); + var resourcePhase = proj.addBuildPhase([], 'PBXResourcesBuildPhase', 'Resources', target.uuid); + var frameworkFile = proj.addFramework('libsqlite3.dylib', options); + var frameworkPhase = proj.addBuildPhase([], 'PBXFrameworkBuildPhase', 'Frameworks', target.uuid); + var headerFile = proj.addHeaderFile('file.h', options); test.ok(sourcePhase); test.ok(resourcePhase); @@ -96,7 +96,7 @@ exports.addWatchApp = { test.equal(frameworkFile.constructor, pbxFile); test.equal(headerFile.constructor, pbxFile); - test.ok(typeof target == 'object'); + test.ok(typeof target === 'object'); test.ok(target.uuid); test.ok(target.pbxNativeTarget); test.ok(target.pbxNativeTarget.isa); @@ -111,4 +111,4 @@ exports.addWatchApp = { test.done(); } -} +}; diff --git a/test/addWatchExtension.js b/test/addWatchExtension.js index 9410488..aff8303 100644 --- a/test/addWatchExtension.js +++ b/test/addWatchExtension.js @@ -15,30 +15,31 @@ under the License. */ -var fullProject = require('./fixtures/full-project') - fullProjectStr = JSON.stringify(fullProject), - pbx = require('../lib/pbxProject'), - pbxFile = require('../lib/pbxFile'), - proj = new pbx('.'); +var fullProject = require('./fixtures/full-project'); -function cleanHash() { +var fullProjectStr = JSON.stringify(fullProject); +var pbx = require('../lib/pbxProject'); +var pbxFile = require('../lib/pbxFile'); +var proj = new pbx('.'); + +function cleanHash () { return JSON.parse(fullProjectStr); } -var TARGET_NAME = 'TestWatchExtension', - TARGET_TYPE = 'watch_extension', - TARGET_SUBFOLDER_NAME = 'TestWatchExtensionFiles'; +var TARGET_NAME = 'TestWatchExtension'; +var TARGET_TYPE = 'watch_extension'; +var TARGET_SUBFOLDER_NAME = 'TestWatchExtensionFiles'; exports.setUp = function (callback) { proj.hash = cleanHash(); callback(); -} +}; exports.addWatchExtension = { 'should create a new watch extension target': function (test) { var target = proj.addTarget(TARGET_NAME, TARGET_TYPE, TARGET_SUBFOLDER_NAME); - test.ok(typeof target == 'object'); + test.ok(typeof target === 'object'); test.ok(target.uuid); test.ok(target.pbxNativeTarget); test.ok(target.pbxNativeTarget.isa); @@ -54,16 +55,15 @@ exports.addWatchExtension = { test.done(); }, 'should create a new watch extension target and add source, framework, resource and header files and the corresponding build phases': function (test) { - var target = proj.addTarget(TARGET_NAME, TARGET_TYPE, TARGET_SUBFOLDER_NAME), - options = { 'target' : target.uuid }; - - var sourceFile = proj.addSourceFile('Plugins/file.m', options), - sourcePhase = proj.addBuildPhase([], 'PBXSourcesBuildPhase', 'Sources', target.uuid), - resourceFile = proj.addResourceFile('assets.bundle', options), - resourcePhase = proj.addBuildPhase([], 'PBXResourcesBuildPhase', 'Resources', target.uuid), - frameworkFile = proj.addFramework('libsqlite3.dylib', options); - frameworkPhase = proj.addBuildPhase([], 'PBXFrameworkBuildPhase', 'Frameworks', target.uuid), - headerFile = proj.addHeaderFile('file.h', options); + var target = proj.addTarget(TARGET_NAME, TARGET_TYPE, TARGET_SUBFOLDER_NAME); + var options = { target: target.uuid }; + var sourceFile = proj.addSourceFile('Plugins/file.m', options); + var sourcePhase = proj.addBuildPhase([], 'PBXSourcesBuildPhase', 'Sources', target.uuid); + var resourceFile = proj.addResourceFile('assets.bundle', options); + var resourcePhase = proj.addBuildPhase([], 'PBXResourcesBuildPhase', 'Resources', target.uuid); + var frameworkFile = proj.addFramework('libsqlite3.dylib', options); + var frameworkPhase = proj.addBuildPhase([], 'PBXFrameworkBuildPhase', 'Frameworks', target.uuid); + var headerFile = proj.addHeaderFile('file.h', options); test.ok(sourcePhase); test.ok(resourcePhase); @@ -74,7 +74,7 @@ exports.addWatchExtension = { test.equal(frameworkFile.constructor, pbxFile); test.equal(headerFile.constructor, pbxFile); - test.ok(typeof target == 'object'); + test.ok(typeof target === 'object'); test.ok(target.uuid); test.ok(target.pbxNativeTarget); test.ok(target.pbxNativeTarget.isa); @@ -92,7 +92,7 @@ exports.addWatchExtension = { 'should not create a new watch extension build phase if no watch app exists': function (test) { var target = proj.addTarget(TARGET_NAME, TARGET_TYPE); - test.ok(typeof target == 'object'); + test.ok(typeof target === 'object'); test.ok(target.uuid); test.ok(target.pbxNativeTarget); test.ok(target.pbxNativeTarget.isa); @@ -105,10 +105,10 @@ exports.addWatchExtension = { test.ok(target.pbxNativeTarget.buildRules); test.ok(target.pbxNativeTarget.dependencies); - var buildPhase = proj.buildPhaseObject('PBXCopyFilesBuildPhase', 'Embed App Extensions', target.uuid) + var buildPhase = proj.buildPhaseObject('PBXCopyFilesBuildPhase', 'Embed App Extensions', target.uuid); test.ok(!buildPhase); test.done(); } -} +}; diff --git a/test/addXCConfigurationList.js b/test/addXCConfigurationList.js index 6ef74c3..acf828e 100644 --- a/test/addXCConfigurationList.js +++ b/test/addXCConfigurationList.js @@ -15,64 +15,67 @@ under the License. */ -var fullProject = require('./fixtures/full-project') - fullProjectStr = JSON.stringify(fullProject), - pbx = require('../lib/pbxProject'), - proj = new pbx('.'), - debugConfiguration = { - isa: 'XCBuildConfiguration', - buildSettings: { - GCC_PREPROCESSOR_DEFINITIONS: [ - '"DEBUG=1"', - '"$(inherited)"', - ], - INFOPLIST_FILE: "Info.Plist", - LD_RUNPATH_SEARCH_PATHS: '"$(inherited) @executable_path/Frameworks @executable_path/../../Frameworks"', - PRODUCT_NAME: '"${TARGET_NAME}"', - SKIP_INSTALL: 'YES' - }, - name: 'Debug' +var fullProject = require('./fixtures/full-project'); + +var fullProjectStr = JSON.stringify(fullProject); +var pbx = require('../lib/pbxProject'); +var proj = new pbx('.'); + +var debugConfiguration = { + isa: 'XCBuildConfiguration', + buildSettings: { + GCC_PREPROCESSOR_DEFINITIONS: [ + '"DEBUG=1"', + '"$(inherited)"' + ], + INFOPLIST_FILE: 'Info.Plist', + LD_RUNPATH_SEARCH_PATHS: '"$(inherited) @executable_path/Frameworks @executable_path/../../Frameworks"', + PRODUCT_NAME: '"${TARGET_NAME}"', // eslint-disable-line + SKIP_INSTALL: 'YES' + }, + name: 'Debug' +}; + +var releaseConfiguration = { + isa: 'XCBuildConfiguration', + buildSettings: { + INFOPLIST_FILE: 'Info.Plist', + LD_RUNPATH_SEARCH_PATHS: '"$(inherited) @executable_path/Frameworks @executable_path/../../Frameworks"', + PRODUCT_NAME: '"${TARGET_NAME}"', // eslint-disable-line + SKIP_INSTALL: 'YES' }, - releaseConfiguration = { - isa: 'XCBuildConfiguration', - buildSettings: { - INFOPLIST_FILE: "Info.Plist", - LD_RUNPATH_SEARCH_PATHS: '"$(inherited) @executable_path/Frameworks @executable_path/../../Frameworks"', - PRODUCT_NAME: '"${TARGET_NAME}"', - SKIP_INSTALL: 'YES' - }, - name: 'Release' - }; - -function cleanHash() { + name: 'Release' +}; + +function cleanHash () { return JSON.parse(fullProjectStr); } exports.setUp = function (callback) { proj.hash = cleanHash(); callback(); -} +}; exports.addXCConfigurationList = { 'should return an XCConfigurationList': function (test) { - var myProj = new pbx('test/parser/projects/full.pbxproj').parseSync(), - xcConfigurationList = myProj.addXCConfigurationList([debugConfiguration, releaseConfiguration], 'Release', 'XCConfigurationList Comment'); + var myProj = new pbx('test/parser/projects/full.pbxproj').parseSync(); + var xcConfigurationList = myProj.addXCConfigurationList([debugConfiguration, releaseConfiguration], 'Release', 'XCConfigurationList Comment'); test.ok(typeof xcConfigurationList === 'object'); test.done(); }, 'should set a uuid on the XCConfigurationList': function (test) { - var myProj = new pbx('test/parser/projects/full.pbxproj').parseSync(), - xcConfigurationList = myProj.addXCConfigurationList([debugConfiguration, releaseConfiguration], 'Release', 'XCConfigurationList Comment'); + var myProj = new pbx('test/parser/projects/full.pbxproj').parseSync(); + var xcConfigurationList = myProj.addXCConfigurationList([debugConfiguration, releaseConfiguration], 'Release', 'XCConfigurationList Comment'); test.ok(xcConfigurationList.uuid); test.done(); }, 'should add configurations to pbxBuildConfigurationSection': function (test) { - var myProj = new pbx('test/parser/projects/full.pbxproj').parseSync(), - pbxBuildConfigurationSection = myProj.pbxXCBuildConfigurationSection(), - xcConfigurationList = myProj.addXCConfigurationList([debugConfiguration, releaseConfiguration], 'Release', 'XCConfigurationList Comment'), - xcConfigurationListConfigurations = xcConfigurationList.xcConfigurationList.buildConfigurations; + var myProj = new pbx('test/parser/projects/full.pbxproj').parseSync(); + var pbxBuildConfigurationSection = myProj.pbxXCBuildConfigurationSection(); + var xcConfigurationList = myProj.addXCConfigurationList([debugConfiguration, releaseConfiguration], 'Release', 'XCConfigurationList Comment'); + var xcConfigurationListConfigurations = xcConfigurationList.xcConfigurationList.buildConfigurations; for (var index = 0; index < xcConfigurationListConfigurations.length; index++) { var configuration = xcConfigurationListConfigurations[index]; @@ -82,30 +85,30 @@ exports.addXCConfigurationList = { test.done(); }, 'should add XCConfigurationList to pbxXCConfigurationListSection': function (test) { - var myProj = new pbx('test/parser/projects/full.pbxproj').parseSync(), - pbxXCConfigurationListSection = myProj.pbxXCConfigurationList(); - xcConfigurationList = myProj.addXCConfigurationList([debugConfiguration, releaseConfiguration], 'Release', 'XCConfigurationList Comment'); + var myProj = new pbx('test/parser/projects/full.pbxproj').parseSync(); + var pbxXCConfigurationListSection = myProj.pbxXCConfigurationList(); + var xcConfigurationList = myProj.addXCConfigurationList([debugConfiguration, releaseConfiguration], 'Release', 'XCConfigurationList Comment'); test.ok(pbxXCConfigurationListSection[xcConfigurationList.uuid]); test.done(); }, 'should add XCConfigurationList object correctly': function (test) { - var myProj = new pbx('test/parser/projects/full.pbxproj').parseSync(), - pbxXCConfigurationListSection = myProj.pbxXCConfigurationList(); - xcConfigurationList = myProj.addXCConfigurationList([debugConfiguration, releaseConfiguration], 'Release', 'XCConfigurationList Comment'), - xcConfigurationListInPbx = pbxXCConfigurationListSection[xcConfigurationList.uuid]; + var myProj = new pbx('test/parser/projects/full.pbxproj').parseSync(); + var pbxXCConfigurationListSection = myProj.pbxXCConfigurationList(); + var xcConfigurationList = myProj.addXCConfigurationList([debugConfiguration, releaseConfiguration], 'Release', 'XCConfigurationList Comment'); + var xcConfigurationListInPbx = pbxXCConfigurationListSection[xcConfigurationList.uuid]; test.deepEqual(xcConfigurationListInPbx, xcConfigurationList.xcConfigurationList); test.done(); }, 'should add correct configurations to XCConfigurationList and to pbxBuildConfigurationSection': function (test) { - var myProj = new pbx('test/parser/projects/full.pbxproj').parseSync(), - pbxXCConfigurationListSection = myProj.pbxXCConfigurationList(); - pbxBuildConfigurationSection = myProj.pbxXCBuildConfigurationSection(), - xcConfigurationList = myProj.addXCConfigurationList([debugConfiguration, releaseConfiguration], 'Release', 'XCConfigurationList Comment'), - xcConfigurationListConfigurations = xcConfigurationList.xcConfigurationList.buildConfigurations, - expectedConfigurations = [], - xcConfigurationListInPbx = pbxXCConfigurationListSection[xcConfigurationList.uuid]; + var myProj = new pbx('test/parser/projects/full.pbxproj').parseSync(); + var pbxXCConfigurationListSection = myProj.pbxXCConfigurationList(); + var pbxBuildConfigurationSection = myProj.pbxXCBuildConfigurationSection(); + var xcConfigurationList = myProj.addXCConfigurationList([debugConfiguration, releaseConfiguration], 'Release', 'XCConfigurationList Comment'); + var xcConfigurationListConfigurations = xcConfigurationList.xcConfigurationList.buildConfigurations; + var expectedConfigurations = []; + var xcConfigurationListInPbx = pbxXCConfigurationListSection[xcConfigurationList.uuid]; for (var index = 0; index < xcConfigurationListConfigurations.length; index++) { var configuration = xcConfigurationListConfigurations[index]; @@ -117,10 +120,10 @@ exports.addXCConfigurationList = { test.done(); }, 'should set comments for pbxBuildConfigurations': function (test) { - var myProj = new pbx('test/parser/projects/full.pbxproj').parseSync(), - pbxBuildConfigurationSection = myProj.pbxXCBuildConfigurationSection(), - xcConfigurationList = myProj.addXCConfigurationList([debugConfiguration, releaseConfiguration], 'Release', 'XCConfigurationList Comment'), - xcConfigurationListConfigurations = xcConfigurationList.xcConfigurationList.buildConfigurations; + var myProj = new pbx('test/parser/projects/full.pbxproj').parseSync(); + var pbxBuildConfigurationSection = myProj.pbxXCBuildConfigurationSection(); + var xcConfigurationList = myProj.addXCConfigurationList([debugConfiguration, releaseConfiguration], 'Release', 'XCConfigurationList Comment'); + var xcConfigurationListConfigurations = xcConfigurationList.xcConfigurationList.buildConfigurations; for (var index = 0; index < xcConfigurationListConfigurations.length; index++) { var configuration = xcConfigurationListConfigurations[index]; @@ -129,4 +132,4 @@ exports.addXCConfigurationList = { test.done(); } -} +}; diff --git a/test/dataModelDocument.js b/test/dataModelDocument.js index 76477ed..241f14f 100644 --- a/test/dataModelDocument.js +++ b/test/dataModelDocument.js @@ -15,54 +15,55 @@ under the License. */ -var jsonProject = require('./fixtures/full-project') - fullProjectStr = JSON.stringify(jsonProject), - path = require('path'), - pbx = require('../lib/pbxProject'), - pbxFile = require('../lib/pbxFile'), - proj = new pbx('.'), - singleDataModelFilePath = __dirname + '/fixtures/single-data-model.xcdatamodeld', - multipleDataModelFilePath = __dirname + '/fixtures/multiple-data-model.xcdatamodeld'; - -function cleanHash() { +var jsonProject = require('./fixtures/full-project'); + +var fullProjectStr = JSON.stringify(jsonProject); +var path = require('path'); +var pbx = require('../lib/pbxProject'); +var pbxFile = require('../lib/pbxFile'); +var proj = new pbx('.'); +var singleDataModelFilePath = path.join(`${__dirname}/fixtures/single-data-model.xcdatamodeld`); +var multipleDataModelFilePath = path.join(`${__dirname}/fixtures/multiple-data-model.xcdatamodeld`); + +function cleanHash () { return JSON.parse(fullProjectStr); } exports.setUp = function (callback) { proj.hash = cleanHash(); callback(); -} +}; exports.dataModelDocument = { 'should return a pbxFile': function (test) { var newFile = proj.addDataModelDocument(singleDataModelFilePath); test.equal(newFile.constructor, pbxFile); - test.done() + test.done(); }, 'should set a uuid on the pbxFile': function (test) { var newFile = proj.addDataModelDocument(singleDataModelFilePath); test.ok(newFile.uuid); - test.done() + test.done(); }, 'should set a fileRef on the pbxFile': function (test) { var newFile = proj.addDataModelDocument(singleDataModelFilePath); test.ok(newFile.fileRef); - test.done() + test.done(); }, 'should set an optional target on the pbxFile': function (test) { - var newFile = proj.addDataModelDocument(singleDataModelFilePath, undefined, { target: target }), - target = proj.findTargetKey('TestApp'); + var target = proj.findTargetKey('TestApp'); + var newFile = proj.addDataModelDocument(singleDataModelFilePath, undefined, { target: target }); test.equal(newFile.target, target); - test.done() + test.done(); }, 'should populate the PBXBuildFile section with 2 fields': function (test) { - var newFile = proj.addDataModelDocument(singleDataModelFilePath), - buildFileSection = proj.pbxBuildFileSection(), - bfsLength = Object.keys(buildFileSection).length; + var newFile = proj.addDataModelDocument(singleDataModelFilePath); + var buildFileSection = proj.pbxBuildFileSection(); + var bfsLength = Object.keys(buildFileSection).length; test.equal(59 + 1, bfsLength); test.ok(buildFileSection[newFile.uuid]); @@ -71,9 +72,9 @@ exports.dataModelDocument = { test.done(); }, 'should populate the PBXFileReference section with 2 fields for single model document': function (test) { - var newFile = proj.addDataModelDocument(singleDataModelFilePath), - fileRefSection = proj.pbxFileReferenceSection(), - frsLength = Object.keys(fileRefSection).length; + var newFile = proj.addDataModelDocument(singleDataModelFilePath); + var fileRefSection = proj.pbxFileReferenceSection(); + var frsLength = Object.keys(fileRefSection).length; test.equal(66 + 2, frsLength); test.ok(fileRefSection[newFile.models[0].fileRef]); @@ -82,9 +83,9 @@ exports.dataModelDocument = { test.done(); }, 'should populate the PBXFileReference section with 2 fields for each model of a model document': function (test) { - var newFile = proj.addDataModelDocument(multipleDataModelFilePath), - fileRefSection = proj.pbxFileReferenceSection(), - frsLength = Object.keys(fileRefSection).length; + var newFile = proj.addDataModelDocument(multipleDataModelFilePath); + var fileRefSection = proj.pbxFileReferenceSection(); + var frsLength = Object.keys(fileRefSection).length; test.equal(66 + 2 * 2, frsLength); test.ok(fileRefSection[newFile.models[0].fileRef]); @@ -95,9 +96,9 @@ exports.dataModelDocument = { test.done(); }, 'should add to resources group by default': function (test) { - var newFile = proj.addDataModelDocument(singleDataModelFilePath); - groupChildren = proj.pbxGroupByName('Resources').children, - found = false; + proj.addDataModelDocument(singleDataModelFilePath); + var groupChildren = proj.pbxGroupByName('Resources').children; + var found = false; for (var index in groupChildren) { if (groupChildren[index].comment === 'single-data-model.xcdatamodeld') { @@ -109,9 +110,9 @@ exports.dataModelDocument = { test.done(); }, 'should add to group specified by key': function (test) { - var group = 'Frameworks', - newFile = proj.addDataModelDocument(singleDataModelFilePath, proj.findPBXGroupKey({ name: group })); - groupChildren = proj.pbxGroupByName(group).children; + var group = 'Frameworks'; + proj.addDataModelDocument(singleDataModelFilePath, proj.findPBXGroupKey({ name: group })); + var groupChildren = proj.pbxGroupByName(group).children; var found = false; for (var index in groupChildren) { @@ -124,9 +125,9 @@ exports.dataModelDocument = { test.done(); }, 'should add to group specified by name': function (test) { - var group = 'Frameworks', - newFile = proj.addDataModelDocument(singleDataModelFilePath, group); - groupChildren = proj.pbxGroupByName(group).children; + var group = 'Frameworks'; + proj.addDataModelDocument(singleDataModelFilePath, group); + var groupChildren = proj.pbxGroupByName(group).children; var found = false; for (var index in groupChildren) { @@ -139,31 +140,31 @@ exports.dataModelDocument = { test.done(); }, 'should add to the PBXSourcesBuildPhase': function (test) { - var newFile = proj.addDataModelDocument(singleDataModelFilePath), - sources = proj.pbxSourcesBuildPhaseObj(); + proj.addDataModelDocument(singleDataModelFilePath); + var sources = proj.pbxSourcesBuildPhaseObj(); test.equal(sources.files.length, 2 + 1); test.done(); }, 'should create a XCVersionGroup section': function (test) { - var newFile = proj.addDataModelDocument(singleDataModelFilePath), - xcVersionGroupSection = proj.xcVersionGroupSection(); + var newFile = proj.addDataModelDocument(singleDataModelFilePath); + var xcVersionGroupSection = proj.xcVersionGroupSection(); test.ok(xcVersionGroupSection[newFile.fileRef]); test.done(); }, 'should populate the XCVersionGroup comment correctly': function (test) { - var newFile = proj.addDataModelDocument(singleDataModelFilePath), - xcVersionGroupSection = proj.xcVersionGroupSection(), - commentKey = newFile.fileRef + '_comment'; + var newFile = proj.addDataModelDocument(singleDataModelFilePath); + var xcVersionGroupSection = proj.xcVersionGroupSection(); + var commentKey = newFile.fileRef + '_comment'; test.equal(xcVersionGroupSection[commentKey], path.basename(singleDataModelFilePath)); test.done(); }, 'should add the XCVersionGroup object correctly': function (test) { - var newFile = proj.addDataModelDocument(singleDataModelFilePath), - xcVersionGroupSection = proj.xcVersionGroupSection(), - xcVersionGroupEntry = xcVersionGroupSection[newFile.fileRef]; + var newFile = proj.addDataModelDocument(singleDataModelFilePath); + var xcVersionGroupSection = proj.xcVersionGroupSection(); + var xcVersionGroupEntry = xcVersionGroupSection[newFile.fileRef]; test.equal(xcVersionGroupEntry.isa, 'XCVersionGroup'); test.equal(xcVersionGroupEntry.children[0], newFile.models[0].fileRef); @@ -176,4 +177,4 @@ exports.dataModelDocument = { test.done(); } -} +}; diff --git a/test/group.js b/test/group.js index af2454e..bd3238f 100644 --- a/test/group.js +++ b/test/group.js @@ -15,12 +15,13 @@ under the License. */ -var pbx = require('../lib/pbxProject'), - pbxFile = require('../lib/pbxFile'), - project, - projectHash; +var pbx = require('../lib/pbxProject'); -var findChildInGroup = function(obj, target) { +var pbxFile = require('../lib/pbxFile'); +var project; +var projectHash; // eslint-disable-line + +var findChildInGroup = function (obj, target) { var found = false; for (var i = 0, j = obj.children.length; i < j; i++) { @@ -31,9 +32,9 @@ var findChildInGroup = function(obj, target) { } return found; -} +}; -var findFileByUUID = function(obj, target) { +var findFileByUUID = function (obj, target) { var found = false; for (var k = 0, l = obj.files.length; k < l; k++) { @@ -44,9 +45,9 @@ var findFileByUUID = function(obj, target) { } return found; -} +}; -var findByFileRef = function(obj, target) { +var findByFileRef = function (obj, target) { var found = false; for (var property in obj) { @@ -58,9 +59,9 @@ var findByFileRef = function(obj, target) { } } return found; -} +}; -var findByName = function(obj, target) { +var findByName = function (obj, target) { var found = false; for (var property in obj) { if (!/comment/.test(property)) { @@ -71,39 +72,38 @@ var findByName = function(obj, target) { } } return found; -} +}; -exports.setUp = function(callback) { +exports.setUp = function (callback) { project = new pbx('test/parser/projects/group.pbxproj'); projectHash = project.parseSync(); callback(); -} +}; exports.getGroupByKey = { - 'should return PBXGroup for Classes': function(test) { - var groupKey = project.findPBXGroupKey({name: 'Classes'}); + 'should return PBXGroup for Classes': function (test) { + var groupKey = project.findPBXGroupKey({ name: 'Classes' }); var group = project.getPBXGroupByKey(groupKey); test.ok(group.name === 'Classes'); test.done(); }, - 'should return PBXGroup for Plugins': function(test) { - var groupKey = project.findPBXGroupKey({name: 'Plugins'}); + 'should return PBXGroup for Plugins': function (test) { + var groupKey = project.findPBXGroupKey({ name: 'Plugins' }); var group = project.getPBXGroupByKey(groupKey); test.ok(group.name === 'Plugins'); test.done(); } -} +}; exports.createGroup = { - 'should create a new Test Group': function(test) { + 'should create a new Test Group': function (test) { var found = false; var groups = project.getPBXObject('PBXGroup'); - var found = findByName(groups, 'Test'); + found = findByName(groups, 'Test'); test.ok(found === false); - - var group = project.findPBXGroupKey({name:'Test'}); + var group = project.findPBXGroupKey({ name: 'Test' }); test.ok(group === undefined); project.pbxCreateGroup('Test', 'Test'); @@ -112,18 +112,18 @@ exports.createGroup = { found = findByName(groups, 'Test'); test.ok(found === true); - group = project.findPBXGroupKey({name:'Test'}); + group = project.findPBXGroupKey({ name: 'Test' }); test.ok(typeof group === 'string'); test.done(); } -} +}; exports.findGroupKey = { - 'should return a valid group key':function(test) { - var keyByName = project.findPBXGroupKey({ name: 'Classes'}); - var keyByPath = project.findPBXGroupKey({ path: 'icons'}); - var keyByPathName = project.findPBXGroupKey({ path: '"HelloCordova/Plugins"', name: 'Plugins'}); - var nonExistingKey = project.findPBXGroupKey({ name: 'Foo'}); + 'should return a valid group key': function (test) { + var keyByName = project.findPBXGroupKey({ name: 'Classes' }); + var keyByPath = project.findPBXGroupKey({ path: 'icons' }); + var keyByPathName = project.findPBXGroupKey({ path: '"HelloCordova/Plugins"', name: 'Plugins' }); + var nonExistingKey = project.findPBXGroupKey({ name: 'Foo' }); test.ok(keyByName === '080E96DDFE201D6D7F000001'); test.ok(keyByPath === '308D052D1370CCF300D202BF'); @@ -132,12 +132,12 @@ exports.findGroupKey = { test.done(); } -} +}; exports.addGroupToGroup = { - 'should create a new test group then add group to Classes group': function(test) { + 'should create a new test group then add group to Classes group': function (test) { var testKey = project.pbxCreateGroup('Test', 'Test'); - var classesKey = project.findPBXGroupKey({name: 'Classes'}); + var classesKey = project.findPBXGroupKey({ name: 'Classes' }); project.addToPbxGroup(testKey, classesKey); var classesGroup = project.getPBXGroupByKey(classesKey); @@ -153,10 +153,10 @@ exports.addGroupToGroup = { test.done(); } -} +}; exports.predefinedPbxGroups = { - setUp: function(callback) { + setUp: function (callback) { project = new pbx('test/parser/projects/empty-groups.pbxproj').parseSync(); this.file = new pbxFile('some-file.m'); @@ -166,14 +166,14 @@ exports.predefinedPbxGroups = { callback(); }, - 'should add a file to "Plugins" group': function(test) { + 'should add a file to "Plugins" group': function (test) { project.addToPluginsPbxGroup(this.file); var foundInGroup = findChildInGroup(project.pbxGroupByName('Plugins'), this.file.fileRef); test.ok(foundInGroup); test.done(); }, - 'should remove a file from "Plugins" group': function(test) { + 'should remove a file from "Plugins" group': function (test) { project.addToPluginsPbxGroup(this.file); project.removeFromPluginsPbxGroup(this.file); @@ -182,7 +182,7 @@ exports.predefinedPbxGroups = { test.done(); }, - 'should add a file to "Resources" group': function(test) { + 'should add a file to "Resources" group': function (test) { project.addToResourcesPbxGroup(this.file); var foundInGroup = findChildInGroup(project.pbxGroupByName('Resources'), this.file.fileRef); @@ -190,7 +190,7 @@ exports.predefinedPbxGroups = { test.done(); }, - 'should remove a file from "Resources" group': function(test) { + 'should remove a file from "Resources" group': function (test) { project.addToResourcesPbxGroup(this.file); project.removeFromResourcesPbxGroup(this.file); @@ -199,7 +199,7 @@ exports.predefinedPbxGroups = { test.done(); }, - 'should add a file to "Frameworks" group': function(test) { + 'should add a file to "Frameworks" group': function (test) { project.addToFrameworksPbxGroup(this.file); var foundInGroup = findChildInGroup(project.pbxGroupByName('Frameworks'), this.file.fileRef); @@ -207,7 +207,7 @@ exports.predefinedPbxGroups = { test.done(); }, - 'should remove a file from "Frameworks" group': function(test) { + 'should remove a file from "Frameworks" group': function (test) { project.addToFrameworksPbxGroup(this.file); project.removeFromFrameworksPbxGroup(this.file); @@ -216,7 +216,7 @@ exports.predefinedPbxGroups = { test.done(); }, - 'should add a file to "Products" group': function(test) { + 'should add a file to "Products" group': function (test) { project.addToProductsPbxGroup(this.file); var foundInGroup = findChildInGroup(project.pbxGroupByName('Products'), this.file.fileRef); @@ -224,7 +224,7 @@ exports.predefinedPbxGroups = { test.done(); }, - 'should remove a file from "Products" group': function(test) { + 'should remove a file from "Products" group': function (test) { project.addToProductsPbxGroup(this.file); project.removeFromProductsPbxGroup(this.file); @@ -235,11 +235,11 @@ exports.predefinedPbxGroups = { }; exports.addSourceFileToGroup = { - 'should create group + add source file' : function(test) { + 'should create group + add source file': function (test) { var testKey = project.pbxCreateGroup('Test', 'Test'); var file = project.addSourceFile('Notifications.m', {}, testKey); - var foundInGroup = findChildInGroup(project.getPBXGroupByKey(testKey),file.fileRef ); + var foundInGroup = findChildInGroup(project.getPBXGroupByKey(testKey), file.fileRef); test.ok(foundInGroup); var foundInBuildFileSection = findByFileRef(project.pbxBuildFileSection(), file.fileRef); @@ -250,14 +250,14 @@ exports.addSourceFileToGroup = { test.done(); } -} +}; exports.removeSourceFileFromGroup = { - 'should create group + add source file then remove source file' : function(test) { + 'should create group + add source file then remove source file': function (test) { var testKey = project.pbxCreateGroup('Test', 'Test'); var file = project.addSourceFile('Notifications.m', {}, testKey); - var foundInGroup = findChildInGroup(project.getPBXGroupByKey(testKey),file.fileRef ); + var foundInGroup = findChildInGroup(project.getPBXGroupByKey(testKey), file.fileRef); test.ok(foundInGroup); var foundInBuildFileSection = findByFileRef(project.pbxBuildFileSection(), file.fileRef); @@ -268,106 +268,105 @@ exports.removeSourceFileFromGroup = { project.removeSourceFile('Notifications.m', {}, testKey); - var foundInGroup = findChildInGroup(project.getPBXGroupByKey(testKey),file.fileRef ); + foundInGroup = findChildInGroup(project.getPBXGroupByKey(testKey), file.fileRef); test.ok(!foundInGroup); - var foundInBuildFileSection = findByFileRef(project.pbxBuildFileSection(), file.fileRef); + foundInBuildFileSection = findByFileRef(project.pbxBuildFileSection(), file.fileRef); test.ok(!foundInBuildFileSection); - var foundInBuildPhase = findFileByUUID(project.pbxSourcesBuildPhaseObj(), file.uuid); + foundInBuildPhase = findFileByUUID(project.pbxSourcesBuildPhaseObj(), file.uuid); test.ok(!foundInBuildPhase); test.done(); } -} +}; exports.addHeaderFileToGroup = { - 'should create group + add header file' : function(test) { + 'should create group + add header file': function (test) { var testKey = project.pbxCreateGroup('Test', 'Test'); var file = project.addHeaderFile('Notifications.h', {}, testKey); - var foundInGroup = findChildInGroup(project.getPBXGroupByKey(testKey),file.fileRef ); + var foundInGroup = findChildInGroup(project.getPBXGroupByKey(testKey), file.fileRef); test.ok(foundInGroup); test.done(); } -} +}; exports.removeHeaderFileFromGroup = { - 'should create group + add source file then remove header file' : function(test) { + 'should create group + add source file then remove header file': function (test) { var testKey = project.pbxCreateGroup('Test', 'Test'); var file = project.addHeaderFile('Notifications.h', {}, testKey); - var foundInGroup = findChildInGroup(project.getPBXGroupByKey(testKey),file.fileRef ); + var foundInGroup = findChildInGroup(project.getPBXGroupByKey(testKey), file.fileRef); test.ok(foundInGroup); project.removeHeaderFile('Notifications.h', {}, testKey); - var foundInGroup = findChildInGroup(project.getPBXGroupByKey(testKey),file.fileRef ); + foundInGroup = findChildInGroup(project.getPBXGroupByKey(testKey), file.fileRef); test.ok(!foundInGroup); test.done(); } -} +}; exports.addResourceFileToGroup = { - 'should add resource file (PNG) to the splash group' : function(test) { - - var testKey = project.findPBXGroupKey({path:'splash'}); + 'should add resource file (PNG) to the splash group': function (test) { + var testKey = project.findPBXGroupKey({ path: 'splash' }); var file = project.addResourceFile('DefaultTest-667h.png', {}, testKey); - var foundInGroup = findChildInGroup(project.getPBXGroupByKey(testKey),file.fileRef ); + var foundInGroup = findChildInGroup(project.getPBXGroupByKey(testKey), file.fileRef); test.ok(foundInGroup); test.done(); } -} +}; exports.removeResourceFileFromGroup = { - 'should add resource file (PNG) then remove resource file from splash group' : function(test) { - var testKey = project.findPBXGroupKey({path:'splash'}); + 'should add resource file (PNG) then remove resource file from splash group': function (test) { + var testKey = project.findPBXGroupKey({ path: 'splash' }); var file = project.addResourceFile('DefaultTest-667h.png', {}, testKey); - var foundInGroup = findChildInGroup(project.getPBXGroupByKey(testKey),file.fileRef ); + var foundInGroup = findChildInGroup(project.getPBXGroupByKey(testKey), file.fileRef); test.ok(foundInGroup); project.removeResourceFile('DefaultTest-667h.png', {}, testKey); - var foundInGroup = findChildInGroup(project.getPBXGroupByKey(testKey),file.fileRef ); + foundInGroup = findChildInGroup(project.getPBXGroupByKey(testKey), file.fileRef); test.ok(!foundInGroup); test.done(); } -} +}; exports.retrieveBuildPropertyForBuild = { - 'should retrieve valid build property ':function(test) { + 'should retrieve valid build property ': function (test) { var releaseTargetedDeviceFamily = project.getBuildProperty('TARGETED_DEVICE_FAMILY', 'Release'); var debugTargetedDeviceFamily = project.getBuildProperty('TARGETED_DEVICE_FAMILY', 'Debug'); var nonExistingProperty = project.getBuildProperty('FOO', 'Debug'); var nonExistingBuild = project.getBuildProperty('TARGETED_DEVICE_FAMILY', 'Foo'); test.equal(releaseTargetedDeviceFamily, '"1,2"'); - test.equal(debugTargetedDeviceFamily,'"1"'); + test.equal(debugTargetedDeviceFamily, '"1"'); test.equal(nonExistingProperty, undefined); test.equal(nonExistingBuild, undefined); test.done(); } -} +}; exports.retrieveBuildConfigByName = { - 'should retrieve valid build config':function(test) { + 'should retrieve valid build config': function (test) { var releaseBuildConfig = project.getBuildConfigByName('Release'); - for (var property in releaseBuildConfig) { - var value = releaseBuildConfig[property]; - test.ok(value.name === 'Release'); + for (var releaseProperty in releaseBuildConfig) { + var releaseValue = releaseBuildConfig[releaseProperty]; + test.ok(releaseValue.name === 'Release'); } var debugBuildConfig = project.getBuildConfigByName('Debug'); - for (var property in debugBuildConfig) { - var value = debugBuildConfig[property]; - test.ok(value.name === 'Debug'); + for (var debugProperty in debugBuildConfig) { + var debugValue = debugBuildConfig[debugProperty]; + test.ok(debugValue.name === 'Debug'); } var nonExistingBuildConfig = project.getBuildConfigByName('Foo'); @@ -375,7 +374,7 @@ exports.retrieveBuildConfigByName = { test.done(); } -} +}; /* This proves the issue in 0.6.7 exports.validatePropReplaceException = { @@ -393,22 +392,22 @@ exports.validatePropReplaceException = { */ exports.validatePropReplaceFix = { - 'should create build configuration for VALID_ARCHS when none existed' : function(test) { + 'should create build configuration for VALID_ARCHS when none existed': function (test) { project.updateBuildProperty('VALID_ARCHS', '"armv7 armv7s"', 'Debug'); test.done(); } -} +}; exports.validateHasFile = { - 'should return true for has file MainViewController.m': function(test) { + 'should return true for has file MainViewController.m': function (test) { var result = project.hasFile('MainViewController.m'); - test.ok(result.path == "MainViewController.m"); + test.ok(result.path === 'MainViewController.m'); test.done(); } -} +}; exports.testWritingPBXProject = { - 'should successfully write to PBXProject TargetAttributes': function(test) { + 'should successfully write to PBXProject TargetAttributes': function (test) { var pbxProjectObj = project.getPBXObject('PBXProject'); var pbxProject; for (var property in pbxProjectObj) { @@ -418,8 +417,7 @@ exports.testWritingPBXProject = { } var target; - var projectTargets = pbxProject.targets; - for (var i = 0, j = pbxProject.targets.length; i < j; i++ ) { + for (var i = 0, j = pbxProject.targets.length; i < j; i++) { target = pbxProject.targets[i].value; } @@ -427,30 +425,30 @@ exports.testWritingPBXProject = { pbxProject.attributes.TargetAttributes[target] = { DevelopmentTeam: 'N6X4RJZZ5D', SystemCapabilities: { - "com.apple.BackgroundModes": { - enabled : 0 + 'com.apple.BackgroundModes': { + enabled: 0 }, - "com.apple.DataProtection" : { - enabled : 0 + 'com.apple.DataProtection': { + enabled: 0 }, - "com.apple.Keychain" : { + 'com.apple.Keychain': { enabled: 1 } } }; - var output = project.writeSync(); + project.writeSync(); test.done(); }, - 'should add target attribute to PBXProject TargetAttributes': function(test) { + 'should add target attribute to PBXProject TargetAttributes': function (test) { project.addTargetAttribute('ProvisioningStyle', 'Manual'); var output = project.writeSync(); test.equal(output.match(/ProvisioningStyle\s*=\s*Manual/g).length, 1); test.done(); }, - 'should change target attribute at PBXProject TargetAttributes': function(test) { + 'should change target attribute at PBXProject TargetAttributes': function (test) { project.addTargetAttribute('ProvisioningStyle', 'Manual'); var output = project.writeSync(); test.equal(output.match(/ProvisioningStyle\s*=\s*Manual/g).length, 1); @@ -462,7 +460,7 @@ exports.testWritingPBXProject = { test.done(); }, - 'should remove target attribute from PBXProject TargetAttributes': function(test) { + 'should remove target attribute from PBXProject TargetAttributes': function (test) { project.addTargetAttribute('ProvisioningStyle', 'Manual'); var output = project.writeSync(); test.equal(output.match(/ProvisioningStyle\s*=\s*Manual/g).length, 1); @@ -473,4 +471,4 @@ exports.testWritingPBXProject = { test.done(); } -} +}; diff --git a/test/knownRegions.js b/test/knownRegions.js index 08ce454..3f0c53e 100644 --- a/test/knownRegions.js +++ b/test/knownRegions.js @@ -15,79 +15,80 @@ under the License. */ -var fullProject = require('./fixtures/full-project') - fullProjectStr = JSON.stringify(fullProject), - pbx = require('../lib/pbxProject'), - project = new pbx('.'); +var fullProject = require('./fixtures/full-project'); -function cleanHash() { +var fullProjectStr = JSON.stringify(fullProject); +var pbx = require('../lib/pbxProject'); +var project = new pbx('.'); + +function cleanHash () { return JSON.parse(fullProjectStr); } exports.setUp = function (callback) { project.hash = cleanHash(); callback(); -} +}; exports.addKnownRegion = { - 'should add new region to existing knownRegions': function (test) { - var knownRegions = project.pbxProjectSection()[project.getFirstProject()['uuid']]['knownRegions']; - test.equal(knownRegions.indexOf('Spanish'), -1); - - project.addKnownRegion('Spanish') - knownRegions = project.pbxProjectSection()[project.getFirstProject()['uuid']]['knownRegions']; - test.notEqual(knownRegions.indexOf('Spanish'), -1); - test.done(); - }, - - 'should not add region if it already exists in knownRegions': function (test) { - var numberOfRegions = project.pbxProjectSection()[project.getFirstProject()['uuid']]['knownRegions'].length; - - project.addKnownRegion('German'); - var newNumberOfRegions = project.pbxProjectSection()[project.getFirstProject()['uuid']]['knownRegions'].length; - test.equal(numberOfRegions, newNumberOfRegions); - test.done(); - }, - - 'should create knownRegions array if it does not exist': function (test) { - delete project.pbxProjectSection()[project.getFirstProject()['uuid']]['knownRegions']; - test.ok(!project.pbxProjectSection()[project.getFirstProject()['uuid']]['knownRegions']); - - project.addKnownRegion('German') - test.ok(project.pbxProjectSection()[project.getFirstProject()['uuid']]['knownRegions']); - test.done(); - }, -} + 'should add new region to existing knownRegions': function (test) { + var knownRegions = project.pbxProjectSection()[project.getFirstProject().uuid].knownRegions; + test.equal(knownRegions.indexOf('Spanish'), -1); + + project.addKnownRegion('Spanish'); + knownRegions = project.pbxProjectSection()[project.getFirstProject().uuid].knownRegions; + test.notEqual(knownRegions.indexOf('Spanish'), -1); + test.done(); + }, + + 'should not add region if it already exists in knownRegions': function (test) { + var numberOfRegions = project.pbxProjectSection()[project.getFirstProject().uuid].knownRegions.length; + + project.addKnownRegion('German'); + var newNumberOfRegions = project.pbxProjectSection()[project.getFirstProject().uuid].knownRegions.length; + test.equal(numberOfRegions, newNumberOfRegions); + test.done(); + }, + + 'should create knownRegions array if it does not exist': function (test) { + delete project.pbxProjectSection()[project.getFirstProject().uuid].knownRegions; + test.ok(!project.pbxProjectSection()[project.getFirstProject().uuid].knownRegions); + + project.addKnownRegion('German'); + test.ok(project.pbxProjectSection()[project.getFirstProject().uuid].knownRegions); + test.done(); + } +}; exports.removeKnownRegion = { - 'should remove named region from knownRegions': function (test) { - var knownRegions = project.pbxProjectSection()[project.getFirstProject()['uuid']]['knownRegions']; - test.notEqual(knownRegions.indexOf('German'), -1); - - project.removeKnownRegion('German'); - knownRegions = project.pbxProjectSection()[project.getFirstProject()['uuid']]['knownRegions']; - test.equal(knownRegions.indexOf('German'), -1); - test.done(); - }, - - 'should do nothing if named region does not exist in knownRegions': function (test) { - var numberOfRegions = project.pbxProjectSection()[project.getFirstProject()['uuid']]['knownRegions'].length; - - project.removeKnownRegion('Korean'); - var newNumberOfRegions = project.pbxProjectSection()[project.getFirstProject()['uuid']]['knownRegions'].length; - test.equal(numberOfRegions, newNumberOfRegions); - test.done(); - }, -} + 'should remove named region from knownRegions': function (test) { + var knownRegions = project.pbxProjectSection()[project.getFirstProject().uuid].knownRegions; + test.notEqual(knownRegions.indexOf('German'), -1); + + project.removeKnownRegion('German'); + knownRegions = project.pbxProjectSection()[project.getFirstProject().uuid].knownRegions; + test.equal(knownRegions.indexOf('German'), -1); + test.done(); + }, + + 'should do nothing if named region does not exist in knownRegions': function (test) { + var numberOfRegions = project.pbxProjectSection()[project.getFirstProject().uuid].knownRegions.length; + + project.removeKnownRegion('Korean'); + var newNumberOfRegions = project.pbxProjectSection()[project.getFirstProject().uuid].knownRegions.length; + test.equal(numberOfRegions, newNumberOfRegions); + test.done(); + } +}; exports.hasKnownRegion = { - 'should return true if named region exists in knownRegions': function (test) { - test.ok(project.hasKnownRegion('German')); - test.done(); - }, - - 'should return false if named region does not exist in knownRegions': function (test) { - test.ok(!project.hasKnownRegion('Ducth')); - test.done(); - }, -} + 'should return true if named region exists in knownRegions': function (test) { + test.ok(project.hasKnownRegion('German')); + test.done(); + }, + + 'should return false if named region does not exist in knownRegions': function (test) { + test.ok(!project.hasKnownRegion('Ducth')); + test.done(); + } +}; diff --git a/test/multipleTargets.js b/test/multipleTargets.js index dbb945f..f08c692 100644 --- a/test/multipleTargets.js +++ b/test/multipleTargets.js @@ -15,156 +15,146 @@ under the License. */ -var fullProject = require('./fixtures/multiple-targets') - fullProjectStr = JSON.stringify(fullProject), - pbx = require('../lib/pbxProject'), - pbxFile = require('../lib/pbxFile'), - proj = new pbx('.'); +var fullProject = require('./fixtures/multiple-targets'); -function cleanHash() { +var fullProjectStr = JSON.stringify(fullProject); +var pbx = require('../lib/pbxProject'); +var pbxFile = require('../lib/pbxFile'); +var proj = new pbx('.'); + +function cleanHash () { return JSON.parse(fullProjectStr); } exports.setUp = function (callback) { proj.hash = cleanHash(); callback(); -} +}; exports.addFilesToTarget = { 'should add the file to a proper target': function (test) { + var target = '1D6058900D05DD3D006BFB54'; + var filename = 'file.m'; - var target = "1D6058900D05DD3D006BFB54"; - var filename = "file.m"; - - var opt = { target : target }; - var newFile = proj.addSourceFile(filename,opt); + var opt = { target: target }; + var newFile = proj.addSourceFile(filename, opt); test.equal(newFile.constructor, pbxFile); var sources = proj.pbxSourcesBuildPhaseObj(target); - test.equal(sources.files[5].comment, filename+" in Sources"); + test.equal(sources.files[5].comment, filename + ' in Sources'); test.done(); }, 'should remove the file from the proper target': function (test) { + var target = '1D6058900D05DD3D006BFB54'; + var filename = 'file.m'; - var target = "1D6058900D05DD3D006BFB54"; - var filename = "file.m"; - - var opt = { target : target }; - var newFile = proj.addSourceFile(filename,opt); + var opt = { target: target }; + var newFile = proj.addSourceFile(filename, opt); test.equal(newFile.constructor, pbxFile); var sources = proj.pbxSourcesBuildPhaseObj(target); - test.equal(sources.files[5].comment, filename+" in Sources"); + test.equal(sources.files[5].comment, filename + ' in Sources'); var l = sources.files.length; - proj.removeSourceFile(filename,opt); - var sources = proj.pbxSourcesBuildPhaseObj(target); - test.equal(sources.files.length,l-1); + proj.removeSourceFile(filename, opt); + sources = proj.pbxSourcesBuildPhaseObj(target); + test.equal(sources.files.length, l - 1); test.done(); }, 'should fail when specifying an invalid target': function (test) { + var target = 'XXXXX'; + var filename = 'file.m'; - var target = "XXXXX"; - var filename = "file.m"; - - var opt = { target : target }; - test.throws(function(){ - proj.addSourceFile(filename,opt); + var opt = { target: target }; + test.throws(function () { + proj.addSourceFile(filename, opt); }); - test.done(); }, - 'should add the library to a proper target': function (test) { + 'should add the library to a proper target': function (test) { + var target = '1D6058900D05DD3D006BFB54'; + var filename = 'library.lib'; - var target = "1D6058900D05DD3D006BFB54"; - var filename = "library.lib"; - - var opt = { target : target }; - var newFile = proj.addStaticLibrary(filename,opt); + var opt = { target: target }; + var newFile = proj.addStaticLibrary(filename, opt); test.equal(newFile.constructor, pbxFile); var libraries = proj.pbxFrameworksBuildPhaseObj(target); - test.equal(libraries.files[4].comment, filename+" in Resources"); + test.equal(libraries.files[4].comment, filename + ' in Resources'); test.done(); }, 'should remove the library to a proper target': function (test) { + var target = '1D6058900D05DD3D006BFB54'; + var filename = 'library.lib'; - var target = "1D6058900D05DD3D006BFB54"; - var filename = "library.lib"; - - var opt = { target : target }; - var newFile = proj.addStaticLibrary(filename,opt); + var opt = { target: target }; + var newFile = proj.addStaticLibrary(filename, opt); test.equal(newFile.constructor, pbxFile); var libraries = proj.pbxFrameworksBuildPhaseObj(target); - test.equal(libraries.files[4].comment, filename+" in Resources"); + test.equal(libraries.files[4].comment, filename + ' in Resources'); var l = libraries.files.length; - proj.removeFramework(filename,opt); - var libraries = proj.pbxFrameworksBuildPhaseObj(target); - test.equal(libraries.files.length,l-1); + proj.removeFramework(filename, opt); + libraries = proj.pbxFrameworksBuildPhaseObj(target); + test.equal(libraries.files.length, l - 1); test.done(); - }, - 'should add the framework to a proper target': function (test) { + 'should add the framework to a proper target': function (test) { + var target = '1D6058900D05DD3D006BFB54'; + var filename = 'delta.framework'; - var target = "1D6058900D05DD3D006BFB54"; - var filename = "delta.framework"; - - var opt = { target : target }; - var newFile = proj.addFramework(filename,opt); + var opt = { target: target }; + var newFile = proj.addFramework(filename, opt); test.equal(newFile.constructor, pbxFile); var frameworks = proj.pbxFrameworksBuildPhaseObj(target); - test.equal(frameworks.files[4].comment, filename+" in Frameworks"); + test.equal(frameworks.files[4].comment, filename + ' in Frameworks'); test.done(); }, 'should add a ressource fileto a proper target': function (test) { + var target = '1D6058900D05DD3D006BFB54'; + var filename = 'delta.png'; - var target = "1D6058900D05DD3D006BFB54"; - var filename = "delta.png"; - - var opt = { target : target }; - var newFile = proj.addResourceFile(filename,opt); + var opt = { target: target }; + var newFile = proj.addResourceFile(filename, opt); test.equal(newFile.constructor, pbxFile); var resources = proj.pbxResourcesBuildPhaseObj(target); - test.equal(resources.files[26].comment, filename+" in Resources"); + test.equal(resources.files[26].comment, filename + ' in Resources'); test.done(); }, - 'should remove a ressource file from a proper target': function (test) { + 'should remove a ressource file from a proper target': function (test) { + var target = '1D6058900D05DD3D006BFB54'; + var filename = 'delta.png'; - var target = "1D6058900D05DD3D006BFB54"; - var filename = "delta.png"; - - var opt = { target : target }; - var newFile = proj.addResourceFile(filename,opt); + var opt = { target: target }; + var newFile = proj.addResourceFile(filename, opt); test.equal(newFile.constructor, pbxFile); var resources = proj.pbxResourcesBuildPhaseObj(target); - test.equal(resources.files[26].comment, filename+" in Resources"); + test.equal(resources.files[26].comment, filename + ' in Resources'); var l = resources.files.length; - proj.removeResourceFile(filename,opt); - var resources = proj.pbxResourcesBuildPhaseObj(target); - test.equal(resources.files.length,l-1); + proj.removeResourceFile(filename, opt); + resources = proj.pbxResourcesBuildPhaseObj(target); + test.equal(resources.files.length, l - 1); test.done(); - }, -} - + } +}; diff --git a/test/parser/build-config.js b/test/parser/build-config.js index 465c352..6bc2d3e 100644 --- a/test/parser/build-config.js +++ b/test/parser/build-config.js @@ -15,33 +15,33 @@ under the License. */ -var PEG = require('pegjs'), - fs = require('fs'), - pbx = fs.readFileSync('test/parser/projects/build-config.pbxproj', 'utf-8'), - grammar = fs.readFileSync('lib/parser/pbxproj.pegjs', 'utf-8'), - parser = PEG.generate(grammar), - rawProj = parser.parse(pbx), - util = require('util'), - project = rawProj.project; +var PEG = require('pegjs'); + +var fs = require('fs'); +var pbx = fs.readFileSync('test/parser/projects/build-config.pbxproj', 'utf-8'); +var grammar = fs.readFileSync('lib/parser/pbxproj.pegjs', 'utf-8'); +var parser = PEG.generate(grammar); +var rawProj = parser.parse(pbx); +var project = rawProj.project; exports['should parse the build config section'] = function (test) { // if it gets this far it's worked test.done(); -} +}; exports['should read a decimal value correctly'] = function (test) { - var xcbConfig = project.objects['XCBuildConfiguration'], - debugSettings = xcbConfig['1D6058950D05DD3E006BFB54'].buildSettings; + var xcbConfig = project.objects.XCBuildConfiguration; + var debugSettings = xcbConfig['1D6058950D05DD3E006BFB54'].buildSettings; - test.strictEqual(debugSettings['IPHONEOS_DEPLOYMENT_TARGET'], '3.0'); + test.strictEqual(debugSettings.IPHONEOS_DEPLOYMENT_TARGET, '3.0'); test.done(); -} +}; exports['should read an escaped value correctly'] = function (test) { - var xcbConfig = project.objects['XCBuildConfiguration'], - debugSettings = xcbConfig['C01FCF4F08A954540054247B'].buildSettings, - expt = '"\\"$(PHONEGAPLIB)/Classes/JSON\\" \\"$(PHONEGAPLIB)/Classes\\""'; + var xcbConfig = project.objects.XCBuildConfiguration; + var debugSettings = xcbConfig.C01FCF4F08A954540054247B.buildSettings; + var expt = '"\\"$(PHONEGAPLIB)/Classes/JSON\\" \\"$(PHONEGAPLIB)/Classes\\""'; - test.strictEqual(debugSettings['USER_HEADER_SEARCH_PATHS'], expt); + test.strictEqual(debugSettings.USER_HEADER_SEARCH_PATHS, expt); test.done(); -} +}; diff --git a/test/parser/comments.js b/test/parser/comments.js index 7be4c38..7aed1ab 100644 --- a/test/parser/comments.js +++ b/test/parser/comments.js @@ -15,15 +15,16 @@ under the License. */ -var PEG = require('pegjs'), - fs = require('fs'), - pbx = fs.readFileSync('test/parser/projects/comments.pbxproj', 'utf-8'), - grammar = fs.readFileSync('lib/parser/pbxproj.pegjs', 'utf-8'), - parser = PEG.generate(grammar); +var PEG = require('pegjs'); + +var fs = require('fs'); +var pbx = fs.readFileSync('test/parser/projects/comments.pbxproj', 'utf-8'); +var grammar = fs.readFileSync('lib/parser/pbxproj.pegjs', 'utf-8'); +var parser = PEG.generate(grammar); // Cordova 1.8 has the Apache headers as comments in the pbxproj file // I DON'T KNOW WHY exports['should ignore comments outside the main object'] = function (test) { parser.parse(pbx); test.done(); -} +}; diff --git a/test/parser/dotsInNames.js b/test/parser/dotsInNames.js index 4121bba..b085cb9 100644 --- a/test/parser/dotsInNames.js +++ b/test/parser/dotsInNames.js @@ -15,18 +15,19 @@ under the License. */ -var PEG = require('pegjs'), - fs = require('fs'), - pbx = fs.readFileSync('test/parser/projects/dots-in-names.pbxproj', 'utf-8'), - grammar = fs.readFileSync('lib/parser/pbxproj.pegjs', 'utf-8'), - parser = PEG.generate(grammar), - rawProj = parser.parse(pbx), - project = rawProj.project; +var PEG = require('pegjs'); + +var fs = require('fs'); +var pbx = fs.readFileSync('test/parser/projects/dots-in-names.pbxproj', 'utf-8'); +var grammar = fs.readFileSync('lib/parser/pbxproj.pegjs', 'utf-8'); +var parser = PEG.generate(grammar); +var rawProj = parser.parse(pbx); +var project = rawProj.project; exports['should parse com.apple.BackgroundModes'] = function (test) { - var targets = project.attributes.TargetAttributes['1D6058900D05DD3D006BFB54'], - backgroundModes = targets.SystemCapabilities['com.apple.BackgroundModes']; + var targets = project.attributes.TargetAttributes['1D6058900D05DD3D006BFB54']; + var backgroundModes = targets.SystemCapabilities['com.apple.BackgroundModes']; - test.deepEqual(backgroundModes, {enabled: 1}); - test.done() -} + test.deepEqual(backgroundModes, { enabled: 1 }); + test.done(); +}; diff --git a/test/parser/file-references.js b/test/parser/file-references.js index 4275378..36624bb 100644 --- a/test/parser/file-references.js +++ b/test/parser/file-references.js @@ -15,15 +15,16 @@ under the License. */ -var PEG = require('pegjs'), - fs = require('fs'), - pbx = fs.readFileSync('test/parser/projects/file-references.pbxproj', 'utf-8'), - grammar = fs.readFileSync('lib/parser/pbxproj.pegjs', 'utf-8'), - parser = PEG.generate(grammar), - rawProj = parser.parse(pbx), - project = rawProj.project; +var PEG = require('pegjs'); + +var fs = require('fs'); +var pbx = fs.readFileSync('test/parser/projects/file-references.pbxproj', 'utf-8'); +var grammar = fs.readFileSync('lib/parser/pbxproj.pegjs', 'utf-8'); +var parser = PEG.generate(grammar); +var rawProj = parser.parse(pbx); +var project = rawProj.project; exports['should have a PBXFileReference section'] = function (test) { - test.ok(project.objects['PBXFileReference']); + test.ok(project.objects.PBXFileReference); test.done(); -} +}; diff --git a/test/parser/hash.js b/test/parser/hash.js index 6ec8106..a67c4d1 100644 --- a/test/parser/hash.js +++ b/test/parser/hash.js @@ -15,38 +15,39 @@ under the License. */ -var PEG = require('pegjs'), - fs = require('fs'), - pbx = fs.readFileSync('test/parser/projects/hash.pbxproj', 'utf-8'), - grammar = fs.readFileSync('lib/parser/pbxproj.pegjs', 'utf-8'), - parser = PEG.generate(grammar), - rawProj = parser.parse(pbx), - project = rawProj.project; +var PEG = require('pegjs'); + +var fs = require('fs'); +var pbx = fs.readFileSync('test/parser/projects/hash.pbxproj', 'utf-8'); +var grammar = fs.readFileSync('lib/parser/pbxproj.pegjs', 'utf-8'); +var parser = PEG.generate(grammar); +var rawProj = parser.parse(pbx); +var project = rawProj.project; exports['should have the top-line comment in place'] = function (test) { test.equals(rawProj.headComment, '!$*UTF8*$!'); - test.done() -} + test.done(); +}; exports['should parse a numeric attribute'] = function (test) { test.strictEqual(project.archiveVersion, 1); test.strictEqual(project.objectVersion, 45); - test.done() -} + test.done(); +}; exports['should parse an empty object'] = function (test) { var empty = project.classes; test.equal(Object.keys(empty).length, 0); - test.done() -} + test.done(); +}; exports['should split out properties and comments'] = function (test) { test.equal(project.rootObject, '29B97313FDCFA39411CA2CEA'); - test.equal(project['rootObject_comment'], 'Project object'); + test.equal(project.rootObject_comment, 'Project object'); test.done(); -} +}; exports['should parse non-commented hash things'] = function (test) { test.equal(project.nonObject, '29B97313FDCFA39411CA2CEF'); test.done(); -} +}; diff --git a/test/parser/header-search.js b/test/parser/header-search.js index 226c301..2e83ba9 100644 --- a/test/parser/header-search.js +++ b/test/parser/header-search.js @@ -15,19 +15,20 @@ under the License. */ -var PEG = require('pegjs'), - fs = require('fs'), - pbx = fs.readFileSync('test/parser/projects/header-search.pbxproj', 'utf-8'), - grammar = fs.readFileSync('lib/parser/pbxproj.pegjs', 'utf-8'), - parser = PEG.generate(grammar), - rawProj = parser.parse(pbx), - project = rawProj.project; +var PEG = require('pegjs'); + +var fs = require('fs'); +var pbx = fs.readFileSync('test/parser/projects/header-search.pbxproj', 'utf-8'); +var grammar = fs.readFileSync('lib/parser/pbxproj.pegjs', 'utf-8'); +var parser = PEG.generate(grammar); +var rawProj = parser.parse(pbx); +var project = rawProj.project; exports['should read a decimal value correctly'] = function (test) { - var debug = project.objects['XCBuildConfiguration']['C01FCF4F08A954540054247B'], - hsPaths = debug.buildSettings['HEADER_SEARCH_PATHS'], - expected = '"\\"$(TARGET_BUILD_DIR)/usr/local/lib/include\\""'; + var debug = project.objects.XCBuildConfiguration.C01FCF4F08A954540054247B; + var hsPaths = debug.buildSettings.HEADER_SEARCH_PATHS; + var expected = '"\\"$(TARGET_BUILD_DIR)/usr/local/lib/include\\""'; test.equal(hsPaths[0], expected); test.done(); -} +}; diff --git a/test/parser/section-entries.js b/test/parser/section-entries.js index 56d578c..dfa2b44 100644 --- a/test/parser/section-entries.js +++ b/test/parser/section-entries.js @@ -15,28 +15,29 @@ under the License. */ -var PEG = require('pegjs'), - fs = require('fs'), - pbx = fs.readFileSync('test/parser/projects/section-entries.pbxproj', 'utf-8'), - grammar = fs.readFileSync('lib/parser/pbxproj.pegjs', 'utf-8'), - parser = PEG.generate(grammar), - rawProj = parser.parse(pbx), - project = rawProj.project; +var PEG = require('pegjs'); + +var fs = require('fs'); +var pbx = fs.readFileSync('test/parser/projects/section-entries.pbxproj', 'utf-8'); +var grammar = fs.readFileSync('lib/parser/pbxproj.pegjs', 'utf-8'); +var parser = PEG.generate(grammar); +var rawProj = parser.parse(pbx); +var project = rawProj.project; exports['should have a PBXVariantGroup section'] = function (test) { - test.ok(project.objects['PBXVariantGroup']); + test.ok(project.objects.PBXVariantGroup); test.done(); -} +}; exports['should have two children for PBXVariantGroup'] = function (test) { - test.ok(project.objects['PBXVariantGroup']['1F766FDF13BBADB100FB74C0']); - test.ok(project.objects['PBXVariantGroup']['1F766FDC13BBADB100FB74C0']); + test.ok(project.objects.PBXVariantGroup['1F766FDF13BBADB100FB74C0']); + test.ok(project.objects.PBXVariantGroup['1F766FDC13BBADB100FB74C0']); test.done(); -} +}; exports['should store quote-surround values correctly'] = function (test) { - var localizable = project.objects['PBXVariantGroup']['1F766FDF13BBADB100FB74C0']; + var localizable = project.objects.PBXVariantGroup['1F766FDF13BBADB100FB74C0']; test.equal(localizable.sourceTree, '""'); test.done(); -} +}; diff --git a/test/parser/section-split.js b/test/parser/section-split.js index cd17247..b411f84 100644 --- a/test/parser/section-split.js +++ b/test/parser/section-split.js @@ -15,38 +15,38 @@ under the License. */ -var PEG = require('pegjs'), - fs = require('fs'), - pbx = fs.readFileSync('test/parser/projects/section-split.pbxproj', 'utf-8'), - grammar = fs.readFileSync('lib/parser/pbxproj.pegjs', 'utf-8'), - parser = PEG.generate(grammar), - rawProj = parser.parse(pbx), - project = rawProj.project; +var PEG = require('pegjs'); + +var fs = require('fs'); +var pbx = fs.readFileSync('test/parser/projects/section-split.pbxproj', 'utf-8'); +var grammar = fs.readFileSync('lib/parser/pbxproj.pegjs', 'utf-8'); +var parser = PEG.generate(grammar); +var rawProj = parser.parse(pbx); +var project = rawProj.project; exports['should have a PBXTargetDependency section'] = function (test) { - test.ok(project.objects['PBXTargetDependency']); - test.done(); -} + test.ok(project.objects.PBXTargetDependency); + test.done(); +}; exports['should have the right child of PBXTargetDependency section'] = function (test) { - test.ok(project.objects['PBXTargetDependency']['301BF551109A68C00062928A']); - test.done(); -} + test.ok(project.objects.PBXTargetDependency['301BF551109A68C00062928A']); + test.done(); +}; exports['should have the right properties on the dependency'] = function (test) { - var dependency = project.objects['PBXTargetDependency']['301BF551109A68C00062928A']; + var dependency = project.objects.PBXTargetDependency['301BF551109A68C00062928A']; - test.equal(dependency.isa, 'PBXTargetDependency') - test.equal(dependency.name, 'PhoneGapLib') - test.equal(dependency.targetProxy, '301BF550109A68C00062928A') - test.equal(dependency['targetProxy_comment'], 'PBXContainerItemProxy') + test.equal(dependency.isa, 'PBXTargetDependency'); + test.equal(dependency.name, 'PhoneGapLib'); + test.equal(dependency.targetProxy, '301BF550109A68C00062928A'); + test.equal(dependency.targetProxy_comment, 'PBXContainerItemProxy'); - test.done(); -} + test.done(); +}; exports['should merge two PBXTargetDependency sections'] = function (test) { - test.ok(project.objects['PBXTargetDependency']['301BF551109A68C00062928A']); - test.ok(project.objects['PBXTargetDependency']['45FDD1944D304A9F96DF3AC6']); - test.done(); -} - + test.ok(project.objects.PBXTargetDependency['301BF551109A68C00062928A']); + test.ok(project.objects.PBXTargetDependency['45FDD1944D304A9F96DF3AC6']); + test.done(); +}; diff --git a/test/parser/section.js b/test/parser/section.js index 65e65fa..b3724dd 100644 --- a/test/parser/section.js +++ b/test/parser/section.js @@ -15,31 +15,32 @@ under the License. */ -var PEG = require('pegjs'), - fs = require('fs'), - pbx = fs.readFileSync('test/parser/projects/section.pbxproj', 'utf-8'), - grammar = fs.readFileSync('lib/parser/pbxproj.pegjs', 'utf-8'), - parser = PEG.generate(grammar), - rawProj = parser.parse(pbx), - project = rawProj.project; +var PEG = require('pegjs'); + +var fs = require('fs'); +var pbx = fs.readFileSync('test/parser/projects/section.pbxproj', 'utf-8'); +var grammar = fs.readFileSync('lib/parser/pbxproj.pegjs', 'utf-8'); +var parser = PEG.generate(grammar); +var rawProj = parser.parse(pbx); +var project = rawProj.project; exports['should have a PBXTargetDependency section'] = function (test) { - test.ok(project.objects['PBXTargetDependency']); + test.ok(project.objects.PBXTargetDependency); test.done(); -} +}; exports['should have the right child of PBXTargetDependency section'] = function (test) { - test.ok(project.objects['PBXTargetDependency']['301BF551109A68C00062928A']); + test.ok(project.objects.PBXTargetDependency['301BF551109A68C00062928A']); test.done(); -} +}; exports['should have the right properties on the dependency'] = function (test) { - var dependency = project.objects['PBXTargetDependency']['301BF551109A68C00062928A']; + var dependency = project.objects.PBXTargetDependency['301BF551109A68C00062928A']; - test.equal(dependency.isa, 'PBXTargetDependency') - test.equal(dependency.name, 'PhoneGapLib') - test.equal(dependency.targetProxy, '301BF550109A68C00062928A') - test.equal(dependency['targetProxy_comment'], 'PBXContainerItemProxy') + test.equal(dependency.isa, 'PBXTargetDependency'); + test.equal(dependency.name, 'PhoneGapLib'); + test.equal(dependency.targetProxy, '301BF550109A68C00062928A'); + test.equal(dependency.targetProxy_comment, 'PBXContainerItemProxy'); test.done(); -} +}; diff --git a/test/parser/two-sections.js b/test/parser/two-sections.js index 3f8e1f4..a3a84dd 100644 --- a/test/parser/two-sections.js +++ b/test/parser/two-sections.js @@ -15,21 +15,22 @@ under the License. */ -var PEG = require('pegjs'), - fs = require('fs'), - pbx = fs.readFileSync('test/parser/projects/two-sections.pbxproj', 'utf-8'), - grammar = fs.readFileSync('lib/parser/pbxproj.pegjs', 'utf-8'), - parser = PEG.generate(grammar), - rawProj = parser.parse(pbx), - project = rawProj.project; +var PEG = require('pegjs'); + +var fs = require('fs'); +var pbx = fs.readFileSync('test/parser/projects/two-sections.pbxproj', 'utf-8'); +var grammar = fs.readFileSync('lib/parser/pbxproj.pegjs', 'utf-8'); +var parser = PEG.generate(grammar); +var rawProj = parser.parse(pbx); +var project = rawProj.project; exports['should parse a project with two sections'] = function (test) { // if it gets this far it's worked test.done(); -} +}; exports['should have both sections on the project object'] = function (test) { - test.ok(project.objects['PBXTargetDependency']); - test.ok(project.objects['PBXSourcesBuildPhase']); + test.ok(project.objects.PBXTargetDependency); + test.ok(project.objects.PBXSourcesBuildPhase); test.done(); -} +}; diff --git a/test/parser/with_array.js b/test/parser/with_array.js index b63ef50..cd5cb7d 100644 --- a/test/parser/with_array.js +++ b/test/parser/with_array.js @@ -15,42 +15,43 @@ under the License. */ -var PEG = require('pegjs'), - fs = require('fs'), - pbx = fs.readFileSync('test/parser/projects/with_array.pbxproj', 'utf-8'), - grammar = fs.readFileSync('lib/parser/pbxproj.pegjs', 'utf-8'), - parser = PEG.generate(grammar), - rawProj = parser.parse(pbx), - project = rawProj.project; +var PEG = require('pegjs'); + +var fs = require('fs'); +var pbx = fs.readFileSync('test/parser/projects/with_array.pbxproj', 'utf-8'); +var grammar = fs.readFileSync('lib/parser/pbxproj.pegjs', 'utf-8'); +var parser = PEG.generate(grammar); +var rawProj = parser.parse(pbx); +var project = rawProj.project; exports['should parse arrays with commented entries'] = function (test) { test.ok(project.files instanceof Array); test.equal(project.files.length, 2); - test.done() -} + test.done(); +}; exports['should parse arrays with uncommented entries'] = function (test) { test.ok(project.ARCHS instanceof Array); test.equal(project.ARCHS.length, 2); - test.done() -} + test.done(); +}; exports['should parse empty arrays'] = function (test) { test.ok(project.empties instanceof Array); test.equal(project.empties.length, 0); test.done(); -} +}; exports['should be correct ordered'] = function (test) { var archs = project.ARCHS; test.equal(archs[0], 'armv6'); test.equal(archs[1], 'armv7'); test.done(); -} +}; exports['should parse values and comments correctly'] = function (test) { - var appDelegate = project.files[1] - test.equal(appDelegate.value, '1D3623260D0F684500981E51') - test.equal(appDelegate.comment, 'AppDelegate.m in Sources') - test.done() -} + var appDelegate = project.files[1]; + test.equal(appDelegate.value, '1D3623260D0F684500981E51'); + test.equal(appDelegate.comment, 'AppDelegate.m in Sources'); + test.done(); +}; diff --git a/test/pbxFile.js b/test/pbxFile.js index 4f0d1a2..8124f41 100644 --- a/test/pbxFile.js +++ b/test/pbxFile.js @@ -17,7 +17,7 @@ var pbxFile = require('../lib/pbxFile'); -exports['lastKnownFileType'] = { +exports.lastKnownFileType = { 'should detect that a .m path means sourcecode.c.objc': function (test) { var sourceFile = new pbxFile('Plugins/ChildBrowser.m'); @@ -83,7 +83,7 @@ exports['lastKnownFileType'] = { 'should allow lastKnownFileType to be overridden': function (test) { var sourceFile = new pbxFile('Plugins/ChildBrowser.m', - { lastKnownFileType: 'somestupidtype' }); + { lastKnownFileType: 'somestupidtype' }); test.equal('somestupidtype', sourceFile.lastKnownFileType); test.done(); @@ -95,9 +95,9 @@ exports['lastKnownFileType'] = { test.equal('unknown', sourceFile.lastKnownFileType); test.done(); } -} +}; -exports['group'] = { +exports.group = { 'should be Sources for source files': function (test) { var sourceFile = new pbxFile('Plugins/ChildBrowser.m'); @@ -129,8 +129,8 @@ exports['group'] = { test.done(); }, 'should be Resources for all other files': function (test) { - var headerFile = new pbxFile('Plugins/ChildBrowser.h'), - xibFile = new pbxFile('Plugins/ChildBrowser.xib'); + var headerFile = new pbxFile('Plugins/ChildBrowser.h'); + var xibFile = new pbxFile('Plugins/ChildBrowser.xib'); test.equal('Resources', headerFile.group); test.equal('Resources', xibFile.group); @@ -142,18 +142,18 @@ exports['group'] = { test.equal('Frameworks', archive.group); test.done(); } -} +}; -exports['basename'] = { +exports.basename = { 'should be as expected': function (test) { var sourceFile = new pbxFile('Plugins/ChildBrowser.m'); test.equal('ChildBrowser.m', sourceFile.basename); test.done(); } -} +}; -exports['sourceTree'] = { +exports.sourceTree = { 'should be SDKROOT for dylibs': function (test) { var sourceFile = new pbxFile('libsqlite3.dylib'); @@ -184,7 +184,7 @@ exports['sourceTree'] = { 'should be overridable either way': function (test) { var sourceFile = new pbxFile('Plugins/ChildBrowser.m', - { sourceTree: 'SOMETHING'}); + { sourceTree: 'SOMETHING' }); test.equal('SOMETHING', sourceFile.sourceTree); test.done(); @@ -196,9 +196,9 @@ exports['sourceTree'] = { test.equal('""', archive.sourceTree); test.done(); } -} +}; -exports['path'] = { +exports.path = { 'should be "usr/lib" for dylibs (relative to SDKROOT)': function (test) { var sourceFile = new pbxFile('libsqlite3.dylib'); @@ -220,21 +220,20 @@ exports['path'] = { test.done(); }, - 'should default to the first argument otherwise': function (test) { var sourceFile = new pbxFile('Plugins/ChildBrowser.m'); test.equal('Plugins/ChildBrowser.m', sourceFile.path); test.done(); } -} +}; -exports['settings'] = { - 'should not be defined by default': function (test) { - var sourceFile = new pbxFile('social.framework'); +exports.settings = { + 'should not be defined by default': function (test) { + var sourceFile = new pbxFile('social.framework'); - test.equal(undefined, sourceFile.settings); - test.done(); + test.equal(undefined, sourceFile.settings); + test.done(); }, 'should be undefined if weak is false or non-boolean': function (test) { @@ -252,7 +251,7 @@ exports['settings'] = { var sourceFile = new pbxFile('social.framework', { weak: true }); - test.deepEqual({ATTRIBUTES:["Weak"]}, sourceFile.settings); + test.deepEqual({ ATTRIBUTES: ['Weak'] }, sourceFile.settings); test.done(); }, @@ -260,7 +259,7 @@ exports['settings'] = { var sourceFile = new pbxFile('signable.framework', { embed: true, sign: true }); - test.deepEqual({ATTRIBUTES:["CodeSignOnCopy"]}, sourceFile.settings); + test.deepEqual({ ATTRIBUTES: ['CodeSignOnCopy'] }, sourceFile.settings); test.done(); }, @@ -268,23 +267,23 @@ exports['settings'] = { var sourceFile = new pbxFile('signableWeak.framework', { embed: true, weak: true, sign: true }); - test.deepEqual({ATTRIBUTES:["Weak", "CodeSignOnCopy"]}, sourceFile.settings); + test.deepEqual({ ATTRIBUTES: ['Weak', 'CodeSignOnCopy'] }, sourceFile.settings); test.done(); }, 'should be {COMPILER_FLAGS:"blah"} if compiler flags specified': function (test) { var sourceFile = new pbxFile('Plugins/BarcodeScanner.m', - { compilerFlags: "-std=c++11 -fno-objc-arc" }); + { compilerFlags: '-std=c++11 -fno-objc-arc' }); - test.deepEqual({COMPILER_FLAGS:'"-std=c++11 -fno-objc-arc"'}, sourceFile.settings); + test.deepEqual({ COMPILER_FLAGS: '"-std=c++11 -fno-objc-arc"' }, sourceFile.settings); test.done(); }, 'should be .appex if {explicitFileType:\'"wrapper.app-extension"\'} specified': function (test) { var sourceFile = new pbxFile('AppExtension', - { explicitFileType: '"wrapper.app-extension"'}); + { explicitFileType: '"wrapper.app-extension"' }); test.equal('AppExtension.appex', sourceFile.basename); test.done(); } -} +}; diff --git a/test/pbxItemByComment.js b/test/pbxItemByComment.js index 5bee287..7bf9a24 100644 --- a/test/pbxItemByComment.js +++ b/test/pbxItemByComment.js @@ -15,19 +15,20 @@ under the License. */ -var fullProject = require('./fixtures/full-project') - fullProjectStr = JSON.stringify(fullProject), - pbx = require('../lib/pbxProject'), - proj = new pbx('.'); +var fullProject = require('./fixtures/full-project'); -function cleanHash() { +var fullProjectStr = JSON.stringify(fullProject); +var pbx = require('../lib/pbxProject'); +var proj = new pbx('.'); + +function cleanHash () { return JSON.parse(fullProjectStr); } exports.setUp = function (callback) { proj.hash = cleanHash(); callback(); -} +}; exports.pbxItemByComment = { 'should return PBXTargetDependency': function (test) { @@ -35,33 +36,33 @@ exports.pbxItemByComment = { test.ok(pbxItem); test.equals(pbxItem.isa, 'PBXTargetDependency'); - test.done() + test.done(); }, 'should return PBXContainerItemProxy': function (test) { var pbxItem = proj.pbxItemByComment('libPhoneGap.a', 'PBXReferenceProxy'); test.ok(pbxItem); test.equals(pbxItem.isa, 'PBXReferenceProxy'); - test.done() + test.done(); }, 'should return PBXResourcesBuildPhase': function (test) { var pbxItem = proj.pbxItemByComment('Resources', 'PBXResourcesBuildPhase'); test.ok(pbxItem); test.equals(pbxItem.isa, 'PBXResourcesBuildPhase'); - test.done() + test.done(); }, 'should return PBXShellScriptBuildPhase': function (test) { var pbxItem = proj.pbxItemByComment('Touch www folder', 'PBXShellScriptBuildPhase'); test.ok(pbxItem); test.equals(pbxItem.isa, 'PBXShellScriptBuildPhase'); - test.done() + test.done(); }, 'should return null when PBXNativeTarget not found': function (test) { var pbxItem = proj.pbxItemByComment('Invalid', 'PBXTargetDependency'); test.equal(pbxItem, null); - test.done() + test.done(); } -} +}; diff --git a/test/pbxProject.js b/test/pbxProject.js index c076b96..071d4e0 100644 --- a/test/pbxProject.js +++ b/test/pbxProject.js @@ -15,13 +15,13 @@ under the License. */ -var pbx = require('../lib/pbxProject'), - buildConfig = require('./fixtures/buildFiles'), - jsonProject = require('./fixtures/full-project'), - fs = require('fs'), - project; +var pbx = require('../lib/pbxProject'); -exports['creation'] = { +var buildConfig = require('./fixtures/buildFiles'); +var jsonProject = require('./fixtures/full-project'); +var fs = require('fs'); + +exports.creation = { 'should create a pbxProject with the new operator': function (test) { var myProj = new pbx('test/parser/projects/hash.pbxproj'); @@ -34,18 +34,18 @@ exports['creation'] = { test.ok(myProj instanceof pbx); test.done(); } -} +}; exports['parseSync function'] = { - 'should return the hash object': function (test) { - var myProj = new pbx('test/parser/projects/hash.pbxproj') - , projHash = myProj.parseSync(); + 'should return the hash object': function (test) { + var myProj = new pbx('test/parser/projects/hash.pbxproj'); + var projHash = myProj.parseSync(); test.ok(projHash); test.done(); - }, - 'should contain valid data in the returned objects hash': function (test) { - var myProj = new pbx('test/parser/projects/hash.pbxproj') - , projHash = myProj.parseSync(); + }, + 'should contain valid data in the returned objects hash': function (test) { + var myProj = new pbx('test/parser/projects/hash.pbxproj'); + var projHash = myProj.parseSync(); test.ok(projHash); test.equal(projHash.hash.project.archiveVersion, 1); @@ -53,8 +53,8 @@ exports['parseSync function'] = { test.equal(projHash.hash.project.nonObject, '29B97313FDCFA39411CA2CEF'); test.done(); - }, -} + } +}; exports['parse function'] = { 'should emit an "end" event': function (test) { @@ -62,22 +62,22 @@ exports['parse function'] = { myProj.parse().on('end', function (err, projHash) { test.done(); - }) + }); }, 'should take the end callback as a parameter': function (test) { var myProj = new pbx('test/parser/projects/hash.pbxproj'); myProj.parse(function (err, projHash) { test.done(); - }) + }); }, 'should allow evented error handling': function (test) { var myProj = new pbx('NotARealPath.pbxproj'); myProj.parse().on('error', function (err) { - test.equal(typeof err, "object"); + test.equal(typeof err, 'object'); test.done(); - }) + }); }, 'should pass the hash object to the callback function': function (test) { var myProj = new pbx('test/parser/projects/hash.pbxproj'); @@ -85,7 +85,7 @@ exports['parse function'] = { myProj.parse(function (err, projHash) { test.ok(projHash); test.done(); - }) + }); }, 'should handle projects with comments in the header': function (test) { var myProj = new pbx('test/parser/projects/comments.pbxproj'); @@ -93,7 +93,7 @@ exports['parse function'] = { myProj.parse(function (err, projHash) { test.ok(projHash); test.done(); - }) + }); }, 'should attach the hash object to the pbx object': function (test) { var myProj = new pbx('test/parser/projects/hash.pbxproj'); @@ -101,7 +101,7 @@ exports['parse function'] = { myProj.parse(function (err, projHash) { test.ok(myProj.hash); test.done(); - }) + }); }, 'it should pass an error object back when the parsing fails': function (test) { var myProj = new pbx('test/parser/projects/fail.pbxproj'); @@ -109,102 +109,102 @@ exports['parse function'] = { myProj.parse(function (err, projHash) { test.ok(err); test.done(); - }) + }); } -} +}; exports['allUuids function'] = { - 'should return the right amount of uuids': function (test) { - var project = new pbx('.'), - uuids; + 'should return the right amount of uuids': function (test) { + var project = new pbx('.'); + var uuids; - project.hash = buildConfig; - uuids = project.allUuids(); + project.hash = buildConfig; + uuids = project.allUuids(); - test.equal(uuids.length, 4); - test.done(); - } -} + test.equal(uuids.length, 4); + test.done(); + } +}; exports['generateUuid function'] = { 'should return a 24 character string': function (test) { - var project = new pbx('.'), - newUUID; + var project = new pbx('.'); + var newUUID; - project.hash = buildConfig; - newUUID = project.generateUuid(); + project.hash = buildConfig; + newUUID = project.generateUuid(); - test.equal(newUUID.length, 24); - test.done(); + test.equal(newUUID.length, 24); + test.done(); }, 'should be an uppercase hex string': function (test) { - var project = new pbx('.'), - uHex = /^[A-F0-9]{24}$/, - newUUID; + var project = new pbx('.'); + var uHex = /^[A-F0-9]{24}$/; + var newUUID; - project.hash = buildConfig; - newUUID = project.generateUuid(); + project.hash = buildConfig; + newUUID = project.generateUuid(); - test.ok(uHex.test(newUUID)); - test.done(); + test.ok(uHex.test(newUUID)); + test.done(); } -} +}; var bcpbx = 'test/parser/projects/build-config.pbxproj'; var original_pbx = fs.readFileSync(bcpbx, 'utf-8'); exports['updateProductName function'] = { - setUp:function(callback) { + setUp: function (callback) { callback(); }, - tearDown:function(callback) { + tearDown: function (callback) { fs.writeFileSync(bcpbx, original_pbx, 'utf-8'); callback(); }, 'should change the PRODUCT_NAME field in the .pbxproj file': function (test) { var myProj = new pbx('test/parser/projects/build-config.pbxproj'); - myProj.parse(function(err, hash) { + myProj.parse(function (err, hash) { myProj.updateProductName('furious anger'); var newContents = myProj.writeSync(); test.ok(newContents.match(/PRODUCT_NAME\s*=\s*"furious anger"/)); test.done(); }); } -} +}; exports['updateBuildProperty function'] = { - setUp:function(callback) { + setUp: function (callback) { callback(); }, - tearDown:function(callback) { + tearDown: function (callback) { fs.writeFileSync(bcpbx, original_pbx, 'utf-8'); callback(); }, 'should change build properties in the .pbxproj file': function (test) { var myProj = new pbx('test/parser/projects/build-config.pbxproj'); - myProj.parse(function(err, hash) { + myProj.parse(function (err, hash) { myProj.updateBuildProperty('TARGETED_DEVICE_FAMILY', '"arm"'); var newContents = myProj.writeSync(); test.ok(newContents.match(/TARGETED_DEVICE_FAMILY\s*=\s*"arm"/)); - myProj.updateBuildProperty('OTHER_LDFLAGS', ['T','E','S','T']); + myProj.updateBuildProperty('OTHER_LDFLAGS', ['T', 'E', 'S', 'T']); newContents = myProj.writeSync(); - test.ok(newContents.match(/OTHER_LDFLAGS\s*=\s*\(\s*T,\s*E,\s*S,\s*T,\s*\)/)) + test.ok(newContents.match(/OTHER_LDFLAGS\s*=\s*\(\s*T,\s*E,\s*S,\s*T,\s*\)/)); test.done(); }); } -} +}; exports['addBuildProperty function'] = { - setUp:function(callback) { + setUp: function (callback) { callback(); }, - tearDown:function(callback) { + tearDown: function (callback) { fs.writeFileSync(bcpbx, original_pbx, 'utf-8'); callback(); }, 'should add 4 build properties in the .pbxproj file': function (test) { var myProj = new pbx('test/parser/projects/build-config.pbxproj'); - myProj.parse(function(err, hash) { + myProj.parse(function (err, hash) { myProj.addBuildProperty('ENABLE_BITCODE', 'NO'); var newContents = myProj.writeSync(); test.equal(newContents.match(/ENABLE_BITCODE\s*=\s*NO/g).length, 4); @@ -213,7 +213,7 @@ exports['addBuildProperty function'] = { }, 'should add 2 build properties in the .pbxproj file for specific build': function (test) { var myProj = new pbx('test/parser/projects/build-config.pbxproj'); - myProj.parse(function(err, hash) { + myProj.parse(function (err, hash) { myProj.addBuildProperty('ENABLE_BITCODE', 'NO', 'Release'); var newContents = myProj.writeSync(); test.equal(newContents.match(/ENABLE_BITCODE\s*=\s*NO/g).length, 2); @@ -222,26 +222,26 @@ exports['addBuildProperty function'] = { }, 'should not add build properties in the .pbxproj file for nonexist build': function (test) { var myProj = new pbx('test/parser/projects/build-config.pbxproj'); - myProj.parse(function(err, hash) { + myProj.parse(function (err, hash) { myProj.addBuildProperty('ENABLE_BITCODE', 'NO', 'nonexist'); var newContents = myProj.writeSync(); test.ok(!newContents.match(/ENABLE_BITCODE\s*=\s*NO/g)); test.done(); }); } -} +}; exports['removeBuildProperty function'] = { - setUp:function(callback) { + setUp: function (callback) { callback(); }, - tearDown:function(callback) { + tearDown: function (callback) { fs.writeFileSync(bcpbx, original_pbx, 'utf-8'); callback(); }, 'should remove all build properties in the .pbxproj file': function (test) { var myProj = new pbx('test/parser/projects/build-config.pbxproj'); - myProj.parse(function(err, hash) { + myProj.parse(function (err, hash) { myProj.removeBuildProperty('IPHONEOS_DEPLOYMENT_TARGET'); var newContents = myProj.writeSync(); test.ok(!newContents.match(/IPHONEOS_DEPLOYMENT_TARGET/)); @@ -250,7 +250,7 @@ exports['removeBuildProperty function'] = { }, 'should remove specific build properties in the .pbxproj file': function (test) { var myProj = new pbx('test/parser/projects/build-config.pbxproj'); - myProj.parse(function(err, hash) { + myProj.parse(function (err, hash) { myProj.removeBuildProperty('IPHONEOS_DEPLOYMENT_TARGET', 'Debug'); var newContents = myProj.writeSync(); test.equal(newContents.match(/IPHONEOS_DEPLOYMENT_TARGET/g).length, 2); @@ -259,7 +259,7 @@ exports['removeBuildProperty function'] = { }, 'should not remove any build properties in the .pbxproj file': function (test) { var myProj = new pbx('test/parser/projects/build-config.pbxproj'); - myProj.parse(function(err, hash) { + myProj.parse(function (err, hash) { myProj.removeBuildProperty('IPHONEOS_DEPLOYMENT_TARGET', 'notexist'); var newContents = myProj.writeSync(); test.equal(newContents.match(/IPHONEOS_DEPLOYMENT_TARGET/g).length, 4); @@ -268,7 +268,7 @@ exports['removeBuildProperty function'] = { }, 'should fine with remove inexist build properties in the .pbxproj file': function (test) { var myProj = new pbx('test/parser/projects/build-config.pbxproj'); - myProj.parse(function(err, hash) { + myProj.parse(function (err, hash) { myProj.removeBuildProperty('ENABLE_BITCODE'); var newContents = myProj.writeSync(); test.ok(!newContents.match(/ENABLE_BITCODE/)); @@ -276,7 +276,7 @@ exports['removeBuildProperty function'] = { }); } -} +}; exports['productName field'] = { 'should return the product name': function (test) { @@ -286,7 +286,7 @@ exports['productName field'] = { test.equal(newProj.productName, 'KitchenSinktablet'); test.done(); } -} +}; exports['addPluginFile function'] = { 'should strip the Plugin path prefix': function (test) { @@ -308,23 +308,23 @@ exports['addPluginFile function'] = { test.done(); }); } -} +}; -exports['hasFile'] = { +exports.hasFile = { 'should return true if the file is in the project': function (test) { var newProj = new pbx('.'); newProj.hash = jsonProject; // sourceTree: '""' - test.ok(newProj.hasFile('AppDelegate.m')) - test.done() + test.ok(newProj.hasFile('AppDelegate.m')); + test.done(); }, 'should return false if the file is not in the project': function (test) { var newProj = new pbx('.'); newProj.hash = jsonProject; // sourceTree: '""' - test.ok(!newProj.hasFile('NotTheAppDelegate.m')) - test.done() + test.ok(!newProj.hasFile('NotTheAppDelegate.m')); + test.done(); } -} +}; diff --git a/test/pbxTargetByName.js b/test/pbxTargetByName.js index 15c956d..e28b2a1 100644 --- a/test/pbxTargetByName.js +++ b/test/pbxTargetByName.js @@ -15,19 +15,20 @@ under the License. */ -var fullProject = require('./fixtures/full-project') - fullProjectStr = JSON.stringify(fullProject), - pbx = require('../lib/pbxProject'), - proj = new pbx('.'); +var fullProject = require('./fixtures/full-project'); -function cleanHash() { +var fullProjectStr = JSON.stringify(fullProject); +var pbx = require('../lib/pbxProject'); +var proj = new pbx('.'); + +function cleanHash () { return JSON.parse(fullProjectStr); } exports.setUp = function (callback) { proj.hash = cleanHash(); callback(); -} +}; exports.pbxTargetByName = { 'should return PBXNativeTarget': function (test) { @@ -35,12 +36,12 @@ exports.pbxTargetByName = { test.ok(pbxTarget); test.equals(pbxTarget.isa, 'PBXNativeTarget'); - test.done() + test.done(); }, 'should return null when PBXNativeTarget not found': function (test) { var pbxTarget = proj.pbxTargetByName('Invalid'); test.equal(pbxTarget, null); - test.done() + test.done(); } -} +}; diff --git a/test/pbxWriter.js b/test/pbxWriter.js index f1e2ee4..b79c4e4 100644 --- a/test/pbxWriter.js +++ b/test/pbxWriter.js @@ -15,11 +15,11 @@ under the License. */ -var pbx = require('../lib/pbxProject'), - fs = require('fs'), - myProj; +var pbx = require('../lib/pbxProject'); -function testProjectContents(filename, test, expectedFilename) { +var fs = require('fs'); + +function testProjectContents (filename, test, expectedFilename) { var myProj = new pbx(filename); var content; @@ -29,35 +29,26 @@ function testProjectContents(filename, test, expectedFilename) { content = fs.readFileSync(filename, 'utf-8'); } // normalize tabs vs strings - content = content.replace(/ /g, '\t'); + content = content.replace(/ {4}/g, '\t'); myProj.parse(function (err, projHash) { var written = myProj.writeSync(); - test.equal(content, written); - test.done(); - }); -} - -// for debugging failing tests -function testContentsInDepth(filename, test) { - var myProj = new pbx(filename), - content = fs.readFileSync(filename, 'utf-8'); - - // normalize tabs vs strings - content = content.replace(/ /g, '\t'); + // for debugging failing tests start + // var writtenLines = written.split('\n'); + // contentLines = content.split('\n'); - myProj.parse(function (err, projHash) { - var written = myProj.writeSync(), - writtenLines = written.split('\n') - contentLines = content.split('\n') + // test.equal(writtenLines.length, contentLines.length); - test.equal(writtenLines.length, contentLines.length); + // for (var i = 0; i < writtenLines.length; i++) { + // test.equal(writtenLines[i], contentLines[i], + // 'match failed on line ' + (i + 1)); + // } + // for debugging failing tests end - for (var i=0; i"'); - var deletedFile = proj.removeHeaderFile('Plugins/file.h'), - fileRefSection = proj.pbxFileReferenceSection(), - fileRefEntry = fileRefSection[deletedFile.fileRef]; + var deletedFile = proj.removeHeaderFile('Plugins/file.h'); + fileRefSection = proj.pbxFileReferenceSection(); + fileRefEntry = fileRefSection[deletedFile.fileRef]; test.ok(!fileRefEntry); test.done(); }, 'should remove from the Plugins PBXGroup group': function (test) { - var newFile = proj.addHeaderFile('Plugins/file.h'), - plugins = proj.pbxGroupByName('Plugins'); + proj.addHeaderFile('Plugins/file.h'); + var plugins = proj.pbxGroupByName('Plugins'); test.equal(plugins.children.length, 1); - var deletedFile = proj.removeHeaderFile('Plugins/file.h'), - plugins = proj.pbxGroupByName('Plugins'); + proj.removeHeaderFile('Plugins/file.h'); + plugins = proj.pbxGroupByName('Plugins'); test.equal(plugins.children.length, 0); test.done(); } -} +}; diff --git a/test/removeResourceFile.js b/test/removeResourceFile.js index bda48f9..551ba71 100644 --- a/test/removeResourceFile.js +++ b/test/removeResourceFile.js @@ -15,20 +15,21 @@ under the License. */ -var fullProject = require('./fixtures/full-project') - fullProjectStr = JSON.stringify(fullProject), - pbx = require('../lib/pbxProject'), - pbxFile = require('../lib/pbxFile'), - proj = new pbx('.'); +var fullProject = require('./fixtures/full-project'); -function cleanHash() { +var fullProjectStr = JSON.stringify(fullProject); +var pbx = require('../lib/pbxProject'); +var pbxFile = require('../lib/pbxFile'); +var proj = new pbx('.'); + +function cleanHash () { return JSON.parse(fullProjectStr); } exports.setUp = function (callback) { proj.hash = cleanHash(); callback(); -} +}; exports.removeResourceFile = { 'should return a pbxFile': function (test) { @@ -40,7 +41,7 @@ exports.removeResourceFile = { test.equal(deletedFile.constructor, pbxFile); - test.done() + test.done(); }, 'should set a uuid on the pbxFile': function (test) { var newFile = proj.addResourceFile('assets.bundle'); @@ -51,7 +52,7 @@ exports.removeResourceFile = { test.ok(deletedFile.uuid); - test.done() + test.done(); }, 'should set a fileRef on the pbxFile': function (test) { var newFile = proj.addResourceFile('assets.bundle'); @@ -62,20 +63,20 @@ exports.removeResourceFile = { test.ok(deletedFile.fileRef); - test.done() + test.done(); }, 'should remove 2 fields from the PBXBuildFile section': function (test) { - var newFile = proj.addResourceFile('assets.bundle'), - buildFileSection = proj.pbxBuildFileSection(), - bfsLength = Object.keys(buildFileSection).length; + var newFile = proj.addResourceFile('assets.bundle'); + var buildFileSection = proj.pbxBuildFileSection(); + var bfsLength = Object.keys(buildFileSection).length; test.equal(60, bfsLength); test.ok(buildFileSection[newFile.uuid]); test.ok(buildFileSection[newFile.uuid + '_comment']); - var deletedFile = proj.removeResourceFile('assets.bundle'), - buildFileSection = proj.pbxBuildFileSection(), - bfsLength = Object.keys(buildFileSection).length; + var deletedFile = proj.removeResourceFile('assets.bundle'); + buildFileSection = proj.pbxBuildFileSection(); + bfsLength = Object.keys(buildFileSection).length; test.equal(58, bfsLength); test.ok(!buildFileSection[deletedFile.uuid]); @@ -84,49 +85,49 @@ exports.removeResourceFile = { test.done(); }, 'should remove the PBXBuildFile comment correctly': function (test) { - var newFile = proj.addResourceFile('assets.bundle'), - commentKey = newFile.uuid + '_comment', - buildFileSection = proj.pbxBuildFileSection(); + var newFile = proj.addResourceFile('assets.bundle'); + var commentKey = newFile.uuid + '_comment'; + var buildFileSection = proj.pbxBuildFileSection(); test.equal(buildFileSection[commentKey], 'assets.bundle in Resources'); - var deletedFile = proj.removeResourceFile('assets.bundle'), - commentKey = deletedFile.uuid + '_comment', - buildFileSection = proj.pbxBuildFileSection(); + var deletedFile = proj.removeResourceFile('assets.bundle'); + commentKey = deletedFile.uuid + '_comment'; + buildFileSection = proj.pbxBuildFileSection(); test.ok(!buildFileSection[commentKey]); test.done(); }, 'should remove the PBXBuildFile object correctly': function (test) { - var newFile = proj.addResourceFile('assets.bundle'), - buildFileSection = proj.pbxBuildFileSection(), - buildFileEntry = buildFileSection[newFile.uuid]; + var newFile = proj.addResourceFile('assets.bundle'); + var buildFileSection = proj.pbxBuildFileSection(); + var buildFileEntry = buildFileSection[newFile.uuid]; test.equal(buildFileEntry.isa, 'PBXBuildFile'); test.equal(buildFileEntry.fileRef, newFile.fileRef); test.equal(buildFileEntry.fileRef_comment, 'assets.bundle'); - var deletedFile = proj.removeResourceFile('assets.bundle'), - buildFileSection = proj.pbxBuildFileSection(), - buildFileEntry = buildFileSection[deletedFile.uuid]; + var deletedFile = proj.removeResourceFile('assets.bundle'); + buildFileSection = proj.pbxBuildFileSection(); + buildFileEntry = buildFileSection[deletedFile.uuid]; test.ok(!buildFileEntry); test.done(); }, 'should remove 2 fields from the PBXFileReference section': function (test) { - var newFile = proj.addResourceFile('assets.bundle'), - fileRefSection = proj.pbxFileReferenceSection(), - frsLength = Object.keys(fileRefSection).length; + var newFile = proj.addResourceFile('assets.bundle'); + var fileRefSection = proj.pbxFileReferenceSection(); + var frsLength = Object.keys(fileRefSection).length; test.equal(68, frsLength); test.ok(fileRefSection[newFile.fileRef]); test.ok(fileRefSection[newFile.fileRef + '_comment']); - var deletedFile = proj.removeResourceFile('assets.bundle'), - fileRefSection = proj.pbxFileReferenceSection(), - frsLength = Object.keys(fileRefSection).length; + var deletedFile = proj.removeResourceFile('assets.bundle'); + fileRefSection = proj.pbxFileReferenceSection(); + frsLength = Object.keys(fileRefSection).length; test.equal(66, frsLength); test.ok(!fileRefSection[deletedFile.fileRef]); @@ -135,15 +136,15 @@ exports.removeResourceFile = { test.done(); }, 'should populate the PBXFileReference comment correctly': function (test) { - var newFile = proj.addResourceFile('assets.bundle'), - fileRefSection = proj.pbxFileReferenceSection(), - commentKey = newFile.fileRef + '_comment'; + var newFile = proj.addResourceFile('assets.bundle'); + var fileRefSection = proj.pbxFileReferenceSection(); + var commentKey = newFile.fileRef + '_comment'; test.equal(fileRefSection[commentKey], 'assets.bundle'); - var deletedFile = proj.removeResourceFile('assets.bundle'), - fileRefSection = proj.pbxFileReferenceSection(), - commentKey = deletedFile.fileRef + '_comment'; + var deletedFile = proj.removeResourceFile('assets.bundle'); + fileRefSection = proj.pbxFileReferenceSection(); + commentKey = deletedFile.fileRef + '_comment'; test.ok(!fileRefSection[commentKey]); test.done(); @@ -151,9 +152,9 @@ exports.removeResourceFile = { 'should remove the PBXFileReference object correctly': function (test) { delete proj.pbxGroupByName('Resources').path; - var newFile = proj.addResourceFile('Resources/assets.bundle'), - fileRefSection = proj.pbxFileReferenceSection(), - fileRefEntry = fileRefSection[newFile.fileRef]; + var newFile = proj.addResourceFile('Resources/assets.bundle'); + var fileRefSection = proj.pbxFileReferenceSection(); + var fileRefEntry = fileRefSection[newFile.fileRef]; test.equal(fileRefEntry.isa, 'PBXFileReference'); test.equal(fileRefEntry.fileEncoding, undefined); @@ -162,34 +163,34 @@ exports.removeResourceFile = { test.equal(fileRefEntry.path, '"Resources/assets.bundle"'); test.equal(fileRefEntry.sourceTree, '""'); - var deletedFile = proj.removeResourceFile('Resources/assets.bundle'), - fileRefSection = proj.pbxFileReferenceSection(), - fileRefEntry = fileRefSection[deletedFile.fileRef]; + var deletedFile = proj.removeResourceFile('Resources/assets.bundle'); + fileRefSection = proj.pbxFileReferenceSection(); + fileRefEntry = fileRefSection[deletedFile.fileRef]; test.ok(!fileRefEntry); test.done(); }, 'should remove from the Resources PBXGroup group': function (test) { - var newFile = proj.addResourceFile('Resources/assets.bundle'), - resources = proj.pbxGroupByName('Resources'); + proj.addResourceFile('Resources/assets.bundle'); + var resources = proj.pbxGroupByName('Resources'); test.equal(resources.children.length, 10); - var deletedFile = proj.removeResourceFile('Resources/assets.bundle'), - resources = proj.pbxGroupByName('Resources'); + proj.removeResourceFile('Resources/assets.bundle'); + resources = proj.pbxGroupByName('Resources'); test.equal(resources.children.length, 9); test.done(); }, 'should remove from the PBXSourcesBuildPhase': function (test) { - var newFile = proj.addResourceFile('Resources/assets.bundle'), - sources = proj.pbxResourcesBuildPhaseObj(); + proj.addResourceFile('Resources/assets.bundle'); + var sources = proj.pbxResourcesBuildPhaseObj(); test.equal(sources.files.length, 13); - var deletedFile = proj.removeResourceFile('Resources/assets.bundle'), - sources = proj.pbxResourcesBuildPhaseObj(); + proj.removeResourceFile('Resources/assets.bundle'); + sources = proj.pbxResourcesBuildPhaseObj(); test.equal(sources.files.length, 12); test.done(); @@ -198,4 +199,4 @@ exports.removeResourceFile = { delete proj.pbxGroupByName('Resources').path; callback(); } -} +}; diff --git a/test/removeSourceFile.js b/test/removeSourceFile.js index de7895e..6806fd6 100644 --- a/test/removeSourceFile.js +++ b/test/removeSourceFile.js @@ -15,20 +15,21 @@ under the License. */ -var fullProject = require('./fixtures/full-project') - fullProjectStr = JSON.stringify(fullProject), - pbx = require('../lib/pbxProject'), - pbxFile = require('../lib/pbxFile'), - proj = new pbx('.'); +var fullProject = require('./fixtures/full-project'); -function cleanHash() { +var fullProjectStr = JSON.stringify(fullProject); +var pbx = require('../lib/pbxProject'); +var pbxFile = require('../lib/pbxFile'); +var proj = new pbx('.'); + +function cleanHash () { return JSON.parse(fullProjectStr); } exports.setUp = function (callback) { proj.hash = cleanHash(); callback(); -} +}; exports.removeSourceFile = { 'should return a pbxFile': function (test) { @@ -36,27 +37,27 @@ exports.removeSourceFile = { var newFile = proj.removeSourceFile('file.m'); test.equal(newFile.constructor, pbxFile); - test.done() + test.done(); }, 'should set a uuid on the pbxFile': function (test) { proj.addSourceFile('file.m'); var newFile = proj.removeSourceFile('file.m'); test.ok(newFile.uuid); - test.done() + test.done(); }, 'should set a fileRef on the pbxFile': function (test) { proj.addSourceFile('file.m'); var newFile = proj.removeSourceFile('file.m'); test.ok(newFile.fileRef); - test.done() + test.done(); }, 'should remove 2 fields from the PBXBuildFile section': function (test) { proj.addSourceFile('file.m'); - var newFile = proj.removeSourceFile('file.m'), - buildFileSection = proj.pbxBuildFileSection(), - bfsLength = Object.keys(buildFileSection).length; + var newFile = proj.removeSourceFile('file.m'); + var buildFileSection = proj.pbxBuildFileSection(); + var bfsLength = Object.keys(buildFileSection).length; test.equal(58, bfsLength); test.ok(!buildFileSection[newFile.uuid]); @@ -66,17 +67,17 @@ exports.removeSourceFile = { }, 'should remove comment from the PBXBuildFile correctly': function (test) { proj.addSourceFile('file.m'); - var newFile = proj.removeSourceFile('file.m'), - commentKey = newFile.uuid + '_comment', - buildFileSection = proj.pbxBuildFileSection(); + var newFile = proj.removeSourceFile('file.m'); + var commentKey = newFile.uuid + '_comment'; + var buildFileSection = proj.pbxBuildFileSection(); test.notEqual(!buildFileSection[commentKey], 'file.m in Sources'); test.done(); }, 'should remove the PBXBuildFile object correctly': function (test) { proj.addSourceFile('file.m'); - var newFile = proj.removeSourceFile('file.m'), - buildFileSection = proj.pbxBuildFileSection(), - buildFileEntry = buildFileSection[newFile.uuid]; + var newFile = proj.removeSourceFile('file.m'); + var buildFileSection = proj.pbxBuildFileSection(); + var buildFileEntry = buildFileSection[newFile.uuid]; test.equal(buildFileEntry, undefined); @@ -84,9 +85,9 @@ exports.removeSourceFile = { }, 'should remove 2 fields from the PBXFileReference section': function (test) { proj.addSourceFile('file.m'); - var newFile = proj.removeSourceFile('file.m'), - fileRefSection = proj.pbxFileReferenceSection(), - frsLength = Object.keys(fileRefSection).length; + var newFile = proj.removeSourceFile('file.m'); + var fileRefSection = proj.pbxFileReferenceSection(); + var frsLength = Object.keys(fileRefSection).length; test.equal(66, frsLength); test.ok(!fileRefSection[newFile.fileRef]); @@ -96,62 +97,62 @@ exports.removeSourceFile = { }, 'should remove the PBXFileReference comment correctly': function (test) { proj.addSourceFile('file.m'); - var newFile = proj.removeSourceFile('file.m'), - fileRefSection = proj.pbxFileReferenceSection(), - commentKey = newFile.fileRef + '_comment'; + var newFile = proj.removeSourceFile('file.m'); + var fileRefSection = proj.pbxFileReferenceSection(); + var commentKey = newFile.fileRef + '_comment'; test.ok(!fileRefSection[commentKey]); test.done(); }, 'should remove the PBXFileReference object correctly': function (test) { proj.addSourceFile('file.m'); - var newFile = proj.removeSourceFile('Plugins/file.m'), - fileRefSection = proj.pbxFileReferenceSection(), - fileRefEntry = fileRefSection[newFile.fileRef]; + var newFile = proj.removeSourceFile('Plugins/file.m'); + var fileRefSection = proj.pbxFileReferenceSection(); + var fileRefEntry = fileRefSection[newFile.fileRef]; test.ok(!fileRefEntry); test.done(); }, 'should remove from the Plugins PBXGroup group': function (test) { proj.addSourceFile('Plugins/file.m'); - var newFile = proj.removeSourceFile('Plugins/file.m'), - plugins = proj.pbxGroupByName('Plugins'); + proj.removeSourceFile('Plugins/file.m'); + var plugins = proj.pbxGroupByName('Plugins'); test.equal(plugins.children.length, 0); test.done(); }, 'should have the right values for the PBXGroup entry': function (test) { proj.addSourceFile('Plugins/file.m'); - var newFile = proj.removeSourceFile('Plugins/file.m'), - plugins = proj.pbxGroupByName('Plugins'), - pluginObj = plugins.children[0]; + proj.removeSourceFile('Plugins/file.m'); + var plugins = proj.pbxGroupByName('Plugins'); + var pluginObj = plugins.children[0]; test.ok(!pluginObj); test.done(); }, 'should remove from the PBXSourcesBuildPhase': function (test) { proj.addSourceFile('Plugins/file.m'); - var newFile = proj.removeSourceFile('Plugins/file.m'), - sources = proj.pbxSourcesBuildPhaseObj(); + proj.removeSourceFile('Plugins/file.m'); + var sources = proj.pbxSourcesBuildPhaseObj(); test.equal(sources.files.length, 2); test.done(); }, 'should have the right values for the Sources entry': function (test) { proj.addSourceFile('Plugins/file.m'); - var newFile = proj.removeSourceFile('Plugins/file.m'), - sources = proj.pbxSourcesBuildPhaseObj(), - sourceObj = sources.files[2]; + proj.removeSourceFile('Plugins/file.m'); + var sources = proj.pbxSourcesBuildPhaseObj(); + var sourceObj = sources.files[2]; test.ok(!sourceObj); test.done(); }, - 'should remove file from PBXFileReference after modified by Xcode': function(test) { + 'should remove file from PBXFileReference after modified by Xcode': function (test) { var fileRef = proj.addSourceFile('Plugins/file.m').fileRef; // Simulate Xcode's behaviour of stripping quotes around path and name // properties. var entry = proj.pbxFileReferenceSection()[fileRef]; - entry.name = entry.name.replace(/^"(.*)"$/, "$1"); - entry.path = entry.path.replace(/^"(.*)"$/, "$1"); + entry.name = entry.name.replace(/^"(.*)"$/, '$1'); + entry.path = entry.path.replace(/^"(.*)"$/, '$1'); var newFile = proj.removeSourceFile('Plugins/file.m'); @@ -159,5 +160,4 @@ exports.removeSourceFile = { test.ok(!proj.pbxFileReferenceSection()[fileRef]); test.done(); } -} - +}; diff --git a/test/variantGroup.js b/test/variantGroup.js index 356a232..bbea147 100644 --- a/test/variantGroup.js +++ b/test/variantGroup.js @@ -15,11 +15,12 @@ under the License. */ -var pbx = require('../lib/pbxProject'), - project, - projectHash; +var pbx = require('../lib/pbxProject'); -var findChildInGroup = function(obj, target) { +var project; +var projectHash; // eslint-disable-line + +var findChildInGroup = function (obj, target) { var found = false; for (var i = 0, j = obj.children.length; i < j; i++) { @@ -30,36 +31,9 @@ var findChildInGroup = function(obj, target) { } return found; -} - -var findFileByUUID = function(obj, target) { - var found = false; - - for (var k = 0, l = obj.files.length; k < l; k++) { - if (obj.files[k].value === target) { - found = true; - break; - } - } - - return found; -} - -var findByFileRef = function(obj, target) { - var found = false; - - for (var property in obj) { - if (!/comment/.test(property)) { - if (obj[property].fileRef === target) { - found = true; - break; - } - } - } - return found; -} +}; -var findByName = function(obj, target) { +var findByName = function (obj, target) { var found = false; for (var property in obj) { if (!/comment/.test(property)) { @@ -70,34 +44,34 @@ var findByName = function(obj, target) { } } return found; -} +}; -exports.setUp = function(callback) { +exports.setUp = function (callback) { project = new pbx('test/parser/projects/variantgroup.pbxproj'); projectHash = project.parseSync(); callback(); -} +}; exports.getVariantGroupByKey = { - 'should return PBXVariantGroup for Localizable.strings': function(test) { - var groupKey = project.findPBXVariantGroupKey({name: 'Localizable.strings'}); + 'should return PBXVariantGroup for Localizable.strings': function (test) { + var groupKey = project.findPBXVariantGroupKey({ name: 'Localizable.strings' }); var group = project.getPBXVariantGroupByKey(groupKey); test.ok(group.name === 'Localizable.strings'); test.done(); } -} +}; exports.createVariantGroup = { - 'should create a new Test Variant Group': function(test) { + 'should create a new Test Variant Group': function (test) { delete project.getPBXObject('PBXVariantGroup'); var found = false; var groups = project.getPBXObject('PBXVariantGroup'); - var found = findByName(groups, 'Test'); + found = findByName(groups, 'Test'); test.ok(found === false); - var group = project.findPBXVariantGroupKey({name:'Test'}); + var group = project.findPBXVariantGroupKey({ name: 'Test' }); test.ok(group === undefined); project.pbxCreateVariantGroup('Test'); @@ -106,33 +80,33 @@ exports.createVariantGroup = { found = findByName(groups, 'Test'); test.ok(found === true); - group = project.findPBXVariantGroupKey({name:'Test'}); + group = project.findPBXVariantGroupKey({ name: 'Test' }); test.ok(typeof group === 'string'); test.done(); } -} +}; exports.findVariantGroupKey = { - 'should return a valid group key':function(test) { - var keyByName = project.findPBXVariantGroupKey({ name: 'Localizable.strings'}); - var nonExistingKey = project.findPBXVariantGroupKey({ name: 'Foo'}); + 'should return a valid group key': function (test) { + var keyByName = project.findPBXVariantGroupKey({ name: 'Localizable.strings' }); + var nonExistingKey = project.findPBXVariantGroupKey({ name: 'Foo' }); test.ok(keyByName === '07E3BDBC1DF1DEA500E49912'); test.ok(nonExistingKey === undefined); test.done(); } -} +}; exports.createLocalisationVariantGroup = { - 'should create a new localisation variationgroup then add group to Resources group': function(test) { + 'should create a new localisation variationgroup then add group to Resources group': function (test) { delete project.getPBXObject('PBXVariantGroup'); var localizationVariantGp = project.addLocalizationVariantGroup('InfoPlist.strings'); - var resourceGroupKey = project.findPBXGroupKey({name: 'Resources'}); + var resourceGroupKey = project.findPBXGroupKey({ name: 'Resources' }); var resourceGroup = project.getPBXGroupByKey(resourceGroupKey); - var foundInResourcesGroup = findChildInGroup(resourceGroup, localizationVariantGp.fileRef ); + var foundInResourcesGroup = findChildInGroup(resourceGroup, localizationVariantGp.fileRef); test.ok(foundInResourcesGroup); var foundInResourcesBuildPhase = false; @@ -147,16 +121,15 @@ exports.createLocalisationVariantGroup = { test.done(); } -} +}; exports.addResourceFileToLocalisationGroup = { - 'should add resource file to the TestVariantGroup group' : function(test) { - + 'should add resource file to the TestVariantGroup group': function (test) { var infoPlistVarGp = project.addLocalizationVariantGroup('InfoPlist.strings'); var testKey = infoPlistVarGp.fileRef; - var file = project.addResourceFile('Resources/en.lproj/Localization.strings', {variantGroup: true}, testKey); + var file = project.addResourceFile('Resources/en.lproj/Localization.strings', { variantGroup: true }, testKey); - var foundInLocalisationVariantGroup = findChildInGroup(project.getPBXVariantGroupByKey(testKey), file.fileRef ); + var foundInLocalisationVariantGroup = findChildInGroup(project.getPBXVariantGroupByKey(testKey), file.fileRef); test.ok(foundInLocalisationVariantGroup); var foundInResourcesBuildPhase = false; @@ -174,21 +147,21 @@ exports.addResourceFileToLocalisationGroup = { test.done(); } -} +}; exports.removeResourceFileFromGroup = { - 'should add resource file then remove resource file from Localizable.strings group' : function(test) { - var testKey = project.findPBXVariantGroupKey({name:'Localizable.strings'}); + 'should add resource file then remove resource file from Localizable.strings group': function (test) { + var testKey = project.findPBXVariantGroupKey({ name: 'Localizable.strings' }); var file = project.addResourceFile('Resources/zh.lproj/Localization.strings', {}, testKey); - var foundInGroup = findChildInGroup(project.getPBXVariantGroupByKey(testKey),file.fileRef ); + var foundInGroup = findChildInGroup(project.getPBXVariantGroupByKey(testKey), file.fileRef); test.ok(foundInGroup); project.removeResourceFile('Resources/zh.lproj/Localization.strings', {}, testKey); - var foundInGroup = findChildInGroup(project.getPBXVariantGroupByKey(testKey),file.fileRef ); + foundInGroup = findChildInGroup(project.getPBXVariantGroupByKey(testKey), file.fileRef); test.ok(!foundInGroup); test.done(); } -} +}; diff --git a/test/xcode5searchPaths.js b/test/xcode5searchPaths.js index 7cdf46c..08c9ceb 100644 --- a/test/xcode5searchPaths.js +++ b/test/xcode5searchPaths.js @@ -15,40 +15,40 @@ under the License. */ -var xcode5proj = require('./fixtures/library-search-paths') - xcode5projStr = JSON.stringify(xcode5proj), - pbx = require('../lib/pbxProject'), - pbxFile = require('../lib/pbxFile'), - proj = new pbx('.'), - libPoop = { path: 'some/path/poop.a' }; +var xcode5proj = require('./fixtures/library-search-paths'); -function cleanHash() { +var xcode5projStr = JSON.stringify(xcode5proj); +var pbx = require('../lib/pbxProject'); +var proj = new pbx('.'); +var libPoop = { path: 'some/path/poop.a' }; + +function cleanHash () { return JSON.parse(xcode5projStr); } exports.setUp = function (callback) { proj.hash = cleanHash(); callback(); -} +}; var PRODUCT_NAME = '"$(TARGET_NAME)"'; exports.addAndRemoveToFromLibrarySearchPaths = { - 'add should add the path to each configuration section':function(test) { - var expected = '"\\"$(SRCROOT)/$(TARGET_NAME)/some/path\\""', - config = proj.pbxXCBuildConfigurationSection(), - ref, lib, refSettings; + 'add should add the path to each configuration section': function (test) { + var expected = '"\\"$(SRCROOT)/$(TARGET_NAME)/some/path\\""'; + var config = proj.pbxXCBuildConfigurationSection(); + var ref; + var lib; + var refSettings; proj.addToLibrarySearchPaths(libPoop); for (ref in config) { - if (ref.indexOf('_comment') > -1) - continue; + if (ref.indexOf('_comment') > -1) { continue; } refSettings = config[ref].buildSettings; - if (refSettings.PRODUCT_NAME != PRODUCT_NAME) - continue; + if (refSettings.PRODUCT_NAME !== PRODUCT_NAME) { continue; } lib = refSettings.LIBRARY_SEARCH_PATHS; test.equal(lib[1], expected); @@ -56,20 +56,22 @@ exports.addAndRemoveToFromLibrarySearchPaths = { test.done(); }, - 'remove should remove from the path to each configuration section':function(test) { - var config, ref, lib; + 'remove should remove from the path to each configuration section': function (test) { + var config; + var ref; + var lib; proj.addToLibrarySearchPaths(libPoop); proj.removeFromLibrarySearchPaths(libPoop); config = proj.pbxXCBuildConfigurationSection(); for (ref in config) { - if (ref.indexOf('_comment') > -1 || config[ref].buildSettings.PRODUCT_NAME != PRODUCT_NAME) continue; + if (ref.indexOf('_comment') > -1 || config[ref].buildSettings.PRODUCT_NAME !== PRODUCT_NAME) continue; lib = config[ref].buildSettings.LIBRARY_SEARCH_PATHS; test.ok(lib.length === 1); - test.ok(lib[0].indexOf('$(SRCROOT)/KitchenSinktablet/some/path') == -1); + test.ok(lib[0].indexOf('$(SRCROOT)/KitchenSinktablet/some/path') === -1); } test.done(); } -} +};