rejoice icon indicating copy to clipboard operation
rejoice copied to clipboard

Passing arbitrary flags through to Node

Open ravinggenius opened this issue 9 years ago • 5 comments

Is there/can there be a way to pass arguments on to Node (for instance to set Node's debug port). For instance if I had rejoice -c manifest.js -p . -- --debug-brk=5959 as the target of a run script, everything after -- would be passed directly to Node.

I posted a work-around on StackOverflow, but having a cleaner syntax[1] would be nicer.

[1] Reaching into node_modules/.bin feels wrong and possibly brittle, and it side-steps one of the major benefits to using run scripts in the first place.

ravinggenius avatar May 01 '17 16:05 ravinggenius

Have you checked out the yargs library?

node index.js --id 'ID ARG' --otherFlag 'other stuff'
const argv = require('yargs')
    .usage('$0 --id default --otherFlag other')
    .option('id', {
        alias: 'id',
        describe: 'flag description',
        demandOption: true,
        type: 'string'
    })
    .option('otherFlag', {
        alias: 'other',
        describe: 'second flag description',
        demandOption: true,
        type: 'string'
    })
    .argv

console.log('ID:', argv.id);
console.log('OTHER:', argv.otherFlag);

Not sure if that's exactly what you're looking for or not.

WesTyler avatar May 01 '17 17:05 WesTyler

I'm not trying to parse command line flags myself, and I am not using a wrapper script around rejoice.

ravinggenius avatar May 03 '17 18:05 ravinggenius

Just to clarify why I'm asking. Currently my package.json scripts include:

"start": "rejoice -c manifest.js -p ."
"debug": "node --debug-brk=5959 node_modules/.bin/rejoice -c manifest.js -p ."

Please note the disparity between start and debug. What I'm asking for would allow me to have this instead:

"start": "rejoice -c manifest.js -p ."
"debug": "rejoice -c manifest.js -p . -- --debug-brk=5959"

Everything after -- would be passed through directly to the underlying Node process.

ravinggenius avatar May 03 '17 18:05 ravinggenius

Ah, sorry, misunderstood the end goal. I'm not sure about how to get there, sorry. :\

Hopefully someone else can lend their insight

WesTyler avatar May 03 '17 18:05 WesTyler

I think what you have is perfectly valid and I have done this approach as well in the past. I am open to suggestions but I would stick with just calling node, passing the args and then calling rejoice just as you have done.

lloydbenson avatar May 03 '17 19:05 lloydbenson