Coder Social home page Coder Social logo

tandem's Introduction

tandem โ€” a fast and small parallel task runner (logo by Hannah Lee)

tandem is a task runner for parallel dev servers.
Small, fast, and pairs great with Makefiles!

Features

  • Small, fast, static binary.
  • Shuts down each command if one fails. No more processes clinging to ports.
  • Supports running npm scripts and binaries.
  • Labels output for each command.

Demo

A screencast demo of using the tandem CLI.

Installation

On macOS, you can install with:

brew install rosszurowski/tap/tandem

If you have Go installed, you can install from the source with:

go install github.com/rosszurowski/tandem@latest

If you're using tandem from a Makefile, this snippet shows how to download a locally cached copy.

Usage

Use tandem by passing a set of commands to run in parallel. Wrap each command in quotes, like so:

tandem 'command1 "arg"' 'command2 "arg"' 'command3 "arg"'

Running a front-end and a backend at once

Working on a Next.js app, you might want to run your front-end dev server alongside a backend API server with live updating changes through nodemon:

$ tandem 'next dev' 'nodemon --quiet ./server.js'
next     ready - started server on 0.0.0.0:3000, url: http://localhost:3000
next     event - compiled client and server successfully in 15 ms (25 modules)
nodemon  starting server...
nodemon  listening on http://localhost:3001

Running npm scripts

If your scripts are defined in package.json, you can reference them by using npm: as a prefix:

{
  "scripts": {
    "dev:php": "...",
    "dev:js": "...",
    "dev:css": "..."
  }
}
$ tandem 'npm:dev:php' 'npm:dev:js' 'npm:dev:css'

Wildcard rules like npm:dev:* are also supported as a shortcut. This line is equivalent to the above:

$ tandem 'npm:dev:*'

Using in Makefiles

In a Makefile, use this snippet to fetch a local copy for your project. Change the .cache path as needed, and add it to your .gitignore.

dev: node_modules .cache/tandem
	@.cache/tandem 'command1' 'command2'
.PHONY: dev

.cache/tandem:
	@mkdir -p $$(dirname $@)
	@curl -fsSL https://raw.githubusercontent.com/rosszurowski/tandem/main/install.sh | bash -s -- --dest="$$(dirname $@)"

Running make dev will download tandem once, and then use it for every run from there on out.

Motivation

I regularly use Makefiles to automate project commands and tools. Makefiles are mostly great! But their biggest failing (also a failing of shells generally) is that it's shockingly hard to coordinate multiple commands as one group:

  • make -jN <a> <b> <c> doesn't end all tasks when another one fails. For running local dev servers, this means you can lose your CSS or JS watcher and not realize.
  • command1 & command2 & wait often leaves commands hanging around in the background, which is annoying when it eats up a port you want to use.
  • Tools like GNU parallel have a confusing syntax, and I've never been able to figure out how to stop all tasks when one fails.

tandem makes running concurrent servers easy. It takes inspiration from concurrently or npm-run-all, but improves performance and works as a static binary.

Acknowledgements

tandem owes a big thanks to hivemind, from which much of the source is drawn. tandem can be thought of as a fork of hivemind, but rather than defining commands in a Procfile, defining them from a list of arguments.

tandem's illustration was drawn by Hannah Lee.

tandem's People

Contributors

rosszurowski avatar

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.