Skip to content

Commit 9bc7077

Browse files
committed
Add complete interface for creating "Copy Files" build phase entries.
1 parent 9037588 commit 9bc7077

File tree

1 file changed

+89
-0
lines changed

1 file changed

+89
-0
lines changed

lib/pbxProject.js

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,59 @@ pbxProject.prototype.removeFramework = function(fpath, opt) {
245245
return file;
246246
}
247247

248+
249+
pbxProject.prototype.addCopyfile = function(fpath, opt) {
250+
var file = new pbxFile(fpath, opt);
251+
252+
// catch duplicates
253+
if (this.hasFile(file.path)) {
254+
file = this.hasFile(file.path);
255+
} else {
256+
file.uuid = this.generateUuid();
257+
file.fileRef = this.generateUuid();
258+
}
259+
260+
file.target = opt ? opt.target : undefined;
261+
file.group = 'CopyFiles';
262+
263+
264+
this.addToPbxBuildFileSection(file); // PBXBuildFile
265+
this.addToPbxFileReferenceSection(file); // PBXFileReference
266+
this.addToPbxCopyfilesBuildPhase(file); // PBXCopyFilesBuildPhase
267+
268+
return file;
269+
}
270+
271+
pbxProject.prototype.pbxCopyfilesBuildPhaseObj = function(target) {
272+
return this.buildPhaseObject('PBXCopyFilesBuildPhase', 'CopyFiles', target);
273+
}
274+
275+
pbxProject.prototype.addToPbxCopyfilesBuildPhase = function(file) {
276+
var sources = this.buildPhaseObject('PBXCopyFilesBuildPhase', 'CopyFiles', file.target);
277+
sources.files.push(pbxBuildPhaseObj(file));
278+
}
279+
280+
pbxProject.prototype.removeCopyfile = function(fpath, opt) {
281+
var file = new pbxFile(fpath, opt);
282+
file.target = opt ? opt.target : undefined;
283+
284+
this.removeFromPbxBuildFileSection(file); // PBXBuildFile
285+
this.removeFromPbxFileReferenceSection(file); // PBXFileReference
286+
this.removeFromPbxCopyfilesBuildPhase(file); // PBXFrameworksBuildPhase
287+
288+
return file;
289+
}
290+
291+
pbxProject.prototype.removeFromPbxCopyfilesBuildPhase = function(file) {
292+
var sources = this.pbxCopyfilesBuildPhaseObj(file.target);
293+
for (i in sources.files) {
294+
if (sources.files[i].comment == longComment(file)) {
295+
sources.files.splice(i, 1);
296+
break;
297+
}
298+
}
299+
}
300+
248301
pbxProject.prototype.addStaticLibrary = function(path, opt) {
249302
opt = opt || {};
250303

@@ -1118,6 +1171,42 @@ function pbxBuildPhaseObj(file) {
11181171
return obj;
11191172
}
11201173

1174+
function pbxCopyFilesBuildPhaseObj(obj, folderType, subfolderPath, phaseName){
1175+
1176+
// Add additional properties for 'CopyFiles' build phase
1177+
var DESTINATION_BY_TARGETTYPE = {
1178+
application: 'wrapper',
1179+
app_extension: 'plugins',
1180+
bundle: 'wrapper',
1181+
command_line_tool: 'wrapper',
1182+
dynamic_library: 'products_directory',
1183+
framework: 'shared_frameworks',
1184+
static_library: 'products_directory',
1185+
unit_test_bundle: 'wrapper',
1186+
watch_app: 'wrapper',
1187+
watch_extension: 'plugins'
1188+
}
1189+
var SUBFOLDERSPEC_BY_DESTINATION = {
1190+
absolute_path: 0,
1191+
executables: 6,
1192+
frameworks: 10,
1193+
java_resources: 15,
1194+
plugins: 13,
1195+
products_directory: 16,
1196+
resources: 7,
1197+
shared_frameworks: 11,
1198+
shared_support: 12,
1199+
wrapper: 1,
1200+
xpc_services: 0
1201+
}
1202+
1203+
obj.name = phaseName || '""';
1204+
obj.dstPath = subfolderPath || '""';
1205+
obj.dstSubfolderSpec = SUBFOLDERSPEC_BY_DESTINATION[DESTINATION_BY_TARGETTYPE[folderType]];
1206+
1207+
return obj;
1208+
}
1209+
11211210
function pbxBuildFileComment(file) {
11221211
return longComment(file);
11231212
}

0 commit comments

Comments
 (0)