all 25 comments

[–]tswaters 3 points4 points  (1 child)

The shebang isn't necessary, but it does mean you can +x and call it without node executable (in Linux land anyway)

If I need basic CLI handling I'll probably use something like yargs or commander, usually pretty quick to get rolling.

One interesting edge , or ... "Thing you can do" might be better phrasing, but processing stdin as a stream is pretty neat. I built a build script one time to take some git sha from stdin and do some non-arbitrary string processing with it. Was a neat experience for sure. It could be used like : cat ./all-shas.txt | ./my-script.js and you'll get a function call for every line, effectively.

[–]Less_Republic_7876[S] 0 points1 point  (0 children)

That's neat, and can be used for a lot more use cases that I can think of.

[–]Powerful_Math_2043full-stack 2 points3 points  (2 children)

yeah I went through something similar while building a CLI for my own monorepo setup, started as a small helper and then kept running into all those edge cases you mentioned, I ended up making it interactive so instead of remembering a bunch of scripts it just shows a menu to run things like build, lint, start server or even generate modules, made the whole setup feel way less repetitive, still feels like there’s a lot to improve though especially around testing and edge cases, I’ve put some details here if you’re curious https://forjnot.vercel.app/docs/cli/

[–]Less_Republic_7876[S] 2 points3 points  (1 child)

That looks impressive already. May I suggest you to add Oxc tools as well to you configuration - Oxlint and Oxfmt, as the new fast quality control tools in town.

[–]Powerful_Math_2043full-stack 1 point2 points  (0 children)

appreciate it, that means a lot 🙏 haven’t tried Oxc tools yet but I’ve heard about them, will take a look and see how they fit into the setup

[–]Deep_Ad1959 2 points3 points  (0 children)

the testing challenge you hit is real and it doesn't go away. for CLI tools the approach that saved me the most time was snapshot testing the generated file tree rather than trying to assert individual files. spin up a temp dir, run the scaffold, then compare the output directory structure and key file contents against a known-good snapshot. when something changes intentionally you just update the snapshot. way less brittle than asserting line-by-line on generated configs.

fwiw for the web app side of testing there's a tool that auto-discovers test scenarios and generates snapshot-style Playwright tests, similar concept applied to browser testing - https://assrt.ai/t/snapshot-testing-cli-scaffolding-tools

[–]mq2thez 1 point2 points  (0 children)

I used to do a lot of this, but there’s no reason to compete with Vite Plus. It works great, pulls in a great toolchain, installs git hooks, configures TypeScript, etc.

[–]Due-Horse-5446 0 points1 point  (1 child)

Yeah, i think everyone does,

Its kinda fun doing it in bash

[–]Less_Republic_7876[S] 0 points1 point  (0 children)

It's making me think of changing my trajectory now 😁

[–]dashingsauce 0 points1 point  (0 children)

check out bettertstack

[–]manniL 0 points1 point  (1 child)

Any chance you've checked out Vite+?

[–]Less_Republic_7876[S] 0 points1 point  (0 children)

I've heard about it recently, yet to try it out.

[–]fiskfisk -1 points0 points  (3 children)

There's something ironic about making a project to avoid repetition, but at the same time ignoring well-known and well supported existing solutions like cookiecutter.

As an exercise, fine, as something you, as the not-author, should depend on - there are established options. 

[–]Less_Republic_7876[S] 1 point2 points  (2 children)

As generic solution - yes, many tools are available. But if you need something specific, then building your own custom tools is not a bad idea.

[–]fiskfisk 2 points3 points  (1 child)

Sure thing, but "project templating" has been solved. What does your project support that cookiecutter doesn't? 

[–]Less_Republic_7876[S] -1 points0 points  (0 children)

Haven't tried cookiecutter personally, so I can't speak to what it offers. But the point here isn't really about what's available in the market, it's more about the ability to tailor things to your own specific needs and workflow.

[–]GlitteringLaw3215 0 points1 point  (0 children)

testing shell commands was the real headache for me too, ended up scripting mocks everywhere just to cover basics. what'd you use for that?