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

peasant

v1.3.0

Published

Opinionated ES6 module build tool helper

Downloads

49

Readme

Peasant

An opinionated build helper for ES6 modules built for Node.js. It includes the ability to lint, transpile, test, and generate coverage reports for your module and is ideal for use in npm scripts to keep your module simple. Let the brave peasant do the heavy lifting.

Built on popular, well-tested components like Babel, ESLint, and Mocha.

Opinionated bits:

  • All source must go in the src folder.
  • All tests must go in the test folder.
  • You must use either .js or .es6 as an extension.
  • Tests must be written for Mocha, but can use any assertion library.
  • Tests should import/require the files from src.
  • All code should use the Airbnb Javascript Style Guide.
  • You package main must point to the transpiled files in lib.

Quick Start

Peasant includes a command to quickly start using it in your project. You can install it globally to use this:

npm install -g peasant

Assuming you want to start a new project, you would do something like this:

mkdir my-new-project
cd my-new-project
npm init
mkdir src test
peasant init

For existing projects, you can omit all but the last step! Note, this may overwrite customized data in your package.json, so be careful. It's best to use version control and see a diff of the changes before you commit to them.

cd my-existing-project
peasant init

You now have several commands available:

# Lint code
npm run lint

# Run tests
npm test

# Run tests filtered by regular expression
npm test -- -g MY_REGEX

# Generate coverage reports
npm run cover

# Run arbitrary subcommands
npm run peasant -- lint build ...

When publishing the package, an additional build step will generate the lib directory with the transpiled sources.

Manual Usage

Instead of using the peasant init command above, you can also manually install and use Peasant.

npm install --save-dev peasant

Then, in your package.json:

{
  "scripts": {
    "test": "peasant test lint"
  }
}

Don't forget to run peasant link if you want to use linting plugins with your text editor that require a local version of ESLint. These links are also automatically created anytime you run peasant lint.

Available Subcommands

The following subcommands are currently available, and can be combined however you want. They will be run in the order given, e.g. peasant test lint.

Init

Bootstrap a project to use Peasant. See the quick start above for an example of how and when to use this command.

peasant init

Link

Manually create symbolic links to enable linting. These links are required if you want to use your text editor for live linting, and are created for you when running the peasant lint subcommand described below or when using peasant init or running npm install in a development checkout. You should not need this subcommand unless setting Peasant up manually.

Creates the following links:

  • ./node_modules/.bin/eslint
  • ./node_modules/eslint
  • ./node_modules/eslint-config-airbnb
  • ./node_modules/babel-eslint
peasant link

Lint

Use the lint subcommand to lint all your source code, using babel-eslint to parse ES6 code. Uses the Airbnb Javascript Style Guide, but you can provide your own rule overrides in .eslintrc.

peasant lint

Build

Use the build subcommand to transpile your source code using babel. This uses the optional Babel runtime component.

# Default build
peasant build

# Enable source maps
peasant -s build

Test

Use the test subcommand to run all your tests using Mocha. Uses the Babel require hook to enable ES6 tests and code. Your tests should directly reference the code in the src directory instead of relying on the transpiled lib directory.

peasant test

Cover

Generate coverage reports from your tests. This will create a new directory called coverage and it will contain an LCOV report as well as HTML in coverage/lcov-report/index.html.

peasant cover

Customization

Nope. Just kidding! Propose something in a new issue!

License

Copyright © 2015 Daniel G. Taylor

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