3

I'm trying to build a CLI using oclif and it doesn't seem to work for anything I tried. I see a lot of people making it work for them so can maybe someone point me to my issue!

My steps:

 1. mkdir test && cd test
 2. npm init -f
 3. npm i oclif
 4. npx oclif generate my_test //this generates a new cli
 5. cd my_test
 6. npx oclif generate command bob
 7. npm link
 8. npx my_test bob

I always get

 ›   Error: command bob not found

Same if I do ./bin/run bob

However, if I run the test for the bob command, the test passes.

Thank you in advance.

Constantin Suiu
  • 214
  • 2
  • 12

2 Answers2

2

Sorry for being late replying... Intel's answer is almost correct - and until version 6 of npm it actually was. Correct is:

npm run build

Whereas oclif generate command just creates the Typescript file for the command and its test class under src/, above will create its Javascript file into dist/. npm link does probably nothing to your project at all - just creates a symlink pointing to it. npm test makes use of ts-node to directly execute Typescript.

  • Thank you!)) I though I was going crazy that no one is complaining about the repo not working besides me :D Was the need to build somewhere in the oclif documentation, that I missed? – Constantin Suiu Apr 07 '22 at 09:41
  • No, I don't think so. Having read the oclif.io documentation only selectively, I haven't seen it mentioned there. – Felix van Hove Apr 07 '22 at 11:37
1

run npm build, then you have it!

Intel
  • 141
  • 1
  • 9
  • 3
    A good answer will always include an explanation why this would solve the issue, so that the OP and any future readers can learn from it. – Tyler2P Mar 06 '22 at 16:15
  • Please read "[answer]". It helps more if you supply an explanation why this is the preferred solution and explain how it works. We want to educate, not just provide code. – the Tin Man Mar 11 '22 at 05:56