dominique-mueller / hugo-installer

Installs hugo into your repository.
https://www.npmjs.com/package/hugo-installer
MIT License
21 stars 4 forks source link

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

Closed h-enk closed 3 years ago

h-enk commented 3 years ago

@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 3 years ago

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.

dominique-mueller commented 3 years ago

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 3 years ago

Ah brilliant /way better solution — thanks!

h-enk commented 3 years ago

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