Skip to content

Commit c8dd88a

Browse files
aalejjoehan
andauthored
Fix issue where projectId and displayName are not getting parsed (#8635)
* Fix issue where projectId and displayName are not getting parsed * Use options --------- Co-authored-by: Joe Hanley <[email protected]>
1 parent 3c3b75f commit c8dd88a

File tree

4 files changed

+45
-34
lines changed

4 files changed

+45
-34
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1+
- Fixed issue where `projects:create` didn't correctly parse the `projectId` and `displayName` input. (#8634)
12
- Improved GetDatabase API call caching for Firestore function deployments. (#8681)
23
- Increased timeout for linking CloudSQL instances to Data Connect.

src/commands/projects-create.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export const command = new Command("projects:create [projectId]")
3434
}
3535
if (!options.nonInteractive) {
3636
// Inserts projectId and displayName
37-
options = { ...options, ...(await promptProjectCreation()) };
37+
options = { ...options, ...(await promptProjectCreation(options)) };
3838
}
3939
if (!options.projectId) {
4040
throw new FirebaseError("Project ID cannot be empty");

src/init/features/project.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import { FirebaseProjectMetadata } from "../../types/project";
1414
import { logger } from "../../logger";
1515
import * as utils from "../../utils";
1616
import * as prompt from "../../prompt";
17+
import { Options } from "../../options";
1718

1819
const OPTION_NO_PROJECT = "Don't set up a default project";
1920
const OPTION_USE_PROJECT = "Use an existing project";
@@ -41,12 +42,12 @@ function toInitProjectInfo(projectMetaData: FirebaseProjectMetadata): InitProjec
4142
};
4243
}
4344

44-
async function promptAndCreateNewProject(): Promise<FirebaseProjectMetadata> {
45+
async function promptAndCreateNewProject(options: Options): Promise<FirebaseProjectMetadata> {
4546
utils.logBullet(
4647
"If you want to create a project in a Google Cloud organization or folder, please use " +
4748
`"firebase projects:create" instead, and return to this command when you've created the project.`,
4849
);
49-
const { projectId, displayName } = await promptProjectCreation();
50+
const { projectId, displayName } = await promptProjectCreation(options);
5051
// N.B. This shouldn't be possible because of the validator on the input field, but it
5152
// is being left around in case there's something I don't know.
5253
if (!projectId) {
@@ -82,7 +83,7 @@ async function projectChoicePrompt(options: any): Promise<FirebaseProjectMetadat
8283
case OPTION_USE_PROJECT:
8384
return getOrPromptProject(options);
8485
case OPTION_NEW_PROJECT:
85-
return promptAndCreateNewProject();
86+
return promptAndCreateNewProject(options);
8687
case OPTION_ADD_FIREBASE:
8788
return promptAndAddFirebaseToCloudProject();
8889
default:

src/management/projects.ts

Lines changed: 39 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { logger } from "../logger";
1010
import * as utils from "../utils";
1111
import { FirebaseProjectMetadata, CloudProjectInfo, ProjectPage } from "../types/project";
1212
import { bestEffortEnsure } from "../ensureApiEnabled";
13+
import { Options } from "../options";
1314

1415
const TIMEOUT_MILLIS = 30000;
1516
const MAXIMUM_PROMPT_LIST = 100;
@@ -29,35 +30,41 @@ export interface ProjectParentResource {
2930
/**
3031
* Prompt user to create a new project
3132
*/
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+
}));
6168

6269
return { projectId, displayName };
6370
}
@@ -137,7 +144,9 @@ function logNewFirebaseProjectInfo(projectInfo: FirebaseProjectMetadata): void {
137144
/**
138145
* Get the user's desired project, prompting if necessary.
139146
*/
140-
export async function getOrPromptProject(options: any): Promise<FirebaseProjectMetadata> {
147+
export async function getOrPromptProject(
148+
options: Partial<Options>,
149+
): Promise<FirebaseProjectMetadata> {
141150
if (options.project) {
142151
return await getFirebaseProject(options.project);
143152
}

0 commit comments

Comments
 (0)