diff --git a/lib/services/assets-generation/assets-generation-service.ts b/lib/services/assets-generation/assets-generation-service.ts index e73a902d47..1a23e5ad65 100644 --- a/lib/services/assets-generation/assets-generation-service.ts +++ b/lib/services/assets-generation/assets-generation-service.ts @@ -71,6 +71,12 @@ export class AssetsGenerationService implements IAssetsGenerationService { const outputPath = assetItem.path; const width = assetItem.width * scale; const height = assetItem.height * scale; + + if (!width || !height) { + this.$logger.warn(`Image ${assetItem.filename} is skipped as its width and height are invalid.`); + continue; + } + let image: Jimp; switch (operation) { case Operations.OverlayWith: diff --git a/lib/services/project-data-service.ts b/lib/services/project-data-service.ts index b9edeb98f0..db02f78245 100644 --- a/lib/services/project-data-service.ts +++ b/lib/services/project-data-service.ts @@ -236,10 +236,12 @@ export class ProjectDataService implements IProjectDataService { private async getIOSAssetSubGroup(dirPath: string): Promise { const pathToContentJson = path.join(dirPath, AssetConstants.iOSResourcesFileName); const content = this.$fs.exists(pathToContentJson) && this.$fs.readJson(pathToContentJson) || { images: [] }; + const finalContent: IAssetSubGroup = { images: [] }; const imageDefinitions = this.getImageDefinitions().ios; _.each(content && content.images, image => { + let foundMatchingDefinition = false; // In some cases the image may not be available, it will just be described. // When this happens, the filename will be empty. // So we'll keep the path empty as well. @@ -247,22 +249,23 @@ export class ProjectDataService implements IProjectDataService { image.path = path.join(dirPath, image.filename); } + if (image.size) { + // size is basically x + const [width, height] = image.size.toString().split(AssetConstants.sizeDelimiter); + if (width && height) { + image.width = +width; + image.height = +height; + } + } + // Find the image size based on the hardcoded values in the image-definitions.json _.each(imageDefinitions, (assetSubGroup: IAssetItem[]) => { const assetItem = _.find(assetSubGroup, assetElement => assetElement.filename === image.filename && path.basename(assetElement.directory) === path.basename(dirPath) ); - if (image.size) { - // size is basically x - const [width, height] = image.size.toString().split(AssetConstants.sizeDelimiter); - if (width && height) { - image.width = +width; - image.height = +height; - } - } - if (assetItem) { + foundMatchingDefinition = true; if (!image.width || !image.height) { image.width = assetItem.width; image.height = assetItem.height; @@ -273,13 +276,18 @@ export class ProjectDataService implements IProjectDataService { image.overlayImageScale = image.overlayImageScale || assetItem.overlayImageScale; image.scale = image.scale || assetItem.scale; image.rgba = assetItem.rgba; + finalContent.images.push(image); // break each return false; } }); + + if (!foundMatchingDefinition && image.filename) { + this.$logger.warn(`Didn't find a matching image definition for file ${path.join(path.basename(dirPath), image.filename)}. This file will be skipped from reources generation.`); + } }); - return content; + return finalContent; } private getAndroidAssetSubGroup(assetItems: IAssetItem[], realPaths: string[]): IAssetSubGroup {