Skip to content

Commit

Permalink
feat(apps): establish firebase base for functions and local emulation
Browse files Browse the repository at this point in the history
Create the initial base function and emulation bazel rules and files
  • Loading branch information
josephperrott committed Apr 4, 2022
1 parent bf5983a commit 82ecd90
Show file tree
Hide file tree
Showing 11 changed files with 2,652 additions and 73 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,6 @@ yarn-error.log

# Don't check in junit test results.
test-results/*

# Ignore firebase debug logs.
apps/*-debug.log
1 change: 1 addition & 0 deletions apps/.firebaserc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
23 changes: 23 additions & 0 deletions apps/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
load("@build_bazel_rules_nodejs//:index.bzl", "nodejs_binary")

nodejs_binary(
name = "serve",
chdir = package_name(),
data = [
# primary firebase configuration file
"firebase.json",

# Firebase function files
"//apps/functions:functions_compiled",
"//apps/functions:functions_files",
],
entry_point = "@npm//:node_modules/firebase-tools/lib/bin/firebase.js",
templated_args = [
"--project",
"angular-caretaker",
"--config",
# TODO: Find a way to do this without relying on the copy_to_bin that works cross platform.
"$$(rlocation $(execpath :firebase.json))",
"emulators:start",
],
)
21 changes: 21 additions & 0 deletions apps/firebase.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"firestore": {
"rules": "firestore.rules",
"indexes": "firestore.indexes.json"
},
"functions": {
"predeploy": "bazel build //apps/functions:functions_compiled",
"source": "../dist/bin/apps/functions"
},
"emulators": {
"functions": {
"port": 5001
},
"firestore": {
"port": 8080
},
"ui": {
"enabled": true
}
}
}
4 changes: 4 additions & 0 deletions apps/firestore.indexes.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"indexes": [],
"fieldOverrides": []
}
7 changes: 7 additions & 0 deletions apps/firestore.rules
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
service cloud.firestore {
match /databases/{database}/documents {
match /{document=**} {
allow read, write: if false
}
}
}
35 changes: 35 additions & 0 deletions apps/functions/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
load("//tools:defaults.bzl", "esbuild", "ts_library")
load("@build_bazel_rules_nodejs//:index.bzl", "copy_to_bin")

package(default_visibility = ["//visibility:private"])

copy_to_bin(
name = "functions_files",
srcs = [
"package.json",
],
visibility = ["//apps:__pkg__"],
)

ts_library(
name = "functions",
srcs = [
"index.ts",
],
deps = [
"@npm//firebase-functions",
],
)

esbuild(
name = "functions_compiled",
entry_points = [
"index.ts",
],
format = "cjs",
visibility = ["//apps:__pkg__"],
deps = [
":functions",
"@npm//firebase-functions",
],
)
1 change: 1 addition & 0 deletions apps/functions/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import * as functions from 'firebase-functions';
8 changes: 8 additions & 0 deletions apps/functions/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"name": "functions",
"engines": {
"node": "16"
},
"main": "index.js",
"private": true
}
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@
"ejs": "^3.1.6",
"firebase": "^9.6.9",
"firebase-admin": "^10.0.2",
"firebase-functions": "^3.19.0",
"firebase-tools": "^10.5.0",
"git-raw-commits": "^2.0.10",
"glob": "7.2.0",
"husky": "^7.0.1",
Expand Down
Loading

0 comments on commit 82ecd90

Please sign in to comment.