cordova-plugin-pixlive
Advanced tools
Comparing version 1.1.6 to 1.1.7
{ | ||
"version": "1.1.6", | ||
"version": "1.1.7", | ||
"name": "cordova-plugin-pixlive", | ||
@@ -4,0 +4,0 @@ "cordova_name": "PixLive", |
@@ -273,4 +273,4 @@ #!/usr/bin/env node | ||
xcodeProject.pbxResourcesBuildPhaseObj(Object.keys(xcodeProject.pbxNativeTarget())[0]).files.push({'value': uuidLocalizableFileSection,'comment': 'Localizable.strings in Resources'}); | ||
xcodeProject.pbxResourcesBuildPhaseObj(Object.keys(xcodeProject.pbxNativeTarget())[0]).files.push({'value': uuidInfoPlistFileSection,'comment': 'InfoPlist.strings in Resources'}); | ||
xcodeProject.pbxResourcesBuildPhaseObj(Object.keys(xcodeProject.pbxNativeTargetSection())[0]).files.push({'value': uuidLocalizableFileSection,'comment': 'Localizable.strings in Resources'}); | ||
xcodeProject.pbxResourcesBuildPhaseObj(Object.keys(xcodeProject.pbxNativeTargetSection())[0]).files.push({'value': uuidInfoPlistFileSection,'comment': 'InfoPlist.strings in Resources'}); | ||
@@ -277,0 +277,0 @@ fs.writeFileSync(xcodeProjectPath2, xcodeProject.writeSync(), 'utf-8'); |
@@ -9,9 +9,8 @@ // parsing is slow and blocking right now | ||
try { | ||
fileContents = fs.readFileSync(path, 'utf-8'), | ||
obj = parser.parse(fileContents) | ||
process.send(obj) | ||
process.exit() | ||
fileContents = fs.readFileSync(path, 'utf-8'); | ||
obj = parser.parse(fileContents); | ||
process.send(obj); | ||
} catch (e) { | ||
process.send(e) | ||
process.exit(1) | ||
process.send(e); | ||
process.exitCode = 1; | ||
} |
var path = require('path'), | ||
util = require('util'), | ||
M_EXTENSION = /[.]m$/, SOURCE_FILE = 'sourcecode.c.objc', | ||
H_EXTENSION = /[.]h$/, HEADER_FILE = 'sourcecode.c.h', | ||
BUNDLE_EXTENSION = /[.]bundle$/, BUNDLE = '"wrapper.plug-in"', | ||
XIB_EXTENSION = /[.]xib$/, XIB_FILE = 'file.xib', | ||
DYLIB_EXTENSION = /[.]dylib$/, DYLIB = '"compiled.mach-o.dylib"', | ||
FRAMEWORK_EXTENSION = /[.]framework/, FRAMEWORK = 'wrapper.framework', | ||
ARCHIVE_EXTENSION = /[.]a$/, ARCHIVE = 'archive.ar', | ||
DEFAULT_SOURCE_TREE = '"<group>"', | ||
DEFAULT_FILE_ENCODING = 4; | ||
util = require('util'); | ||
function detectLastType(path) { | ||
if (M_EXTENSION.test(path)) | ||
return SOURCE_FILE; | ||
var DEFAULT_SOURCETREE = '"<group>"', | ||
DEFAULT_PRODUCT_SOURCETREE = 'BUILT_PRODUCTS_DIR', | ||
DEFAULT_FILEENCODING = 4, | ||
DEFAULT_GROUP = 'Resources', | ||
DEFAULT_FILETYPE = 'unknown'; | ||
if (H_EXTENSION.test(path)) | ||
return HEADER_FILE; | ||
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', | ||
xcassets: 'folder.assetcatalog', | ||
xcconfig: 'text.xcconfig', | ||
xcdatamodel: 'wrapper.xcdatamodel', | ||
xcodeproj: 'wrapper.pb-project', | ||
xctest: 'wrapper.cfbundle', | ||
xib: 'file.xib' | ||
}, | ||
GROUP_BY_FILETYPE = { | ||
'archive.ar': 'Frameworks', | ||
'compiled.mach-o.dylib': 'Frameworks', | ||
'wrapper.framework': 'Frameworks', | ||
'sourcecode.c.h': 'Resources', | ||
'sourcecode.c.objc': 'Sources', | ||
'sourcecode.swift': 'Sources' | ||
}, | ||
PATH_BY_FILETYPE = { | ||
'compiled.mach-o.dylib': 'usr/lib/', | ||
'wrapper.framework': 'System/Library/Frameworks/' | ||
}, | ||
SOURCETREE_BY_FILETYPE = { | ||
'compiled.mach-o.dylib': '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 | ||
}; | ||
if (BUNDLE_EXTENSION.test(path)) | ||
return BUNDLE; | ||
if (XIB_EXTENSION.test(path)) | ||
return XIB_FILE; | ||
function unquoted(text){ | ||
return text.replace (/(^")|("$)/g, '') | ||
} | ||
if (FRAMEWORK_EXTENSION.test(path)) | ||
return FRAMEWORK; | ||
function detectType(filePath) { | ||
var extension = path.extname(filePath).substring(1), | ||
filetype = FILETYPE_BY_EXTENSION[unquoted(extension)]; | ||
if (DYLIB_EXTENSION.test(path)) | ||
return DYLIB; | ||
if (!filetype) { | ||
return DEFAULT_FILETYPE; | ||
} | ||
if (ARCHIVE_EXTENSION.test(path)) | ||
return ARCHIVE; | ||
return filetype; | ||
} | ||
// dunno | ||
return 'unknown'; | ||
function defaultExtension(fileRef) { | ||
var 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)] === filetype ) | ||
return extension; | ||
} | ||
} | ||
} | ||
function fileEncoding(file) { | ||
if (file.lastType != BUNDLE && !file.customFramework) { | ||
return DEFAULT_FILE_ENCODING; | ||
function defaultEncoding(fileRef) { | ||
var filetype = fileRef.lastKnownFileType || fileRef.explicitFileType, | ||
encoding = ENCODING_BY_FILETYPE[unquoted(filetype)]; | ||
if (encoding) { | ||
return encoding; | ||
} | ||
} | ||
function defaultSourceTree(file) { | ||
if (( file.lastType == DYLIB || file.lastType == FRAMEWORK ) && !file.customFramework) { | ||
return 'SDKROOT'; | ||
} else { | ||
return DEFAULT_SOURCE_TREE; | ||
function detectGroup(fileRef) { | ||
var filetype = fileRef.lastKnownFileType || fileRef.explicitFileType, | ||
groupName = GROUP_BY_FILETYPE[unquoted(filetype)]; | ||
if (!groupName) { | ||
return DEFAULT_GROUP; | ||
} | ||
return groupName; | ||
} | ||
function correctPath(file, filepath) { | ||
if (file.lastType == FRAMEWORK && !file.customFramework) { | ||
return 'System/Library/Frameworks/' + filepath; | ||
} else if (file.lastType == DYLIB) { | ||
return 'usr/lib/' + filepath; | ||
} else { | ||
return filepath; | ||
function detectSourcetree(fileRef) { | ||
var filetype = fileRef.lastKnownFileType || fileRef.explicitFileType, | ||
sourcetree = SOURCETREE_BY_FILETYPE[unquoted(filetype)]; | ||
if (fileRef.explicitFileType) { | ||
return DEFAULT_PRODUCT_SOURCETREE; | ||
} | ||
if (fileRef.customFramework) { | ||
return DEFAULT_SOURCETREE; | ||
} | ||
if (!sourcetree) { | ||
return DEFAULT_SOURCETREE; | ||
} | ||
return sourcetree; | ||
} | ||
function correctGroup(file) { | ||
if (file.lastType == SOURCE_FILE) { | ||
return 'Sources'; | ||
} else if (file.lastType == DYLIB || file.lastType == ARCHIVE || file.lastType == FRAMEWORK) { | ||
return 'Frameworks'; | ||
} else { | ||
return 'Resources'; | ||
function defaultPath(fileRef, filePath) { | ||
var filetype = fileRef.lastKnownFileType || fileRef.explicitFileType, | ||
defaultPath = PATH_BY_FILETYPE[unquoted(filetype)]; | ||
if (fileRef.customFramework) { | ||
return filePath; | ||
} | ||
if (defaultPath) { | ||
return path.join(defaultPath, path.basename(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 || {}; | ||
self = this; | ||
this.lastType = opt.lastType || detectLastType(filepath); | ||
this.lastKnownFileType = opt.lastKnownFileType || detectType(filepath); | ||
this.group = detectGroup(self); | ||
// for custom frameworks | ||
if(opt.customFramework == true) { | ||
this.customFramework = true; | ||
this.dirname = path.dirname(filepath); | ||
if (opt.customFramework == true) { | ||
this.customFramework = true; | ||
this.dirname = path.dirname(filepath); | ||
} | ||
this.basename = path.basename(filepath); | ||
this.path = correctPath(this, filepath); | ||
this.group = correctGroup(this); | ||
this.path = defaultPath(this, filepath); | ||
this.fileEncoding = this.defaultEncoding = opt.defaultEncoding || defaultEncoding(self); | ||
this.sourceTree = opt.sourceTree || defaultSourceTree(this); | ||
this.fileEncoding = opt.fileEncoding || fileEncoding(this); | ||
if (opt.weak && opt.weak === true) | ||
this.settings = { ATTRIBUTES: ['Weak'] }; | ||
// When referencing products / build output files | ||
if (opt.explicitFileType) { | ||
this.explicitFileType = opt.explicitFileType; | ||
this.basename = this.basename + '.' + defaultExtension(this); | ||
delete this.path; | ||
delete this.lastKnownFileType; | ||
delete this.group; | ||
delete this.defaultEncoding; | ||
} | ||
this.sourceTree = opt.sourceTree || detectSourcetree(self); | ||
this.includeInIndex = 0; | ||
if (opt.weak && opt.weak === true) | ||
this.settings = { ATTRIBUTES: ['Weak'] }; | ||
if (opt.compilerFlags) { | ||
if (!this.settings) | ||
this.settings = {}; | ||
this.settings.COMPILER_FLAGS = util.format('"%s"', opt.compilerFlags); | ||
this.settings = {}; | ||
this.settings.COMPILER_FLAGS = util.format('"%s"', opt.compilerFlags); | ||
} | ||
@@ -99,0 +192,0 @@ } |
@@ -22,6 +22,6 @@ var util = require('util'), | ||
pbxProject.prototype.parse = function (cb) { | ||
pbxProject.prototype.parse = function(cb) { | ||
var worker = fork(__dirname + '/parseJob.js', [this.filepath]) | ||
worker.on('message', function (msg) { | ||
worker.on('message', function(msg) { | ||
if (msg.name == 'SyntaxError' || msg.code) { | ||
@@ -43,3 +43,3 @@ this.emit('error', msg); | ||
pbxProject.prototype.parseSync = function () { | ||
pbxProject.prototype.parseSync = function() { | ||
var file_contents = fs.readFileSync(this.filepath, 'utf-8'); | ||
@@ -51,3 +51,3 @@ | ||
pbxProject.prototype.writeSync = function () { | ||
pbxProject.prototype.writeSync = function() { | ||
this.writer = new pbxWriter(this.hash); | ||
@@ -57,3 +57,3 @@ return this.writer.writeSync(); | ||
pbxProject.prototype.allUuids = function () { | ||
pbxProject.prototype.allUuids = function() { | ||
var sections = this.hash.project.objects, | ||
@@ -68,3 +68,3 @@ uuids = [], | ||
uuids = uuids.filter(function (str) { | ||
uuids = uuids.filter(function(str) { | ||
return !COMMENT_KEY.test(str) && str.length == 24; | ||
@@ -76,7 +76,7 @@ }); | ||
pbxProject.prototype.generateUuid = function () { | ||
pbxProject.prototype.generateUuid = function() { | ||
var id = uuid.v4() | ||
.replace(/-/g,'') | ||
.substr(0,24) | ||
.toUpperCase() | ||
.replace(/-/g, '') | ||
.substr(0, 24) | ||
.toUpperCase() | ||
@@ -90,3 +90,3 @@ if (this.allUuids().indexOf(id) >= 0) { | ||
pbxProject.prototype.addPluginFile = function (path, opt) { | ||
pbxProject.prototype.addPluginFile = function(path, opt) { | ||
var file = new pbxFile(path, opt); | ||
@@ -108,3 +108,3 @@ | ||
pbxProject.prototype.removePluginFile = function (path, opt) { | ||
pbxProject.prototype.removePluginFile = function(path, opt) { | ||
var file = new pbxFile(path, opt); | ||
@@ -119,6 +119,42 @@ correctForPluginsPath(file, this); | ||
pbxProject.prototype.addProductFile = function(targetPath, opt) { | ||
var file = new pbxFile(targetPath, opt); | ||
pbxProject.prototype.addSourceFile = function (path, opt) { | ||
var file = this.addPluginFile(path, opt); | ||
file.includeInIndex = 0; | ||
file.fileRef = this.generateUuid(); | ||
file.target = opt ? opt.target : undefined; | ||
file.group = opt ? opt.group : undefined; | ||
file.uuid = this.generateUuid(); | ||
file.path = file.basename; | ||
this.addToPbxFileReferenceSection(file); | ||
this.addToProductsPbxGroup(file); // PBXGroup | ||
return file; | ||
} | ||
pbxProject.prototype.removeProductFile = function(path, opt) { | ||
var file = new pbxFile(path, opt); | ||
this.removeFromProductsPbxGroup(file); // PBXGroup | ||
return file; | ||
} | ||
/** | ||
* | ||
* @param path {String} | ||
* @param opt {Object} see pbxFile for avail options | ||
* @param group {String} group key | ||
* @returns {Object} file; see pbxFile | ||
*/ | ||
pbxProject.prototype.addSourceFile = function (path, opt, group) { | ||
var file; | ||
if (group) { | ||
file = this.addFile(path, group, opt); | ||
} | ||
else { | ||
file = this.addPluginFile(path, opt); | ||
} | ||
if (!file) return false; | ||
@@ -135,5 +171,17 @@ | ||
pbxProject.prototype.removeSourceFile = function (path, opt) { | ||
var file = this.removePluginFile(path, opt) | ||
/** | ||
* | ||
* @param path {String} | ||
* @param opt {Object} see pbxFile for avail options | ||
* @param group {String} group key | ||
* @returns {Object} file; see pbxFile | ||
*/ | ||
pbxProject.prototype.removeSourceFile = function (path, opt, group) { | ||
var file; | ||
if (group) { | ||
file = this.removeFile(path, group, opt); | ||
} | ||
else { | ||
file = this.removePluginFile(path, opt); | ||
} | ||
file.target = opt ? opt.target : undefined; | ||
@@ -146,11 +194,35 @@ this.removeFromPbxBuildFileSection(file); // PBXBuildFile | ||
pbxProject.prototype.addHeaderFile = function (path, opt) { | ||
return this.addPluginFile(path, opt) | ||
/** | ||
* | ||
* @param path {String} | ||
* @param opt {Object} see pbxFile for avail options | ||
* @param group {String} group key | ||
* @returns {Object} file; see pbxFile | ||
*/ | ||
pbxProject.prototype.addHeaderFile = function (path, opt, group) { | ||
if (group) { | ||
return this.addFile(path, group, opt); | ||
} | ||
else { | ||
return this.addPluginFile(path, opt); | ||
} | ||
} | ||
pbxProject.prototype.removeHeaderFile = function (path, opt) { | ||
return this.removePluginFile(path, opt) | ||
/** | ||
* | ||
* @param path {String} | ||
* @param opt {Object} see pbxFile for avail options | ||
* @param group {String} group key | ||
* @returns {Object} file; see pbxFile | ||
*/ | ||
pbxProject.prototype.removeHeaderFile = function (path, opt, group) { | ||
if (group) { | ||
return this.removeFile(path, group, opt); | ||
} | ||
else { | ||
return this.removePluginFile(path, opt); | ||
} | ||
} | ||
pbxProject.prototype.addResourceFile = function (path, opt) { | ||
pbxProject.prototype.addResourceFile = function(path, opt) { | ||
opt = opt || {}; | ||
@@ -187,6 +259,6 @@ | ||
pbxProject.prototype.removeResourceFile = function (path, opt) { | ||
pbxProject.prototype.removeResourceFile = function(path, opt) { | ||
var file = new pbxFile(path, opt); | ||
file.target = opt ? opt.target : undefined; | ||
correctForResourcesPath(file, this); | ||
@@ -198,15 +270,15 @@ | ||
this.removeFromPbxResourcesBuildPhase(file); // PBXResourcesBuildPhase | ||
return file; | ||
} | ||
pbxProject.prototype.addFramework = function (fpath, opt) { | ||
pbxProject.prototype.addFramework = function(fpath, opt) { | ||
var file = new pbxFile(fpath, opt); | ||
// catch duplicates | ||
if (this.hasFile(file.path)) return false; | ||
file.uuid = this.generateUuid(); | ||
file.fileRef = this.generateUuid(); | ||
file.fileRef = this.generateUuid(); | ||
file.target = opt ? opt.target : undefined; | ||
if (this.hasFile(file.path)) return false; | ||
@@ -217,5 +289,5 @@ this.addToPbxBuildFileSection(file); // PBXBuildFile | ||
this.addToPbxFrameworksBuildPhase(file); // PBXFrameworksBuildPhase | ||
if(opt && opt.customFramework == true) { | ||
this.addToFrameworkSearchPaths(file); | ||
if (opt && opt.customFramework == true) { | ||
this.addToFrameworkSearchPaths(file); | ||
} | ||
@@ -226,3 +298,3 @@ | ||
pbxProject.prototype.removeFramework = function (fpath, opt) { | ||
pbxProject.prototype.removeFramework = function(fpath, opt) { | ||
var file = new pbxFile(fpath, opt); | ||
@@ -235,5 +307,5 @@ file.target = opt ? opt.target : undefined; | ||
this.removeFromPbxFrameworksBuildPhase(file); // PBXFrameworksBuildPhase | ||
if(opt && opt.customFramework) { | ||
this.removeFromFrameworkSearchPaths(path.dirname(fpath)); | ||
if (opt && opt.customFramework) { | ||
this.removeFromFrameworkSearchPaths(path.dirname(fpath)); | ||
} | ||
@@ -244,3 +316,52 @@ | ||
pbxProject.prototype.addStaticLibrary = function (path, opt) { | ||
pbxProject.prototype.addCopyfile = function(fpath, opt) { | ||
var file = new pbxFile(fpath, opt); | ||
// catch duplicates | ||
if (this.hasFile(file.path)) { | ||
file = this.hasFile(file.path); | ||
} | ||
file.fileRef = file.uuid = this.generateUuid(); | ||
file.target = opt ? opt.target : undefined; | ||
this.addToPbxBuildFileSection(file); // PBXBuildFile | ||
this.addToPbxFileReferenceSection(file); // PBXFileReference | ||
this.addToPbxCopyfilesBuildPhase(file); // PBXCopyFilesBuildPhase | ||
return file; | ||
} | ||
pbxProject.prototype.pbxCopyfilesBuildPhaseObj = function(target) { | ||
return this.buildPhaseObject('PBXCopyFilesBuildPhase', 'Copy Files', target); | ||
} | ||
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) { | ||
var file = new pbxFile(fpath, opt); | ||
file.target = opt ? opt.target : undefined; | ||
this.removeFromPbxBuildFileSection(file); // PBXBuildFile | ||
this.removeFromPbxFileReferenceSection(file); // PBXFileReference | ||
this.removeFromPbxCopyfilesBuildPhase(file); // PBXFrameworksBuildPhase | ||
return file; | ||
} | ||
pbxProject.prototype.removeFromPbxCopyfilesBuildPhase = function(file) { | ||
var sources = this.pbxCopyfilesBuildPhaseObj(file.target); | ||
for (i in sources.files) { | ||
if (sources.files[i].comment == longComment(file)) { | ||
sources.files.splice(i, 1); | ||
break; | ||
} | ||
} | ||
} | ||
pbxProject.prototype.addStaticLibrary = function(path, opt) { | ||
opt = opt || {}; | ||
@@ -274,3 +395,3 @@ | ||
// helper addition functions | ||
pbxProject.prototype.addToPbxBuildFileSection = function (file) { | ||
pbxProject.prototype.addToPbxBuildFileSection = function(file) { | ||
var commentKey = f("%s_comment", file.uuid); | ||
@@ -282,7 +403,7 @@ | ||
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) { | ||
for (uuid in this.pbxBuildFileSection()) { | ||
if (this.pbxBuildFileSection()[uuid].fileRef_comment == file.basename) { | ||
file.uuid = uuid; | ||
@@ -296,3 +417,71 @@ delete this.pbxBuildFileSection()[uuid]; | ||
pbxProject.prototype.addToPbxFileReferenceSection = function (file) { | ||
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 : '"<group>"' | ||
}, | ||
fileReferenceSection = this.pbxFileReferenceSection(), | ||
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]; | ||
filePathToReference[fileReference.path] = { fileRef: fileReferenceKey, basename: fileReferenceSection[key] }; | ||
} | ||
for (var index = 0; index < filePathsArray.length; index++) { | ||
var filePath = filePathsArray[index], | ||
filePathQuoted = "\"" + filePath + "\""; | ||
if (filePathToReference[filePath]) { | ||
pbxGroup.children.push(pbxGroupChild(filePathToReference[filePath])); | ||
continue; | ||
} else if (filePathToReference[filePathQuoted]) { | ||
pbxGroup.children.push(pbxGroupChild(filePathToReference[filePathQuoted])); | ||
continue; | ||
} | ||
var file = new pbxFile(filePath); | ||
file.uuid = this.generateUuid(); | ||
file.fileRef = this.generateUuid(); | ||
this.addToPbxFileReferenceSection(file); // PBXFileReference | ||
this.addToPbxBuildFileSection(file); // PBXBuildFile | ||
pbxGroup.children.push(pbxGroupChild(file)); | ||
} | ||
if (groups) { | ||
groups[pbxGroupUuid] = pbxGroup; | ||
groups[commentKey] = name; | ||
} | ||
return { uuid: pbxGroupUuid, pbxGroup: pbxGroup }; | ||
} | ||
pbxProject.prototype.addToPbxProjectSection = function(target) { | ||
var newTarget = { | ||
value: target.uuid, | ||
comment: pbxNativeTargetComment(target.pbxNativeTarget) | ||
}; | ||
this.pbxProjectSection()[this.getFirstProject()['uuid']]['targets'].push(newTarget); | ||
} | ||
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); | ||
@@ -304,11 +493,11 @@ | ||
pbxProject.prototype.removeFromPbxFileReferenceSection = function (file) { | ||
pbxProject.prototype.removeFromPbxFileReferenceSection = function(file) { | ||
var i; | ||
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 (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; | ||
@@ -320,3 +509,3 @@ delete this.pbxFileReferenceSection()[i]; | ||
var commentKey = f("%s_comment", file.fileRef); | ||
if(this.pbxFileReferenceSection()[commentKey] != undefined) { | ||
if (this.pbxFileReferenceSection()[commentKey] != undefined) { | ||
delete this.pbxFileReferenceSection()[commentKey]; | ||
@@ -328,3 +517,3 @@ } | ||
pbxProject.prototype.addToPluginsPbxGroup = function (file) { | ||
pbxProject.prototype.addToPluginsPbxGroup = function(file) { | ||
var pluginsGroup = this.pbxGroupByName('Plugins'); | ||
@@ -334,7 +523,7 @@ pluginsGroup.children.push(pbxGroupChild(file)); | ||
pbxProject.prototype.removeFromPluginsPbxGroup = function (file) { | ||
pbxProject.prototype.removeFromPluginsPbxGroup = function(file) { | ||
var pluginsGroupChildren = this.pbxGroupByName('Plugins').children, i; | ||
for(i in pluginsGroupChildren) { | ||
if(pbxGroupChild(file).value == pluginsGroupChildren[i].value && | ||
pbxGroupChild(file).comment == pluginsGroupChildren[i].comment) { | ||
for (i in pluginsGroupChildren) { | ||
if (pbxGroupChild(file).value == pluginsGroupChildren[i].value && | ||
pbxGroupChild(file).comment == pluginsGroupChildren[i].comment) { | ||
pluginsGroupChildren.splice(i, 1); | ||
@@ -346,3 +535,3 @@ break; | ||
pbxProject.prototype.addToResourcesPbxGroup = function (file) { | ||
pbxProject.prototype.addToResourcesPbxGroup = function(file) { | ||
var pluginsGroup = this.pbxGroupByName('Resources'); | ||
@@ -352,7 +541,7 @@ pluginsGroup.children.push(pbxGroupChild(file)); | ||
pbxProject.prototype.removeFromResourcesPbxGroup = function (file) { | ||
pbxProject.prototype.removeFromResourcesPbxGroup = function(file) { | ||
var pluginsGroupChildren = this.pbxGroupByName('Resources').children, i; | ||
for(i in pluginsGroupChildren) { | ||
if(pbxGroupChild(file).value == pluginsGroupChildren[i].value && | ||
pbxGroupChild(file).comment == pluginsGroupChildren[i].comment) { | ||
for (i in pluginsGroupChildren) { | ||
if (pbxGroupChild(file).value == pluginsGroupChildren[i].value && | ||
pbxGroupChild(file).comment == pluginsGroupChildren[i].comment) { | ||
pluginsGroupChildren.splice(i, 1); | ||
@@ -364,3 +553,3 @@ break; | ||
pbxProject.prototype.addToFrameworksPbxGroup = function (file) { | ||
pbxProject.prototype.addToFrameworksPbxGroup = function(file) { | ||
var pluginsGroup = this.pbxGroupByName('Frameworks'); | ||
@@ -370,8 +559,8 @@ pluginsGroup.children.push(pbxGroupChild(file)); | ||
pbxProject.prototype.removeFromFrameworksPbxGroup = function (file) { | ||
pbxProject.prototype.removeFromFrameworksPbxGroup = function(file) { | ||
var pluginsGroupChildren = this.pbxGroupByName('Frameworks').children; | ||
for(i in pluginsGroupChildren) { | ||
if(pbxGroupChild(file).value == pluginsGroupChildren[i].value && | ||
pbxGroupChild(file).comment == pluginsGroupChildren[i].comment) { | ||
for (i in pluginsGroupChildren) { | ||
if (pbxGroupChild(file).value == pluginsGroupChildren[i].value && | ||
pbxGroupChild(file).comment == pluginsGroupChildren[i].comment) { | ||
pluginsGroupChildren.splice(i, 1); | ||
@@ -382,3 +571,21 @@ break; | ||
} | ||
pbxProject.prototype.addToPbxSourcesBuildPhase = function (file) { | ||
pbxProject.prototype.addToProductsPbxGroup = function(file) { | ||
var productsGroup = this.pbxGroupByName('Products'); | ||
productsGroup.children.push(pbxGroupChild(file)); | ||
} | ||
pbxProject.prototype.removeFromProductsPbxGroup = function(file) { | ||
var productsGroupChildren = this.pbxGroupByName('Products').children, i; | ||
for (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) { | ||
var sources = this.pbxSourcesBuildPhaseObj(file.target); | ||
@@ -388,9 +595,9 @@ sources.files.push(pbxBuildPhaseObj(file)); | ||
pbxProject.prototype.removeFromPbxSourcesBuildPhase = function (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)) { | ||
for (i in sources.files) { | ||
if (sources.files[i].comment == longComment(file)) { | ||
sources.files.splice(i, 1); | ||
break; | ||
break; | ||
} | ||
@@ -400,3 +607,3 @@ } | ||
pbxProject.prototype.addToPbxResourcesBuildPhase = function (file) { | ||
pbxProject.prototype.addToPbxResourcesBuildPhase = function(file) { | ||
var sources = this.pbxResourcesBuildPhaseObj(file.target); | ||
@@ -406,7 +613,7 @@ sources.files.push(pbxBuildPhaseObj(file)); | ||
pbxProject.prototype.removeFromPbxResourcesBuildPhase = function (file) { | ||
pbxProject.prototype.removeFromPbxResourcesBuildPhase = function(file) { | ||
var sources = this.pbxResourcesBuildPhaseObj(file.target), i; | ||
for(i in sources.files) { | ||
if(sources.files[i].comment == longComment(file)) { | ||
for (i in sources.files) { | ||
if (sources.files[i].comment == longComment(file)) { | ||
sources.files.splice(i, 1); | ||
@@ -418,3 +625,3 @@ break; | ||
pbxProject.prototype.addToPbxFrameworksBuildPhase = function (file) { | ||
pbxProject.prototype.addToPbxFrameworksBuildPhase = function(file) { | ||
var sources = this.pbxFrameworksBuildPhaseObj(file.target); | ||
@@ -424,6 +631,6 @@ 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 (i in sources.files) { | ||
if (sources.files[i].comment == longComment(file)) { | ||
sources.files.splice(i, 1); | ||
@@ -435,20 +642,188 @@ 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 | ||
}; | ||
for (var index = 0; index < configurationObjectsArray.length; index++) { | ||
var configuration = configurationObjectsArray[index], | ||
configurationUuid = this.generateUuid(), | ||
configurationCommentKey = f("%s_comment", configurationUuid); | ||
pbxBuildConfigurationSection[configurationUuid] = configuration; | ||
pbxBuildConfigurationSection[configurationCommentKey] = configuration.name; | ||
xcConfigurationList.buildConfigurations.push({ value: configurationUuid, comment: configuration.name }); | ||
} | ||
if (pbxXCConfigurationListSection) { | ||
pbxXCConfigurationListSection[xcConfigurationListUuid] = xcConfigurationList; | ||
pbxXCConfigurationListSection[commentKey] = comment; | ||
} | ||
return { uuid: xcConfigurationListUuid, xcConfigurationList: xcConfigurationList }; | ||
} | ||
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); | ||
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]; | ||
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 | ||
}; | ||
if (pbxContainerItemProxySection && pbxTargetDependencySection) { | ||
pbxContainerItemProxySection[itemProxyUuid] = itemProxy; | ||
pbxContainerItemProxySection[itemProxyCommentKey] = pbxContainerItemProxy; | ||
pbxTargetDependencySection[targetDependencyUuid] = targetDependency; | ||
pbxTargetDependencySection[targetDependencyCommentKey] = pbxTargetDependency; | ||
nativeTargets[target].dependencies.push({ value: targetDependencyUuid, comment: pbxTargetDependency }) | ||
} | ||
} | ||
return { uuid: target, target: nativeTargets[target] }; | ||
} | ||
pbxProject.prototype.addBuildPhase = function(filePathsArray, buildPhaseType, comment, target, folderType, 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 = {}; | ||
if (buildPhaseType === 'PBXCopyFilesBuildPhase') { | ||
buildPhase = pbxCopyFilesBuildPhaseObj(buildPhase, folderType, subfolderPath, comment); | ||
} | ||
if (!this.hash.project.objects[buildPhaseType]) { | ||
this.hash.project.objects[buildPhaseType] = new Object(); | ||
} | ||
if (!this.hash.project.objects[buildPhaseType][buildPhaseUuid]) { | ||
this.hash.project.objects[buildPhaseType][buildPhaseUuid] = buildPhase; | ||
this.hash.project.objects[buildPhaseType][commentKey] = comment; | ||
} | ||
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]; | ||
if (!fileReference) continue; | ||
var pbxFileObj = new pbxFile(fileReference.path); | ||
filePathToBuildFile[fileReference.path] = { uuid: buildFileKey, basename: pbxFileObj.basename, group: pbxFileObj.group }; | ||
} | ||
for (var index = 0; index < filePathsArray.length; index++) { | ||
var filePath = filePathsArray[index], | ||
filePathQuoted = "\"" + filePath + "\"", | ||
file = new pbxFile(filePath); | ||
if (filePathToBuildFile[filePath]) { | ||
buildPhase.files.push(pbxBuildPhaseObj(filePathToBuildFile[filePath])); | ||
continue; | ||
} else if (filePathToBuildFile[filePathQuoted]) { | ||
buildPhase.files.push(pbxBuildPhaseObj(filePathToBuildFile[filePathQuoted])); | ||
continue; | ||
} | ||
file.uuid = this.generateUuid(); | ||
file.fileRef = this.generateUuid(); | ||
this.addToPbxFileReferenceSection(file); // PBXFileReference | ||
this.addToPbxBuildFileSection(file); // PBXBuildFile | ||
buildPhase.files.push(pbxBuildPhaseObj(file)); | ||
} | ||
if (buildPhaseSection) { | ||
buildPhaseSection[buildPhaseUuid] = buildPhase; | ||
buildPhaseSection[commentKey] = comment; | ||
} | ||
return { uuid: buildPhaseUuid, buildPhase: buildPhase }; | ||
} | ||
// helper access functions | ||
pbxProject.prototype.pbxBuildFileSection = function () { | ||
pbxProject.prototype.pbxProjectSection = function() { | ||
return this.hash.project.objects['PBXProject']; | ||
} | ||
pbxProject.prototype.pbxBuildFileSection = function() { | ||
return this.hash.project.objects['PBXBuildFile']; | ||
} | ||
pbxProject.prototype.pbxXCBuildConfigurationSection = function () { | ||
pbxProject.prototype.pbxXCBuildConfigurationSection = function() { | ||
return this.hash.project.objects['XCBuildConfiguration']; | ||
} | ||
pbxProject.prototype.pbxFileReferenceSection = function () { | ||
pbxProject.prototype.pbxFileReferenceSection = function() { | ||
return this.hash.project.objects['PBXFileReference']; | ||
} | ||
pbxProject.prototype.pbxNativeTarget = function () { | ||
pbxProject.prototype.pbxNativeTargetSection = function() { | ||
return this.hash.project.objects['PBXNativeTarget']; | ||
} | ||
pbxProject.prototype.pbxXCConfigurationList = function () { | ||
pbxProject.prototype.pbxXCConfigurationList = function() { | ||
return this.hash.project.objects['XCConfigurationList']; | ||
@@ -470,3 +845,3 @@ } | ||
pbxProject.prototype.pbxGroupByName = function (name) { | ||
pbxProject.prototype.pbxGroupByName = function(name) { | ||
var groups = this.hash.project.objects['PBXGroup'], | ||
@@ -488,16 +863,37 @@ key, groupKey; | ||
pbxProject.prototype.pbxSourcesBuildPhaseObj = function (target) { | ||
pbxProject.prototype.pbxTargetByName = function(name) { | ||
return this.pbxItemByComment(name, 'PBXNativeTarget'); | ||
} | ||
pbxProject.prototype.pbxItemByComment = function(name, pbxSectionName) { | ||
var section = this.hash.project.objects[pbxSectionName], | ||
key, itemKey; | ||
for (key in section) { | ||
// only look for comments | ||
if (!COMMENT_KEY.test(key)) continue; | ||
if (section[key] == name) { | ||
itemKey = key.split(COMMENT_KEY)[0]; | ||
return section[itemKey]; | ||
} | ||
} | ||
return null; | ||
} | ||
pbxProject.prototype.pbxSourcesBuildPhaseObj = function(target) { | ||
return this.buildPhaseObject('PBXSourcesBuildPhase', 'Sources', target); | ||
} | ||
pbxProject.prototype.pbxResourcesBuildPhaseObj = function (target) { | ||
return this.buildPhaseObject('PBXResourcesBuildPhase', 'Resources',target); | ||
pbxProject.prototype.pbxResourcesBuildPhaseObj = function(target) { | ||
return this.buildPhaseObject('PBXResourcesBuildPhase', 'Resources', target); | ||
} | ||
pbxProject.prototype.pbxFrameworksBuildPhaseObj = function (target) { | ||
return this.buildPhaseObject('PBXFrameworksBuildPhase', 'Frameworks',target); | ||
pbxProject.prototype.pbxFrameworksBuildPhaseObj = function(target) { | ||
return this.buildPhaseObject('PBXFrameworksBuildPhase', 'Frameworks', target); | ||
} | ||
// Find Build Phase from group/target | ||
pbxProject.prototype.buildPhase = function (group,target) { | ||
pbxProject.prototype.buildPhase = function(group, target) { | ||
@@ -507,8 +903,8 @@ if (!target) | ||
var nativeTargets = this.pbxNativeTarget(); | ||
var nativeTargets = this.pbxNativeTargetSection(); | ||
if (typeof nativeTargets[target] == "undefined") | ||
throw new Error("Invalid target: "+target); | ||
throw new Error("Invalid target: " + target); | ||
var nativeTarget= nativeTargets[target]; | ||
var buildPhases = nativeTarget.buildPhases; | ||
var nativeTarget = nativeTargets[target]; | ||
var buildPhases = nativeTarget.buildPhases; | ||
for(var i in buildPhases) | ||
@@ -518,35 +914,70 @@ { | ||
if (buildPhase.comment==group) | ||
return buildPhase.value+"_comment"; | ||
} | ||
} | ||
return buildPhase.value + "_comment"; | ||
} | ||
} | ||
pbxProject.prototype.buildPhaseObject = function (name, group,target) { | ||
pbxProject.prototype.buildPhaseObject = function(name, group, target) { | ||
var section = this.hash.project.objects[name], | ||
obj, sectionKey, key; | ||
var buildPhase = this.buildPhase(group, target); | ||
var buildPhase = this.buildPhase(group,target); | ||
for (key in section) { | ||
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) { | ||
sectionKey = key.split(COMMENT_KEY)[0]; | ||
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.updateBuildProperty = function(prop, value) { | ||
var config = this.pbxXCBuildConfigurationSection(); | ||
propReplace(config, prop, value); | ||
for (key in configurations){ | ||
configuration = configurations[key]; | ||
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; | ||
for (key in configurations){ | ||
configuration = configurations[key]; | ||
if (configuration.buildSettings[prop] && | ||
!build_name || configuration.name === build_name){ | ||
delete configuration.buildSettings[prop]; | ||
} | ||
} | ||
} | ||
/** | ||
* | ||
* @param prop {String} | ||
* @param value {String|Array|Object|Number|Boolean} | ||
* @param build {String} Release or Debug | ||
*/ | ||
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) ) { | ||
config.buildSettings[prop] = value; | ||
} | ||
} | ||
} | ||
} | ||
pbxProject.prototype.updateProductName = function(name) { | ||
@@ -556,3 +987,3 @@ this.updateBuildProperty('PRODUCT_NAME', '"' + name + '"'); | ||
pbxProject.prototype.removeFromFrameworkSearchPaths = function (file) { | ||
pbxProject.prototype.removeFromFrameworkSearchPaths = function(file) { | ||
var configurations = nonComments(this.pbxXCBuildConfigurationSection()), | ||
@@ -585,3 +1016,3 @@ INHERITED = '"$(inherited)"', | ||
pbxProject.prototype.addToFrameworkSearchPaths = function (file) { | ||
pbxProject.prototype.addToFrameworkSearchPaths = function(file) { | ||
var configurations = nonComments(this.pbxXCBuildConfigurationSection()), | ||
@@ -598,3 +1029,3 @@ INHERITED = '"$(inherited)"', | ||
if (!buildSettings['FRAMEWORK_SEARCH_PATHS'] | ||
|| buildSettings['FRAMEWORK_SEARCH_PATHS'] === INHERITED) { | ||
|| buildSettings['FRAMEWORK_SEARCH_PATHS'] === INHERITED) { | ||
buildSettings['FRAMEWORK_SEARCH_PATHS'] = [INHERITED]; | ||
@@ -607,3 +1038,3 @@ } | ||
pbxProject.prototype.removeFromLibrarySearchPaths = function (file) { | ||
pbxProject.prototype.removeFromLibrarySearchPaths = function(file) { | ||
var configurations = nonComments(this.pbxXCBuildConfigurationSection()), | ||
@@ -636,3 +1067,3 @@ INHERITED = '"$(inherited)"', | ||
pbxProject.prototype.addToLibrarySearchPaths = function (file) { | ||
pbxProject.prototype.addToLibrarySearchPaths = function(file) { | ||
var configurations = nonComments(this.pbxXCBuildConfigurationSection()), | ||
@@ -649,3 +1080,3 @@ INHERITED = '"$(inherited)"', | ||
if (!buildSettings['LIBRARY_SEARCH_PATHS'] | ||
|| buildSettings['LIBRARY_SEARCH_PATHS'] === INHERITED) { | ||
|| buildSettings['LIBRARY_SEARCH_PATHS'] === INHERITED) { | ||
buildSettings['LIBRARY_SEARCH_PATHS'] = [INHERITED]; | ||
@@ -662,3 +1093,3 @@ } | ||
pbxProject.prototype.removeFromHeaderSearchPaths = function (file) { | ||
pbxProject.prototype.removeFromHeaderSearchPaths = function(file) { | ||
var configurations = nonComments(this.pbxXCBuildConfigurationSection()), | ||
@@ -688,3 +1119,3 @@ INHERITED = '"$(inherited)"', | ||
} | ||
pbxProject.prototype.addToHeaderSearchPaths = function (file) { | ||
pbxProject.prototype.addToHeaderSearchPaths = function(file) { | ||
var configurations = nonComments(this.pbxXCBuildConfigurationSection()), | ||
@@ -712,3 +1143,3 @@ INHERITED = '"$(inherited)"', | ||
// a JS getter. hmmm | ||
pbxProject.prototype.__defineGetter__("productName", function () { | ||
pbxProject.prototype.__defineGetter__("productName", function() { | ||
var configurations = nonComments(this.pbxXCBuildConfigurationSection()), | ||
@@ -727,3 +1158,3 @@ config, productName; | ||
// check if file is present | ||
pbxProject.prototype.hasFile = function (filePath) { | ||
pbxProject.prototype.hasFile = function(filePath) { | ||
var files = nonComments(this.pbxFileReferenceSection()), | ||
@@ -734,3 +1165,3 @@ file, id; | ||
if (file.path == filePath || file.path == ('"' + filePath + '"')) { | ||
return true; | ||
return file; | ||
} | ||
@@ -742,2 +1173,108 @@ } | ||
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(); | ||
// Check type against list of allowed target types | ||
if (!targetName) { | ||
throw new Error("Target name missing."); | ||
} | ||
// Check type against list of allowed target types | ||
if (!targetType) { | ||
throw new Error("Target type missing."); | ||
} | ||
// Check type against list of allowed target types | ||
if (!producttypeForTargettype(targetType)) { | ||
throw new Error("Target type invalid: " + targetType); | ||
} | ||
// Build Configuration: Create | ||
var buildConfigurationsList = [ | ||
{ | ||
name: 'Debug', | ||
isa: 'XCBuildConfiguration', | ||
buildSettings: { | ||
GCC_PREPROCESSOR_DEFINITIONS: ['"DEBUG=1"', '"$(inherited)"'], | ||
INFOPLIST_FILE: '"' + path.join(targetSubfolder, targetSubfolder + '-Info.plist' + '"'), | ||
LD_RUNPATH_SEARCH_PATHS: '"$(inherited) @executable_path/Frameworks @executable_path/../../Frameworks"', | ||
PRODUCT_NAME: '"' + targetName + '"', | ||
SKIP_INSTALL: 'YES' | ||
} | ||
}, | ||
{ | ||
name: 'Release', | ||
isa: 'XCBuildConfiguration', | ||
buildSettings: { | ||
INFOPLIST_FILE: '"' + path.join(targetSubfolder, targetSubfolder + '-Info.plist' + '"'), | ||
LD_RUNPATH_SEARCH_PATHS: '"$(inherited) @executable_path/Frameworks @executable_path/../../Frameworks"', | ||
PRODUCT_NAME: '"' + targetName + '"', | ||
SKIP_INSTALL: 'YES' | ||
} | ||
} | ||
]; | ||
// Build Configuration: Add | ||
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; | ||
// 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: [] | ||
} | ||
}; | ||
// Target: Add to PBXNativeTarget section | ||
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) | ||
// Add product to CopyFiles phase | ||
this.addToPbxCopyfilesBuildPhase(productFile) | ||
// this.addBuildPhaseToTarget(newPhase.buildPhase, this.getFirstTarget().uuid) | ||
}; | ||
// Target: Add uuid to root project | ||
this.addToPbxProjectSection(target); | ||
// Target: Add dependency for this target to first (main) target | ||
this.addTargetDependency(this.getFirstTarget().uuid, [target.uuid]); | ||
// Return target on success | ||
return target; | ||
}; | ||
// helper recursive prop search+replace | ||
@@ -770,16 +1307,14 @@ function propReplace(obj, prop, value) { | ||
function pbxFileReferenceObj(file) { | ||
var obj = Object.create(null); | ||
var fileObject = { | ||
isa: "PBXFileReference", | ||
name: "\"" + file.basename + "\"", | ||
path: "\"" + file.path.replace(/\\/g, '/') + "\"", | ||
sourceTree: file.sourceTree, | ||
fileEncoding: file.fileEncoding, | ||
lastKnownFileType: file.lastKnownFileType, | ||
explicitFileType: file.explicitFileType, | ||
includeInIndex: file.includeInIndex | ||
}; | ||
obj.isa = 'PBXFileReference'; | ||
obj.lastKnownFileType = file.lastType; | ||
obj.name = "\"" + file.basename + "\""; | ||
obj.path = "\"" + file.path.replace(/\\/g, '/') + "\""; | ||
obj.sourceTree = file.sourceTree; | ||
if (file.fileEncoding) | ||
obj.fileEncoding = file.fileEncoding; | ||
return obj; | ||
return fileObject; | ||
} | ||
@@ -805,2 +1340,38 @@ | ||
function pbxCopyFilesBuildPhaseObj(obj, folderType, subfolderPath, phaseName){ | ||
// Add additional properties for 'CopyFiles' build phase | ||
var DESTINATION_BY_TARGETTYPE = { | ||
application: 'wrapper', | ||
app_extension: 'plugins', | ||
bundle: 'wrapper', | ||
command_line_tool: 'wrapper', | ||
dynamic_library: 'products_directory', | ||
framework: 'shared_frameworks', | ||
static_library: 'products_directory', | ||
unit_test_bundle: 'wrapper', | ||
watch_app: 'wrapper', | ||
watch_extension: 'plugins' | ||
} | ||
var SUBFOLDERSPEC_BY_DESTINATION = { | ||
absolute_path: 0, | ||
executables: 6, | ||
frameworks: 10, | ||
java_resources: 15, | ||
plugins: 13, | ||
products_directory: 16, | ||
resources: 7, | ||
shared_frameworks: 11, | ||
shared_support: 12, | ||
wrapper: 1, | ||
xpc_services: 0 | ||
} | ||
obj.name = '"' + phaseName + '"'; | ||
obj.dstPath = subfolderPath || '""'; | ||
obj.dstSubfolderSpec = SUBFOLDERSPEC_BY_DESTINATION[DESTINATION_BY_TARGETTYPE[folderType]]; | ||
return obj; | ||
} | ||
function pbxBuildFileComment(file) { | ||
@@ -811,5 +1382,9 @@ return longComment(file); | ||
function pbxFileReferenceComment(file) { | ||
return file.basename; | ||
return file.basename || path.basename(file.path); | ||
} | ||
function pbxNativeTargetComment(target) { | ||
return target.name; | ||
} | ||
function longComment(file) { | ||
@@ -878,2 +1453,239 @@ return f("%s in %s", file.basename, file.group); | ||
function buildPhaseNameForIsa (isa) { | ||
BUILDPHASENAME_BY_ISA = { | ||
PBXCopyFilesBuildPhase: 'Copy Files', | ||
PBXResourcesBuildPhase: 'Resources', | ||
PBXSourcesBuildPhase: 'Sources', | ||
PBXFrameworksBuildPhase: 'Frameworks' | ||
} | ||
return BUILDPHASENAME_BY_ISA[isa] | ||
} | ||
function producttypeForTargettype (targetType) { | ||
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', | ||
watch_extension: 'com.apple.product-type.watchkit-extension' | ||
}; | ||
return PRODUCTTYPE_BY_TARGETTYPE[targetType] | ||
} | ||
function filetypeForProducttype (productType) { | ||
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.watchkit-extension': '"wrapper.app-extension"' | ||
}; | ||
return FILETYPE_BY_PRODUCTTYPE[productType] | ||
} | ||
pbxProject.prototype.getFirstProject = function() { | ||
// Get pbxProject container | ||
var pbxProjectContainer = this.pbxProjectSection(); | ||
// Get first pbxProject UUID | ||
var firstProjectUuid = Object.keys(pbxProjectContainer)[0]; | ||
// Get first pbxProject | ||
var firstProject = pbxProjectContainer[firstProjectUuid]; | ||
return { | ||
uuid: firstProjectUuid, | ||
firstProject: firstProject | ||
} | ||
} | ||
pbxProject.prototype.getFirstTarget = function() { | ||
// Get first targets UUID | ||
var firstTargetUuid = this.getFirstProject()['firstProject']['targets'][0].value; | ||
// Get first pbxNativeTarget | ||
var firstTarget = this.pbxNativeTargetSection()[firstTargetUuid]; | ||
return { | ||
uuid: firstTargetUuid, | ||
firstTarget: firstTarget | ||
} | ||
} | ||
/*** NEW ***/ | ||
pbxProject.prototype.addToPbxGroup = function (file, groupKey) { | ||
var group = this.getPBXGroupByKey(groupKey); | ||
if (group && group.children !== undefined) { | ||
if (typeof file === 'string') { | ||
//Group Key | ||
var childGroup = { | ||
value:file, | ||
comment: this.getPBXGroupByKey(file).name | ||
}; | ||
group.children.push(childGroup); | ||
} | ||
else { | ||
//File Object | ||
group.children.push(pbxGroupChild(file)); | ||
} | ||
} | ||
} | ||
pbxProject.prototype.removeFromPbxGroup = function (file, groupKey) { | ||
var group = this.getPBXGroupByKey(groupKey); | ||
if (group) { | ||
var groupChildren = group.children, i; | ||
for(i in groupChildren) { | ||
if(pbxGroupChild(file).value == groupChildren[i].value && | ||
pbxGroupChild(file).comment == groupChildren[i].comment) { | ||
groupChildren.splice(i, 1); | ||
break; | ||
} | ||
} | ||
} | ||
} | ||
pbxProject.prototype.getPBXGroupByKey = function(key) { | ||
return this.hash.project.objects['PBXGroup'][key]; | ||
}; | ||
pbxProject.prototype.findPBXGroupKey = function(criteria) { | ||
var groups = this.hash.project.objects['PBXGroup']; | ||
var target; | ||
for (var key in groups) { | ||
// only look for comments | ||
if (COMMENT_KEY.test(key)) continue; | ||
var group = groups[key]; | ||
if (criteria && criteria.path && criteria.name) { | ||
if (criteria.path === group.path && criteria.name === group.name) { | ||
target = key; | ||
break | ||
} | ||
} | ||
else if (criteria && criteria.path) { | ||
if (criteria.path === group.path) { | ||
target = key; | ||
break | ||
} | ||
} | ||
else if (criteria && criteria.name) { | ||
if (criteria.name === group.name) { | ||
target = key; | ||
break | ||
} | ||
} | ||
} | ||
return target; | ||
} | ||
pbxProject.prototype.pbxCreateGroup = function(name, pathName) { | ||
//Create object | ||
var model = { | ||
isa:"PBXGroup", | ||
children: [], | ||
name: name, | ||
path: pathName, | ||
sourceTree: '"<group>"' | ||
}; | ||
var key = this.generateUuid(); | ||
//Create comment | ||
var commendId = key + '_comment'; | ||
//add obj and commentObj to groups; | ||
var groups = this.hash.project.objects['PBXGroup']; | ||
groups[commendId] = name; | ||
groups[key] = model; | ||
return key; | ||
} | ||
pbxProject.prototype.getPBXObject = function(name) { | ||
return this.hash.project.objects[name]; | ||
} | ||
pbxProject.prototype.addFile = function (path, group, opt) { | ||
var file = new pbxFile(path, opt); | ||
// null is better for early errors | ||
if (this.hasFile(file.path)) return null; | ||
file.fileRef = this.generateUuid(); | ||
this.addToPbxFileReferenceSection(file); // PBXFileReference | ||
this.addToPbxGroup(file, group); // PBXGroup | ||
return file; | ||
} | ||
pbxProject.prototype.removeFile = function (path, group, opt) { | ||
var file = new pbxFile(path, opt); | ||
this.removeFromPbxFileReferenceSection(file); // PBXFileReference | ||
this.removeFromPbxGroup(file, group); // PBXGroup | ||
return file; | ||
} | ||
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 (config.buildSettings[prop] !== undefined) { | ||
target = config.buildSettings[prop]; | ||
} | ||
} | ||
} | ||
} | ||
return target; | ||
} | ||
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) { | ||
target[configName] = config; | ||
} | ||
} | ||
} | ||
return target; | ||
} | ||
module.exports = pbxProject; |
Sorry, the diff of this file is not supported yet
221162
4709