by bandergirl · 2y ago · 0 comments
This isn’t “better” than your tool of choice. This is a tool for JavaScript developers to write non-trivial scripts in a portable way without getting lost in POSIX hell. Who came up with this stuff?
https://stackoverflow.com/a/13373256
If you can write shell code, Perl, Python, COBOL, suit yourself. This is for JavaScript developers in JavaScript projects.
That used to be a shell script. But this I can way more easily read (even after not touching it for a long time), I get autocompletion, and I can use the APIs I'm already familiar with. It's a pretty neat QoL improvement for me specifically.
await Promise.all(
unneededPages.map(async (page) => {
await fs.move(page, `scripts/.cache/${page}`, { overwrite: true });
})
);
Similar to what you do on line 26.I could have appended it to the Promises that I'm creating on line 9 to run it in parallel with those moves, but this is not performance-critical code, and moving the two conceptually-unrelated concepts into the same expression wouldn't aid legibility, in my opinion. And since I'm the only one who needs to read the code, that opinion wins by default :)
You don't need the second `await` for blocking purposes.
Sure, it is your code to do as you like, but if you're going to post it as an example, you might want to correct it first so that others don't make the same mistakes.
[1] https://journal.stuffwithstuff.com/2015/02/01/what-color-is-...
They're probably on the spectrum.
(I'll get my coat...)