builder
builder copied to clipboard
`hathora init` throws an error
Was about to try making a project from scratch, and discovered that hathora init fails with this error:
<path>/node_modules/hathora/cli.js:28
throw new Error("Doesn't appear to be inside a hathora project");
^
Error: Doesn't appear to be inside a hathora project
at getProjectRoot (<path>/node_modules/hathora/cli.js:28:15)
at getProjectRoot (<path>/node_modules/hathora/cli.js:30:12)
at getProjectRoot (<path>/node_modules/hathora/cli.js:30:12)
at getProjectRoot (<path>/node_modules/hathora/cli.js:30:12)
at getProjectRoot (<path>/node_modules/hathora/cli.js:30:12)
at getProjectRoot (<path>/node_modules/hathora/cli.js:30:12)
at Object.<anonymous> (<path>/node_modules/hathora/cli.js:132:17)
at Module._compile (node:internal/modules/cjs/loader:1101:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
at Module.load (node:internal/modules/cjs/loader:981:32)
Looks like the issue is that cli.ts (line 140) calls getProjectRoot at the top level of the file, but in the init scenario hathora.yml doesn't exist yet - and so it throws.
Additionally, running hathora --help throws the same error - which makes it hard to understand what is expected as a new user - since it's unclear what a 'hathora project' is yet.
Reading through the other issues - probably best to fix this along with a CLI restructure referenced in #157
Ok my bad - I thought this generated a hathora project from scratch, but as I work through the uno tutorial, I see that the expected workflow is:
- Create
hathora.ymlby hand - Run
hathora initto generate project from that
Probably a couple things that should be improved here:
- cli shouldn't call
getProjectRoot()at the top level - there should potentially be a separate
hathora createcommand
What do you think about having hathora init create the hathora.yml from a template - similar to npm init or bundle init conventions - and then hathora generate does the generation?
Actually I haven't checked what the difference is between init and generate, but I have been running generate as I tweak the yaml definition during development.
Right now, hathora init is responsible for project bootstrapping, i.e. creating the initial directory structure for your application (independent of what you put in your hathora.yml. hathora generate runs the codegen based on your hathora.yml.
I like the idea of being able to create something from a template so you don't have to create your hathora.yml from scratch when starting your project. Not sure whether it should be a separate hathora create --template <templateName> command or just folded into the existing hathora init command.
I didn't explain myself well - what I meant was that I think many package managers follow the npm/bundle convention where the init command either interactively or statically creates that pkg manager's respective manifest - package.json or Gemfile - and then they have other commands to do the subsequent generation.
Actually come to think of it rails uses new.
Ok maybe there is no fixed convention - and it's the wild west. Something to think about for the CLI UX.
To add onto this, I had to create .env by hand as well. Would be nice if it prompted me to enter my app ID/secret if .env doesn't exist, and create a hathora.yml by default.