GSI - Employe Self Service Mobile
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

283 lines
20 KiB

2 months ago
  1. # Firebase CLI [![Actions Status][gh-actions-badge]][gh-actions] [![Node Version][node-badge]][npm] [![NPM version][npm-badge]][npm]
  2. The Firebase Command Line Interface (CLI) Tools can be used to test, manage, and deploy your Firebase project from the command line.
  3. - Deploy code and assets to your Firebase projects
  4. - Run a local web server for your Firebase Hosting site
  5. - Interact with data in your Firebase database
  6. - Import/Export users into/from Firebase Auth
  7. To get started with the Firebase CLI, read the full list of commands below or check out the [documentation](https://firebase.google.com/docs/cli).
  8. ## Installation
  9. ### Node Package
  10. You can install the Firebase CLI using npm (the Node Package Manager). Note that you will need to install
  11. [Node.js](http://nodejs.org/) and [npm](https://npmjs.org/). Installing Node.js should install npm as well.
  12. To download and install the Firebase CLI run the following command:
  13. ```bash
  14. npm install -g firebase-tools
  15. ```
  16. This will provide you with the globally accessible `firebase` command.
  17. ### Standalone Binary
  18. The standalone binary distribution of the Firebase CLI allows you to download a `firebase` executable
  19. without any dependencies.
  20. To download and install the CLI run the following command:
  21. ```bash
  22. curl -sL firebase.tools | bash
  23. ```
  24. ## Commands
  25. **The command `firebase --help` lists the available commands and `firebase <command> --help` shows more details for an individual command.**
  26. If a command is project-specific, you must either be inside a project directory with an
  27. active project alias or specify the Firebase project id with the `-P <project_id>` flag.
  28. Below is a brief list of the available commands and their function:
  29. ### Configuration Commands
  30. | Command | Description |
  31. | -------------- | ----------------------------------------------------------------------------------------------------------------------------------------------- |
  32. | **login** | Authenticate to your Firebase account. Requires access to a web browser. |
  33. | **logout** | Sign out of the Firebase CLI. |
  34. | **login:ci** | Generate an authentication token for use in non-interactive environments. |
  35. | **login:add** | Authorize the CLI for an additional account. |
  36. | **login:list** | List authorized CLI accounts. |
  37. | **login:use** | Set the default account to use for this project |
  38. | **use** | Set active Firebase project, manage project aliases. |
  39. | **open** | Quickly open a browser to relevant project resources. |
  40. | **init** | Setup a new Firebase project in the current directory. This command will create a `firebase.json` configuration file in your current directory. |
  41. | **help** | Display help information about the CLI or specific commands. |
  42. Append `--no-localhost` to login (i.e., `firebase login --no-localhost`) to copy and paste code instead of starting a local server for authentication. A use case might be if you SSH into an instance somewhere and you need to authenticate to Firebase on that machine.
  43. ### Project Management Commands
  44. | Command | Description |
  45. | ------------------------ | ---------------------------------------------------------- |
  46. | **apps:create** | Create a new Firebase app in a project. |
  47. | **apps:list** | List the registered apps of a Firebase project. |
  48. | **apps:sdkconfig** | Print the configuration of a Firebase app. |
  49. | **projects:addfirebase** | Add Firebase resources to a Google Cloud Platform project. |
  50. | **projects:create** | Create a new Firebase project. |
  51. | **projects:list** | Print a list of all of your Firebase projects. |
  52. ### Deployment and Local Emulation
  53. These commands let you deploy and interact with your Firebase services.
  54. | Command | Description |
  55. | ----------------------------- | ----------------------------------------------------------------------------------------------------------------------------- |
  56. | **emulators:exec** | Start the local Firebase emulators, run a test script, then shut down the emulators. |
  57. | **emulators:start** | Start the local Firebase emulators. |
  58. | **deploy** | Deploys your Firebase project. Relies on `firebase.json` configuration and your local project folder. |
  59. | **serve** | Start a local server with your Firebase Hosting configuration and HTTPS-triggered Cloud Functions. Relies on `firebase.json`. |
  60. | **setup:emulators:database** | Downloads the database emulator. |
  61. | **setup:emulators:firestore** | Downloads the firestore emulator. |
  62. ### App Distribution Commands
  63. | Command | Description |
  64. | ------------------------------ | ---------------------- |
  65. | **appdistribution:distribute** | Upload a distribution. |
  66. ### Auth Commands
  67. | Command | Description |
  68. | --------------- | ------------------------------------------------------ |
  69. | **auth:import** | Batch importing accounts into Firebase from data file. |
  70. | **auth:export** | Batch exporting accounts from Firebase into data file. |
  71. Detailed doc is [here](https://firebase.google.com/docs/cli/auth).
  72. ### Realtime Database Commands
  73. | Command | Description |
  74. | ----------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------- |
  75. | **database:get** | Fetch data from the current project's database and display it as JSON. Supports querying on indexed data. |
  76. | **database:set** | Replace all data at a specified location in the current project's database. Takes input from file, STDIN, or command-line argument. |
  77. | **database:push** | Push new data to a list at a specified location in the current project's database. Takes input from file, STDIN, or command-line argument. |
  78. | **database:remove** | Delete all data at a specified location in the current project's database. |
  79. | **database:update** | Perform a partial update at a specified location in the current project's database. Takes input from file, STDIN, or command-line argument. |
  80. | **database:profile** | Profile database usage and generate a report. |
  81. | **database:instances:create** | Create a realtime database instance. |
  82. | **database:instances:list** | List realtime database instances. |
  83. | **database:settings:get** | Read the realtime database setting at path |
  84. | **database:settings:set** | Set the realtime database setting at path. |
  85. ### Extensions Commands
  86. | Command | Description |
  87. | ----------------- | ------------------------------------------------------------------------------------------- |
  88. | **ext** | Display information on how to use ext commands and extensions installed to your project. |
  89. | **ext:configure** | Configure an existing extension instance. |
  90. | **ext:info** | Display information about an extension by name (extensionName@x.y.z for a specific version) |
  91. | **ext:install** | Install an extension. |
  92. | **ext:list** | List all the extensions that are installed in your Firebase project. |
  93. | **ext:uninstall** | Uninstall an extension that is installed in your Firebase project by Instance ID. |
  94. | **ext:update** | Update an existing extension instance to the latest version. |
  95. ### Cloud Firestore Commands
  96. | Command | Description |
  97. | --------------------- | ------------------------------------------------------------------------------------------------------------------- |
  98. | **firestore:delete** | Delete documents or collections from the current project's database. Supports recursive deletion of subcollections. |
  99. | **firestore:indexes** | List all deployed indexes from the current project. |
  100. ### Cloud Functions Commands
  101. | Command | Description |
  102. | ----------------------------- | ------------------------------------------------------------------------------------------------------------ |
  103. | **functions:log** | Read logs from deployed Cloud Functions. |
  104. | **functions:list** | List all deployed functions in your Firebase project. |
  105. | **functions:config:set** | Store runtime configuration values for the current project's Cloud Functions. |
  106. | **functions:config:get** | Retrieve existing configuration values for the current project's Cloud Functions. |
  107. | **functions:config:unset** | Remove values from the current project's runtime configuration. |
  108. | **functions:config:clone** | Copy runtime configuration from one project environment to another. |
  109. | **functions:secrets:set** | Create or update a secret for use in Cloud Functions for Firebase. |
  110. | **functions:secrets:get** | Get metadata for secret and its versions. |
  111. | **functions:secrets:access** | Access secret value given secret and its version. Defaults to accessing the latest version. |
  112. | **functions:secrets:prune** | Destroys unused secrets. |
  113. | **functions:secrets:destroy** | Destroy a secret. Defaults to destroying the latest version. |
  114. | **functions:delete** | Delete one or more Cloud Functions by name or group name. |
  115. | **functions:shell** | Locally emulate functions and start Node.js shell where these local functions can be invoked with test data. |
  116. ### Hosting Commands
  117. | Command | Description |
  118. | ------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
  119. | **hosting:disable** | Stop serving Firebase Hosting traffic for the active project. A "Site Not Found" message will be displayed at your project's Hosting URL after running this command. |
  120. ### Remote Config Commands
  121. | Command | Description |
  122. | ------------------------------ | ---------------------------------------------------------------------------------------------------------- |
  123. | **remoteconfig:get** | Get a Firebase project's Remote Config template. |
  124. | **remoteconfig:versions:list** | Get a list of the most recent Firebase Remote Config template versions that have been published. |
  125. | **remoteconfig:rollback** | Roll back a project's published Remote Config template to the version provided by `--version_number` flag. |
  126. Use `firebase:deploy --only remoteconfig` to update and publish a project's Firebase Remote Config template.
  127. ## Authentication
  128. ### General
  129. The Firebase CLI can use one of four authentication methods listed in descending priority:
  130. - **User Token** - **DEPRECATED: this authentication method will be removed in a future major version of `firebase-tools`; use a service account to authenticate instead** - provide an explicit long-lived Firebase user token generated from `firebase login:ci`. Note that these tokens are extremely sensitive long-lived credentials and are not the right option for most cases. Consider using service account authorization instead. The token can be set in one of two ways:
  131. - Set the `--token` flag on any command, for example `firebase --token="<token>" projects:list`.
  132. - Set the `FIREBASE_TOKEN` environment variable.
  133. - **Local Login** - run `firebase login` to log in to the CLI directly as yourself. The CLI will cache an authorized user credential on your machine.
  134. - **Service Account** - set the `GOOGLE_APPLICATION_CREDENTIALS` environment variable to point to the path of a JSON service account key file. For more details, see Google Cloud's [Getting started with authentication](https://cloud.google.com/docs/authentication/getting-started) guide.
  135. - **Application Default Credentials** - if you use the `gcloud` CLI and log in with `gcloud auth application-default login`, the Firebase CLI will use them if none of the above credentials are present.
  136. ### Multiple Accounts
  137. By default `firebase login` sets a single global account for use on all projects.
  138. If you have multiple Google accounts which you use for Firebase projects you can
  139. authorize multiple accounts and use them on a per-project or per-command basis.
  140. To authorize an additonal account for use with the CLI, run `firebase login:add`.
  141. You can view the list of authorized accounts with `firebase login:list`.
  142. To set the default account for a specific Firebase project directory, run
  143. `firebase login:use` from within the directory and select the desired account.
  144. To check the default account for a directory, run `firebase login:list` and the
  145. default account for the current context will be listed first.
  146. To set the account for a specific command invocation, use the `--account` flag
  147. with any command. For example `firebase --account=user@domain.com deploy`. The
  148. specified account must have already been added to the Firebase CLI using
  149. `firebase login:add`.
  150. ### Cloud Functions Emulator
  151. The Cloud Functions emulator is exposed through commands like `emulators:start`,
  152. `serve` and `functions:shell`. Emulated Cloud Functions run as independent `node` processes
  153. on your development machine which means they have their own credential discovery mechanism.
  154. By default these `node` processes are not able to discover credentials from `firebase login`.
  155. In order to provide a better development experience, when you are logged in to the CLI
  156. through `firebase login` we take the user credentials and construct a temporary credential
  157. that we pass into the emulator through `GOOGLE_APPLICATION_CREDENTIALS`. We **only** do this
  158. if you have not already set the `GOOGLE_APPLICATION_CREDENTIALS` environment variable
  159. yourself.
  160. ## Using behind a proxy
  161. The CLI supports HTTP(S) proxies via environment variables. To use a proxy, set the `HTTPS_PROXY`
  162. or `HTTP_PROXY` value in your environment to the URL of your proxy (e.g.
  163. `HTTP_PROXY=http://127.0.0.1:12345`).
  164. ## Using with CI Systems
  165. The Firebase CLI requires a browser to complete authentication, but is fully
  166. compatible with CI and other headless environments.
  167. Complete the following steps to run Firebase commands in a CI environment. Find detailed instructions for each step in Google Cloud's [Getting started with authentication](https://cloud.google.com/docs/authentication/getting-started) guide.
  168. 1. Create a service account and grant it the appropriate level of access to your project.
  169. 1. Create a service account key (JSON file) for that service account.
  170. 1. Store the key file in a secure, accessible way in your CI system.
  171. 1. Set `GOOGLE_APPLICATION_CREDENTIALS=/path/to/key.json` in your CI system when running Firebase commands.
  172. To disable access for the service account, [find the service account](https://console.cloud.google.com/projectselector/iam-admin/serviceaccounts) for your project in the Google Cloud Console, and then either remove the key, or disable or delete the service account.
  173. ## Using as a Module
  174. The Firebase CLI can also be used programmatically as a standard Node module.
  175. Each command is exposed as a function that takes positional arguments followed
  176. by an options object and returns a Promise.
  177. So if we run this command at our command line:
  178. ```bash
  179. $ firebase --project="foo" apps:list ANDROID
  180. ```
  181. That translates to the following in Node:
  182. ```js
  183. const client = require("firebase-tools");
  184. client.apps
  185. .list("ANDROID", { project: "foo" })
  186. .then((data) => {
  187. // ...
  188. })
  189. .catch((err) => {
  190. // ...
  191. });
  192. ```
  193. The options object must be the very last argument and any unspecified
  194. positional argument will get the default value of `""`. The following
  195. two invocations are equivalent:
  196. ```js
  197. const client = require("firebase-tools");
  198. // #1 - No arguments or options, defaults will be inferred
  199. client.apps.list();
  200. // #2 - Explicitly provide "" for all arguments and {} for options
  201. client.apps.list("", {});
  202. ```
  203. Note: when used in a limited environment like Cloud Functions, not all `firebase-tools` commands will work programatically
  204. because they require access to a local filesystem.
  205. [gh-actions]: https://github.com/firebase/firebase-tools/actions
  206. [npm]: https://www.npmjs.com/package/firebase-tools
  207. [gh-actions-badge]: https://github.com/firebase/firebase-tools/workflows/CI%20Tests/badge.svg
  208. [node-badge]: https://img.shields.io/node/v/firebase-tools.svg
  209. [npm-badge]: https://img.shields.io/npm/v/firebase-tools.svg