@@ -10,6 +10,7 @@ import { logger } from "../logger";
10
10
import * as utils from "../utils" ;
11
11
import { FirebaseProjectMetadata , CloudProjectInfo , ProjectPage } from "../types/project" ;
12
12
import { bestEffortEnsure } from "../ensureApiEnabled" ;
13
+ import { Options } from "../options" ;
13
14
14
15
const TIMEOUT_MILLIS = 30000 ;
15
16
const MAXIMUM_PROMPT_LIST = 100 ;
@@ -29,35 +30,41 @@ export interface ProjectParentResource {
29
30
/**
30
31
* Prompt user to create a new project
31
32
*/
32
- export async function promptProjectCreation ( ) : Promise < { projectId : string ; displayName : string } > {
33
- const projectId = await prompt . input ( {
34
- message :
35
- "Please specify a unique project id " +
36
- `(${ clc . yellow ( "warning" ) } : cannot be modified afterward) [6-30 characters]:\n` ,
37
- validate : ( projectId : string ) => {
38
- if ( projectId . length < 6 ) {
39
- return "Project ID must be at least 6 characters long" ;
40
- } else if ( projectId . length > 30 ) {
41
- return "Project ID cannot be longer than 30 characters" ;
42
- } else {
43
- return true ;
44
- }
45
- } ,
46
- } ) ;
47
-
48
- const displayName = await prompt . input ( {
49
- default : projectId ,
50
- message : "What would you like to call your project? (defaults to your project ID)" ,
51
- validate : ( displayName : string ) => {
52
- if ( displayName . length < 4 ) {
53
- return "Project name must be at least 4 characters long" ;
54
- } else if ( displayName . length > 30 ) {
55
- return "Project name cannot be longer than 30 characters" ;
56
- } else {
57
- return true ;
58
- }
59
- } ,
60
- } ) ;
33
+ export async function promptProjectCreation (
34
+ options : Options ,
35
+ ) : Promise < { projectId : string ; displayName : string } > {
36
+ const projectId =
37
+ options . projectId ??
38
+ ( await prompt . input ( {
39
+ message :
40
+ "Please specify a unique project id " +
41
+ `(${ clc . yellow ( "warning" ) } : cannot be modified afterward) [6-30 characters]:\n` ,
42
+ validate : ( projectId : string ) => {
43
+ if ( projectId . length < 6 ) {
44
+ return "Project ID must be at least 6 characters long" ;
45
+ } else if ( projectId . length > 30 ) {
46
+ return "Project ID cannot be longer than 30 characters" ;
47
+ } else {
48
+ return true ;
49
+ }
50
+ } ,
51
+ } ) ) ;
52
+
53
+ const displayName =
54
+ ( options . displayName as string ) ??
55
+ ( await prompt . input ( {
56
+ default : projectId ,
57
+ message : "What would you like to call your project? (defaults to your project ID)" ,
58
+ validate : ( displayName : string ) => {
59
+ if ( displayName . length < 4 ) {
60
+ return "Project name must be at least 4 characters long" ;
61
+ } else if ( displayName . length > 30 ) {
62
+ return "Project name cannot be longer than 30 characters" ;
63
+ } else {
64
+ return true ;
65
+ }
66
+ } ,
67
+ } ) ) ;
61
68
62
69
return { projectId, displayName } ;
63
70
}
@@ -137,7 +144,9 @@ function logNewFirebaseProjectInfo(projectInfo: FirebaseProjectMetadata): void {
137
144
/**
138
145
* Get the user's desired project, prompting if necessary.
139
146
*/
140
- export async function getOrPromptProject ( options : any ) : Promise < FirebaseProjectMetadata > {
147
+ export async function getOrPromptProject (
148
+ options : Partial < Options > ,
149
+ ) : Promise < FirebaseProjectMetadata > {
141
150
if ( options . project ) {
142
151
return await getFirebaseProject ( options . project ) ;
143
152
}
0 commit comments