-
Notifications
You must be signed in to change notification settings - Fork 606
feat: add create-spacetime CLI tool #3251
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
base: master
Are you sure you want to change the base?
Conversation
My two cents: |
…into tien/feat/create-spacetime
|
console.log(); | ||
} | ||
|
||
if (options.template && !isValidTemplate(options.template)) { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this 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.
…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.
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.
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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}"`, |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this 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
.
Co-authored-by: Tyler Cloutier <[email protected]> Signed-off-by: clockwork-tien <[email protected]>
…pacetimedb package
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.yaml
to include new packagetemplates/create-spacetime/README.md
Screenshots
npm create spacetime@latest
Testing
pnpm run build
withintemplates/create-spacetime
) and runs without errors (pnpm run test
)