-
Notifications
You must be signed in to change notification settings - Fork 918
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adding extensions to firebase init #5701
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,9 @@ | ||
- Adds new commands for provisioning and managing Firestore databases: (#5616) | ||
- firestore:databases:list | ||
- firestore:databases:create | ||
- firestore:databases:get | ||
- firestore:databases:update | ||
- firestore:databases:delete | ||
- firestore:locations | ||
- firestore:databases:list | ||
- firestore:databases:create | ||
- firestore:databases:get | ||
- firestore:databases:update | ||
- firestore:databases:delete | ||
- firestore:locations | ||
- Adds `extensions` as an option in `firebase init`. | ||
- Relaxed repo URI validation in ext:dev:publish (#5698). |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,12 @@ | ||
import * as clc from "colorette"; | ||
import * as path from "path"; | ||
import * as fs from "fs-extra"; | ||
|
||
import * as refs from "./refs"; | ||
import { Config } from "../config"; | ||
import { getExtensionSpec, ManifestInstanceSpec } from "../deploy/extensions/planner"; | ||
import { logger } from "../logger"; | ||
import { promptOnce } from "../prompt"; | ||
import { confirm, promptOnce } from "../prompt"; | ||
import { readEnvFile } from "./paramHelper"; | ||
import { FirebaseError } from "../error"; | ||
import * as utils from "../utils"; | ||
|
@@ -60,6 +62,31 @@ export async function writeToManifest( | |
await writeLocalSecrets(specs, config, options.force); | ||
} | ||
|
||
export async function writeEmptyManifest( | ||
config: Config, | ||
options: { nonInteractive: boolean; force: boolean } | ||
): Promise<void> { | ||
if (!fs.existsSync(config.path("extensions"))) { | ||
fs.mkdirSync(config.path("extensions")); | ||
} | ||
if (config.has("extensions") && Object.keys(config.get("extensions")).length) { | ||
const currentExtensions = Object.entries(config.get("extensions")) | ||
.map((i) => `${i[0]}: ${i[1]}`) | ||
.join("\n\t"); | ||
if ( | ||
!(await confirm({ | ||
message: `firebase.json already contains extensions:\n${currentExtensions}\nWould you like to overwrite them?`, | ||
nonInteractive: options.nonInteractive, | ||
force: options.force, | ||
default: false, | ||
})) | ||
) { | ||
return; | ||
} | ||
} | ||
config.set("extensions", {}); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This doesn't delete the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a little awkward as is, but intentional. I'd like init to be idempotent so that it can more safely be used into scripts - init is meant as an interactive command, but some folks still try to use it non interactively. I considered cleaning up the .env files, with a prompt, only in interactive mode, but leaving them doesn't have any ill effects. |
||
} | ||
|
||
/** | ||
* Write the secrets in a list of ManifestInstanceSpec into extensions/{instance-id}.secret.local. | ||
* | ||
|
@@ -173,7 +200,7 @@ export function getInstanceRef(instanceId: string, config: Config): refs.Ref { | |
return refs.parse(source); | ||
} | ||
|
||
function writeExtensionsToFirebaseJson(specs: ManifestInstanceSpec[], config: Config): void { | ||
export function writeExtensionsToFirebaseJson(specs: ManifestInstanceSpec[], config: Config): void { | ||
const extensions = config.get("extensions", {}); | ||
for (const s of specs) { | ||
let target; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { requirePermissions } from "../../../requirePermissions"; | ||
import { Options } from "../../../options"; | ||
import { ensure } from "../../../ensureApiEnabled"; | ||
import { Config } from "../../../config"; | ||
import * as manifest from "../../../extensions/manifest"; | ||
|
||
/** | ||
* Set up a new firebase project for extensions. | ||
*/ | ||
export async function doSetup(setup: any, config: Config, options: Options): Promise<any> { | ||
const projectId = setup?.rcfile?.projects?.default; | ||
if (projectId) { | ||
await requirePermissions({ ...options, project: projectId }); | ||
await Promise.all([ensure(projectId, "firebaseextensions.googleapis.com", "unused", true)]); | ||
} | ||
return manifest.writeEmptyManifest(config, options); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggested copy: "firebase.json already contains extensions:\n${currentExtensions}\nThese extensions will be removed from the manifest if you choose to re-initialize. Would you like to overwrite them?"
Just to be extra clear what overwrite means.