gulpjs / gulp-cli

Command Line Interface for gulp.
MIT License
401 stars 106 forks source link

How to add additional, non-Gulp tasks as args on command line #172

Closed stclairdaniel closed 6 years ago

stclairdaniel commented 6 years ago

This may be a super silly question: I have a gulp task in my gulpfile called start and in my package.json I have a script: "start": "gulp start",

I would like to call this from the command line like npm start staging and use the staging argument inside the start task to determine the env. This of course produces an error: Task never defined: staging

I was able to get around it by adding a bogus flag: "start": "gulp start --junkFlag" This now works correctly and I can access staging from the args list.

However, a) I'm not sure why this works, and I don't like comitting code I don't understand b) It is extraordinarily hacky :(

I would appreciate any advice!

sttk commented 6 years ago

@stclairdaniel Gulp (gulp-cli) treats non-flag args as task name, but not about flags and flag values. To separate non-flag args and flags/flag values, gulp-cli uses yargs. So please check yargs's document.

About npm's "script" field, please check npm's documents.