Skip to content

Conversation

clockwork-tien
Copy link

@clockwork-tien clockwork-tien commented Sep 17, 2025

Description of Changes

  • Introduce CLI tool for scaffolding SpacetimeDB projects and create applications with React frontends and Rust or C# backends
  • Add templates/create-spacetime/ with complete CLI implementation which supports interactive project creation, package manager detection, and deployment options (Maincloud and local deployment)
  • Update pnpm-workspace.yaml to include new package
  • Detailed package description and usage examples provided in templates/create-spacetime/README.md

Screenshots

  • Run CLI tool using npm create spacetime@latest
image image

Testing

  • Package builds successfully (pnpm run build within templates/create-spacetime) and runs without errors (pnpm run test)
  • CLI creates projects with interactive prompts, which support both Rust and C# templates with React and deployment options for local or Maincloud

@clockwork-tien clockwork-tien changed the title feat: create-spacetime command and package feat: add create-spacetime CLI tool Sep 17, 2025
@egormanga
Copy link

My two cents:
I'd call it spacetime-create instead, as it'll be easier to comprehend in terms of namespaces, and to tab-complete when you forgot the second word (otherwise there's nothing to complete if it comes first).

@bfops bfops added the release-any To be landed in any release window label Sep 22, 2025
@cloutiertyler
Copy link
Contributor

My two cents: I'd call it spacetime-create instead, as it'll be easier to comprehend in terms of namespaces, and to tab-complete when you forgot the second word (otherwise there's nothing to complete if it comes first).

npm create is an npm command, we don't have control over that

console.log();
}

if (options.template && !isValidTemplate(options.template)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Would it be possible to modify the script so that if it's not in the list of built in templates, it tries to clone the template from GitHub?

Copy link
Author

Choose a reason for hiding this comment

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

Thank you, I have updated to add support/option for non built-in templates.

Copy link
Contributor

@cloutiertyler cloutiertyler left a comment

Choose a reason for hiding this comment

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

This is looking really really good. I just left one more request about downloading templates from GitHub if the user specifies one that we don't know about.

Also as a minor nit, create-spacetime itself is not really a template, so it probably shouldn't go in the templates directory. I would imagine the templates directory is where we store/host all the built in templates.

@egormanga
Copy link

@cloutiertyler Oh, I see now. Thought you were making a standalone scaffolding binary called that. Alright then!

@clockwork-tien
Copy link
Author

clockwork-tien commented Sep 24, 2025

@cloutiertyler Thank you for the review! I have updated to rely on root eslint.config.js instead, implemented support/option for non built-in templates, moved create-spacetime from templates folder to cli folder, and published new version.


export const SPACETIME_VERSIONS = {
SDK: "^1.3.1",
RUNTIME: "1.3.*",
Copy link
Contributor

Choose a reason for hiding this comment

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

This doesn't appear to be used anywhere.

Copy link
Author

Choose a reason for hiding this comment

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

Thank you, I removed this unused variable.

process.exit(1);
}

if (!deps.spacetime) {
Copy link
Contributor

@cloutiertyler cloutiertyler Sep 25, 2025

Choose a reason for hiding this comment

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

Is there a reason we couldn't just install this for them? Obviously we'd ask them first, but then we could just run the appropriate install script based on the platform.

Copy link
Contributor

Choose a reason for hiding this comment

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

Eventually I think we'd like to move most of this functionality directly into the spacetime cli command, so it would make sense that this actually just becomes a simple bootstrapping TypeScript script to install the CLI and then run a command like:

spacetime init --template foobar/baz

Copy link
Author

Choose a reason for hiding this comment

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

Ah I could do it as well 👍 . Initially I had a version for that but held back due to cross-platform complexity.

Copy link
Contributor

Choose a reason for hiding this comment

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

Could you rename cli to npm-packages instead? Sorry for the back and forth on this.

Copy link
Author

Choose a reason for hiding this comment

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

Yes I renamed cli to npm-packages 👍

content = content.replace(/log\.workspace = true/g, 'log = "0.4"');
content = content.replace(
/spacetimedb = \{ path = ".*" \}/g,
`spacetimedb = "${SPACETIME_VERSIONS.CLI}"`,
Copy link
Contributor

Choose a reason for hiding this comment

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

Why are we changing the version here at all? Shouldn't this version be specified in the template?

Additionally, this is not the CLI version. We typically call this version the "module library version". Arguably it should be whatever is in the template, or arguably it could be the wildcard version, although that would cause templates to break silently if we push breaking changes.

Copy link
Author

Choose a reason for hiding this comment

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

The template uses a relative path spacetimedb = { path = "../../crates/bindings" } instead of a published version, this path doesn't exist when cloning outside the SpacetimeDB monorepo, so I needed to update with a fixed version.

clientPackage.name = `${name}-client`;

if (clientPackage.dependencies?.[SPACETIME_SDK_PACKAGE]) {
clientPackage.dependencies[SPACETIME_SDK_PACKAGE] = SPACETIME_VERSIONS.SDK;
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm also not sure why we're editing the template to add our own version in here as well. I guess to get them on the most up to date version?

Copy link
Author

Choose a reason for hiding this comment

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

The template has "spacetimedb": "workspace:*" in package.json, which didn't work when cloning standalone version so I needed to update with a fixed version.

Copy link
Contributor

@cloutiertyler cloutiertyler left a comment

Choose a reason for hiding this comment

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

I'm having the terrible realization that most of this code should really exist within spacetime init and be written in Rust. That way people who don't want to execute npm or npx can still use the template creator.

This tool would then become a thin wrapper which would essentially just install spacetime if it was not there and then execute spacetime init --template.

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.

4 participants