Return to Blog Home

#100Devs Asset Manager CRUD CLI

Source 

#100Devs Asset Manager CRUD CLI

I had been manually Creating and Updating assets for too long...it was time to fix that!

For each new #100Devs class, I had been manually creating a new folder, manually adding the links files, manually downloading the chat, manually downloading the YouTube captions, and manually downloading the office hours videos, it was time to automate most of this!

At this point my #100Devs Organization CLI already had the Read in CRUD working, and that was all it did. So adding the Create and Update operations wouldn't be too big of a step, which started with me getting distracted and having to abstract my class-selection code. There were currently two places in my code where the user could choose a class, and there was about to be a third - which led me to turning this behavior into it's own function.

Unfortunately my TypeScript skills weren't enough to figure out how to both make the function simple to use, yet generic enough to allow the selecting of either multiple classes, or just a single class, so with one // @ts-ignore I was on my way.

Create

After that though, I started with the easiest of the two: Creation. Creation would be the easiest as there are only a few things that all classes have:

Update

Updating is where all the work would be, from files to automating asset generation. I started off with the easiest of the two: updating simple files, of which were only links and markers. Thanks to inquirer having a editor type, I had little work to do aside from asking the question with the default content and updating the file.

Finally came the asset generation:

As many of these required utilities that were not command-wide - the caption simplification and chat downloading - I decided to receive these command paths via Environment variable, therefore dotenv got added to the project. First one I went with was the downloading of chat, which was straightforward enough:

Then was the caption generation, which was a little more complicated as I wanted to preserve the original filenames, so needed to ensure the filename was always escaped, but similar to the captions only had a few steps:

Lastly was the video, which was had simple enough steps:

But as I wanted to see the progress while downloading, but also needed to retrieve information from the output - the name of the file generated - I needed to wrap a ChildProcess.exec up in a quick promise, so I could both pipe stdout and save it for the filename parsing later.

Thankfully this wasn't too difficult, and with that the Creation and Updating of assets was simplified quite a bit - though I still had to choose what to do, any further automation would be left to another day.