Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions .eslintrc.yml
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@
under the License.
*/

exports.project = require('./lib/pbxProject')
exports.project = require('./lib/pbxProject');
10 changes: 6 additions & 4 deletions lib/parseJob.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
209 changes: 97 additions & 112 deletions lib/pbxFile.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,80 +15,81 @@
under the License.
*/

var path = require('path'),
util = require('util');
var path = require('path');

var DEFAULT_SOURCETREE = '"<group>"',
DEFAULT_PRODUCT_SOURCETREE = 'BUILT_PRODUCTS_DIR',
DEFAULT_FILEENCODING = 4,
DEFAULT_GROUP = 'Resources',
DEFAULT_FILETYPE = 'unknown';
var util = require('util');
var DEFAULT_SOURCETREE = '"<group>"';
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;
Expand All @@ -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; }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ugh, why does the auto-fix format that onto one line 😒 There are a few instances of changes like this. No deal breakers but not pretty either.

}
}
}

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';
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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, '/');
}
Expand All @@ -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');
}
}

Expand Down
Loading