Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

homerun

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

homerun

Turn package scripts into commands

  • 0.4.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1
decreased by-83.33%
Maintainers
1
Weekly downloads
 
Created
Source

Homerun npm version

Turn npm package scripts into CLI commands

Since npm 2.0, you can pass arguments to scripts... wait... what if you could use that for creating CLIs? Homerun is a little experiment that lets you just do that. If you need more, I highly recommend minimist.

Usage

Let's say you have a script called add that you can run this way:

npm run add -- 1 2
3

Install homerun

npm install homerun --save

Add it to your package.json

{
  "name": "cli"
  "bin": "./node_modules/.bin/homerun" // <-- here
  "scripts": {
    "add": "node commands/add"
  }
}

Now, without any other setup, if you npm link or npm publish you get a CLI for free:

cli add 1 2
3

And of course, while you develop, you can still use npm run add -- 1 2 to test your command.

Options

Homerun will use these scripts in case no command is provided or matches.

"scripts": {
  "index": "node commands/index"  // no command provided
  "unknown": "node commands/help" // unknown command provided
}

Module

If you need to customize, homerun can be used as a module.

// index.js
var homerun = require('homerun')
var scripts = require('./package.json').scripts

homerun(scripts, process.argv).spawn()
// package.json
{
  "bin": "index.js"
}

Test

To test your commands, you can use homerun.exec()

var assert = require('assert')

var argv = [,, 'add', '1', '2']

homerun(scripts, argv).exec(function(err, stdout, stderr) {
  assert.equal(err, null)
  assert.equal('', stderr)
  assert.equal('3\n', stdout)
})

Limit

Homerun doesn't support multiple commands. For example, echo foo && echo bar won't work.

License

MIT - Typicode

Keywords

FAQs

Package last updated on 09 Sep 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc