This repository has been archived by the owner on Nov 11, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 60
/
rundev.js
69 lines (60 loc) · 1.67 KB
/
rundev.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/**
* @file Development script, which performs the following actions.
*
* 1. Runs `npm run build -- --watch` on the functions directory.
* 2. Starts the Firebase Local Emulator Suite.
* 3. Manually executes the `clearConnections` function on a schedule.
* 4. Starts the frontend React app with Fast Refresh enabled.
*/
const path = require("path");
const { spawn, spawnSync } = require("child_process");
const { PubSub } = require("@google-cloud/pubsub");
let build, emulators, app;
process.on("exit", () => {
if (build && !build.killed) build.kill();
if (emulators && !emulators.killed) emulators.kill();
if (app && !app.killed) app.kill();
});
// Initial build
spawnSync("npm", ["run", "build"], {
cwd: path.join(__dirname, "functions"),
stdio: ["ignore", "inherit", "inherit"],
});
// Incremental watch builds
build = spawn(
"npm",
["run", "build", "--", "--watch", "--preserveWatchOutput"],
{
cwd: path.join(__dirname, "functions"),
stdio: ["ignore", "inherit", "inherit"],
}
);
// Start emulators
emulators = spawn(
"firebase",
[
"emulators:start",
"--project",
"staging",
"--import=./data",
"--export-on-exit",
],
{
cwd: __dirname,
stdio: ["ignore", "inherit", "inherit"],
}
);
// Frontend application
app = spawn("npm", ["start"], {
cwd: __dirname,
stdio: ["ignore", "pipe", "inherit"],
env: Object.assign({ FORCE_COLOR: true }, process.env),
});
app.stdout.pipe(process.stdout);
const pubsub = new PubSub({
apiEndpoint: "localhost:8085",
projectId: "setwithfriends-dev",
});
setInterval(async () => {
await pubsub.topic("firebase-schedule-clearConnections").publishJSON({});
}, 60 * 1000); // every minute