I want to execute a node.js script in a pre-commit hook.
- Expected result: node.js script is executed
- Actual result: Nothing happens, no error, no logs, nothing
#!/usr/bin/env bash
echo "Run pre-commit hook"
node [project]/scripts/generate-social-media-preview/index.js
git add .
echo "Finished pre-commit hook"
exit 0
Of course, I also tried to run the node.js directly in the pre-commit
, by changing the first line to: #!/usr/bin/env node
. Same result.
The script executes playwright, manipulates an HTML template, takes a screenshot, and saves it. All of this lives in a nuxt.js project, so the script and the rest of the project are using one shared node-modules folder and package.json.
If I just run [project]/scripts/generate-social-media-preview/index.js
it does exactly what it should do. I made the file executable.
I normally commit via Webstorm, but I also did it with the terminal and I never saw an output or that the images got generated accordingly.
Also, husky and pre-commit were on my list, but it behaved as with the native pre-commit hook.
I would be happy to solve this "within the code" to not have a plugin or local script which triggers this, also running this during npm run generate
isn't working as my website is hosted at Netlify and of course, there isn't chromium available for playwright.
The whole code can be seen here (with all my test commits...): https://github.com/LukaHarambasic/harambasic.de/pull/46