GithubHelp home page GithubHelp logo

coderaiser / redrun Goto Github PK

View Code? Open in Web Editor NEW
121.0 4.0 3.0 743 KB

✨🐌 🐎✨ fastest npm scripts runner

License: MIT License

JavaScript 95.98% Shell 4.02%
cli npm-scripts task-runner parser shell nodejs npm npm-run-all parallel series

redrun's Introduction

Redrun License NPM version Build Status Coverage Status

CLI tool to run multiple npm-scripts fast. Supports madly comfortable 🏎 Madrun.

Redrun

Install

npm i redrun -g

Usage

Usage: redrun [...tasks] [options] [-- ...args]
Options:
  -p, --parallel          run scripts in parallel
  -s, --series            run scripts in series
  -q, --quiet             do not output result command before execution
  -c, --calm              return zero exit code when command completed with error
  -P, --parallel-calm     run scripts in parallel and return zero exit code
  -S, --series-calm       run scripts in series and return zero exit code
  -h, --help              display this help and exit
  -v, --version           output version information and exit

Completion

You can enable tab-completion of npm scripts similar to npm's completion using:

redrun-completion >> ~/.bashrc
redrun-completion >> ~/.zshrc

You may also pipe the output of redrun-completion to a file such as /usr/local/etc/bash_completion.d/redrun if you have a system that will read that file for you.

How it works

package.json:

{
    "scripts": {
        "one": "npm run two",
        "two": "npm run three",
        "three": "echo 'hello'"
    }
}

Usually these expressions would be executed one after another:

coderaiser@cloudcmd:~/redrun$ npm run one

> [email protected] one /home/coderaiser/redrun
> npm run two


> [email protected] two /home/coderaiser/redrun
> npm run three


> [email protected] three /home/coderaiser/redrun
> echo 'hello'

hello

All these npm run commands that are created are slow, because each time it creates a new process.

redrun makes it faster:

coderaiser@cloudcmd:~/redrun$ redrun one
> echo 'hello'
hello

How to use?

Redrun could be used via the command line, the scripts section of package.json or in a script:

import redrun from 'redrun';

await redrun('one', {
    one: 'npm run two',
    two: 'npm run three',
    three: `echo 'hello'`,
});

// returns
`echo 'hello'`;

await redrun('one', {
    one: 'redrun -p two three',
    two: 'redrun four five',
    three: `echo 'hello'`,
    four: 'jshint lib',
    five: 'jscs test',
});

// returns
`jshint lib && jscs test & echo 'hello'`;

Speed comparison

The less spend time is better:

  • npm-run-all: 1m12.570s
  • npm run && npm run: 1m10.727s
  • redrun: 0m38.312s

Here are logs:

npm-run-all:

coderaiser@cloudcmd:~/redrun$ time npm run speed:npm-run-all

> speed:npm-run-all /home/coderaiser/redrun
> npm-run-all lint:*


> [email protected] lint:jshint /home/coderaiser/redrun
> jshint bin lib test


> [email protected] lint:eslint-bin /home/coderaiser/redrun
> eslint --rule 'no-console:0' bin


> [email protected] lint:eslint-lib /home/coderaiser/redrun
> eslint lib test


> [email protected] lint:jscs /home/coderaiser/redrun
> jscs --esnext bin lib test


real    1m12.570s
user    0m14.431s
sys     0m17.147s

npm run && npm run

coderaiserser@cloudcmd:~/redrun$ time npm run speed:npm-run

[email protected] speed:npm-run /home/coderaiser/redrun
> npm run lint:jshint && npm run lint:eslint-bin && npm run lint:eslint-lib && npm run lint:jscs


> [email protected] lint:jshint /home/coderaiser/redrun
> jshint bin lib test


> [email protected] lint:eslint-bin /home/coderaiser/redrun
> eslint --rule 'no-console:0' bin


> [email protected] lint:eslint-lib /home/coderaiser/redrun
> eslint lib test


> [email protected] lint:jscs /home/coderaiser/redrun
> jscs --esnext bin lib test


real    1m10.727s
user    0m14.670s
sys     0m16.663s

redrun

coderaiser@cloudcmd:~/redrun$ redrun lint:*
> jshint bin lib test && eslint --rule 'no-console:0' bin && eslint lib test && jscs --esnext bin lib test

real    0m38.312s
user    0m8.198s
sys     0m9.113s

As you can see redrun is much faster and more DRY way of using npm scripts than regular solutions.

Related

  • madrun - CLI tool to run multiple npm-scripts in a madly comfortable way.

License

MIT

redrun's People

Contributors

bn-l avatar coderaiser avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

redrun's Issues

Should redrun work on Windows machines?

Should redrun work on Windows machines?
In my case (windows 10) it's not working as expected.

npm script: "start": "redrun -p serve:src lint:watch"

console output:

> redrun -p serve:src lint:watch
> babel-node tools/server.dev.js & esw src tools webpackConfig --color --watch

Server starts, linter doesn't (at least I can't see output).

"npm-run-all -p serve:src lint:watch" works as expected.

If it's Unix-only solution it would be nice to add related info into package description.
Otherwise I'd be glad to provide additional info to help close the issue.

Support per-script arguments

In npm-run-all, you can pass script-specific arguments. AFAICT, redrun only supports passing arguments to all scripts.

So e.g in the following…

{
  "clean": "rm -rf build && mkdir build",
  "build": "babel",
  "build:watch": "redrun clean build -- --watch"
}

… redrun will expand build:watch to rm -rf build && mkdir build --watch && babel --watch, which means an undesirable --watch dir is created.

Adding an intermediary script fixes this, but it's a little verbose:

{
  "clean": "rm -rf build && mkdir build",
  "build": "babel",
  "build:watch": "redrun build -- --watch",
  "watch": "redrun clean build:watch"
}

Something like the following would be handy:

{
  "clean": "rm -rf build && mkdir build",
  "build": "babel",
  "build:watch": "redrun clean 'build -- --watch'"
}

… which expands to rm -rf build && mkdir build && babel --watch.

wraps & in quotes

I have a script that looks like this:

scripts: {
   "predev":"npm run build -- --watch --skip-initial-build &",
    "build": "babel src --out-dir lib",
    "dev": "NODE_ENV=development nodemon -d 1 lib/server.js"
}

Here's how I run it through redrun:

const redrun = require('redrun');
const scripts = require('./package.json').scripts;

redrun('dev', scripts);

however, the trailing & at the end of the predev script, ends up getting wrapped in quotes.

image

is there any way to remove the quotes from the & in this example?

yarn?

Any thoughts on yarn?

Populating the same set of environment variables that npm run does

Awesome project!

I am one of the maintainers of pnpm and I think it would be awesome to use redrun instead of npm run to make pnpm even faster.

However, currently redrun does not populate all the env variables that npm run does. For instance, this won't work with redrun:

{
    "one": "npm run two",
    "two": "npm run three",
    "three": "printenv npm_lifecycle_event"
}

Getting "Directory not empty" error when running clean script

Here's the task:

  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "clean": "rm -rf dist",
    "postclean": "mkdir -p dist/assets/{css,js}",
    "prebuild": "npm run clean",
    "build": "npx redrun -p build:*",
    "build:html": "npx pug -b src src/pages -o dist",
    "build:css": "npx node-sass src/css -o dist/assets/css",
    "build:js": "cp -R src/js/ dist/assets/js",
    "build:static": "cp -R src/static/ dist",
    "watch": "npx redrun -p watch:*",
    "watch:html": "npx pug -w -b src src/pages -o dist",
    "watch:css": "npx gaze 'node-sass $path -o dist/assets/css/' 'src/**/*.{css,scss}'",
    "watch:js": "npx gaze 'cp $path dist/assets/js' 'src/**/*.js'",
    "watch:static": "npx gaze 'cp $path dist' 'src/static/**/*'",
    "images": "npx -p sharp-cli sharp -i src/static/assets/img/* -o dist/assets/img -q90 -- resize 800 --optimise --nearLossless",
    "serve": "npx browser-sync start --no-open --no-ui --no-notify -s dist -f dist",
    "start": "npx redrun -p build watch serve"
  },

and the output

> rm -rf dist && mkdir -p dist/assets/{css,js} && npx npx pug -b src src/pages -o dist || true & npx node-sass src/css -o dist/assets/css || true & cp -R src/js/ dist/assets/js || true & cp -R src/static/ dist || true & npx npx pug -w -b src src/pages -o dist & npx gaze 'node-sass $path -o dist/assets/css/' 'src/**/*.{css,scss}' & npx gaze 'cp $path dist/assets/js' 'src/**/*.js' & npx gaze 'cp $path dist' 'src/static/**/*' & npx browser-sync start --no-open --no-ui --no-notify -s dist -f dist
rm: dist/assets/js: Directory not empty
rm: dist/assets: Directory not empty
rm: dist: Directory not empty
Watching 3 files/directories, pattern:  [ 'src/**/*.{css,scss}' ]
Watching 5 files/directories, pattern:  [ 'src/**/*.js' ]
Watching 26 files/directories, pattern:  [ 'src/static/**/*' ]
...

also when I would manually remove the dist folder and run npm start the cp command would fail saying that the dist/assets/js folder doesn't exist.

also notice that there are 2 npx commands in the output of the concatenated command and not in the scripts. && npx npx pug

Can't throw error code on any command, that not last, on parallel exec

  • Version (redrun -v): 7.1.5
  • Node Version node -v: 11.11.0
  • OS (uname -a on Linux): Linux 4.19.28-1-MANJARO
  • Used Command Line Parameters: redrun -p one two three

For example, if command one or two exit with non-zero code, redrun exit with zero code.
It works properly only with last three command

Cannot run redrun in parallel - unclear how to use the command

  • 10.0.2 (redrun -v):
  • 16.14.2 node -v:
  • Windows (uname -a on Linux):
  • Chrome:
  • redrun -p:

I am having issues understanding how to actually use the command. I have a command

"pipeline-redrun-lint-checks-parallel": "redrun -p pipeline-eslint-check && pipeline-stylelint-check",

That I want to run those two other npm scripts,

"pipeline-eslint-check": "eslint ./ClientApp/app --ext .ts,.html --max-warnings=0",
"pipeline-stylelint-check": "stylelint **/*.scss --quiet"

How do I run these two npm scripts from the first npm script? Perhaps the syntax of redrun could be simpler? npm-run-all has a really intuitive cli.

parallel option not recognized

I'm trying to run redrun with the following setup:

{
	"build": "redrun feed-info stops routes trips stop-times calendar calendar-dates agency -p",
	"feed-info": "node build/feed-info.js > dest/feed_info.txt",
	"stops": "node build/stops.js > dest/stops.txt",
	"routes": "node build/routes.js > dest/routes.txt",
	"trips": "node build/trips.js > dest/trips.txt",
	"stop-times": "node build/stop-times.js > dest/stop_times.txt",
	"calendar": "node build/calendar.js > dest/calendar.txt",
	"calendar-dates": "node build/calendar-dates.js > dest/calendar_dates.txt",
	"agency": "curl -sL 'https://vbb-gtfs.jannisr.de/latest/agency.txt' > dest/agency.txt"
}

Running npm run build doesn't run the individual scripts in parallel. In fact, logging arg here reveals that there is no parallel flag set.

Looking at the parsing logic, I wondered why there handwritten parsing wrapped around yargs-parser…?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.