Skip to content

Commit 4c962b9

Browse files
drogusbradleyshepclockwork-labs-botcloutiertyler
authored
spacetime.json config implementation (#4199)
# Description of Changes This PR implements support for the `spacetime.json` configuration file that can be used to set up common `generate` and `publish` targets. An example of `spacetime.json` could look like this: ``` { "dev_run": "pnpm dev", "generate": [ { "out-dir": "./foobar", "module-path": "region-module", "language": "c-sharp" }, { "out-dir": "./global", "module-path": "global-module", "language": "c-sharp" }, ], "publish": { "database": "bitcraft", "module-path": "spacetimedb", "server": "local", "children": [ { "database": "region-1", "module-path": "region-module", server: "local" }, { "database": "region-2", "module-path": "region-module", server: "local" } ] } } ``` With this config, running `spacetime generate` without any arguments would generate bindings for two targets: `region-module` and `global-module`. `spacetime publish` without any arguments would publish three modules, starting from the parent: `bitcraft`, `region-1`, and `region-2`. On top of that, the command `pnpm dev` would be executed when using `spacetime dev`. It is also possible to pass additional command line arguments when calling the `publish` and `generate` commands, but there are certain limitations. There is a special case when passing either a module path to generate or a module name to publish. Doing that will filter out entries in the config file that do not match. For example, running: ``` spacetime generate --project-path global-module ``` would only generate bindings for the second entry in the `generate` list. In a similar fashion, running: ``` spacetime publish region-1 ``` would only publish the child database with the name `region-1` Passing other existing arguments is also possible, but not all of the arguments are available for multiple configs. For example, when running `spacetime publish --server maincloud`, the publish command would be applied to all of the modules listed in the config file, but the `server` value from the command line arguments would take precedence. Running with arguments like `--bin-path` would, however, would throw an error as `--bin-path` makes sense only in a context of a specific module, thus this wouldn't work: `spacetime publish --bin-path spacetimedb/target/debug/bitcraft.wasm`. I will throw an error unless there is only one entry to process, thus `spacetime publish --bin-path spacetimedb/target/debug/bitcraft.wasm bitcraft` would work, as it filters the publish targets to one entry. # API and ABI breaking changes None # Expected complexity level and risk 3 The config file in itself is not overly complex, but when coupled with the CLI it is somewhat tricky to get right. There are also some changes that I had to make to how clap arguments are validated - because the values can now come from both the config file and the clap config, we can't use some of the built-in validations like `required`, or at least I haven't found a clean way to do so. # Testing I've added some automated tests, but more tests and manual testing is coming. --------- Signed-off-by: Tyler Cloutier <cloutiertyler@users.noreply.github.com> Co-authored-by: bradleyshep <148254416+bradleyshep@users.noreply.github.com> Co-authored-by: clockwork-labs-bot <clockwork-labs-bot@users.noreply.github.com> Co-authored-by: = <cloutiertyler@gmail.com> Co-authored-by: Tyler Cloutier <cloutiertyler@users.noreply.github.com>
1 parent 3f58b59 commit 4c962b9

84 files changed

Lines changed: 5784 additions & 671 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Cargo.lock

Lines changed: 62 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,7 @@ insta = { version = "1.21.0", features = ["toml", "filters"] }
220220
is-terminal = "0.4"
221221
itertools = "0.12"
222222
itoa = "1"
223+
json5 = "0.4"
223224
jsonwebtoken = { package = "spacetimedb-jsonwebtoken", version = "9.3.0" }
224225
junction = "1"
225226
jwks = { package = "spacetimedb-jwks", version = "0.1.3" }

crates/bindings-cpp/tests/client-comparison/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ cd crates/bindings-cpp/tests/client-comparison
6868
```bash
6969
# Rust baseline
7070
cd rust-sdk-test
71-
spacetime generate --lang rust --out-dir . --project-path ../../../modules/sdk-test
71+
spacetime generate --lang rust --out-dir . --module-path ../../../modules/sdk-test
7272

7373
# Rust baseline
7474
./scripts/regenerate_rust_client.sh

crates/bindings-cpp/tests/client-comparison/scripts/regenerate_rust_client.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ fi
7575
# Generate new Rust client
7676
echo "Generating new Rust client from sdk-test module..."
7777
cd "$RUST_DIR"
78-
"$CLI_PATH" generate --lang rust --out-dir . --project-path "$SDK_TEST_DIR" >/dev/null 2>&1
78+
"$CLI_PATH" generate --lang rust --out-dir . --module-path "$SDK_TEST_DIR" >/dev/null 2>&1
7979

8080
if [ $? -eq 0 ]; then
8181
echo ""

crates/bindings-typescript/test-react-router-app/package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@
1313
"lint": "eslint . && prettier . --check --ignore-path ../../../.prettierignore",
1414
"preview": "vite preview",
1515
"generate": "cargo run -p gen-bindings -- --replacement ../../../src/index && prettier --write src/module_bindings",
16-
"spacetime:generate": "spacetime generate --lang typescript --out-dir src/module_bindings --project-path server",
17-
"spacetime:start": "spacetime start server",
18-
"spacetime:publish:local": "spacetime publish game --project-path server --server local",
19-
"spacetime:publish": "spacetime publish game --project-path server --server maincloud"
16+
"spacetime:generate": "spacetime generate --lang typescript --out-dir src/module_bindings --module-path server",
17+
"spacetime:start": "spacetime start",
18+
"spacetime:publish:local": "spacetime publish game --module-path server --server local",
19+
"spacetime:publish": "spacetime publish game --module-path server --server maincloud"
2020
},
2121
"dependencies": {
2222
"react": "^18.3.1",

crates/cli/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ http.workspace = true
4949
is-terminal.workspace = true
5050
itertools.workspace = true
5151
indicatif.workspace = true
52+
json5.workspace = true
5253
jsonwebtoken.workspace = true
5354
mimalloc.workspace = true
5455
percent-encoding.workspace = true
@@ -76,6 +77,7 @@ wasmbin.workspace = true
7677
webbrowser.workspace = true
7778
clap-markdown.workspace = true
7879
git2.workspace = true
80+
glob.workspace = true
7981
dialoguer = { workspace = true, features = ["fuzzy-select"] }
8082
rolldown.workspace = true
8183
rolldown_common.workspace = true

crates/cli/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ mod config;
44
pub(crate) mod detect;
55
mod edit_distance;
66
mod errors;
7+
pub mod spacetime_config;
78
mod subcommands;
89
mod tasks;
910
pub mod util;

0 commit comments

Comments
 (0)