Skip to content

Commit 750e789

Browse files
committed
fix: plist added to build phase, assets not added to resources
1 parent 2ab57b2 commit 750e789

File tree

2 files changed

+47
-22
lines changed

2 files changed

+47
-22
lines changed

lib/pbxFile.js

+12-3
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,7 @@ var FILETYPE_BY_EXTENSION = {
7575
'sourcecode.c.objc': 'Sources',
7676
'sourcecode.swift': 'Sources',
7777
'sourcecode.cpp.cpp': 'Sources',
78-
'sourcecode.cpp.objcpp': 'Sources',
79-
'text.plist.entitlements': 'Reference' //only in file reference
78+
'sourcecode.cpp.objcpp': 'Sources'
8079
},
8180
PATH_BY_FILETYPE = {
8281
'compiled.mach-o.dylib': 'usr/lib/',
@@ -112,6 +111,10 @@ function isSourceFileType(fileType) {
112111
return fileType.startsWith(SOURCE_CODE_FILE_TYPE_PREFIX) && !isHeaderFileType(fileType);
113112
}
114113

114+
function isAssetFileType(fileType) {
115+
return fileType === FILETYPE_BY_EXTENSION.xcassets;
116+
}
117+
115118
function isResource(group) {
116119
return group === "Resources";
117120
}
@@ -120,6 +123,10 @@ function isEntitlement(fileType) {
120123
return fileType.endsWith(ENTITLEMENTS_FILE_TYPE_SUFFIX);
121124
}
122125

126+
function isPlist(fileType) {
127+
return fileType === FILETYPE_BY_EXTENSION.plist;
128+
}
129+
123130
function unquoted(text){
124131
return text == null ? '' : text.replace (/(^")|("$)/g, '')
125132
}
@@ -273,5 +280,7 @@ module.exports = {
273280
isSourceFileType,
274281
isHeaderFileType,
275282
isResource,
276-
isEntitlement
283+
isEntitlement,
284+
isAssetFileType,
285+
isPlist
277286
}

lib/pbxProject.js

+35-19
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@ var util = require('util'),
2626
isSourceFileType = require('./pbxFile').isSourceFileType,
2727
isHeaderFileType = require('./pbxFile').isHeaderFileType,
2828
isResource = require('./pbxFile').isResource,
29-
isEntitlement = require('./pbxFile').isEntitlement
29+
isEntitlement = require('./pbxFile').isEntitlement,
30+
isAssetFileType = require('./pbxFile').isAssetFileType,
31+
isPlist = require('./pbxFile').isPlist,
3032
fs = require('fs'),
3133
parser = require('./parser/pbxproj'),
3234
plist = require('simple-plist'),
@@ -566,18 +568,11 @@ pbxProject.prototype.addPbxGroup = function (filePathsArray, name, path, sourceT
566568
if(opt.target) {
567569
file.target = opt.target;
568570
}
569-
if (fs.existsSync(filePath) && fs.lstatSync(filePath).isDirectory()) {
571+
if (fs.existsSync(filePath) && fs.lstatSync(filePath).isDirectory() && !isAssetFileType(file.lastKnownFileType)) {
570572
file.fileRef = file.uuid;
571573
var files = fs.readdirSync(filePath).map(p => $path.join(filePath, p));
572574
if($path.extname(filePath) === ".lproj") {
573-
for (var i = 0; i < files.length; i++) {
574-
var variantGroup = this.addLocalizationVariantGroup($path.basename(files[i]), { target: opt.target, skipAddToResourcesGroup: true });
575-
var refFile = new pbxFile($path.relative(srcRootPath, files[i]), {basename: $path.parse(file.basename).name});
576-
refFile.fileRef = this.generateUuid();
577-
this.addToPbxFileReferenceSection(refFile);
578-
this.addToPbxVariantGroup(refFile, variantGroup.fileRef);
579-
pbxGroup.children.push(pbxGroupChild(variantGroup));
580-
}
575+
addLocalizationGroup.call(this, pbxGroup, file, files, srcRootPath, opt);
581576
} else {
582577
this.addToPbxFileReferenceSection(file); // PBXFileReference
583578
this.addToPbxBuildFileSection(file);
@@ -587,18 +582,22 @@ pbxProject.prototype.addPbxGroup = function (filePathsArray, name, path, sourceT
587582
} else {
588583
this.addToPbxFileReferenceSection(file); // PBXFileReference
589584
pbxGroup.children.push(pbxGroupChild(file));
590-
if(isHeaderFileType(file.lastKnownFileType)) {
585+
if(isHeaderFileType(file.lastKnownFileType) || isPlist(file.lastKnownFileType)) {
591586
continue;
592-
} else if (isSourceFileType(file.lastKnownFileType)) {
593-
this.addToPbxBuildFileSection(file); // PBXBuildFile
594-
this.addToPbxSourcesBuildPhase(file);
595-
} else if(isEntitlement(file.lastKnownFileType)) {
587+
}
588+
589+
if(isEntitlement(file.lastKnownFileType)) {
596590
this.addToBuildSettings('CODE_SIGN_ENTITLEMENTS', file.path, opt.target);
591+
continue;
592+
}
593+
594+
if (isSourceFileType(file.lastKnownFileType)) { // PBXBuildFile
595+
this.addToPbxSourcesBuildPhase(file);
597596
} else if(isResource(file.group)) {
598597
this.addToPbxResourcesBuildPhase(file)
599-
} else {
600-
this.addToPbxBuildFileSection(file);
601598
}
599+
600+
this.addToPbxBuildFileSection(file);
602601
}
603602
}
604603

@@ -619,6 +618,21 @@ pbxProject.prototype.addPbxGroup = function (filePathsArray, name, path, sourceT
619618
return {uuid: pbxGroupUuid, pbxGroup: pbxGroup};
620619
}
621620

621+
function addLocalizationGroup(pbxGroup, variantFile, files, srcRootPath, opt) {
622+
for (var i = 0; i < files.length; i++) {
623+
var variantGroupName = $path.parse($path.basename(files[i])).name + ".storyboard";
624+
var variantGroup = this.findPBXVariantGroupKey({name: variantGroupName});
625+
if(!variantGroup) {
626+
variantGroup = this.addLocalizationVariantGroup(variantGroupName, { target: opt.target, skipAddToResourcesGroup: true });
627+
pbxGroup.children.push(pbxGroupChild(variantGroup));
628+
}
629+
var refFile = new pbxFile($path.relative(srcRootPath, files[i]), {basename: $path.parse(variantFile.basename).name});
630+
refFile.fileRef = this.generateUuid();
631+
this.addToPbxFileReferenceSection(refFile);
632+
this.addToPbxVariantGroup(refFile, variantGroup.fileRef);
633+
}
634+
}
635+
622636
pbxProject.prototype.removePbxGroup = function(groupName, path) {
623637
var group = this.pbxGroupByName(groupName);
624638
if (!group) {
@@ -1375,15 +1389,17 @@ pbxProject.prototype.removeFromHeaderSearchPaths = function(file) {
13751389

13761390
}
13771391
}
1378-
pbxProject.prototype.addToHeaderSearchPaths = function(file) {
1392+
pbxProject.prototype.addToHeaderSearchPaths = function(file, productName) {
13791393
var configurations = nonComments(this.pbxXCBuildConfigurationSection()),
13801394
INHERITED = '"$(inherited)"',
13811395
config, buildSettings, searchPaths;
13821396

1397+
productName = unquote(productName || this.productName);
1398+
13831399
for (config in configurations) {
13841400
buildSettings = configurations[config].buildSettings;
13851401

1386-
if (unquote(buildSettings['PRODUCT_NAME']) != this.productName)
1402+
if (unquote(buildSettings['PRODUCT_NAME']) != productName)
13871403
continue;
13881404

13891405
if (!buildSettings['HEADER_SEARCH_PATHS']) {

0 commit comments

Comments
 (0)