darkguy2008 / parallelshell

Run multiple shell commands in parallel
501 stars 44 forks source link

Shortcut for running npm scripts #31

Open keithamus opened 9 years ago

keithamus commented 9 years ago

It'd be nice if parallelshell has a shortcut for running npm scripts, something like:

parallelshell 'npm run build' # old style
parallelshell -n 'build' # shorthand style

We could also use globbing here, to expand multiple npm scripts; for example:

parallelshell 'npm run build:js' 'npm run build:css' 'npm run build:html' # old style
parallelshell -n 'build:js' -n 'build:css' -n 'build:html'  # new shorthand style
parallelshell -n 'build:*' # new shorthand style with globs

Of course, each string would have the -n flag so they could be mixed and matched:

parallelshell 'npm run build:js' 'echo normal command' 'npm run build:html' # old style
parallelshell -n 'build:js' 'echo normal command' -n 'build:html' # new shorthand style
paulpflug commented 9 years ago

I like it Argument parsing would need a rewrite and we would need something to translate the globbing.. Npm has no API for it, does it? So simple project.json grep?

Am 3. September 2015 12:34:01 vorm. schrieb Keith Cirkel notifications@github.com:

It'd be nice if parallelshell has a shortcut for running npm scripts, something like:

parallelshell 'npm run build' # old style
parallelshell -n 'build' # shorthand style

We could also use globbing here, to expand multiple npm scripts; for example:

parallelshell 'npm run build:js' 'npm run build:css' 'npm run build:html' # 
old style
parallelshell -n 'build:*' # new shorthand style

Reply to this email directly or view it on GitHub: https://github.com/keithamus/parallelshell/issues/31

keithamus commented 9 years ago

Grepping the project.json would be the most straightforward. I think we only (realistically) need to support foo* or *foo - in other words a search by prefixes or suffixes. We could trivially implement this by parsing the package.json in the cwd, calculating if the glob is a prefix or suffix glob, iterating over keys and match using indexOf().

For argument parsing, I'd recommend we use minimist, as it is trivial to use and can pass multiple flags as an array of values, e.g.:

node -p 'require("minimist")(process.argv.slice(1));' -- 'foo' 'bar' -n 'foo' -n 'bar'
{ _: [ 'foo', 'bar' ], n: [ 'foo', 'bar' ] }