Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dev: improve node dev #2255

Merged
merged 2 commits into from
Feb 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ quadratic-core/tmp.txt
quadratic-files/target/
quadratic-files/storage
quadratic-multiplayer/target/
quadratic-rust-client/target/

quadratic-multiplayer/updateAlertVersion.json
quadratic-rust-shared/src/auto_gen_path.rs
Expand Down
2 changes: 1 addition & 1 deletion dev/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export class CLI {
this.options.core = true;
this.options.multiplayer = true;
this.options.files = true;
this.options.connector = true;
this.options.connection = true;
this.options.rustClient = true;
this.options.python = true;
}
Expand Down
4 changes: 2 additions & 2 deletions dev/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export class CLI {
core: boolean;
multiplayer: boolean;
files: boolean;
connector: boolean;
connection: boolean;
python: boolean;
rustClient: boolean;
skipTypes: boolean;
Expand Down Expand Up @@ -75,7 +75,7 @@ export class CLI {
this.options.core = true;
this.options.multiplayer = true;
this.options.files = true;
this.options.connector = true;
this.options.connection = true;
this.options.rustClient = true;
this.options.python = true;
}
Expand Down
2 changes: 1 addition & 1 deletion dev/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export const COMPONENTS = {
shortcut: "m",
},
files: { color: "yellow", dark: "yellow", name: "Files", shortcut: "f" },
connector: {
connection: {
color: "blue",
dark: "blue",
name: "Connection",
Expand Down
2 changes: 1 addition & 1 deletion dev/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export const COMPONENTS = {
shortcut: "m",
},
files: { color: "yellow", dark: "yellow", name: "Files", shortcut: "f" },
connector: {
connection: {
color: "blue",
dark: "blue",
name: "Connection",
Expand Down
172 changes: 78 additions & 94 deletions dev/control.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export class Control {
client;
multiplayer;
files;
connector;
connection;
python;
rustClient;
db;
Expand All @@ -24,7 +24,7 @@ export class Control {
core: false,
multiplayer: false,
files: false,
connector: false,
connection: false,
python: false,
rustClient: false,
types: false,
Expand All @@ -48,7 +48,7 @@ export class Control {
this.kill("client"),
this.kill("multiplayer"),
this.kill("files"),
this.kill("connector"),
this.kill("connection"),
this.kill("python"),
this.kill("rustClient"),
]);
Expand Down Expand Up @@ -107,7 +107,7 @@ export class Control {
}
});
}
async runApi() {
async runApi(restart) {
if (this.quitting)
return;
this.status.api = false;
Expand All @@ -129,20 +129,29 @@ export class Control {
success: "Server running on port",
error: "npm ERR!",
start: "> quadratic-api",
}, () => {
if (!restart) {
if (this.status.multiplayer !== "killed" && !this.multiplayer) {
this.runMultiplayer();
}
if (this.status.files !== "killed" && !this.files) {
this.runFiles();
}
if (this.status.connection !== "killed" && !this.connection) {
this.runConnection();
}
}
}));
}
async restartApi() {
this.cli.options.api = !this.cli.options.api;
this.runApi();
this.runApi(true);
}
async runTypes(restart) {
this.ui.print("types");
this.status.types = false;
await this.kill("types");
if (this.cli.options.skipTypes && !restart) {
this.runCore();
}
else {
if (!this.cli.options.skipTypes || restart) {
this.types = spawn("npm", ["run", "build:wasm:types"]);
this.ui.printOutput("types", (data) => {
this.handleResponse("types", data, {
Expand All @@ -152,9 +161,6 @@ export class Control {
});
});
this.types.on("exit", () => {
if (!restart) {
this.runCore();
}
this.types = undefined;
this.ui.print("types", "completed.");
});
Expand Down Expand Up @@ -209,58 +215,21 @@ export class Control {
this.ui.print("core");
await this.kill("core");
this.signals.core = new AbortController();
if (this.cli.options.core) {
this.core = spawn("npm", [
"run",
this.cli.options.perf
? "watch:wasm:perf:javascript"
: "watch:wasm:javascript",
], { signal: this.signals.core.signal });
let firstRun = true;
this.ui.printOutput("core", (data) => this.handleResponse("core", data, {
success: "[Finished running. Exit status: 0",
error: "error[",
start: ["> quadratic", "[Running "],
}, () => {
if (!restart && firstRun) {
firstRun = false;
this.runNpmInstall();
if (this.status.multiplayer !== "killed" && !this.multiplayer) {
this.runMultiplayer();
}
else {
this.runFiles();
this.runConnection();
}
}
}));
}
else {
this.core = spawn("npm", [
"run",
this.cli.options.perf
? "build:wasm:perf:javascript"
: "build:wasm:javascript",
], { signal: this.signals.core.signal });
this.ui.printOutput("core", (data) => this.handleResponse("core", data, {
success: "Your wasm pkg is ready to publish",
error: "error[",
start: "[Running ",
}));
this.core.on("exit", () => {
if (!restart) {
this.core = undefined;
this.runNpmInstall();
if (this.status.multiplayer !== "killed") {
this.runMultiplayer();
}
else {
this.runFiles();
this.runConnection();
}
}
});
}
this.core = spawn("npm", [
"run",
this.cli.options.perf
? "watch:wasm:perf:javascript"
: "watch:wasm:javascript",
], { signal: this.signals.core.signal });
this.ui.printOutput("core", (data) => this.handleResponse("core", data, {
success: "[Finished running. Exit status: 0",
error: "error[",
start: ["> quadratic", "[Running "],
}, () => {
if (!restart) {
this.runNpmInstall();
}
}));
}
kill(name) {
if (!this[name])
Expand Down Expand Up @@ -313,7 +282,9 @@ export class Control {
catch (e) { }
this.signals.multiplayer = new AbortController();
this.ui.print("multiplayer");
this.multiplayer = spawn("cargo", this.cli.options.multiplayer ? ["watch", "-x", "'run'"] : ["run"], {
this.multiplayer = spawn("cargo", this.cli.options.multiplayer
? ["watch", "-x", "run -p quadratic-multiplayer --target-dir=target"]
: ["run", "-p", "quadratic-multiplayer", "--target-dir=target"], {
signal: this.signals.multiplayer.signal,
cwd: "quadratic-multiplayer",
env: { ...process.env, RUST_LOG: "info" },
Expand All @@ -322,11 +293,6 @@ export class Control {
success: "listening on",
error: "error[",
start: " Compiling",
}, () => {
if (!restart) {
this.runFiles();
this.runConnection();
}
}));
}
async restartMultiplayer() {
Expand All @@ -343,8 +309,16 @@ export class Control {
this.status.files = false;
this.ui.print("files");
await this.kill("files");
try {
this.ui.print("files", "killing port 3002 to ensure it's really good and dead...");
await killPort(3002);
// need to ignore the error if there is no process running on port 3001
}
catch (e) { }
this.signals.files = new AbortController();
this.files = spawn("cargo", this.cli.options.files ? ["watch", "-x", "'run'"] : ["run"], {
this.files = spawn("cargo", this.cli.options.files
? ["watch", "-x", "run -p quadratic-files --target-dir=target"]
: ["run", "-p", "quadratic-files", "--target-dir=target"], {
signal: this.signals.files.signal,
cwd: "quadratic-files",
env: { ...process.env, RUST_LOG: "info" },
Expand Down Expand Up @@ -380,43 +354,51 @@ export class Control {
async runConnection() {
if (this.quitting)
return;
if (this.status.connector === "killed")
if (this.status.connection === "killed")
return;
this.status.connector = false;
this.ui.print("connector");
await this.kill("connector");
this.signals.connector = new AbortController();
this.connector = spawn("cargo", this.cli.options.connector ? ["watch", "-x", "'run'"] : ["run"], {
signal: this.signals.connector.signal,
this.status.connection = false;
this.ui.print("connection");
await this.kill("connection");
try {
this.ui.print("connection", "killing port 3003 to ensure it's really good and dead...");
await killPort(3003);
// need to ignore the error if there is no process running on port 3001
}
catch (e) { }
this.signals.connection = new AbortController();
this.connection = spawn("cargo", this.cli.options.connection
? ["watch", "-x", "run -p quadratic-connection --target-dir=target"]
: ["run", "-p", "quadratic-connection", "--target-dir=target"], {
signal: this.signals.connection.signal,
cwd: "quadratic-connection",
env: { ...process.env, RUST_LOG: "info" },
});
this.ui.printOutput("connector", (data) => {
this.handleResponse("connector", data, {
this.ui.printOutput("connection", (data) => {
this.handleResponse("connection", data, {
success: "listening on",
error: ["error[", "npm ERR!"],
start: " Compiling",
});
});
}
async restartConnection() {
this.cli.options.connector = !this.cli.options.connector;
if (this.connector) {
this.cli.options.connection = !this.cli.options.connection;
if (this.connection) {
this.runConnection();
}
}
async killConnection() {
if (this.status.connector === "killed") {
this.status.connector = false;
this.ui.print("connector", "restarting...");
if (this.status.connection === "killed") {
this.status.connection = false;
this.ui.print("connection", "restarting...");
this.runConnection();
}
else {
if (this.connector) {
await this.kill("connector");
this.ui.print("connector", "killed", "red");
if (this.connection) {
await this.kill("connection");
this.ui.print("connection", "killed", "red");
}
this.status.connector = "killed";
this.status.connection = "killed";
}
}
async runPython() {
Expand Down Expand Up @@ -448,10 +430,11 @@ export class Control {
"run",
this.cli.options.rustClient
? this.cli.options.perf
? "dev:perf"
: "dev"
: "build",
"--workspace=quadratic-rust-client",
? "watch:rust-client:perf"
: "watch:rust-client"
: this.cli.options.perf
? "build:rust-client:perf"
: "build:rust-client",
], { signal: this.signals.rustClient.signal });
this.ui.printOutput("rustClient", (data) => this.handleResponse("rustClient", data, {
success: "Your wasm pkg is ready to publish",
Expand Down Expand Up @@ -519,6 +502,8 @@ export class Control {
this.status.rust = "error";
}
this.runTypes();
this.runCore();
this.runRustClient();
});
}
isRedisRunning() {
Expand Down Expand Up @@ -572,6 +557,5 @@ export class Control {
this.runRust();
this.runDb();
this.runPython();
this.runRustClient();
}
}
Loading
Loading