feat: add create-spacetime CLI tool#3251
Conversation
|
My two cents: |
…into tien/feat/create-spacetime
|
| console.log(); | ||
| } | ||
|
|
||
| if (options.template && !isValidTemplate(options.template)) { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Thank you, I have updated to add support/option for non built-in templates.
cloutiertyler
left a comment
There was a problem hiding this comment.
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.
…se eslint.config.js format
…into tien/feat/create-spacetime
|
@cloutiertyler Oh, I see now. Thought you were making a standalone scaffolding binary called that. Alright then! |
|
@cloutiertyler Thank you for the review! I have updated to rely on root |
|
|
||
| export const SPACETIME_VERSIONS = { | ||
| SDK: "^1.3.1", | ||
| RUNTIME: "1.3.*", |
There was a problem hiding this comment.
This doesn't appear to be used anywhere.
There was a problem hiding this comment.
Thank you, I removed this unused variable.
| process.exit(1); | ||
| } | ||
|
|
||
| if (!deps.spacetime) { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Ah I could do it as well 👍 . Initially I had a version for that but held back due to cross-platform complexity.
There was a problem hiding this comment.
Could you rename cli to npm-packages instead? Sorry for the back and forth on this.
There was a problem hiding this comment.
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}"`, |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
cloutiertyler
left a comment
There was a problem hiding this comment.
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.
Co-authored-by: Tyler Cloutier <cloutiertyler@users.noreply.github.com> Signed-off-by: clockwork-tien <tien@clockworklabs.io>
…pacetimedb package
|
Closing since we decided to go with |
Description of Changes
templates/create-spacetime/with complete CLI implementation which supports interactive project creation, package manager detection, and deployment options (Maincloud and local deployment)pnpm-workspace.yamlto include new packagetemplates/create-spacetime/README.mdScreenshots
npm create spacetime@latestTesting
pnpm run buildwithintemplates/create-spacetime) and runs without errors (pnpm run test)