builder icon indicating copy to clipboard operation
builder copied to clipboard

`hathora init` throws an error

Open vyder opened this issue 3 years ago • 7 comments

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.

vyder avatar May 08 '22 07:05 vyder

Reading through the other issues - probably best to fix this along with a CLI restructure referenced in #157

vyder avatar May 08 '22 07:05 vyder

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:

  1. Create hathora.yml by hand
  2. Run hathora init to generate project from that

vyder avatar May 08 '22 08:05 vyder

Probably a couple things that should be improved here:

  1. cli shouldn't call getProjectRoot() at the top level
  2. there should potentially be a separate hathora create command

hpx7 avatar May 09 '22 05:05 hpx7

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.

vyder avatar May 09 '22 05:05 vyder

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.

hpx7 avatar May 09 '22 06:05 hpx7

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.

vyder avatar May 09 '22 09:05 vyder

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.

francislavoie avatar Jun 21 '23 21:06 francislavoie