fiberplane / fpx

Supercharge your local development
https://fiberplane.dev
MIT License
43 stars 1 forks source link

Revamp the npx cli user experience, and support safe production deploys #60

Closed brettimus closed 2 months ago

brettimus commented 2 months ago

Demo

https://github.com/fiberplane/fpx/assets/3201327/81125a08-e62f-4afa-b64f-75f517d405d2

Description

This PR does two things:

  1. Modify the cli to initialize fpx. This runs a small wizard that creates a local configuration folder, and a (versioned) configuration file.
  2. Update the middleware to only send log/trace/event data to the fpx api when an FPX_ENDPOINT is defined in the user's api's environment

(2) Is very simple, just changed a few lines of code in the client-library, so the rest of this description will focus on (1)

Initializing FPX from the CLI

The CLI will create (or read from) .fpxconfig/fpx.config.v0.json. This is assumed to be an object whose keys are environment variables. These are considered "User Variables".

{
  "FPX_SERVICE_TARGET": "8787",
  "FPX_PORT": "8788",
  // This database file path will be set based off of platform (windows vs *nix-like)
  "FPX_DATABASE_URL": "file:.fpxconfig/fpx.db"
}

When determining the port on which FPX studio should run, it checks:

It falls back to asking the user for the port on which it should run. The default is 8788.

When determining the url for the user's service, it checks:

Then, it also silently configures the service name based on what's in wrangler.toml or package.json (if one exists).

In addition to the above it:

Testing locally

There are instructions in the api readme for this, but @keturiosakys pointed out it's also possible to just run

npx ../path/to/fpx/api

But! You need to build the studio before running that.

cd /path/to/fpx
# from the project root!
npm run build:fpx-studio