Tuesday, September 27, 2016

shelljs node module

Let me share a little gem I've found: shelljs node module. I was working on updating my Cordova hooks to work with Windows environment and had to replace my bash script with the corresponding JS code. Unfortunately, the node modules I've found were disappointing, especially copying the files. Surely I could write the copying code by myself, but I supposed that in 2016 year one is not required to do such menial tasks.

The biggest problem for the modules I've tried was the glob matching - I have to copy files from the sibling directory, and modules couldn't find it (looks like they don't parse ".." notation). I've tried fs.extra, fs-extra, ncp, filecopy, cp, but no luck. I guess I could find the good module after all, but after I've discovered shelljs I don't need it anymore anyway. With shelljs porting the code was a piece of cake - see the results below (the original and the new scripts).