Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
84 changes: 84 additions & 0 deletions lib/pbxProject.js
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,7 @@ pbxProject.prototype.addResourceFile = function(path, opt, group) {

file.uuid = this.generateUuid();
file.target = opt ? opt.target : undefined;
file.settings = opt ? opt.settings : undefined;

if (!opt.plugin) {
correctForResourcesPath(file, this);
Expand Down Expand Up @@ -2198,4 +2199,87 @@ pbxProject.prototype.removeTargetAttribute = function(prop, target) {
}
}

pbxProject.prototype.addAssetTag = function(assetTagName, resourcesFolder) {
assetTagName = sanitiseTag(assetTagName)
var project = this.getFirstProject()['firstProject'];
if (project['attributes'] === undefined) {
project['attributes'] = {};
}
var attributes = project['attributes']
console.log(this.getFirstProject())
if (attributes['KnownAssetTags'] === undefined) {
attributes['KnownAssetTags'] = [];
}
if (!attributes['KnownAssetTags'].includes(assetTagName)) {
attributes['KnownAssetTags'].push(assetTagName)
}

this.addResourceFile(resourcesFolder, {
"settings": {
"ASSET_TAGS": [
assetTagName
]
}
})
}

function sanitiseTag(tag) {
return `"${tag}"`
}

function stripQuotes(tag) {
return tag.replace(/"/g, "")
}

pbxProject.prototype.removeTaggedResourceFiles = function() {
for (const [ uuid, value ] of Object.entries(this.pbxBuildFileSection())) {
// console.log(value);
if (value["settings"] !== undefined) {
if (value["settings"]["ASSET_TAGS"] !== undefined && value.fileRef_comment !== undefined) {
const file = this.pbxFileReferenceSection()[value.fileRef]
if (file) {
this.removeResourceFile(file.path)
delete this.pbxBuildFileSection()[uuid]
}
}
}
}
}

pbxProject.prototype.listAssetTags = function() {
var project = this.getFirstProject()['firstProject'];
if (project['attributes'] === undefined) {
return []
}
var attributes = project['attributes']

if (attributes['KnownAssetTags'] == undefined) {
return []
}
return attributes['KnownAssetTags'].map(stripQuotes)
}

pbxProject.prototype.removeAssetTags = function() {
var project = this.getFirstProject()['firstProject'];
if (project['attributes'] === undefined) {
project['attributes'] = {};
}
var attributes = project['attributes']
console.log("=======")
// console.log(this.getFirstProject())

if (attributes['KnownAssetTags'] !== undefined) {
console.log(attributes['KnownAssetTags'])
attributes['KnownAssetTags'].forEach(tag => {
console.log(` tag found ${tag}`);

})
}

this.removeTaggedResourceFiles()

attributes['KnownAssetTags'] = [];
}


module.exports = pbxProject;
118 changes: 118 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"node": ">=10.0.0"
},
"dependencies": {
"merge-deep": "^3.0.2",
"simple-plist": "^1.1.0",
"uuid": "^7.0.3"
},
Expand Down
Loading