Skip to content

Commit 2d2d88e

Browse files
committed
fix (pbxFile): Fixed minor issues in pbxFile. Streamlined file quoting style via quote normaliser function.
2 parents 5db21ba + 8155233 commit 2d2d88e

File tree

1 file changed

+39
-22
lines changed

1 file changed

+39
-22
lines changed

lib/pbxFile.js

Lines changed: 39 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ var FILETYPE_BY_EXTENSION = {
3434
'archive.ar': 'Frameworks',
3535
'compiled.mach-o.dylib': 'Frameworks',
3636
'wrapper.framework': 'Frameworks',
37-
'sourcecode.c.h': 'Sources',
37+
'sourcecode.c.h': 'Resources',
3838
'sourcecode.c.objc': 'Sources',
3939
'sourcecode.swift': 'Sources'
4040
},
@@ -58,38 +58,44 @@ var FILETYPE_BY_EXTENSION = {
5858
};
5959

6060

61+
function unquoted(text){
62+
return text.replace (/(^")|("$)/g, '')
63+
}
64+
6165
function detectType(filePath) {
62-
var extension = path.extname(filePath),
63-
type = FILETYPE_BY_EXTENSION[extension];
66+
var extension = path.extname(filePath).substring(1),
67+
filetype = FILETYPE_BY_EXTENSION[unquoted(extension)];
6468

65-
if (!type) {
69+
if (!filetype) {
6670
return DEFAULT_FILETYPE;
6771
}
6872

69-
return type;
73+
return filetype;
7074
}
7175

7276
function defaultExtension(fileRef) {
73-
var filetype = fileRef.explicitFileType.replace(/^"|"$/g, '');
77+
var filetype = fileRef.lastKnownFileType || fileRef.explicitFileType;
7478

7579
for(var extension in FILETYPE_BY_EXTENSION) {
76-
if(FILETYPE_BY_EXTENSION.hasOwnProperty(extension) ) {
77-
if(FILETYPE_BY_EXTENSION[extension] === filetype )
80+
if(FILETYPE_BY_EXTENSION.hasOwnProperty(unquoted(extension)) ) {
81+
if(FILETYPE_BY_EXTENSION[unquoted(extension)] === filetype )
7882
return extension;
7983
}
8084
}
8185
}
8286

8387
function defaultEncoding(fileRef) {
84-
var encoding = ENCODING_BY_FILETYPE[fileRef.lastKnownFileType];
88+
var filetype = fileRef.lastKnownFileType || fileRef.explicitFileType,
89+
encoding = ENCODING_BY_FILETYPE[unquoted(filetype)];
8590

8691
if (encoding) {
8792
return encoding;
8893
}
8994
}
9095

91-
function defaultGroup(fileRef) {
92-
var groupName = GROUP_BY_FILETYPE[fileRef.lastKnownFileType];
96+
function detectGroup(fileRef) {
97+
var filetype = fileRef.lastKnownFileType || fileRef.explicitFileType,
98+
groupName = GROUP_BY_FILETYPE[unquoted(filetype)];
9399

94100
if (!groupName) {
95101
return DEFAULT_GROUP;
@@ -98,28 +104,36 @@ function defaultGroup(fileRef) {
98104
return groupName;
99105
}
100106

101-
function defaultSourcetree(fileRef) {
102-
var sourcetree = SOURCETREE_BY_FILETYPE[fileRef.lastKnownFileType];
103-
104-
if (fileRef.customFramework) {
105-
return filePath;
106-
}
107+
function detectSourcetree(fileRef) {
108+
109+
var filetype = fileRef.lastKnownFileType || fileRef.explicitFileType,
110+
sourcetree = SOURCETREE_BY_FILETYPE[unquoted(filetype)];
107111

108112
if (fileRef.explicitFileType) {
109113
return DEFAULT_PRODUCT_SOURCETREE;
110114
}
115+
116+
if (fileRef.customFramework) {
117+
return DEFAULT_SOURCETREE;
118+
}
119+
120+
if (!sourcetree) {
121+
return DEFAULT_SOURCETREE;
122+
}
111123

112124
return sourcetree;
113125
}
114126

115127
function defaultPath(fileRef, filePath) {
116-
var defaultPath = PATH_BY_FILETYPE[fileRef.lastKnownFileType];
128+
var filetype = fileRef.lastKnownFileType || fileRef.explicitFileType,
129+
defaultPath = PATH_BY_FILETYPE[unquoted(filetype)];
117130

118131
if (fileRef.customFramework) {
119132
return filePath;
120133
}
134+
121135
if (defaultPath) {
122-
return path.join(defaultPath, filePath);
136+
return path.join(defaultPath, path.basename(filePath));
123137
}
124138

125139
return filePath;
@@ -137,9 +151,11 @@ function defaultGroup(fileRef) {
137151

138152
function pbxFile(filepath, opt) {
139153
var opt = opt || {};
154+
155+
self = this;
140156

141157
this.lastKnownFileType = opt.lastKnownFileType || detectType(filepath);
142-
this.group = defaultGroup(this);
158+
this.group = detectGroup(self);
143159

144160
// for custom frameworks
145161
if (opt.customFramework == true) {
@@ -149,7 +165,7 @@ function pbxFile(filepath, opt) {
149165

150166
this.basename = path.basename(filepath);
151167
this.path = defaultPath(this, filepath);
152-
this.defaultEncoding = opt.defaultEncoding || defaultEncoding(this);
168+
this.fileEncoding = this.defaultEncoding = opt.defaultEncoding || defaultEncoding(self);
153169

154170

155171
// When referencing products / build output files
@@ -162,7 +178,8 @@ function pbxFile(filepath, opt) {
162178
delete this.defaultEncoding;
163179
}
164180

165-
this.sourceTree = opt.sourceTree || defaultSourcetree(this);
181+
this.sourceTree = opt.sourceTree || detectSourcetree(self);
182+
this.includeInIndex = 0;
166183

167184
if (opt.weak && opt.weak === true)
168185
this.settings = { ATTRIBUTES: ['Weak'] };

0 commit comments

Comments
 (0)