Skip to content

Commit 63109ad

Browse files
fix(assets): Fix asset generation
Fix the generation of asset - the filter is incorrect and fails with `Cannot read property 'splashImages' of null, TypeError: Cannot read property 'splashImages' of null` Also fix the scale - it has been incorrectly declared as number, when it is string (1x, 2x, etc.). Use the scale correctly by parsing it and use it when generate the image. Also fix the using of resizeOperation property - it was not passed correctly for iOS assets.
1 parent d341285 commit 63109ad

File tree

3 files changed

+39
-24
lines changed

3 files changed

+39
-24
lines changed

lib/definitions/project.d.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ interface IAssetItem {
157157
height: number;
158158
filename: string;
159159
directory: string;
160-
scale: number;
160+
scale: string;
161161
idiom: string;
162162
resizeOperation?: string;
163163
}

lib/services/assets-generation/assets-generation-service.ts

+13-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import * as Jimp from "jimp";
22
import * as Color from "color";
33
import { exported } from "../../common/decorators";
4+
import { AssetConstants } from "../../constants";
45

56
export const enum Operations {
67
OverlayWith = "overlayWith",
@@ -39,12 +40,12 @@ export class AssetsGenerationService implements IAssetsGenerationService {
3940
const assetsStructure = await this.$projectDataService.getAssetsStructure(generationData);
4041

4142
const assetItems = _(assetsStructure)
42-
.filter((assetGroup: IAssetGroup, platform: string) => {
43-
return !generationData.platform || platform.toLowerCase() === generationData.platform.toLowerCase();
44-
})
43+
.filter((assetGroup: IAssetGroup, platform: string) =>
44+
!generationData.platform || platform.toLowerCase() === generationData.platform.toLowerCase()
45+
)
4546
.map((assetGroup: IAssetGroup) =>
4647
_.filter(assetGroup, (assetSubGroup: IAssetSubGroup, imageTypeKey: string) =>
47-
propertiesToEnumerate.indexOf(imageTypeKey) !== -1 && !assetSubGroup[imageTypeKey]
48+
assetSubGroup && propertiesToEnumerate.indexOf(imageTypeKey) !== -1 && assetSubGroup[imageTypeKey]
4849
)
4950
)
5051
.flatten<IAssetSubGroup>()
@@ -55,7 +56,14 @@ export class AssetsGenerationService implements IAssetsGenerationService {
5556

5657
for (const assetItem of assetItems) {
5758
const operation = assetItem.resizeOperation || Operations.Resize;
58-
const scale = assetItem.scale || 0.8;
59+
let tempScale: number = null;
60+
if (assetItem.scale && !_.isNumber(assetItem.scale)) {
61+
const splittedElements = `${assetItem.scale}`.split(AssetConstants.sizeDelimiter);
62+
tempScale = splittedElements && splittedElements.length && splittedElements[0] && +splittedElements[0];
63+
}
64+
65+
const scale = tempScale || 0.8;
66+
5967
const outputPath = assetItem.path;
6068

6169
switch (operation) {

lib/services/project-data-service.ts

+25-18
Original file line numberDiff line numberDiff line change
@@ -137,25 +137,32 @@ export class ProjectDataService implements IProjectDataService {
137137
image.path = path.join(dirPath, image.filename);
138138
}
139139

140-
if (image.size) {
141-
// size is basically <width>x<height>
142-
const [width, height] = image.size.toString().split(AssetConstants.sizeDelimiter);
143-
if (width && height) {
144-
image.width = +width;
145-
image.height = +height;
146-
}
147-
} else {
148-
// Find the image size based on the hardcoded values in the image-definitions.json
149-
_.each(imageDefinitions, (assetSubGroup: IAssetItem[]) => {
150-
_.each(assetSubGroup, assetItem => {
151-
if (assetItem.filename === image.filename && path.basename(assetItem.directory) === path.basename(dirPath)) {
152-
image.width = assetItem.width;
153-
image.height = assetItem.height;
154-
image.size = `${assetItem.width}${AssetConstants.sizeDelimiter}${assetItem.height}`;
140+
// Find the image size based on the hardcoded values in the image-definitions.json
141+
_.each(imageDefinitions, (assetSubGroup: IAssetItem[]) => {
142+
const assetItem = _.find(assetSubGroup, assetElement =>
143+
assetElement.filename === image.filename && path.basename(assetElement.directory) === path.basename(dirPath)
144+
);
145+
146+
if (assetItem) {
147+
if (image.size) {
148+
// size is basically <width>x<height>
149+
const [width, height] = image.size.toString().split(AssetConstants.sizeDelimiter);
150+
if (width && height) {
151+
image.width = +width;
152+
image.height = +height;
155153
}
156-
});
157-
});
158-
}
154+
}
155+
156+
if (!image.width || !image.height) {
157+
image.width = assetItem.width;
158+
image.height = assetItem.height;
159+
image.size = image.size || `${assetItem.width}${AssetConstants.sizeDelimiter}${assetItem.height}`;
160+
}
161+
162+
// break each
163+
return false;
164+
}
165+
});
159166
});
160167

161168
return content;

0 commit comments

Comments
 (0)