Skip to content

Commit 1542225

Browse files
committed
Windows path fix
1 parent ff9f67a commit 1542225

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
@@ -653,7 +653,7 @@ function pbxFileReferenceObj(file) {
653653
obj.lastKnownFileType = file.lastType;
654654

655655
obj.name = "\"" + file.basename + "\"";
656-
obj.path = "\"" + file.path + "\"";
656+
obj.path = "\"" + file.path.replace(/\\/g, '/') + "\"";
657657

658658
obj.sourceTree = file.sourceTree;
659659

@@ -695,28 +695,22 @@ function longComment(file) {
695695

696696
// respect <group> path
697697
function correctForPluginsPath(file, project) {
698-
var r_plugin_dir = /^Plugins\//;
699-
700-
if (project.pbxGroupByName('Plugins').path)
701-
file.path = file.path.replace(r_plugin_dir, '');
702-
703-
return file;
698+
return correctForPath(file, project, 'Plugins');
704699
}
705700

706701
function correctForResourcesPath(file, project) {
707-
var r_resources_dir = /^Resources\//;
708-
709-
if (project.pbxGroupByName('Resources').path)
710-
file.path = file.path.replace(r_resources_dir, '');
711-
712-
return file;
702+
return correctForPath(file, project, 'Resources');
713703
}
714704

715705
function correctForFrameworksPath(file, project) {
716-
var r_resources_dir = /^Frameworks\//;
706+
return correctForPath(file, project, 'Frameworks');
707+
}
708+
709+
function correctForPath(file, project, group) {
710+
var r_group_dir = new RegExp('^' + group + '[\\\\/]');
717711

718-
if (project.pbxGroupByName('Frameworks').path)
719-
file.path = file.path.replace(r_resources_dir, '');
712+
if (project.pbxGroupByName(group).path)
713+
file.path = file.path.replace(r_group_dir, '');
720714

721715
return file;
722716
}

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)