Skip to content

Commit 91c9791

Browse files
BBosmane2l3n
authored andcommitted
Windows path fix
1 parent 6c772ff commit 91c9791

File tree

2 files changed

+31
-15
lines changed

2 files changed

+31
-15
lines changed

lib/pbxProject.js

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -763,28 +763,22 @@ function longComment(file, opt) {
763763

764764
// respect <group> path
765765
function correctForPluginsPath(file, project) {
766-
var r_plugin_dir = /^Plugins\//;
767-
768-
if (project.pbxGroupByName('Plugins').path)
769-
file.path = file.path.replace(r_plugin_dir, '');
770-
771-
return file;
766+
return correctForPath(file, project, 'Plugins');
772767
}
773768

774769
function correctForResourcesPath(file, project) {
775-
var r_resources_dir = /^Resources\//;
776-
777-
if (project.pbxGroupByName('Resources').path)
778-
file.path = file.path.replace(r_resources_dir, '');
779-
780-
return file;
770+
return correctForPath(file, project, 'Resources');
781771
}
782772

783773
function correctForFrameworksPath(file, project) {
784-
var r_resources_dir = /^Frameworks\//;
774+
return correctForPath(file, project, 'Frameworks');
775+
}
776+
777+
function correctForPath(file, project, group) {
778+
var r_group_dir = new RegExp('^' + group + '[\\\\/]');
785779

786-
if (project.pbxGroupByName('Frameworks').path)
787-
file.path = file.path.replace(r_resources_dir, '');
780+
if (project.pbxGroupByName(group).path)
781+
file.path = file.path.replace(r_group_dir, '');
788782

789783
return file;
790784
}

test/pbxProject.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,28 @@ exports['productName field'] = {
184184
}
185185
}
186186

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

0 commit comments

Comments
 (0)