@@ -8,12 +8,8 @@ export const enum Operations {
8
8
Resize = "resize"
9
9
}
10
10
11
- interface IGenerateImagesData extends ISplashesGenerationData {
12
- propertiesToEnumerate : string [ ] ;
13
- }
14
-
15
11
export class AssetsGenerationService implements IAssetsGenerationService {
16
- private get propertiesToEnumerate ( ) : any {
12
+ private get propertiesToEnumerate ( ) : IDictionary < string [ ] > {
17
13
return {
18
14
icon : [ "icons" ] ,
19
15
splash : [ "splashBackgrounds" , "splashCenterImages" , "splashImages" ]
@@ -27,65 +23,56 @@ export class AssetsGenerationService implements IAssetsGenerationService {
27
23
@exported ( "assetsGenerationService" )
28
24
public async generateIcons ( resourceGenerationData : IResourceGenerationData ) : Promise < void > {
29
25
this . $logger . info ( "Generating icons ..." ) ;
30
- const generationData = ( < IGenerateImagesData > resourceGenerationData ) ;
31
- generationData . propertiesToEnumerate = this . propertiesToEnumerate . icon ;
32
- await this . generateImagesForDefinitions ( generationData ) ;
26
+ await this . generateImagesForDefinitions ( resourceGenerationData , this . propertiesToEnumerate . icon ) ;
33
27
this . $logger . info ( "Icons generation completed." ) ;
34
28
}
35
29
36
30
@exported ( "assetsGenerationService" )
37
31
public async generateSplashScreens ( splashesGenerationData : ISplashesGenerationData ) : Promise < void > {
38
32
this . $logger . info ( "Generating splash screens ..." ) ;
39
- const generationData = ( < IGenerateImagesData > splashesGenerationData ) ;
40
- generationData . propertiesToEnumerate = this . propertiesToEnumerate . splash ;
41
- await this . generateImagesForDefinitions ( generationData ) ;
33
+ await this . generateImagesForDefinitions ( splashesGenerationData , this . propertiesToEnumerate . splash ) ;
42
34
this . $logger . info ( "Splash screens generation completed." ) ;
43
35
}
44
36
45
- private async generateImagesForDefinitions ( data : IGenerateImagesData ) : Promise < void > {
46
- data . background = data . background || "white" ;
47
- const assetsStructure = await this . $projectDataService . getAssetsStructure ( { projectDir : data . projectDir } ) ;
48
-
49
- for ( const platform in assetsStructure ) {
50
- if ( data . platform && platform . toLowerCase ( ) !== data . platform . toLowerCase ( ) ) {
51
- continue ;
52
- }
53
-
54
- const platformAssetsStructure = assetsStructure [ platform ] ;
55
-
56
- for ( const imageTypeKey in platformAssetsStructure ) {
57
- if ( data . propertiesToEnumerate . indexOf ( imageTypeKey ) === - 1 || ! platformAssetsStructure [ imageTypeKey ] ) {
58
- continue ;
59
- }
60
-
61
- const imageType = platformAssetsStructure [ imageTypeKey ] ;
62
-
63
- for ( const assetItem of imageType . images ) {
64
- if ( ! assetItem . filename ) {
65
- continue ;
66
- }
67
-
68
- const operation = assetItem . resizeOperation || Operations . Resize ;
69
- const scale = assetItem . scale || 0.8 ;
70
- const outputPath = assetItem . path ;
71
-
72
- switch ( operation ) {
73
- case Operations . OverlayWith :
74
- const imageResize = Math . round ( Math . min ( assetItem . width , assetItem . height ) * scale ) ;
75
- const image = await this . resize ( data . imagePath , imageResize , imageResize ) ;
76
- await this . generateImage ( data . background , assetItem . width , assetItem . height , outputPath , image ) ;
77
- break ;
78
- case Operations . Blank :
79
- await this . generateImage ( data . background , assetItem . width , assetItem . height , outputPath ) ;
80
- break ;
81
- case Operations . Resize :
82
- const resizedImage = await this . resize ( data . imagePath , assetItem . width , assetItem . height ) ;
83
- resizedImage . write ( outputPath ) ;
84
- break ;
85
- default :
86
- throw new Error ( `Invalid image generation operation: ${ operation } ` ) ;
87
- }
88
- }
37
+ private async generateImagesForDefinitions ( generationData : ISplashesGenerationData , propertiesToEnumerate : string [ ] ) : Promise < void > {
38
+ generationData . background = generationData . background || "white" ;
39
+ const assetsStructure = await this . $projectDataService . getAssetsStructure ( generationData ) ;
40
+
41
+ const assetItems = _ ( assetsStructure )
42
+ . filter ( ( assetGroup : IAssetGroup , platform : string ) => {
43
+ return ! generationData . platform || platform . toLowerCase ( ) === generationData . platform . toLowerCase ( ) ;
44
+ } )
45
+ . map ( ( assetGroup : IAssetGroup ) =>
46
+ _ . filter ( assetGroup , ( assetSubGroup : IAssetSubGroup , imageTypeKey : string ) =>
47
+ propertiesToEnumerate . indexOf ( imageTypeKey ) !== - 1 && ! assetSubGroup [ imageTypeKey ]
48
+ )
49
+ )
50
+ . flatten < IAssetSubGroup > ( )
51
+ . map ( assetSubGroup => assetSubGroup . images )
52
+ . flatten < IAssetItem > ( )
53
+ . filter ( assetItem => ! ! assetItem . filename )
54
+ . value ( ) ;
55
+
56
+ for ( const assetItem of assetItems ) {
57
+ const operation = assetItem . resizeOperation || Operations . Resize ;
58
+ const scale = assetItem . scale || 0.8 ;
59
+ const outputPath = assetItem . path ;
60
+
61
+ switch ( operation ) {
62
+ case Operations . OverlayWith :
63
+ const imageResize = Math . round ( Math . min ( assetItem . width , assetItem . height ) * scale ) ;
64
+ const image = await this . resize ( generationData . imagePath , imageResize , imageResize ) ;
65
+ await this . generateImage ( generationData . background , assetItem . width , assetItem . height , outputPath , image ) ;
66
+ break ;
67
+ case Operations . Blank :
68
+ await this . generateImage ( generationData . background , assetItem . width , assetItem . height , outputPath ) ;
69
+ break ;
70
+ case Operations . Resize :
71
+ const resizedImage = await this . resize ( generationData . imagePath , assetItem . width , assetItem . height ) ;
72
+ resizedImage . write ( outputPath ) ;
73
+ break ;
74
+ default :
75
+ throw new Error ( `Invalid image generation operation: ${ operation } ` ) ;
89
76
}
90
77
}
91
78
}
0 commit comments