UNPKG

@firemono/nx

Version:

Nx plugin for Firebase development with proper architecture - Functions as Nx apps building to dist, live reloading, and auto-persisted emulator data

196 lines (143 loc) โ€ข 5.6 kB
# @firemono/nx > Nx plugin for Firebase development with proper architecture An Nx plugin that integrates Firebase projects into your Nx workspace with the **correct architecture** - Firebase Functions as proper Nx applications building to `dist/`, live reloading during development, and auto-persisted emulator data. ## โœจ Features - ๐Ÿš€ **Functions as Nx Apps**: Firebase Functions are real Nx applications with proper TypeScript, ESLint, and testing setup - ๐Ÿ“‚ **Builds to dist/**: Functions build to workspace `dist/` directory following Nx conventions - ๐Ÿ”„ **Live Reloading**: Watch mode rebuilds functions automatically during development - ๐Ÿ’พ **Auto-Persisted Data**: Emulator data automatically saved/restored between sessions - ๐Ÿ—๏ธ **esbuild**: Fast builds with `@nx/esbuild` executor - ๐Ÿงน **Clean Architecture**: No copying, Firebase reads directly from dist - ๐Ÿ”ง **Full Nx Integration**: Lint, test, build, and deploy with Nx tooling ## ๐Ÿ“ฆ Installation ```bash # Install the plugin npm install -D @firemono/nx # Or with yarn yarn add -D @firemono/nx ``` ## ๐Ÿš€ Quick Start ### 1. Initialize Firebase Project First, create your Firebase project configuration: ```bash mkdir my-firebase-init cd my-firebase-init firebase init # Select: Functions, Firestore, Hosting, Emulators # Choose TypeScript for functions cd .. ``` ### 2. Generate Nx Firebase Project ```bash nx generate @firemono/nx:init --name my-app --directory apps/my-app --initDirectory ./my-firebase-init ``` This creates: - `apps/my-app/functions/` - Nx Functions app (builds to `dist/my-app/functions`) - `apps/my-app/firebase/` - Firebase project (uses functions from dist) ### 3. Start Development ```bash # Start with live reloading nx dev my-app-firebase # Or build manually nx build my-app-firebase # Deploy to Firebase nx deploy my-app-firebase ``` ## ๐Ÿ—๏ธ Architecture ``` apps/ โ”œโ”€โ”€ my-app/ โ”‚ โ”œโ”€โ”€ functions/ # Nx Functions app โ”‚ โ”‚ โ”œโ”€โ”€ src/index.ts # Source code โ”‚ โ”‚ โ””โ”€โ”€ project.json # โ†’ builds to dist/my-app/functions โ”‚ โ””โ”€โ”€ firebase/ # Firebase project โ”‚ โ”œโ”€โ”€ firebase.json # โ†’ source: "../../../dist/my-app/functions" โ”‚ โ””โ”€โ”€ emulator-data/ # Auto-persisted data โ””โ”€โ”€ dist/ โ””โ”€โ”€ my-app/ โ””โ”€โ”€ functions/ # Firebase reads from here! ``` ## ๐ŸŽฏ Benefits - **โœ… Proper Nx Apps**: Functions follow Nx conventions with full tooling support - **โœ… Workspace dist/**: All builds go to workspace `dist/` directory - **โœ… No File Copying**: Firebase reads directly from dist (no build step copying) - **โœ… Live Development**: Watch mode + Firebase emulators = instant feedback - **โœ… Auto-Persistence**: Emulator data saved/restored automatically - **โœ… TypeScript First**: Full TypeScript support with proper configurations - **โœ… Fast Builds**: esbuild for lightning-fast function builds ## ๐Ÿ“‹ Generator Options ```bash nx generate @firemono/nx:init [options] ``` | Option | Description | Required | |--------|-------------|----------| | `--name` | Name of the Firebase project | โœ… | | `--directory` | Directory where project should be created | โœ… | | `--initDirectory` | Path to Firebase init directory | โœ… | ### Example ```bash nx generate @firemono/nx:init \ --name ecommerce \ --directory apps/ecommerce \ --initDirectory ./firebase-init-ecommerce ``` Creates: - `apps/ecommerce/functions/` (Nx app building to `dist/ecommerce/functions`) - `apps/ecommerce/firebase/` (Firebase project using dist functions) ## ๐Ÿ”ง Generated Commands Each Firebase project gets these Nx targets: ```bash # Development with live reloading nx dev my-app-firebase # Build functions and prepare for deployment nx build my-app-firebase # Deploy to Firebase nx deploy my-app-firebase nx deploy-functions my-app-firebase # Emulator management nx emulators:start my-app-firebase nx emulators:debug my-app-firebase nx emulators:stop my-app-firebase # Data management (auto-handled during dev) nx data:export my-app-firebase nx data:import my-app-firebase ``` ## ๐Ÿ”„ Development Workflow 1. **Start Development**: ```bash nx dev my-app-firebase ``` This runs: - `nx build my-app-functions --watch` (rebuilds on changes) - Firebase emulators with auto-import/export 2. **Edit Functions**: - Edit `apps/my-app/functions/src/index.ts` - Functions rebuild automatically - Firebase sees changes instantly 3. **Data Persists**: - Stop emulators (Ctrl+C) โ†’ data auto-exported - Restart โ†’ data auto-imported - Zero manual data management ## ๐Ÿท๏ธ Project Tags Generated projects include semantic tags: - `type:firebase` - Firebase infrastructure project - `scope:{name}` - Groups related projects - `platform:firebase` - Firebase deployment platform - `feature:{detected}` - Auto-detected Firebase features Use tags for targeted operations: ```bash # Test all Firebase projects nx run-many --target=test --projects=tag:type:firebase # Build all projects in scope nx run-many --target=build --projects=tag:scope:my-app ``` ## ๐Ÿ“‹ Requirements - Nx workspace (v20.0.0+) - Node.js 18+ - Firebase CLI (for deployment and emulators) ## ๐Ÿค Contributing Contributions welcome! Please read the [contributing guide](https://github.com/johannesnormannjensen/firemono/blob/main/CONTRIBUTING.md). ## ๐Ÿ“„ License MIT ยฉ [Johannes Firemono](https://github.com/johannesnormannjensen/firemono) --- **Built with โค๏ธ for the Nx and Firebase communities**