Skip to content

Commit cbecfa1

Browse files
author
Anis Kadri
committed
Merge branch 'BBosman-windows'
2 parents 95aba21 + 923eaee commit cbecfa1

File tree

2 files changed

+32
-16
lines changed

2 files changed

+32
-16
lines changed

lib/pbxProject.js

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -709,7 +709,7 @@ function pbxFileReferenceObj(file) {
709709
obj.lastKnownFileType = file.lastType;
710710

711711
obj.name = "\"" + file.basename + "\"";
712-
obj.path = "\"" + file.path + "\"";
712+
obj.path = "\"" + file.path.replace(/\\/g, '/') + "\"";
713713

714714
obj.sourceTree = file.sourceTree;
715715

@@ -751,28 +751,22 @@ function longComment(file) {
751751

752752
// respect <group> path
753753
function correctForPluginsPath(file, project) {
754-
var r_plugin_dir = /^Plugins\//;
755-
756-
if (project.pbxGroupByName('Plugins').path)
757-
file.path = file.path.replace(r_plugin_dir, '');
758-
759-
return file;
754+
return correctForPath(file, project, 'Plugins');
760755
}
761756

762757
function correctForResourcesPath(file, project) {
763-
var r_resources_dir = /^Resources\//;
764-
765-
if (project.pbxGroupByName('Resources').path)
766-
file.path = file.path.replace(r_resources_dir, '');
767-
768-
return file;
758+
return correctForPath(file, project, 'Resources');
769759
}
770760

771761
function correctForFrameworksPath(file, project) {
772-
var r_resources_dir = /^Frameworks\//;
762+
return correctForPath(file, project, 'Frameworks');
763+
}
764+
765+
function correctForPath(file, project, group) {
766+
var r_group_dir = new RegExp('^' + group + '[\\\\/]');
773767

774-
if (project.pbxGroupByName('Frameworks').path)
775-
file.path = file.path.replace(r_resources_dir, '');
768+
if (project.pbxGroupByName(group).path)
769+
file.path = file.path.replace(r_group_dir, '');
776770

777771
return file;
778772
}

test/pbxProject.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,28 @@ exports['productName field'] = {
187187
}
188188
}
189189

190+
exports['addPluginFile function'] = {
191+
'should strip the Plugin path prefix': function (test) {
192+
var myProj = new pbx('test/parser/projects/full.pbxproj');
193+
194+
myProj.parse(function (err, hash) {
195+
test.equal(myProj.addPluginFile('Plugins/testMac.m').path, 'testMac.m');
196+
test.equal(myProj.addPluginFile('Plugins\\testWin.m').path, 'testWin.m');
197+
test.done();
198+
});
199+
},
200+
'should add files to the .pbxproj file using the / path seperator': function (test) {
201+
var myProj = new pbx('test/parser/projects/full.pbxproj');
202+
203+
myProj.parse(function (err, hash) {
204+
var file = myProj.addPluginFile('myPlugin\\newFile.m');
205+
206+
test.equal(myProj.pbxFileReferenceSection()[file.fileRef].path, '"myPlugin/newFile.m"');
207+
test.done();
208+
});
209+
}
210+
}
211+
190212
exports['hasFile'] = {
191213
'should return true if the file is in the project': function (test) {
192214
var newProj = new pbx('.');

0 commit comments

Comments
 (0)