Skip to content

Commit faf4114

Browse files
committed
respect <group> of Plugins
1 parent d504220 commit faf4114

File tree

4 files changed

+31
-2
lines changed

4 files changed

+31
-2
lines changed

lib/pbxProject.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ pbxProject.prototype.addSourceFile = function (path, opt) {
7777

7878
file.uuid = this.generateUuid();
7979
file.fileRef = this.generateUuid();
80+
correctForPluginsPath(file, this);
8081

8182
this.addToPbxBuildFileSection(file); // PBXBuildFile
8283
this.addToPbxFileReferenceSection(file); // PBXFileReference
@@ -90,6 +91,7 @@ pbxProject.prototype.addHeaderFile = function (path, opt) {
9091
var file = new pbxFile(path, opt);
9192

9293
file.fileRef = this.generateUuid();
94+
correctForPluginsPath(file, this);
9395

9496
this.addToPbxFileReferenceSection(file); // PBXFileReference
9597
this.addToPluginsPbxGroup(file); // PBXGroup
@@ -102,6 +104,7 @@ pbxProject.prototype.addResourceFile = function (path, opt) {
102104

103105
file.uuid = this.generateUuid();
104106
file.fileRef = this.generateUuid();
107+
correctForPluginsPath(file, this);
105108

106109
this.addToPbxBuildFileSection(file); // PBXBuildFile
107110
this.addToPbxFileReferenceSection(file); // PBXFileReference
@@ -276,4 +279,14 @@ function longComment(file) {
276279
return f("%s in %s", file.basename, file.group);
277280
}
278281

282+
// respect <group> path
283+
function correctForPluginsPath(file, project) {
284+
var r_plugin_dir = /^Plugins\//;
285+
286+
if (project.pbxGroupByName('Plugins').path)
287+
file.path = file.path.replace(r_plugin_dir, '');
288+
289+
return file;
290+
}
291+
279292
module.exports = pbxProject;

test/addHeaderFile.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ exports.addHeaderFile = {
5454
test.equal(fileRefEntry.fileEncoding, 4);
5555
test.equal(fileRefEntry.lastKnownFileType, 'sourcecode.c.h');
5656
test.equal(fileRefEntry.name, 'file.h');
57-
test.equal(fileRefEntry.path, 'Plugins/file.h');
57+
test.equal(fileRefEntry.path, 'file.h');
5858
test.equal(fileRefEntry.sourceTree, '"<group>"');
5959

6060
test.done();

test/addResourceFile.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,8 @@ exports.addResourceFile = {
8282
test.done();
8383
},
8484
'should add the PBXFileReference object correctly': function (test) {
85+
delete proj.pbxGroupByName('Plugins').path;
86+
8587
var newFile = proj.addResourceFile('Plugins/assets.bundle'),
8688
fileRefSection = proj.pbxFileReferenceSection(),
8789
fileRefEntry = fileRefSection[newFile.fileRef];
@@ -126,5 +128,19 @@ exports.addResourceFile = {
126128
test.equal(sourceObj.comment, 'assets.bundle in Resources');
127129
test.equal(sourceObj.value, newFile.uuid);
128130
test.done();
131+
},
132+
'should remove "Plugins/" from path if group path is set': function (test) {
133+
var plugins = proj.pbxGroupByName('Plugins'),
134+
newFile;
135+
136+
plugins.path = '"Test200/Plugins"';
137+
newFile = proj.addResourceFile('Plugins/assets.bundle');
138+
139+
test.equal(newFile.path, 'assets.bundle');
140+
test.done();
141+
},
142+
tearDown: function (callback) {
143+
delete proj.pbxGroupByName('Plugins').path;
144+
callback();
129145
}
130146
}

test/addSourceFile.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ exports.addSourceFile = {
9090
test.equal(fileRefEntry.fileEncoding, 4);
9191
test.equal(fileRefEntry.lastKnownFileType, 'sourcecode.c.objc');
9292
test.equal(fileRefEntry.name, 'file.m');
93-
test.equal(fileRefEntry.path, 'Plugins/file.m');
93+
test.equal(fileRefEntry.path, 'file.m');
9494
test.equal(fileRefEntry.sourceTree, '"<group>"');
9595

9696
test.done();

0 commit comments

Comments
 (0)