Skip to content

Commit 23d24df

Browse files
author
Dimitar Kerezov
committed
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 3085e40 commit 23d24df

File tree

2 files changed

+68
-0
lines changed

2 files changed

+68
-0
lines changed

lib/pbxProject.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -744,6 +744,12 @@ function pbxFileReferenceObj(file) {
744744

745745
if (file.fileEncoding)
746746
obj.fileEncoding = file.fileEncoding;
747+
748+
if (file.explicitFileType)
749+
obj.explicitFileType = file.explicitFileType;
750+
751+
if ('includeInIndex' in file)
752+
obj.includeInIndex = file.includeInIndex;
747753

748754
return obj;
749755
}
Lines changed: 62 additions & 0 deletions
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)