I recently wanted to split of a series of scripts I made for a postgres project I was working on into its own cli tool. I started by outlining the tool, I wanted a pgrun bundle
, and a pgrun test
command. This is what I had after a little bit of development:
.
βββ README.md
βββ args.ts
βββ bundle.ts
βββ cli.ts
βββ context.ts
βββ main.ts
βββ options.ts
βββ organizer.ts
βββ organizer2.ts
βββ parse.ts
βββ run.sh
βββ shake.ts
βββ sort.ts
βββ sort2.ts
βββ sql.ts
βββ walk.ts
I had a whole bunch of functions spit into their own files, and it started to be a headache to maintain. I felt every time I made some new thing, Iβd isolate it in itβs own file. Iβve vented about files and folders in the past, as well as invented whole new ways to organize typescript projects.
But nothing is as simple as this:
.
βββ README.md
βββ bin.ts
βββ deno.lock
βββ mod.ts
βββ test.ts
βββ types.ts
Whatβs the shift? Simply having all the functions in one mod.ts file, itβs still under 500 lines. It became a shift slightly but utilizing search and replace within the same file became much easier than digging around the files for the function, and having to deal with import / exports.
This is a gentle reminder to myself to not break things out early on, and keep it simple, keep it all contained in one file if you can, it makes it so much easier to manage.