Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can we use node script instead? (argv is empty) #514

Closed
mk0y opened this issue Jun 26, 2019 · 2 comments
Closed

Can we use node script instead? (argv is empty) #514

mk0y opened this issue Jun 26, 2019 · 2 comments

Comments

@mk0y
Copy link

mk0y commented Jun 26, 2019

Hi all,

I'm working on a commit-msg hook, but I'm writing it in Node.

Problem is that then process.argv is empty in such scripts.

My file begins with:

#!/usr/bin/env node

And it only contains console.log(process.argv).

Husky hook in package.json is "commit-msg": "scripts/commit-msg.js -E HUSKY_GIT_PARAMS". (file has been chmod +x)

Console.log only has array of:

[ '/usr/local/Cellar/node/11.12.0/bin/node', '/path/to/scripts/commit-msg.js', '-E', 'HUSKY_GIT_PARAMS']

So my question is how to pass git params (a commit message) to node scripts?

@mk0y
Copy link
Author

mk0y commented Jun 26, 2019

I'm reading commit message from

const msg = fs.readFileSync(path.join(__dirname, '../.git/COMMIT_EDITMSG'), { encoding: 'utf8' })

@mk0y mk0y closed this as completed Jun 26, 2019
@rheaditi
Copy link

rheaditi commented Aug 8, 2019

If anyone finds this issue, here's how I got it to work in a node script:
"commit-msg": "scripts/commit-msg.js -E HUSKY_GIT_PARAMS"

scripts/commit-msg.js:

#!/usr/bin/env node
const fs = require('fs');
const {
  HUSKY_GIT_PARAMS: gitMessagePath,
} = process.env;

const message = fs.readFileSync(gitMessagePath, { encoding: 'utf8' });

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants