npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

ladon

v1.0.6

Published

Run commands in parallel on many files, like GNU parallel

Downloads

130

Readme

Ladon

Dependency Status Build Status NPM version NPM license

A small, simple utility to process many files in parallel. It is meant for people comfortable with using a terminal but strives to be as easy to use as humanly possible.

Ladon is named after the multiheaded serpent dragon from Greek mythology, slain by Heracles and thrust into the sky as the constellation Draco. His many heads allow you to efficiently work on many files at once.

Features

  • Supports Windows, Mac OS X, Linux, etc
  • Select files via a simple glob
  • Autodetects system CPU count
  • Configurable parallel process count
  • Simple command template syntax
  • Built-in templated mkdir -p support

Installation

The only dependency is Node.js. Standard global installation via NPM applies:

sudo npm install -g ladon

Examples

The following are some examples of what is possible:

# Print all text file names relative to the current directory
ladon "**/*.txt" -- echo RELPATH

# Calculate SHA1 sums of all your PDFs and save them in a file
ladon "~/Documents/**/*.pdf" -- shasum FULLPATH >hashes.txt

# Generate thumbnails with ImageMagick and keep directory structure
ladon -m thumbs/RELDIR "**/*.jpg" -- convert FULLPATH -thumbnail 100x100^ -gravity center -extent 100x100 thumbs/RELNAME'

You can also replace common bash-isms with true parallel processing:

# Typical bash for loop
for f in ~/Music/*.wav; do lame -V 2 $f ${f%.*}.mp3; done

# Parallelized via ladon to use all CPUs
ladon "~/Music/*.wav" -- lame -V 2 FULLPATH DIRNAME/BASENAME.mp3

Tutorial

The following is a brief walkthrough of how to use ladon.

Command Structure

The basic command structure consists of two parts that are split by --. The first part consists of the ladon command and its options, while the second consists of the command you want to run in parallel. The only required ladon option is a file selector glob.

ladon [options] glob -- command

Ladon works by selecting files via a glob, which supports wildcards like * and ** to match any file or any directory recursively. For example, *.txt would select all the text files in the current directory, while **/*.txt would select all the text files in the current directory and any child directories. Read the full glob syntax.

The second half of the command structure is the command you wish to run in parallel over the selected files. It can be anything you want and can use special variables (documented below).

Using Variables

A full variable reference can be found below. The most common use case is to get the full path to a file that you wish to process, and this can be done via the FULLPATH variable. For example, to print out the full path to each file that is selected by your glob:

ladon "*" -- echo FULLPATH

You can also safely mix variables with normal text to construct new paths:

ladon "*" -- echo RELDIR/BASENAME.zip

Making Directories

Many commands will generate a new file. Sometimes you want to overwrite existing files, but other times you'd rather create a copy. Ladon has built-in support for a templated mkdir -p feature which will recursively ensure directories exist before running your command on a selected file. The RELDIR variable is very useful here. This is perhaps best illustrated via example:

# Recursively copy all files and keep directory structure
ladon -m foo/RELDIR "myfiles/**/*" -- cp FULLPATH foo/RELPATH

In the example above every file and directory in the myfiles directory will be copied over to the new directory foo. If there is a myfiles/docs/test.txt then there will be a foo/docs/test.txt file created.

Variable Reference

The following variables can be used in both the command and the directory name when using the --makedirs option. The examples below assume that the current working directory is /home/dan/.

| Variable | Description | Example | | ------------ | --------------------------------------------- | ------------------------- | | FULLPATH | Full path, equivalent to DIRNAME/BASENAME.EXT | /home/dan/books/foo.txt | | DIRNAME | Directory name | /home/dan/books | | BASENAME | File name without extension | foo | | EXT | File name extension | txt | | RELDIR | Relative directory name | books | | RELPATH | Relative file path | books/foo.txt |

Use as a Library

You can also use ladon as a basic library in Node.js.

npm install ladon

Then, just require and use it:

var ladon = require('ladon');

// The command parser (based on yargs)
var args = ladon.parser.parse(['ladon', '**/*.txt', '--', 'echo', 'FULLPATH']);

// Run the command
ladon.run(args, function (err) {
    if (err) console.error(err.toString());
});

Alternatives

License

See http://dgt.mit-license.org/