Skip to content

Commit

Permalink
feat: add option to exclude dir(s) from compiling to assests catalog … (
Browse files Browse the repository at this point in the history
#13484)

* feat: add option to exclude dir(s) from compiling to assests catalog when app-thinning is used

* Update gather.js

fixed lint error

* feat: fixed lint error

* fixed RegEx Lint warning
  • Loading branch information
mbender74 committed Jun 28, 2022
1 parent 6f96424 commit d0ab654
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
30 changes: 27 additions & 3 deletions cli/lib/gather.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ class Walker {
*/
async _visitListing(results, dirent, src, dest, ignore, origSrc, prefix) {
const name = dirent.name;

if (ignore && ignore.test(name)) { // if we should ignore this file/dir, skip it
return;
}
Expand Down Expand Up @@ -193,6 +194,7 @@ class Walker {
*/
_visitFile(results, from, to, name, src, origSrc, prefix) {
// if we should ignore this file, skip it

if (this.ignoreFiles && this.ignoreFiles.test(name)) {
return;
}
Expand All @@ -211,6 +213,7 @@ class Categorizer {
* @param {string} [options.platform] 'ios', 'android'
*/
constructor(options) {
this.excludeAssestsDir = options.excludeAssestsDir ? options.excludeAssestsDir : null;
this.useAppThinning = options.useAppThinning;
this.platform = options.platform;
this.jsFilesNotToProcess = options.jsFilesNotToProcess || [];
Expand Down Expand Up @@ -268,6 +271,17 @@ class Categorizer {
results.launchImages.set(relPath, info);
return;
}
if (this.excludeAssestsDir !== null) {
let testPath = this.excludeAssestsDir;
const checkRegEx = new RegExp(`${testPath}`);
if (!relPath.match(checkRegEx)) {
results.imageAssets.set(relPath, info);
return;
}
} else {
results.imageAssets.set(relPath, info);
return;
}
}
// fall through to lump with JPG...

Expand Down Expand Up @@ -297,14 +311,24 @@ class Categorizer {
// if we are using app thinning, then don't copy the image, instead mark the
// image to be injected into the asset catalog. Also, exclude images that are
// managed by their bundles.

if (this.useAppThinning && !relPath.match(BUNDLE_FILE_REGEXP)) {
results.imageAssets.set(relPath, info);
return;
if (this.excludeAssestsDir !== null) {
let testPath = this.excludeAssestsDir;
const checkRegEx = new RegExp(`${testPath}`);
if (!relPath.match(checkRegEx)) {
results.imageAssets.set(relPath, info);
return;
}
} else {
results.imageAssets.set(relPath, info);
return;
}
}
}

// Normal PNG/JPG, so just copy it
results.resourcesToCopy.set(relPath, info);

break;

case 'html':
Expand Down
1 change: 1 addition & 0 deletions iphone/cli/commands/_build.js
Original file line number Diff line number Diff line change
Expand Up @@ -5229,6 +5229,7 @@ iOSBuilder.prototype.gatherResources = async function gatherResources() {
tiappIcon: this.tiapp.icon,
useAppThinning: this.useAppThinning,
platform: 'ios',
excludeAssestsDir: this.tiapp.ios['exclude-dir-from-asset-catalog'] ? this.tiapp.ios['exclude-dir-from-asset-catalog'] : undefined,
});
const categorized = await categorizer.run(combined);

Expand Down

0 comments on commit d0ab654

Please sign in to comment.