Skip to content

Commit 98628fe

Browse files
committed
[pbxProject] "plugin" option to addResourceFile
restores behaviour changed by aa3bd6b
1 parent a5da621 commit 98628fe

File tree

2 files changed

+92
-7
lines changed

2 files changed

+92
-7
lines changed

lib/pbxProject.js

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -131,17 +131,31 @@ pbxProject.prototype.removeHeaderFile = function (path, opt) {
131131
}
132132

133133
pbxProject.prototype.addResourceFile = function (path, opt) {
134-
var file = new pbxFile(path, opt);
134+
opt = opt || {};
135+
136+
var file;
137+
138+
if (opt.plugin) {
139+
file = this.addPluginFile(path, opt);
140+
} else {
141+
file = new pbxFile(path, opt);
142+
}
135143

136-
correctForResourcesPath(file, this);
137144
file.uuid = this.generateUuid();
138-
file.fileRef = this.generateUuid();
145+
146+
if (!opt.plugin) {
147+
correctForResourcesPath(file, this);
148+
file.fileRef = this.generateUuid();
149+
}
139150

140151
this.addToPbxBuildFileSection(file); // PBXBuildFile
141-
this.addToPbxFileReferenceSection(file); // PBXFileReference
142-
this.addToResourcesPbxGroup(file); // PBXGroup
143152
this.addToPbxResourcesBuildPhase(file); // PBXResourcesBuildPhase
144153

154+
if (!opt.plugin) {
155+
this.addToPbxFileReferenceSection(file); // PBXFileReference
156+
this.addToResourcesPbxGroup(file); // PBXGroup
157+
}
158+
145159
return file;
146160
}
147161

@@ -471,10 +485,10 @@ function correctForPluginsPath(file, project) {
471485
}
472486

473487
function correctForResourcesPath(file, project) {
474-
var r_plugin_dir = /^Resources\//;
488+
var r_resources_dir = /^Resources\//;
475489

476490
if (project.pbxGroupByName('Resources').path)
477-
file.path = file.path.replace(r_plugin_dir, '');
491+
file.path = file.path.replace(r_resources_dir, '');
478492

479493
return file;
480494
}

test/addResourceFile.js

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,77 @@ exports.addResourceFile = {
139139
test.equal(newFile.path, 'assets.bundle');
140140
test.done();
141141
},
142+
'when added with { plugin: true }': {
143+
144+
'should add the PBXFileReference with the "Plugins" path': function (test) {
145+
delete proj.pbxGroupByName('Plugins').path;
146+
147+
var newFile = proj.addResourceFile('Plugins/assets.bundle',
148+
{ plugin: true }),
149+
fileRefSection = proj.pbxFileReferenceSection(),
150+
fileRefEntry = fileRefSection[newFile.fileRef];
151+
152+
test.equal(fileRefEntry.isa, 'PBXFileReference');
153+
test.equal(fileRefEntry.fileEncoding, undefined);
154+
test.equal(fileRefEntry.lastKnownFileType, '"wrapper.plug-in"');
155+
test.equal(fileRefEntry.name, 'assets.bundle');
156+
test.equal(fileRefEntry.path, 'Plugins/assets.bundle');
157+
test.equal(fileRefEntry.sourceTree, '"<group>"');
158+
test.done();
159+
},
160+
161+
'should add to the Plugins PBXGroup group': function (test) {
162+
var newFile = proj.addResourceFile('Plugins/assets.bundle',
163+
{ plugin: true }),
164+
plugins = proj.pbxGroupByName('Plugins');
165+
166+
test.equal(plugins.children.length, 1);
167+
test.done();
168+
},
169+
170+
'should have the Plugins values for the PBXGroup entry': function (test) {
171+
var newFile = proj.addResourceFile('Plugins/assets.bundle',
172+
{ plugin: true }),
173+
plugins = proj.pbxGroupByName('Plugins'),
174+
pluginObj = plugins.children[0];
175+
176+
test.equal(pluginObj.comment, 'assets.bundle');
177+
test.equal(pluginObj.value, newFile.fileRef);
178+
test.done();
179+
},
180+
181+
'should add to the PBXSourcesBuildPhase': function (test) {
182+
var newFile = proj.addResourceFile('Plugins/assets.bundle',
183+
{ plugin: true }),
184+
sources = proj.pbxResourcesBuildPhaseObj();
185+
186+
test.equal(sources.files.length, 13);
187+
test.done();
188+
},
189+
190+
'should have the right values for the Sources entry': function (test) {
191+
var newFile = proj.addResourceFile('Plugins/assets.bundle',
192+
{ plugin: true }),
193+
sources = proj.pbxResourcesBuildPhaseObj(),
194+
sourceObj = sources.files[12];
195+
196+
test.equal(sourceObj.comment, 'assets.bundle in Resources');
197+
test.equal(sourceObj.value, newFile.uuid);
198+
test.done();
199+
},
200+
201+
'should remove "Plugins/" from path if group path is set': function (test) {
202+
var plugins = proj.pbxGroupByName('Plugins'),
203+
newFile;
204+
205+
plugins.path = '"Test200/Plugins"';
206+
newFile = proj.addResourceFile('Plugins/assets.bundle',
207+
{ plugin: true });
208+
209+
test.equal(newFile.path, 'assets.bundle');
210+
test.done();
211+
}
212+
},
142213
tearDown: function (callback) {
143214
delete proj.pbxGroupByName('Resources').path;
144215
callback();

0 commit comments

Comments
 (0)