Skip to content

Commit 8e3afdf

Browse files
Dimitar Kerezove2l3n
Dimitar Kerezov
authored andcommitted
Allow setting of 'includeInIndex' and 'explicitFileType' properties
This enables greater customization when adding file to FileReference Section, like for example adding build output files (e.g. .app files or .appex files)
1 parent 4888306 commit 8e3afdf

File tree

2 files changed

+68
-0
lines changed

2 files changed

+68
-0
lines changed

lib/pbxProject.js

+6
Original file line numberDiff line numberDiff line change
@@ -921,6 +921,12 @@ function pbxFileReferenceObj(file) {
921921

922922
if (file.fileEncoding)
923923
obj.fileEncoding = file.fileEncoding;
924+
925+
if (file.explicitFileType)
926+
obj.explicitFileType = file.explicitFileType;
927+
928+
if ('includeInIndex' in file)
929+
obj.includeInIndex = file.includeInIndex;
924930

925931
return obj;
926932
}

test/addToPbxFileReferenceSection.js

+62
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
var jsonProject = require('./fixtures/full-project')
2+
fullProjectStr = JSON.stringify(jsonProject),
3+
pbx = require('../lib/pbxProject'),
4+
pbxFile = require('../lib/pbxFile'),
5+
myProj = new pbx('.');
6+
7+
function cleanHash() {
8+
return JSON.parse(fullProjectStr);
9+
}
10+
11+
exports.setUp = function (callback) {
12+
myProj.hash = cleanHash();
13+
callback();
14+
}
15+
16+
exports['addToPbxFileReferenceSection function'] = {
17+
'should add file and comment to fileReferenceSection': function (test) {
18+
var file = new pbxFile('file.m');
19+
file.fileRef = myProj.generateUuid();
20+
21+
myProj.addToPbxFileReferenceSection(file)
22+
23+
test.equal(myProj.pbxFileReferenceSection()[file.fileRef].isa, 'PBXFileReference');
24+
test.equal(myProj.pbxFileReferenceSection()[file.fileRef].lastKnownFileType, 'sourcecode.c.objc');
25+
test.equal(myProj.pbxFileReferenceSection()[file.fileRef].name, '"file.m"');
26+
test.equal(myProj.pbxFileReferenceSection()[file.fileRef].path, '"file.m"');
27+
test.equal(myProj.pbxFileReferenceSection()[file.fileRef].sourceTree, '"<group>"');
28+
test.equal(myProj.pbxFileReferenceSection()[file.fileRef].fileEncoding, 4);
29+
test.equal(myProj.pbxFileReferenceSection()[file.fileRef + "_comment"], 'file.m');
30+
test.done();
31+
},
32+
'should add file with preset explicitFileType to fileReferenceSection correctly': function (test) {
33+
var appexFile = { fileRef: myProj.generateUuid(), isa: 'PBXFileReference', explicitFileType: '"wrapper.app-extension"', path: "WatchKit Extension.appex"};
34+
35+
myProj.addToPbxFileReferenceSection(appexFile)
36+
37+
test.equal(myProj.pbxFileReferenceSection()[appexFile.fileRef].isa, 'PBXFileReference');
38+
test.equal(myProj.pbxFileReferenceSection()[appexFile.fileRef].explicitFileType, '"wrapper.app-extension"');
39+
test.equal(myProj.pbxFileReferenceSection()[appexFile.fileRef].path, '"WatchKit Extension.appex"');
40+
test.done();
41+
},
42+
'should add file with preset includeInIndex to fileReferenceSection correctly': function (test) {
43+
var appexFile = { fileRef: myProj.generateUuid(), isa: 'PBXFileReference', includeInIndex: 0, path: "WatchKit Extension.appex"};
44+
45+
myProj.addToPbxFileReferenceSection(appexFile)
46+
47+
test.equal(myProj.pbxFileReferenceSection()[appexFile.fileRef].isa, 'PBXFileReference');
48+
test.equal(myProj.pbxFileReferenceSection()[appexFile.fileRef].includeInIndex, 0);
49+
test.equal(myProj.pbxFileReferenceSection()[appexFile.fileRef].path, '"WatchKit Extension.appex"');
50+
test.done();
51+
},
52+
'should add file with preset sourceTree to fileReferenceSection correctly': function (test) {
53+
var appexFile = { fileRef: myProj.generateUuid(), isa: 'PBXFileReference', sourceTree: 'BUILT_PRODUCTS_DIR', path: "WatchKit Extension.appex"};
54+
55+
myProj.addToPbxFileReferenceSection(appexFile)
56+
57+
test.equal(myProj.pbxFileReferenceSection()[appexFile.fileRef].isa, 'PBXFileReference');
58+
test.equal(myProj.pbxFileReferenceSection()[appexFile.fileRef].sourceTree, 'BUILT_PRODUCTS_DIR');
59+
test.equal(myProj.pbxFileReferenceSection()[appexFile.fileRef].path, '"WatchKit Extension.appex"');
60+
test.done();
61+
}
62+
}

0 commit comments

Comments
 (0)