Q:

Pass flag values to node scripts

I am creating a script to run through the entire 'build and push to git' flow.  To commit my changes, I need to include the commit messages, but I want to have a unique message for every execution.  Can I include a bash variable so that the user can create a message?  I essentially want to do something like:
//package.json
{
  ...
  "scripts": {
     "build:push2Git $message": "npm run build:local ;
        npm run build:webpack && git add . && git commit -m $message
        && git push origin my-branch || echo 'Failed to push to git'",
        ...
   }
}

And then the script would be run as `npm run build:push2Git 'commit message #23445'. Is this possible? I realize my example may be horribly wrong, just my thought to explain what I want and how I would think it would work.
Just to give an update to what I tired, and passing it as a bash variable doesn't work.
So I tried :
//package.json
{
  ...
  "scripts": {
     "build:push2Git $message": "npm run build:local ;
        npm run build:webpack && git add . && git commit -m '$1'
        && git push origin my-branch || echo 'Failed to push to git'",
        ...
   }
}

and then try to call it as npm run build:push2Git my_custom_message .  Does not work.  Pushed my code to my stash with the commit message "$1".

A:

I'm not an npm coder, but I do know bash.  Try this:
//package.json
{
  …
  "scripts": {
     "build:push2Git": "p2g() { npm run build:local ;
        npm run build:webpack && git add . && git commit -m '$@'
        && git push origin my-branch || echo 'Failed to push to git' ; }; p2g",
        …
   }
}

Assuming bash functions can be used and assuming scripts are called like bash aliases (with arguments getting tacked onto the end of the command), this should allow you to invoke your script as npm run build:push2Git -- "this is a commit message". (See also this answer.)
This establishes a shell function called p2g() that thanks to $@ will absorb your arguments (you really want "$@" to properly preserve your spacing, but I don't know how to properly escape or format the JSON to make that work).  Arguments appear to need to be delimited by --.
Here's a simpler version that doesn't use a function:
//package.json
{
  …
  "scripts": {
     "build:push2Git": "git commit",
        …
   }
}

You can use this one like: npm run build:push2Git -- -m "this is a commit message"

