Giter Club home page Giter Club logo

firebase-project-manager's Introduction

firebase-project-manager

Build Status Coverage Status TypeScript NPM Version License

Create and manage your Firebase projects from the command line or with code!

Example Usage

As a Command-Line Tool

$ firebase-project-manager login
$ firebase-project-manager create my-new-project

As a Node.JS Dependency

const { authenticate, createFirebaseProject } = require('firebase-project-manager');

await authenticate();
const createdProjectId = await createFirebaseProject('my-new-project');
console.log('Successfully created new Firebase project:', createdProjectId);

Installation

As a package dependency:

$ yarn add firebase-project-manager 
# OR
$ npm i firebase-project-manager

As a global binary tool:

$ yarn global add firebase-project-manager
# OR
$ npm i -g firebase-project-manager

CLI Usage

This utility can either be used in an interactive mode, or single-command/single-action mode.
To access the interactive tool, use the following command:

$ firebase-project-manager

To utilize a single function of the executable, run the following to view all options (API is subject to change):

$ firebase-project-manager --help

Note: You may need to use $ yarn firebase-project-manager if you do not have the package installed globally.

Node.JS API Usage

Embedded below are all of the functions available for import through this package currently. Since the APIs are subject to heavy change right now, official documentation will not be produced until the package is ready for an initial major release. Using exact symver numbers in your package.json recommended until then as any changes up until v1.0.0 can be considered breaking changes.

// src/index.ts

import { googleapis } from './apis';
import * as auth from './auth';
import * as firebase from './firebase';
import { EventCB } from './firebase.types';
import { noop } from './util';

export { ERRORS, EVENTS, EventCB } from './firebase.types';

/** Static OAuth client managed by `authenticate` and `deauthenticate` */
export const oauth2Client = auth.oauth2Client;

/**
 * Authenticates client with Firebase Project Manager and retains a refresh token in the
 * system's configuration store for later usage.
 * @param verbose If true, authentication status will be logged with `console.log`.
 * @return Void promise resolved upon completion
 */
export const authenticate = auth.authenticate;

/**
 * Deauthenticates the currently logged in user, revokes and deletes the currently cached
 * refresh_token stored in the system's configuration store.
 * @param verbose If true, authentication status will be logged with `console.log`.
 * @return Void promise resolved upon completion
 */
export const deauthenticate = auth.deauthenticate;

/**
 * Creates a new Firebase Project via a two step process of first creating a CGP Project
 * and then secondly adding Firebase resources to it.
 * @param name Desired display name for the underlying GCP project. If available, this name
 * will also be used as a `projectId` by replacing all non-whitespace characters with '-'
 * and making all alphabetic characters lower-case.
 * @param cb function called with progress of project creation.
 * @return Promise to the newly created project's `projectId`.
 */
export function createFirebaseProject(name: string, cb: EventCB = noop) {
	return firebase.createFirebaseProject(googleapis, name, cb);
}

/**
 * Creates a new GCP project using Google `cloudresourcemanager`.
 * @param name Desired display name for the underlying GCP project. If available, this name
 * will also be used as a `projectId` by replacing all non-whitespace characters with `-`
 * and making all alphabetic characters lower-case.
 * @param cb function called with progress of project creation.
 * @return Promise to the newly created project's `projectId`.
 */
export function createGCProject(name: string, cb: EventCB = noop) {
	return firebase.createGCProject(googleapis, name, cb);
}

/**
 * Adds Firebase resources to a GCP Project
 * @param projectId projectId of the GCP Project to add Firebase features to.
 * @param cb function called with progress of project creation.
 * @return Void promise resolved upon completion
 */
export function addFirebaseFeatures(projectId: string, cb: EventCB = noop) {
	return firebase.addFirebaseFeatures(googleapis, projectId, cb);
}

/**
 * Lists all GCP Projects with Firebase resources.
 * @param pageSize The maximum number of Projects to return
 * @param pageToken Token returned from a previous call indicating where in the
 * set of Projects to resume listing.
 * @return Promise to an array of Firebase Projects
 */
export function listFirebaseProjects(pageSize?: number, pageToken?: string) {
	return firebase.listFirebaseProjects(googleapis, pageSize, pageToken);
}
/**
 * Lists all GCP Projects lacking Firebase resources, but that are available to become Firebase
 * projects.
 * @param pageSize The maximum number of Projects to return
 * @param pageToken Token returned from a previous call indicating where in the
 * set of Projects to resume listing.
 * @return Promise to an array of GCP Projects
 */
export function listAvailableProjects(pageSize?: number, pageToken?: string) {
	return firebase.listAvailableProjects(googleapis, pageSize, pageToken);
}

/**
 * Retrieves information for a given Firebase project.
 * @param projectId projectId of the Firebase project to retrieve
 * @return Promise to a Firebase Project
 */
export function getFirebaseProject(projectId: string) {
	return firebase.getFirebaseProject(googleapis, projectId);
}

/**
 * Lists all applications associated with a Firebase Project.
 * @param projectId projectId of the Firebase project to retrieve apps of
 * @param pageSize The maximum number of Apps to return
 * @param pageToken Token returned from a previous call indicating where in the
 * set of Apps to resume listing.
 */
export function listFirebaseProjectApps(projectId: string, pageSize?: number, pageToken?: string) {
	return firebase.listFirebaseProjectApps(googleapis, projectId, pageSize, pageToken);
}

/**
 * Creates a new web application under a given Firebase Project.
 * @param projectId projectId of the parent Firebase project to create an application for
 * @param displayName User-assigned display name of the App.
 * @param appUrls Fully qualified URLs where the App is hosted.
 */
export function createFirebaseWebapp(projectId: string, displayName?: string, appUrls?: string[]) {
	return firebase.createFirebaseWebapp(googleapis, projectId, displayName, appUrls);
}

/**
 * Retrieves information for a given Firebase Project's app.
 * @param name Fully qualified identifier for the webapp (Eg: `/projects/.../webApp/...`)
 */
export function getFirebaseWebapp(name: string): ReturnType<typeof firebase.getFirebaseWebapp>;
/**
 * Retrieves information for a given Firebase Project's app.
 * @param projectId projectId of the parent Firebase project
 * @param appId The webapp's ID.
 */
export function getFirebaseWebapp(projectId: string, appId?: string): ReturnType<typeof firebase.getFirebaseWebapp>;
export function getFirebaseWebapp(projectId: string, appId?: string) {
	return firebase.getFirebaseWebapp(googleapis, projectId, appId);
}

/**
 * Retrieves configuration information for a given Firebase Project's app.
 * @param name Fully qualified identifier for the webapp (Eg: `/projects/.../webApp/...`)
 */
export function getFirebaseWebappConfig(name: string): ReturnType<typeof firebase.getFirebaseWebappConfig>;
/**
 * Retrieves configuration information for a given Firebase Project's app.
 * @param projectId projectId of the parent Firebase project
 * @param appId The webapp's ID.
 */
export function getFirebaseWebappConfig(
	projectId: string,
	appId?: string
): ReturnType<typeof firebase.getFirebaseWebappConfig>;
export function getFirebaseWebappConfig(projectId: string, appId?: string) {
	return firebase.getFirebaseWebappConfig(googleapis, projectId, appId);
}

firebase-project-manager's People

Contributors

dependabot-preview[bot] avatar rioam2 avatar

Stargazers

 avatar  avatar

Watchers

 avatar

firebase-project-manager's Issues

Extract CLI helpers from main repo

Right now the CLI helper class is located in utils.ts for convenience. This should be formalized and branched off into a separate repository with its own documentation.

Basic functional tests

Implement basic functional tests utilizing dependency stubbing for googleapis

  • Inject googleapis dependency into core functions to allow for testing
  • Use sinon.js to stub out calls to api methods for googleapis
  • Write functional tests for core methods
    • Write basic tests for createGCProject
    • Write basic tests for createFirebaseProject

Add functional tests for core API methods

Functional tests need to be added for the following core API methods:

  • getFirebaseWebappConfig
  • getFirebaseWebapp
  • createFirebaseWebapp
  • listFirebaseProjectApps
  • getFirebaseProject
  • listAvailableProjects
  • listFirebaseProjects

Submit oauth approval request

Once repository is public and has sufficient usage details, approval should be requested for oauth client via GCP

Implement inquirer.js for interactive CLI

When no command line arguments are supplied to the tool, inquirer.js should provide an interactive CLI for performing actions

  • (1) Add Inquirer.js (5m)
  • (2) Explore inquirer functionality (1hr)
  • (3) Figure out a way to consolidate/fork logic for cli arguments and inquirer options (30m)

Add documentation

Command line interface and exported API need documentation once design is finalized

  • README
  • Function headers

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.