diff --git a/src/commands/init.ts b/src/commands/init.ts index 9a306947dc4..1220b9cc382 100644 --- a/src/commands/init.ts +++ b/src/commands/init.ts @@ -70,6 +70,11 @@ const choices = [ name: "Extensions: Set up an empty Extensions manifest", checked: false, }, + { + value: "frameworkstack", + name: "Frameworkstack: Get started with Frameworks project", + checked: false, + }, ]; const featureNames = choices.map((choice) => choice.value); diff --git a/src/init/features/frameworkstack/constants.ts b/src/init/features/frameworkstack/constants.ts new file mode 100644 index 00000000000..07160810536 --- /dev/null +++ b/src/init/features/frameworkstack/constants.ts @@ -0,0 +1,15 @@ +export const DEFAULT_REGION = "us-central1"; +export const ALLOWED_REGIONS = [ + { name: "us-east1 (South California)", value: "us-east1" }, + { name: "us-east4 (Northern Virginia)", value: "us-east4" }, + { name: "us-east5 (Columbus)", value: "us-east5" }, + { name: "us-central1 (Iowa)", value: "us-central1" }, + { name: "us-central2 (Chicago, IL)", value: "us-central2" }, + { name: "us-south1 (Dallas)", value: "us-south1" }, + { name: "us-west1 (Oregon)", value: "us-west1" }, +]; +export const DEFAULT_DEPLOY_METHOD = "github"; +export const ALLOWED_DEPLOY_METHODS = [ + { name: "Deploy using github", value: "github" }, + { name: "Deploy manual", value: "manually" }, +]; diff --git a/src/init/features/frameworkstack/index.ts b/src/init/features/frameworkstack/index.ts new file mode 100644 index 00000000000..893d879df82 --- /dev/null +++ b/src/init/features/frameworkstack/index.ts @@ -0,0 +1,66 @@ +import * as clc from "colorette"; +import { Options } from "../../../options"; +import { Config } from "../../../config"; +import { requirePermissions } from "../../../requirePermissions"; +import { ensure } from "../../../ensureApiEnabled"; +import * as utils from "../../../utils"; +import { logger } from "../../../logger"; +import { promptOnce } from "../../../prompt"; +import { + DEFAULT_REGION, + ALLOWED_REGIONS, + DEFAULT_DEPLOY_METHOD, + ALLOWED_DEPLOY_METHODS, +} from "./constants"; + +/** + * Setup new Frameworkstack project. + */ +export async function doSetup(setup: any, config: Config, options: Options): Promise { + const projectId = setup?.rcfile?.projects?.default; + if (projectId) { + await requirePermissions({ ...options, project: projectId }); + await Promise.all([ensure(projectId, "firebaseextensions.googleapis.com", "unused", true)]); + } + setup.frameworkstack = {}; + + utils.logBullet("First we need a few details to create your service."); + + await promptOnce( + { + name: "serviceName", + type: "input", + default: "acme-inc-web", + message: "Create a name for your service [1-64 characters]", + }, + setup.frameworkstack + ); + + await promptOnce( + { + name: "regionName", + type: "list", + default: DEFAULT_REGION, + message: + "Please select a region " + + `(${clc.yellow("info")}: Your region determines where your backend is located):\n`, + choices: ALLOWED_REGIONS, + }, + setup.frameworkstack + ); + + utils.logSuccess(`Region set to ${setup.frameworkstack.regionName}.`); + + logger.info(clc.bold(`\n${clc.white("===")} Deploy Setup`)); + + await promptOnce( + { + name: "deployMethod", + type: "list", + default: DEFAULT_DEPLOY_METHOD, + message: "How do you want to deploy", + choices: ALLOWED_DEPLOY_METHODS, + }, + setup.frameworkstack + ); +} diff --git a/src/init/features/index.ts b/src/init/features/index.ts index a52bfd6f400..fe6b0e0ace9 100644 --- a/src/init/features/index.ts +++ b/src/init/features/index.ts @@ -10,3 +10,4 @@ export { doSetup as extensions } from "./extensions"; export { doSetup as project } from "./project"; export { doSetup as remoteconfig } from "./remoteconfig"; export { initGitHub as hostingGithub } from "./hosting/github"; +export { doSetup as frameworkstack } from "./frameworkstack"; diff --git a/src/init/index.ts b/src/init/index.ts index 19565c19769..e4ca74465b4 100644 --- a/src/init/index.ts +++ b/src/init/index.ts @@ -29,6 +29,7 @@ const featureFns = new Map P ["project", features.project], // always runs, sets up .firebaserc ["remoteconfig", features.remoteconfig], ["hosting:github", features.hostingGithub], + ["frameworkstack", features.frameworkstack], ]); export async function init(setup: Setup, config: any, options: any): Promise {