CLI Commands

A Firebase project has three config artifacts that have to agree with your data model: firestore.rules, firestore.indexes.json, and whatever Cloud Functions keep denormalized copies current. All three are normally maintained by hand, in three different languages, with nothing checking them against the model they describe. The CLI reads your decorated classes and writes all three from that single source.

The CLI requires a Pro or Team license key. See the License Key section to set one up.

Configuration

javascript
// firemap.config.js
export default {
  models: ["src/models/**/*.ts"],
  outDir: "./generated",
  licenseKey: "fmk_pro_...", // or use FIREMAP_LICENSE_KEY env var
};

models is a list of glob patterns; every matching file is imported so its decorators run and register themselves, which means a model file that no glob reaches is invisible to every generator and produces no error. It defaults to src/models/**/*.ts, and outDir defaults to ./generated. A third option, chunkSize, controls how many documents each batch write in the generated Cloud Functions touches; it defaults to 400, comfortably under Firestore's hard limit of 500 operations per batch.

Configuration is discovered with the usual cosmiconfig search, so a firemap.config.ts, firemap.config.json, .firemaprc or a firemap key in package.json all work. Every command also accepts --config <path> to point at a specific file, which is what you want in a monorepo where the search would otherwise find the wrong package's config. If no config is found the defaults are used silently.

Generators

bash
# Install CLI
npm install -g @firemap/cli

# Generate all files (functions, indexes, rules)
firemap generate:all

# Individual generators
firemap generate:functions
firemap generate:indexes
firemap generate:rules

# Preview without writing files
firemap generate:rules --dry-run

# Verbose output
firemap generate:all --verbose

# Machine-readable JSON output
firemap generate:indexes --json

Each generator writes one file into outDir: generate:rules produces firestore.rules from your rule decorators and field metadata, generate:indexes produces firestore.indexes.json from @Index, and generate:functions produces functions.ts from your denormalization declarations. generate:all simply runs the three in sequence.

The shared flags are worth using deliberately. --dry-run and --json both print the generated output to stdout and skip writing files entirely, which makes them the right way to diff a rules change in CI before it can touch a real project. --verbose reports which globs were scanned, how many model files were found, and how many collections registered — the first thing to reach for when a generator produces an empty file, which almost always means the model glob matched nothing.

The license check happens before any model is loaded, so an invalid or missing key fails fast with a non-zero exit code rather than half-writing output. Treat the generated files as build artifacts: commit them so reviewers can see a rules or index change land in the same pull request as the model change that caused it, then deploy them with firebase deploy.

Export Schema

Export your decorator-defined schema as JSON. This can be pasted into the web Schema Designer to visualize your models.

bash
# Export schema metadata as JSON
firemap export

# Pipe to a file
firemap export > schema.json

# With verbose logging (logs go to stderr, JSON to stdout)
firemap export --verbose

Keeping the JSON on stdout and the logs on stderr is what lets you redirect the output straight into a file or a clipboard command without stripping anything out first. See Code → Web for what the Schema Designer does with it.