Comparing version 0.5.5 to 0.6.0
@@ -83,4 +83,7 @@ var path = require('path'), | ||
this.fileEncoding = opt.fileEncoding || fileEncoding(this); | ||
if (opt.weak && opt.weak === true) | ||
this.settings = { ATTRIBUTES: ['Weak'] }; | ||
} | ||
module.exports = pbxFile; |
@@ -88,4 +88,7 @@ var util = require('util'), | ||
file.plugin = true; // durr | ||
correctForPluginsPath(file, this); | ||
correctForPluginsPath(file, this); | ||
// null is better for early errors | ||
if (this.hasFile(file.path)) return null; | ||
file.fileRef = this.generateUuid(); | ||
@@ -102,3 +105,3 @@ | ||
correctForPluginsPath(file, this); | ||
this.removeFromPbxFileReferenceSection(file); // PBXFileReference | ||
@@ -111,4 +114,6 @@ this.removeFromPluginsPbxGroup(file); // PBXGroup | ||
pbxProject.prototype.addSourceFile = function (path, opt) { | ||
var file = this.addPluginFile(path, opt) | ||
var file = this.addPluginFile(path, opt); | ||
if (!file) return false; | ||
file.uuid = this.generateUuid(); | ||
@@ -145,4 +150,6 @@ | ||
file = this.addPluginFile(path, opt); | ||
if (!file) return false; | ||
} else { | ||
file = new pbxFile(path, opt); | ||
if (this.hasFile(file.path)) return false; | ||
} | ||
@@ -184,2 +191,5 @@ | ||
// catch duplicates | ||
if (this.hasFile(file.path)) return false; | ||
file.uuid = this.generateUuid(); | ||
@@ -214,4 +224,6 @@ file.fileRef = this.generateUuid(); | ||
file = this.addPluginFile(path, opt); | ||
if (!file) return false; | ||
} else { | ||
file = new pbxFile(path, opt); | ||
if (this.hasFile(file.path)) return false; | ||
} | ||
@@ -313,3 +325,2 @@ | ||
pbxProject.prototype.addToFrameworksPbxGroup = function (file) { | ||
@@ -475,2 +486,18 @@ var pluginsGroup = this.pbxGroupByName('Frameworks'); | ||
// check if file is present | ||
pbxProject.prototype.hasFile = function (filePath) { | ||
var files = nonComments(this.pbxFileReferenceSection()), | ||
file, id; | ||
for (id in files) { | ||
file = files[id]; | ||
if (file.path == filePath) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
// helper recursive prop search+replace | ||
@@ -496,2 +523,3 @@ function propReplace(obj, prop, value) { | ||
obj.fileRef_comment = file.basename; | ||
if (file.settings) obj.settings = file.settings; | ||
@@ -506,4 +534,6 @@ return obj; | ||
obj.lastKnownFileType = file.lastType; | ||
obj.name = file.basename; | ||
obj.path = file.path; | ||
obj.name = "\"" + file.basename + "\""; | ||
obj.path = "\"" + file.path + "\""; | ||
obj.sourceTree = file.sourceTree; | ||
@@ -510,0 +540,0 @@ |
@@ -5,3 +5,3 @@ { | ||
"description": "parser for xcodeproj/project.pbxproj files", | ||
"version": "0.5.5", | ||
"version": "0.6.0", | ||
"main":"index.js", | ||
@@ -8,0 +8,0 @@ "repository": { |
@@ -55,4 +55,4 @@ var fullProject = require('./fixtures/full-project') | ||
test.equal(fileRefEntry.lastKnownFileType, '"compiled.mach-o.dylib"'); | ||
test.equal(fileRefEntry.name, 'libsqlite3.dylib'); | ||
test.equal(fileRefEntry.path, 'usr/lib/libsqlite3.dylib'); | ||
test.equal(fileRefEntry.name, '"libsqlite3.dylib"'); | ||
test.equal(fileRefEntry.path, '"usr/lib/libsqlite3.dylib"'); | ||
test.equal(fileRefEntry.sourceTree, 'SDKROOT'); | ||
@@ -89,5 +89,18 @@ | ||
test.equal(buildFileEntry.fileRef_comment, 'libsqlite3.dylib'); | ||
test.equal(buildFileEntry.settings, undefined); | ||
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]; | ||
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.done(); | ||
}, | ||
'should add to the Frameworks PBXGroup': function (test) { | ||
@@ -125,3 +138,11 @@ var newLength = proj.pbxGroupByName('Frameworks').children.length + 1, | ||
test.done(); | ||
}, | ||
'duplicate entries': { | ||
'should return false': function (test) { | ||
var newFile = proj.addFramework('libsqlite3.dylib'); | ||
test.ok(!proj.addFramework('libsqlite3.dylib')); | ||
test.done(); | ||
} | ||
} | ||
} |
@@ -56,4 +56,4 @@ var fullProject = require('./fixtures/full-project') | ||
test.equal(fileRefEntry.lastKnownFileType, 'sourcecode.c.h'); | ||
test.equal(fileRefEntry.name, 'file.h'); | ||
test.equal(fileRefEntry.path, 'file.h'); | ||
test.equal(fileRefEntry.name, '"file.h"'); | ||
test.equal(fileRefEntry.path, '"file.h"'); | ||
test.equal(fileRefEntry.sourceTree, '"<group>"'); | ||
@@ -78,3 +78,23 @@ | ||
test.done(); | ||
}, | ||
'duplicate entries': { | ||
'should return false': function (test) { | ||
var newFile = 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'); | ||
test.equal(68, frsLength); | ||
test.equal(plugins.children.length, 1); | ||
test.done(); | ||
} | ||
} | ||
} |
@@ -94,4 +94,4 @@ var fullProject = require('./fixtures/full-project') | ||
test.equal(fileRefEntry.lastKnownFileType, '"wrapper.plug-in"'); | ||
test.equal(fileRefEntry.name, 'assets.bundle'); | ||
test.equal(fileRefEntry.path, 'Resources/assets.bundle'); | ||
test.equal(fileRefEntry.name, '"assets.bundle"'); | ||
test.equal(fileRefEntry.path, '"Resources/assets.bundle"'); | ||
test.equal(fileRefEntry.sourceTree, '"<group>"'); | ||
@@ -156,4 +156,4 @@ | ||
test.equal(fileRefEntry.lastKnownFileType, '"wrapper.plug-in"'); | ||
test.equal(fileRefEntry.name, 'assets.bundle'); | ||
test.equal(fileRefEntry.path, 'Plugins/assets.bundle'); | ||
test.equal(fileRefEntry.name, '"assets.bundle"'); | ||
test.equal(fileRefEntry.path, '"Plugins/assets.bundle"'); | ||
test.equal(fileRefEntry.sourceTree, '"<group>"'); | ||
@@ -215,2 +215,36 @@ test.done(); | ||
}, | ||
'duplicate entries': { | ||
'should return false': function (test) { | ||
var newFile = 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 }); | ||
test.ok(!proj.addResourceFile('Plugins/assets.bundle', | ||
{ 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'); | ||
// check lengths | ||
test.equal(60, bfsLength); | ||
test.equal(68, frsLength); | ||
test.equal(resources.children.length, 10); | ||
test.equal(sources.files.length, 13); | ||
test.done(); | ||
} | ||
}, | ||
tearDown: function (callback) { | ||
@@ -217,0 +251,0 @@ delete proj.pbxGroupByName('Resources').path; |
@@ -92,4 +92,4 @@ var fullProject = require('./fixtures/full-project') | ||
test.equal(fileRefEntry.lastKnownFileType, 'sourcecode.c.objc'); | ||
test.equal(fileRefEntry.name, 'file.m'); | ||
test.equal(fileRefEntry.path, 'file.m'); | ||
test.equal(fileRefEntry.name, '"file.m"'); | ||
test.equal(fileRefEntry.path, '"file.m"'); | ||
test.equal(fileRefEntry.sourceTree, '"<group>"'); | ||
@@ -130,4 +130,30 @@ | ||
test.done(); | ||
}, | ||
'duplicate entries': { | ||
'should return false': function (test) { | ||
var newFile = 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(); | ||
// duplicate! | ||
proj.addSourceFile('Plugins/file.m'); | ||
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.done(); | ||
} | ||
} | ||
} | ||
@@ -126,4 +126,4 @@ var fullProject = require('./fixtures/full-project') | ||
test.equal(fileRefEntry.lastKnownFileType, 'archive.ar'); | ||
test.equal(fileRefEntry.name, 'libGoogleAnalytics.a'); | ||
test.equal(fileRefEntry.path, 'libGoogleAnalytics.a'); | ||
test.equal(fileRefEntry.name, '"libGoogleAnalytics.a"'); | ||
test.equal(fileRefEntry.path, '"libGoogleAnalytics.a"'); | ||
test.equal(fileRefEntry.sourceTree, '"<group>"'); | ||
@@ -235,3 +235,19 @@ | ||
} | ||
}, | ||
'duplicate entries': { | ||
'should return false': function (test) { | ||
var newFile = 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 }); | ||
test.ok(!proj.addStaticLibrary('Plugins/libGoogleAnalytics.a', | ||
{ plugin: true })); | ||
test.done(); | ||
}, | ||
} | ||
} |
@@ -168,1 +168,29 @@ var pbxFile = require('../lib/pbxFile'); | ||
} | ||
exports['settings'] = { | ||
'should not be defined by default': function (test) { | ||
var sourceFile = new pbxFile('social.framework'); | ||
test.equal(undefined, sourceFile.settings); | ||
test.done(); | ||
}, | ||
'should be undefined if weak is false or non-boolean': function (test) { | ||
var sourceFile1 = new pbxFile('social.framework', | ||
{ weak: false }); | ||
var sourceFile2 = new pbxFile('social.framework', | ||
{ weak: 'bad_value' }); | ||
test.equal(undefined, sourceFile1.settings); | ||
test.equal(undefined, sourceFile2.settings); | ||
test.done(); | ||
}, | ||
'should be {ATTRIBUTES:["Weak"]} if weak linking specified': function (test) { | ||
var sourceFile = new pbxFile('social.framework', | ||
{ weak: true }); | ||
test.deepEqual({ATTRIBUTES:["Weak"]}, sourceFile.settings); | ||
test.done(); | ||
} | ||
} |
@@ -167,1 +167,20 @@ var pbx = require('../lib/pbxProject'), | ||
} | ||
exports['hasFile'] = { | ||
'should return true if the file is in the project': function (test) { | ||
var newProj = new pbx('.'); | ||
newProj.hash = jsonProject; | ||
// sourceTree: '"<group>"' | ||
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: '"<group>"' | ||
test.ok(!newProj.hasFile('NotTheAppDelegate.m')) | ||
test.done() | ||
} | ||
} |
@@ -80,4 +80,4 @@ var fullProject = require('./fixtures/full-project') | ||
test.equal(fileRefEntry.lastKnownFileType, 'sourcecode.c.h'); | ||
test.equal(fileRefEntry.name, 'file.h'); | ||
test.equal(fileRefEntry.path, 'file.h'); | ||
test.equal(fileRefEntry.name, '"file.h"'); | ||
test.equal(fileRefEntry.path, '"file.h"'); | ||
test.equal(fileRefEntry.sourceTree, '"<group>"'); | ||
@@ -84,0 +84,0 @@ |
@@ -144,4 +144,4 @@ var fullProject = require('./fixtures/full-project') | ||
test.equal(fileRefEntry.lastKnownFileType, '"wrapper.plug-in"'); | ||
test.equal(fileRefEntry.name, 'assets.bundle'); | ||
test.equal(fileRefEntry.path, 'Resources/assets.bundle'); | ||
test.equal(fileRefEntry.name, '"assets.bundle"'); | ||
test.equal(fileRefEntry.path, '"Resources/assets.bundle"'); | ||
test.equal(fileRefEntry.sourceTree, '"<group>"'); | ||
@@ -148,0 +148,0 @@ |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
263242
4962