Skip to content

Conversation

@drogus
Copy link
Collaborator

@drogus drogus commented Oct 7, 2025

This is a draft of the new functionality for spacetime init. In order to run it with built-in templates you have to set the path to the config file:

export SPACETIMEDB_CLI_TEMPLATES_FILE=crates/cli/.init-templates.json

In the future it will fetch the list from GH.

A few notes:

  • the previous functionality of spacetime init does not work at the moment
  • the code needs a bit more cleanup and tests before merging
  • there is a bit of a mix in how we generate empty server and client projects. For Rust we use the existing way of generating. For TypeScript we clone an empty project from the repo. I wanted to play with both ways of doing things, and I'm still not sure which is better. Generation in Rust means that the generated code will match the CLI version and not necessarily whatever is in Git. On the other hand, for the builtin templates we will be fetching the newest version from GH, which I guess might also not what we want, ie. we probably want only stable templates. More discussion is needed here
  • we use spacetimedb directory for the server files
  • I don't particularly like the inability to disable interactive mode easily. We discussed disabling it by default if all of the required arguments are passed, but I don't think it's feature proof. For example, if someone relies on a non-interactive mode, and we add a new required argument, instead of printing a message missing --foo, we will automatically launch interactive mode, which is harder to debug. That's why I think I'd prefer to implement --non-interactive argument
  • it's kind of hard to keep the legacy behaviour. If you don't pass any arguments, we go into interactive mode. In the legacy version, we would print required arguments. If someone passes --lang or --project-path explicitly, I guess we could run the legacy workflow, but not sure if it's worth it, as the command was marked as unstable anyway
  • the project path defaults to the project name, but I think we should probably replace change whitespaces to dashes, or at least ask for the project path with the project name being the default (or both)

@drogus drogus self-assigned this Oct 7, 2025
@drogus drogus marked this pull request as draft October 7, 2025 10:55
@drogus drogus force-pushed the drogus/spacetime-init branch 18 times, most recently from c022d34 to ea0f0f7 Compare October 15, 2025 20:52
@drogus drogus force-pushed the drogus/spacetime-init branch from ea0f0f7 to e536cc3 Compare October 15, 2025 20:53
@drogus drogus force-pushed the drogus/spacetime-init branch from 10f14ee to cc118cc Compare October 16, 2025 11:49
@cloutiertyler
Copy link
Contributor

cloutiertyler commented Oct 22, 2025

The following tests gave me an error:

image image

@drogus
Copy link
Collaborator Author

drogus commented Oct 23, 2025

@cloutiertyler sorry about that. I'm not sure what was wrong, but yesterday when I was working on spacetime dev yesterday I got annoyed by the time it takes to clone stuff, so I ended up putting the templates in the binary, and now all of the templates work (as they're parsed on build time, so there is also no risk of mismatch of the git references etc). I've ran the command for all of the templates:

Output
Testing template: basic-rust
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 1.23s
     Running `target/debug/spacetimedb-cli init --name test-basic-rust --template basic-rust /var/folders/5c/tgs43q5s7_g1snt37h2dm8mm0000gn/T/tmp.ZDhSpbPFx6/test-basic-rust --non-interactive`
WARNING: This command is UNSTABLE and subject to breaking changes.

You are logged in to SpacetimeDB.
Initializing project from template...
Setting up client (rust)...
Setting up server (rust)...
Project initialized successfully!

Next steps:
  cd /var/folders/5c/tgs43q5s7_g1snt37h2dm8mm0000gn/T/tmp.ZDhSpbPFx6/test-basic-rust
  spacetime publish --project-path spacetimedb test-basic-rust
  spacetime generate --lang rust --out-dir src/module_bindings --project-path spacetimedb
  cargo run

Learn more: https://spacetimedb.com/docs
✓ Template basic-rust succeeded
  Generated files:
/var/folders/5c/tgs43q5s7_g1snt37h2dm8mm0000gn/T/tmp.ZDhSpbPFx6/test-basic-rust/.cursorrules
/var/folders/5c/tgs43q5s7_g1snt37h2dm8mm0000gn/T/tmp.ZDhSpbPFx6/test-basic-rust/Cargo.toml
/var/folders/5c/tgs43q5s7_g1snt37h2dm8mm0000gn/T/tmp.ZDhSpbPFx6/test-basic-rust/README.md
/var/folders/5c/tgs43q5s7_g1snt37h2dm8mm0000gn/T/tmp.ZDhSpbPFx6/test-basic-rust/spacetimedb/.cargo/config.toml
/var/folders/5c/tgs43q5s7_g1snt37h2dm8mm0000gn/T/tmp.ZDhSpbPFx6/test-basic-rust/spacetimedb/.gitignore
/var/folders/5c/tgs43q5s7_g1snt37h2dm8mm0000gn/T/tmp.ZDhSpbPFx6/test-basic-rust/spacetimedb/Cargo.toml
/var/folders/5c/tgs43q5s7_g1snt37h2dm8mm0000gn/T/tmp.ZDhSpbPFx6/test-basic-rust/spacetimedb/src/lib.rs
/var/folders/5c/tgs43q5s7_g1snt37h2dm8mm0000gn/T/tmp.ZDhSpbPFx6/test-basic-rust/src/main.rs
  Cleaning up /var/folders/5c/tgs43q5s7_g1snt37h2dm8mm0000gn/T/tmp.ZDhSpbPFx6

Testing template: basic-typescript
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.52s
     Running `target/debug/spacetimedb-cli init --name test-basic-typescript --template basic-typescript /var/folders/5c/tgs43q5s7_g1snt37h2dm8mm0000gn/T/tmp.3GGmtl6bHu/test-basic-typescript --non-interactive`
WARNING: This command is UNSTABLE and subject to breaking changes.

You are logged in to SpacetimeDB.
Initializing project from template...
Setting up client (typescript)...
Setting up server (typescript)...
Note: Run 'npm install' in the project directory to install dependencies
Project initialized successfully!

Next steps:
  cd /var/folders/5c/tgs43q5s7_g1snt37h2dm8mm0000gn/T/tmp.3GGmtl6bHu/test-basic-typescript
  npm install
  spacetime publish --project-path spacetimedb test-basic-typescript
  spacetime generate --lang typescript --out-dir src/module_bindings --project-path spacetimedb
  npm run dev

Learn more: https://spacetimedb.com/docs

TypeScript server requires dependencies to be installed before publishing.
Please install dependencies by running your package manager's install command in the /var/folders/5c/tgs43q5s7_g1snt37h2dm8mm0000gn/T/tmp.3GGmtl6bHu/test-basic-typescript/spacetimedb directory.
✓ Template basic-typescript succeeded
  Generated files:
/var/folders/5c/tgs43q5s7_g1snt37h2dm8mm0000gn/T/tmp.3GGmtl6bHu/test-basic-typescript/.cursorrules
/var/folders/5c/tgs43q5s7_g1snt37h2dm8mm0000gn/T/tmp.3GGmtl6bHu/test-basic-typescript/.gitignore
/var/folders/5c/tgs43q5s7_g1snt37h2dm8mm0000gn/T/tmp.3GGmtl6bHu/test-basic-typescript/index.html
/var/folders/5c/tgs43q5s7_g1snt37h2dm8mm0000gn/T/tmp.3GGmtl6bHu/test-basic-typescript/package.json
/var/folders/5c/tgs43q5s7_g1snt37h2dm8mm0000gn/T/tmp.3GGmtl6bHu/test-basic-typescript/spacetimedb/.gitignore
/var/folders/5c/tgs43q5s7_g1snt37h2dm8mm0000gn/T/tmp.3GGmtl6bHu/test-basic-typescript/spacetimedb/package.json
/var/folders/5c/tgs43q5s7_g1snt37h2dm8mm0000gn/T/tmp.3GGmtl6bHu/test-basic-typescript/spacetimedb/src/index.ts
/var/folders/5c/tgs43q5s7_g1snt37h2dm8mm0000gn/T/tmp.3GGmtl6bHu/test-basic-typescript/spacetimedb/tsconfig.json
/var/folders/5c/tgs43q5s7_g1snt37h2dm8mm0000gn/T/tmp.3GGmtl6bHu/test-basic-typescript/src/main.ts
/var/folders/5c/tgs43q5s7_g1snt37h2dm8mm0000gn/T/tmp.3GGmtl6bHu/test-basic-typescript/tsconfig.json
/var/folders/5c/tgs43q5s7_g1snt37h2dm8mm0000gn/T/tmp.3GGmtl6bHu/test-basic-typescript/vite.config.ts
  Cleaning up /var/folders/5c/tgs43q5s7_g1snt37h2dm8mm0000gn/T/tmp.3GGmtl6bHu

Testing template: basic-react
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.51s
     Running `target/debug/spacetimedb-cli init --name test-basic-react --template basic-react /var/folders/5c/tgs43q5s7_g1snt37h2dm8mm0000gn/T/tmp.ibWx6C4Nfw/test-basic-react --non-interactive`
^C  Cleaning up /var/folders/5c/tgs43q5s7_g1snt37h2dm8mm0000gn/T/tmp.ibWx6C4Nfw


SpacetimeDB on  drogus/spacetime-init [$?] via 🐳 desktop-linux is 📦 v1.6.0 via .NET v8.0.400 via  v24.8.0 via 🦀 v1.90.0 on ☁️   (us-east-1) took 5s
❯ ./test-templates.sh
Found 6 templates to test

Testing template: basic-rust
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 1.29s
     Running `target/debug/spacetimedb-cli init --name test-basic-rust --template basic-rust /var/folders/5c/tgs43q5s7_g1snt37h2dm8mm0000gn/T/tmp.M5Kdzgmrhj/test-basic-rust --non-interactive`
WARNING: This command is UNSTABLE and subject to breaking changes.

You are logged in to SpacetimeDB.
Initializing project from template...
Setting up client (rust)...
Setting up server (rust)...
Project initialized successfully!

Next steps:
  cd /var/folders/5c/tgs43q5s7_g1snt37h2dm8mm0000gn/T/tmp.M5Kdzgmrhj/test-basic-rust
  spacetime publish --project-path spacetimedb test-basic-rust
  spacetime generate --lang rust --out-dir src/module_bindings --project-path spacetimedb
  cargo run

Learn more: https://spacetimedb.com/docs
✓ Template basic-rust succeeded
  Generated files:
.cursorrules
Cargo.toml
README.md
spacetimedb/.cargo/config.toml
spacetimedb/.gitignore
spacetimedb/Cargo.toml
spacetimedb/src/lib.rs
src/main.rs
  Cleaning up /var/folders/5c/tgs43q5s7_g1snt37h2dm8mm0000gn/T/tmp.M5Kdzgmrhj

Testing template: basic-typescript
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.56s
     Running `target/debug/spacetimedb-cli init --name test-basic-typescript --template basic-typescript /var/folders/5c/tgs43q5s7_g1snt37h2dm8mm0000gn/T/tmp.Kz0saC5tml/test-basic-typescript --non-interactive`
WARNING: This command is UNSTABLE and subject to breaking changes.

You are logged in to SpacetimeDB.
Initializing project from template...
Setting up client (typescript)...
Setting up server (typescript)...
Note: Run 'npm install' in the project directory to install dependencies
Project initialized successfully!

Next steps:
  cd /var/folders/5c/tgs43q5s7_g1snt37h2dm8mm0000gn/T/tmp.Kz0saC5tml/test-basic-typescript
  npm install
  spacetime publish --project-path spacetimedb test-basic-typescript
  spacetime generate --lang typescript --out-dir src/module_bindings --project-path spacetimedb
  npm run dev

Learn more: https://spacetimedb.com/docs

TypeScript server requires dependencies to be installed before publishing.
Please install dependencies by running your package manager's install command in the /var/folders/5c/tgs43q5s7_g1snt37h2dm8mm0000gn/T/tmp.Kz0saC5tml/test-basic-typescript/spacetimedb directory.
✓ Template basic-typescript succeeded
  Generated files:
.cursorrules
.gitignore
index.html
package.json
spacetimedb/.gitignore
spacetimedb/package.json
spacetimedb/src/index.ts
spacetimedb/tsconfig.json
src/main.ts
tsconfig.json
vite.config.ts
  Cleaning up /var/folders/5c/tgs43q5s7_g1snt37h2dm8mm0000gn/T/tmp.Kz0saC5tml

Testing template: basic-react
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.54s
     Running `target/debug/spacetimedb-cli init --name test-basic-react --template basic-react /var/folders/5c/tgs43q5s7_g1snt37h2dm8mm0000gn/T/tmp.uw30UKWEIz/test-basic-react --non-interactive`
WARNING: This command is UNSTABLE and subject to breaking changes.

You are logged in to SpacetimeDB.
Initializing project from template...
Setting up client (typescript)...
Setting up server (typescript)...
Note: Run 'npm install' in the project directory to install dependencies
Project initialized successfully!

Next steps:
  cd /var/folders/5c/tgs43q5s7_g1snt37h2dm8mm0000gn/T/tmp.uw30UKWEIz/test-basic-react
  npm install
  spacetime publish --project-path spacetimedb test-basic-react
  spacetime generate --lang typescript --out-dir src/module_bindings --project-path spacetimedb
  npm run dev

Learn more: https://spacetimedb.com/docs

TypeScript server requires dependencies to be installed before publishing.
Please install dependencies by running your package manager's install command in the /var/folders/5c/tgs43q5s7_g1snt37h2dm8mm0000gn/T/tmp.uw30UKWEIz/test-basic-react/spacetimedb directory.
✓ Template basic-react succeeded
  Generated files:
.cursorrules
.gitignore
index.html
package.json
spacetimedb/package.json
spacetimedb/src/index.ts
src/App.tsx
src/main.tsx
tsconfig.json
vite.config.ts
  Cleaning up /var/folders/5c/tgs43q5s7_g1snt37h2dm8mm0000gn/T/tmp.uw30UKWEIz

Testing template: quickstart-chat-rust
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.53s
     Running `target/debug/spacetimedb-cli init --name test-quickstart-chat-rust --template quickstart-chat-rust /var/folders/5c/tgs43q5s7_g1snt37h2dm8mm0000gn/T/tmp.b3hRs0GfLS/test-quickstart-chat-rust --non-interactive`
WARNING: This command is UNSTABLE and subject to breaking changes.

You are logged in to SpacetimeDB.
Initializing project from template...
Setting up client (rust)...
Setting up server (rust)...
Project initialized successfully!

Next steps:
  cd /var/folders/5c/tgs43q5s7_g1snt37h2dm8mm0000gn/T/tmp.b3hRs0GfLS/test-quickstart-chat-rust
  spacetime publish --project-path spacetimedb test-quickstart-chat-rust
  spacetime generate --lang rust --out-dir src/module_bindings --project-path spacetimedb
  cargo run

Learn more: https://spacetimedb.com/docs
✓ Template quickstart-chat-rust succeeded
  Generated files:
.cursorrules
README.md
main.rs
module_bindings/identity_connected_reducer.rs
module_bindings/identity_disconnected_reducer.rs
module_bindings/message_table.rs
module_bindings/message_type.rs
module_bindings/mod.rs
module_bindings/send_message_reducer.rs
module_bindings/set_name_reducer.rs
module_bindings/user_table.rs
module_bindings/user_type.rs
spacetimedb/.cargo/config.toml
spacetimedb/.gitignore
spacetimedb/Cargo.toml
spacetimedb/LICENSE
spacetimedb/README.md
spacetimedb/src/lib.rs
  Cleaning up /var/folders/5c/tgs43q5s7_g1snt37h2dm8mm0000gn/T/tmp.b3hRs0GfLS

Testing template: quickstart-chat-c-sharp
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.50s
     Running `target/debug/spacetimedb-cli init --name test-quickstart-chat-c-sharp --template quickstart-chat-c-sharp /var/folders/5c/tgs43q5s7_g1snt37h2dm8mm0000gn/T/tmp.28pT50NLfx/test-quickstart-chat-c-sharp --non-interactive`
WARNING: This command is UNSTABLE and subject to breaking changes.

You are logged in to SpacetimeDB.
Initializing project from template...
Setting up client (csharp)...
Setting up server (csharp)...
Project initialized successfully!

Next steps:
  cd /var/folders/5c/tgs43q5s7_g1snt37h2dm8mm0000gn/T/tmp.28pT50NLfx/test-quickstart-chat-c-sharp
  spacetime publish --project-path spacetimedb test-quickstart-chat-c-sharp
  spacetime generate --lang csharp --out-dir src/module_bindings --project-path spacetimedb

Learn more: https://spacetimedb.com/docs
✓ Template quickstart-chat-c-sharp succeeded
  Generated files:
.cursorrules
Program.cs
README.md
client.csproj
module_bindings/Reducers/ClientConnected.g.cs
module_bindings/Reducers/ClientDisconnected.g.cs
module_bindings/Reducers/SendMessage.g.cs
module_bindings/Reducers/SetName.g.cs
module_bindings/SpacetimeDBClient.g.cs
module_bindings/Tables/Message.g.cs
module_bindings/Tables/User.g.cs
module_bindings/Types/Message.g.cs
module_bindings/Types/User.g.cs
spacetimedb/.gitignore
spacetimedb/Lib.cs
spacetimedb/StdbModule.csproj
spacetimedb/global.json
  Cleaning up /var/folders/5c/tgs43q5s7_g1snt37h2dm8mm0000gn/T/tmp.28pT50NLfx

Testing template: quickstart-chat-typescript
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.51s
     Running `target/debug/spacetimedb-cli init --name test-quickstart-chat-typescript --template quickstart-chat-typescript /var/folders/5c/tgs43q5s7_g1snt37h2dm8mm0000gn/T/tmp.AF2LkSMVCH/test-quickstart-chat-typescript --non-interactive`
WARNING: This command is UNSTABLE and subject to breaking changes.

You are logged in to SpacetimeDB.
Initializing project from template...
Setting up client (typescript)...
Setting up server (typescript)...
Note: Run 'npm install' in the project directory to install dependencies
Project initialized successfully!

Next steps:
  cd /var/folders/5c/tgs43q5s7_g1snt37h2dm8mm0000gn/T/tmp.AF2LkSMVCH/test-quickstart-chat-typescript
  npm install
  spacetime publish --project-path spacetimedb test-quickstart-chat-typescript
  spacetime generate --lang typescript --out-dir src/module_bindings --project-path spacetimedb
  npm run dev

Learn more: https://spacetimedb.com/docs

TypeScript server requires dependencies to be installed before publishing.
Please install dependencies by running your package manager's install command in the /var/folders/5c/tgs43q5s7_g1snt37h2dm8mm0000gn/T/tmp.AF2LkSMVCH/test-quickstart-chat-typescript/spacetimedb directory.
✓ Template quickstart-chat-typescript succeeded
  Generated files:
.cursorrules
.gitignore
CHANGELOG.md
README.md
index.html
package.json
public/vite.svg
spacetimedb/package-lock.json
spacetimedb/package.json
spacetimedb/src/index.ts
spacetimedb/tsconfig.json
src/.gitattributes
src/App.css
src/App.integration.test.tsx
src/App.tsx
src/assets/react.svg
src/index.css
src/main.tsx
src/module_bindings/identity_connected_reducer.ts
src/module_bindings/identity_disconnected_reducer.ts
src/module_bindings/index.ts
src/module_bindings/message_table.ts
src/module_bindings/message_type.ts
src/module_bindings/send_message_reducer.ts
src/module_bindings/set_name_reducer.ts
src/module_bindings/user_table.ts
src/module_bindings/user_type.ts
src/setupTests.ts
src/vite-env.d.ts
tsconfig.app.json
tsconfig.json
tsconfig.node.json
vite.config.ts
vitest.config.ts
  Cleaning up /var/folders/5c/tgs43q5s7_g1snt37h2dm8mm0000gn/T/tmp.AF2LkSMVCH

All templates tested successfully! (6/6)

@drogus
Copy link
Collaborator Author

drogus commented Oct 23, 2025

While looking at this in context of spacetime dev, I see that I'll have to adjust post generate instructions cause they don't make sense anymore with spacetime dev available.

@drogus drogus force-pushed the drogus/spacetime-init branch from dfa4da7 to db22a7f Compare October 23, 2025 13:24
}

let cursorrules_content = embedded::get_cursorrules();
let cursorrules_path = project_path.join(".cursorrules");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the cursorrules_content should go in .cursor/rules/spacetime-rules.mdc. (kebab case is preferred)

.cursorrules is deprecated

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release-any To be landed in any release window

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants