dominique-mueller/hugo-installer

Running bin/hugo/hugo as part of an npm script

h-enk opened this issue · 4 comments

h-enk commented

@dominique-mueller, nice work! I'm considering using hugo-installer in Doks, however I can't get it to work — on Windows.

Running bin/hugo/hugo version works for me from the command line, but not as part of an npm script (on Windows):

$ npm run check

> hugo-installer@1.0.0 check
> bin/hugo/hugo version

'bin' is not recognized as an internal or external command,
operable program or batch file.

I'm using Node.js v16.3.0 /npm v7.16.0

How would I get this to work — cross platform?

POC: https://github.com/h-enk/hugo-installer-poc

h-enk commented

OK, I got it.

script-shell: default: '/bin/sh' on POSIX systems, 'cmd.exe' on Windows

I've added a script to use Powershell: "init:windows": "npm config set script-shell pwsh --userconfig ./.npmrc". Will try to automate this.

Yeah, some time ago I also discovered that running executable (.exe) files from within an npm script sadly does not work on Windows.

At that time I decided to write a tiny npm library that allows me to do exactly that: https://github.com/dominique-mueller/exec-bin. With that library, you just need to prepend exec-bin to every command. For instance, to check the version:

exec-bin bin/hugo/hugo version

I will probably extend the README docs to cover this.

h-enk commented

Ah brilliant /way better solution — thanks!

h-enk commented

I'm surely going to make the switch to hugo-installer for Doks!