Skip to content

Commit

Permalink
Adjust order of operations and modify some prompts.
Browse files Browse the repository at this point in the history
  • Loading branch information
rosalyntan committed Sep 20, 2024
1 parent 923a9c5 commit 0a82694
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 24 deletions.
36 changes: 15 additions & 21 deletions src/init/features/dataconnect/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ export interface RequiredInfo {
isNewDatabase: boolean;
schemaGql: File[];
shouldProvisionCSQL: boolean;
sdkInfo?: sdk.SDKInfo;
}

const defaultConnector = {
Expand All @@ -67,14 +66,27 @@ const defaultConnector = {

// doSetup is split into 2 phases - ask questions and then actuate files and API calls based on those answers.
export async function doSetup(setup: Setup, config: Config): Promise<void> {

Check warning on line 68 in src/init/features/dataconnect/index.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Missing JSDoc comment
const info = await askQuestions(setup, config);
const info = await askQuestions(setup);
await actuate(setup, config, info);

const promptForSDKGeneration = await confirm({
message: `Would you like to configure generated SDKs now?`,
default: true,
});
if (promptForSDKGeneration) {
await sdk.doSetup(setup, config);
} else {
logBullet(
`If you'd like to generate an SDK for your new connector later, run ${clc.bold("firebase init dataconnect:sdk")}`,
);
}

logger.info("");
}

// askQuestions prompts the user about the Data Connect service they want to init. Any prompting
// logic should live here, and _no_ actuation logic should live here.
async function askQuestions(setup: Setup, config: Config): Promise<RequiredInfo> {
async function askQuestions(setup: Setup): Promise<RequiredInfo> {
let info: RequiredInfo = {
serviceId: "",
locationId: "",
Expand All @@ -85,7 +97,6 @@ async function askQuestions(setup: Setup, config: Config): Promise<RequiredInfo>
connectors: [defaultConnector],
schemaGql: [],
shouldProvisionCSQL: false,
sdkInfo: undefined,
};
const isBillingEnabled = setup.projectId ? await checkBillingEnabled(setup.projectId) : false;
info = await promptForService(setup, info, isBillingEnabled);
Expand Down Expand Up @@ -120,19 +131,6 @@ async function askQuestions(setup: Setup, config: Config): Promise<RequiredInfo>
default: true,
}))
);

const promptForSDKGeneration = await confirm({
message: `Would you like to configure generated SDKs now?`,
default: true,
});
if (promptForSDKGeneration) {
info.sdkInfo = await sdk.askQuestions(setup, config);
} else {
logBullet(
`If you'd like to generate an SDK for your new connector later, run ${clc.bold("firebase init dataconnect:sdk")}`,
);
}

return info;
}

Expand All @@ -151,10 +149,6 @@ export async function actuate(setup: Setup, config: Config, info: RequiredInfo)
waitForCreation: false,
});
}

if (info.sdkInfo) {
await sdk.actuate(info.sdkInfo, setup.projectId);
}
}

async function writeFiles(config: Config, info: RequiredInfo) {

Check warning on line 154 in src/init/features/dataconnect/index.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Missing return type on function
Expand Down
8 changes: 6 additions & 2 deletions src/init/features/dataconnect/sdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,12 @@ export type SDKInfo = {
export async function doSetup(setup: Setup, config: Config): Promise<void> {
const sdkInfo = await askQuestions(setup, config);
await actuate(sdkInfo, setup.projectId);
logSuccess(
`If you'd like to generate additional SDKs, run ${clc.bold("firebase init dataconnect:sdk")}`,
);
}

export async function askQuestions(setup: Setup, config: Config): Promise<SDKInfo> {
async function askQuestions(setup: Setup, config: Config): Promise<SDKInfo> {
const serviceCfgs = readFirebaseJson(config);
// TODO: This current approach removes comments from YAML files. Consider a different approach that won't.
const serviceInfos = await Promise.all(
Expand Down Expand Up @@ -78,7 +81,8 @@ export async function askQuestions(setup: Setup, config: Config): Promise<SDKInf
logBullet(`Couldn't automatically detect your app directory.`);
appDir = await promptForDirectory({
config,
message: "Where is your app directory?",
message:
"Where is your app directory? Leave blank to set up a generated SDK in your current directory.",
});
const platformGuess = await getPlatformFromFolder(appDir);
if (platformGuess !== Platform.UNDETERMINED) {
Expand Down
2 changes: 1 addition & 1 deletion src/prompt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ export async function promptForDirectory(args: {
while (!dir) {
const target = args.config.path(
await promptOnce({
message: "Where is your app directory?",
message: args.message,
}),
);
if (fileExistsSync(target)) {
Expand Down

0 comments on commit 0a82694

Please sign in to comment.