1
1
import * as clc from "colorette" ;
2
- import * as ora from "ora" ;
3
2
4
3
import { Command } from "../command" ;
5
4
import { needProjectId } from "../projectUtils" ;
@@ -8,42 +7,16 @@ import {
8
7
AndroidAppMetadata ,
9
8
AppMetadata ,
10
9
AppPlatform ,
11
- createAndroidApp ,
12
- createIosApp ,
13
- createWebApp ,
14
10
getAppPlatform ,
15
11
IosAppMetadata ,
12
+ sdkInit ,
13
+ SdkInitOptions ,
16
14
WebAppMetadata ,
17
15
} from "../management/apps" ;
18
- import { prompt , promptOnce , Question } from "../prompt" ;
16
+ import { promptOnce } from "../prompt" ;
19
17
import { requireAuth } from "../requireAuth" ;
20
18
import { logger } from "../logger" ;
21
-
22
- const DISPLAY_NAME_QUESTION : Question = {
23
- type : "input" ,
24
- name : "displayName" ,
25
- default : "" ,
26
- message : "What would you like to call your app?" ,
27
- } ;
28
-
29
- interface CreateFirebaseAppOptions {
30
- project : string ;
31
- nonInteractive : boolean ;
32
- displayName ?: string ;
33
- }
34
-
35
- interface CreateIosAppOptions extends CreateFirebaseAppOptions {
36
- bundleId ?: string ;
37
- appStoreId ?: string ;
38
- }
39
-
40
- interface CreateAndroidAppOptions extends CreateFirebaseAppOptions {
41
- packageName : string ;
42
- }
43
-
44
- interface CreateWebAppOptions extends CreateFirebaseAppOptions {
45
- displayName : string ;
46
- }
19
+ import { Options } from "../options" ;
47
20
48
21
function logPostAppCreationInformation (
49
22
appMetadata : IosAppMetadata | AndroidAppMetadata | WebAppMetadata ,
@@ -72,91 +45,10 @@ function logPostAppCreationInformation(
72
45
logger . info ( ` firebase apps:sdkconfig ${ appPlatform } ${ appMetadata . appId } ` ) ;
73
46
}
74
47
75
- async function initiateIosAppCreation ( options : CreateIosAppOptions ) : Promise < IosAppMetadata > {
76
- if ( ! options . nonInteractive ) {
77
- await prompt ( options , [
78
- DISPLAY_NAME_QUESTION ,
79
- {
80
- type : "input" ,
81
- default : "" ,
82
- name : "bundleId" ,
83
- message : "Please specify your iOS app bundle ID:" ,
84
- } ,
85
- {
86
- type : "input" ,
87
- default : "" ,
88
- name : "appStoreId" ,
89
- message : "Please specify your iOS app App Store ID:" ,
90
- } ,
91
- ] ) ;
92
- }
93
- if ( ! options . bundleId ) {
94
- throw new FirebaseError ( "Bundle ID for iOS app cannot be empty" ) ;
95
- }
96
-
97
- const spinner = ora ( "Creating your iOS app" ) . start ( ) ;
98
- try {
99
- const appData = await createIosApp ( options . project , {
100
- displayName : options . displayName ,
101
- bundleId : options . bundleId ,
102
- appStoreId : options . appStoreId ,
103
- } ) ;
104
- spinner . succeed ( ) ;
105
- return appData ;
106
- } catch ( err : unknown ) {
107
- spinner . fail ( ) ;
108
- throw err ;
109
- }
110
- }
111
-
112
- async function initiateAndroidAppCreation (
113
- options : CreateAndroidAppOptions ,
114
- ) : Promise < AndroidAppMetadata > {
115
- if ( ! options . nonInteractive ) {
116
- await prompt ( options , [
117
- DISPLAY_NAME_QUESTION ,
118
- {
119
- type : "input" ,
120
- default : "" ,
121
- name : "packageName" ,
122
- message : "Please specify your Android app package name:" ,
123
- } ,
124
- ] ) ;
125
- }
126
- if ( ! options . packageName ) {
127
- throw new FirebaseError ( "Package name for Android app cannot be empty" ) ;
128
- }
129
-
130
- const spinner = ora ( "Creating your Android app" ) . start ( ) ;
131
- try {
132
- const appData = await createAndroidApp ( options . project , {
133
- displayName : options . displayName ,
134
- packageName : options . packageName ,
135
- } ) ;
136
- spinner . succeed ( ) ;
137
- return appData ;
138
- } catch ( err : unknown ) {
139
- spinner . fail ( ) ;
140
- throw err ;
141
- }
142
- }
143
-
144
- async function initiateWebAppCreation ( options : CreateWebAppOptions ) : Promise < WebAppMetadata > {
145
- if ( ! options . nonInteractive ) {
146
- await prompt ( options , [ DISPLAY_NAME_QUESTION ] ) ;
147
- }
148
- if ( ! options . displayName ) {
149
- throw new FirebaseError ( "Display name for Web app cannot be empty" ) ;
150
- }
151
- const spinner = ora ( "Creating your Web app" ) . start ( ) ;
152
- try {
153
- const appData = await createWebApp ( options . project , { displayName : options . displayName } ) ;
154
- spinner . succeed ( ) ;
155
- return appData ;
156
- } catch ( err : unknown ) {
157
- spinner . fail ( ) ;
158
- throw err ;
159
- }
48
+ interface AppsCreateOptions extends Options {
49
+ packageName : string ;
50
+ bundleId : string ;
51
+ appStoreId : string ;
160
52
}
161
53
162
54
export const command = new Command ( "apps:create [platform] [displayName]" )
@@ -169,9 +61,9 @@ export const command = new Command("apps:create [platform] [displayName]")
169
61
. before ( requireAuth )
170
62
. action (
171
63
async (
172
- platform : string = "" ,
64
+ platform = "" ,
173
65
displayName : string | undefined ,
174
- options : any ,
66
+ options : AppsCreateOptions ,
175
67
) : Promise < AppMetadata > => {
176
68
const projectId = needProjectId ( options ) ;
177
69
@@ -194,21 +86,7 @@ export const command = new Command("apps:create [platform] [displayName]")
194
86
195
87
logger . info ( `Create your ${ appPlatform } app in project ${ clc . bold ( projectId ) } :` ) ;
196
88
options . displayName = displayName ; // add displayName into options to pass into prompt function
197
- let appData ;
198
- switch ( appPlatform ) {
199
- case AppPlatform . IOS :
200
- appData = await initiateIosAppCreation ( options ) ;
201
- break ;
202
- case AppPlatform . ANDROID :
203
- appData = await initiateAndroidAppCreation ( options ) ;
204
- break ;
205
- case AppPlatform . WEB :
206
- appData = await initiateWebAppCreation ( options ) ;
207
- break ;
208
- default :
209
- throw new FirebaseError ( "Unexpected error. This should not happen" ) ;
210
- }
211
-
89
+ const appData = await sdkInit ( appPlatform , options as SdkInitOptions ) ;
212
90
logPostAppCreationInformation ( appData , appPlatform ) ;
213
91
return appData ;
214
92
} ,
0 commit comments