@@ -28,91 +28,92 @@ export function generateRunOptions(platform: Platform, resourcesDirectory: strin
28
28
const types = validateResourceTypes ( typeOption ? [ typeOption ] : RESOURCE_TYPES ) ;
29
29
30
30
return {
31
- [ ResourceType . ADAPTIVE_ICON ] : types . includes ( ResourceType . ADAPTIVE_ICON ) ? parseAdaptiveIconOptions ( platform , resourcesDirectory , args ) : undefined ,
32
- [ ResourceType . ICON ] : types . includes ( ResourceType . ICON ) ? parseIconOptions ( platform , resourcesDirectory , args ) : undefined ,
33
- [ ResourceType . SPLASH ] : types . includes ( ResourceType . SPLASH ) ? parseSplashOptions ( platform , resourcesDirectory , args ) : undefined ,
31
+ [ ResourceType . ADAPTIVE_ICON ] : types . includes ( ResourceType . ADAPTIVE_ICON ) ? parseAdaptiveIconResourceOptions ( platform , resourcesDirectory , args ) : undefined ,
32
+ [ ResourceType . ICON ] : types . includes ( ResourceType . ICON ) ? parseSimpleResourceOptions ( platform , ResourceType . ICON , resourcesDirectory , args ) : undefined ,
33
+ [ ResourceType . SPLASH ] : types . includes ( ResourceType . SPLASH ) ? parseSimpleResourceOptions ( platform , ResourceType . SPLASH , resourcesDirectory , args ) : undefined ,
34
34
} ;
35
35
}
36
36
37
- export function parseAdaptiveIconOptions ( platform : Platform , resourcesDirectory : string , args : ReadonlyArray < string > ) : AdaptiveIconResourceOptions | undefined {
37
+ export function parseAdaptiveIconResourceOptions ( platform : Platform , resourcesDirectory : string , args : ReadonlyArray < string > ) : AdaptiveIconResourceOptions | undefined {
38
38
if ( platform !== Platform . ANDROID ) {
39
39
return ;
40
40
}
41
41
42
42
return {
43
- foreground : parseAdaptiveIconTypeOptions ( ResourceKey . FOREGROUND , resourcesDirectory , args ) ,
44
- background : parseAdaptiveIconTypeOptions ( ResourceKey . BACKGROUND , resourcesDirectory , args ) ,
43
+ icon : parseSimpleResourceOptions ( platform , ResourceType . ICON , resourcesDirectory , args ) ,
44
+ foreground : parseAdaptiveIconForegroundOptions ( resourcesDirectory , args ) ,
45
+ background : parseAdaptiveIconBackgroundOptions ( resourcesDirectory , args ) ,
45
46
} ;
46
47
}
47
48
48
- export function parseAdaptiveIconTypeOptions ( type : ResourceKey . FOREGROUND | ResourceKey . BACKGROUND , resourcesDirectory : string , args : ReadonlyArray < string > ) : AdaptiveIconResourceOptions [ typeof type ] {
49
- const sourceOption = getOptionValue ( args , `--icon-${ type } -source` ) ;
50
- const options : Partial < AdaptiveIconResourceOptions [ typeof type ] > = { } ;
49
+ export function parseAdaptiveIconForegroundOptions ( resourcesDirectory : string , args : ReadonlyArray < string > ) : AdaptiveIconResourceOptions [ 'foreground' ] {
50
+ const source = parseAdaptiveIconSourceFromArgs ( ResourceKey . FOREGROUND , args ) ;
51
51
52
- if ( sourceOption ) {
53
- const source : Source = sourceOption . startsWith ( '#' )
54
- ? { type : SourceType . COLOR , color : sourceOption }
55
- : { type : SourceType . RASTER , src : sourceOption } ;
52
+ if ( source && source . type !== SourceType . RASTER ) {
53
+ throw new BadInputError ( 'Adaptive icon foreground must be an image.' ) ;
54
+ }
56
55
57
- if ( type === ResourceKey . FOREGROUND && source . type !== SourceType . RASTER ) {
58
- throw new BadInputError ( 'Adaptive icon foreground must be an image.' ) ;
59
- }
56
+ return {
57
+ sources : source
58
+ ? [ source ]
59
+ : getDefaultAdaptiveIconSources ( ResourceKey . FOREGROUND , resourcesDirectory ) ,
60
+ } ;
61
+ }
60
62
61
- options . sources = [ source ] ;
62
- }
63
+ export function parseAdaptiveIconBackgroundOptions ( resourcesDirectory : string , args : ReadonlyArray < string > ) : AdaptiveIconResourceOptions [ 'background' ] {
64
+ const source = parseAdaptiveIconSourceFromArgs ( ResourceKey . BACKGROUND , args ) ;
63
65
64
66
return {
65
- sources : [
66
- `${ resourcesDirectory } /android/icon-${ type } .png` ,
67
- `${ resourcesDirectory } /android/icon-${ type } .jpg` ,
68
- `${ resourcesDirectory } /android/icon-${ type } .jpeg` ,
69
- ] ,
70
- ...options ,
67
+ sources : source
68
+ ? [ source ]
69
+ : getDefaultAdaptiveIconSources ( ResourceKey . BACKGROUND , resourcesDirectory ) ,
71
70
} ;
72
71
}
73
72
74
- export function parseIconOptions ( platform : Platform , resourcesDirectory : string , args : ReadonlyArray < string > ) : SimpleResourceOptions {
75
- const sourceOption = getOptionValue ( args , '--icon-source' ) ;
76
- const options : Partial < SimpleResourceOptions > = { } ;
73
+ export function parseSimpleResourceOptions ( platform : Platform , type : ResourceType . ICON | ResourceType . SPLASH , resourcesDirectory : string , args : ReadonlyArray < string > ) : SimpleResourceOptions {
74
+ const source = parseSourceFromArgs ( type , args ) ;
75
+ return { sources : source ? [ source ] : getDefaultSources ( platform , type , resourcesDirectory ) } ;
76
+ }
77
77
78
- if ( sourceOption ) {
79
- options . sources = [ sourceOption ] ;
78
+ export function parseAdaptiveIconSourceFromArgs ( type : ResourceKey . FOREGROUND | ResourceKey . BACKGROUND , args : ReadonlyArray < string > ) : Source | undefined {
79
+ const sourceOption = getOptionValue ( args , `--icon-${ type } -source` ) ;
80
+
81
+ if ( ! sourceOption ) {
82
+ return ;
80
83
}
81
84
82
- return {
83
- ...{
84
- sources : [
85
- `${ resourcesDirectory } /${ platform } /icon.png` ,
86
- `${ resourcesDirectory } /${ platform } /icon.jpg` ,
87
- `${ resourcesDirectory } /${ platform } /icon.jpeg` ,
88
- `${ resourcesDirectory } /icon.png` ,
89
- `${ resourcesDirectory } /icon.jpg` ,
90
- `${ resourcesDirectory } /icon.jpeg` ,
91
- ] ,
92
- } ,
93
- ...options ,
94
- } ;
85
+ return parseSource ( sourceOption ) ;
95
86
}
96
87
97
- export function parseSplashOptions ( platform : Platform , resourcesDirectory : string , args : ReadonlyArray < string > ) : SimpleResourceOptions {
98
- const sourceOption = getOptionValue ( args , '--splash-source' ) ;
99
- const options : Partial < SimpleResourceOptions > = { } ;
88
+ export function parseSourceFromArgs ( type : ResourceType . ICON | ResourceType . SPLASH , args : ReadonlyArray < string > ) : string | undefined {
89
+ const sourceOption = getOptionValue ( args , `--${ type } -source` ) ;
100
90
101
91
if ( sourceOption ) {
102
- options . sources = [ sourceOption ] ;
92
+ return sourceOption ;
103
93
}
94
+ }
104
95
105
- return {
106
- ...{
107
- sources : [
108
- `${ resourcesDirectory } /${ platform } /splash.png` ,
109
- `${ resourcesDirectory } /${ platform } /splash.jpg` ,
110
- `${ resourcesDirectory } /${ platform } /splash.jpeg` ,
111
- `${ resourcesDirectory } /splash.png` ,
112
- `${ resourcesDirectory } /splash.jpg` ,
113
- `${ resourcesDirectory } /splash.jpeg` ,
114
- ] ,
115
- } ,
116
- ...options ,
117
- } ;
96
+ export function parseSource ( sourceOption : string ) : Source {
97
+ return sourceOption . startsWith ( '#' )
98
+ ? { type : SourceType . COLOR , color : sourceOption }
99
+ : { type : SourceType . RASTER , src : sourceOption } ;
100
+ }
101
+
102
+ export function getDefaultSources ( platform : Platform , type : ResourceType , resourcesDirectory : string ) : string [ ] {
103
+ return [
104
+ `${ resourcesDirectory } /${ platform } /${ type } .png` ,
105
+ `${ resourcesDirectory } /${ platform } /${ type } .jpg` ,
106
+ `${ resourcesDirectory } /${ platform } /${ type } .jpeg` ,
107
+ `${ resourcesDirectory } /${ type } .png` ,
108
+ `${ resourcesDirectory } /${ type } .jpg` ,
109
+ `${ resourcesDirectory } /${ type } .jpeg` ,
110
+ ] ;
111
+ }
112
+
113
+ export function getDefaultAdaptiveIconSources ( type : ResourceKey . FOREGROUND | ResourceKey . BACKGROUND , resourcesDirectory : string ) : string [ ] {
114
+ return [
115
+ `${ resourcesDirectory } /android/icon-${ type } .png` ,
116
+ `${ resourcesDirectory } /android/icon-${ type } .jpg` ,
117
+ `${ resourcesDirectory } /android/icon-${ type } .jpeg` ,
118
+ ] ;
118
119
}
0 commit comments