parallelshell icon indicating copy to clipboard operation
parallelshell copied to clipboard

Shortcut for running npm scripts

Open keithamus opened this issue 10 years ago • 2 comments

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

keithamus avatar Sep 02 '15 22:09 keithamus

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 [email protected]:

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

paulpflug avatar Sep 02 '15 22:09 paulpflug

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' ] }

keithamus avatar Sep 03 '15 09:09 keithamus