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

@retailmenot/roux

v2.2.0

Published

Roux SDK and specification

Downloads

13

Readme

@retailmenot/roux

The SDK for the Roux component architecture, Roux ingredient spec, and a node interface to a pantry.

Build Status Coverage Status

Installation

npm install @retailmenot/roux

Usage

var roux = require('@retailmenot/roux');

var pantry = roux.initialize({
  name: 'my-pantry',
  path: 'path/to/my/pantry',
  predicates: {
    less: /^index.less$/
  }
});

API

initialize

Initialize a Pantry instance for a pantry of ingredients. This method returns a promise of the initialized instance and also accepts an optional Node.js-style callback that can be used in lieu of the promise.

  • config - Configuration object for the Pantry instance
    • name - the name of the pantry
    • path - the path to the pantry
    • [predicates] - optional object of entry point predicates which will be checked against the files contained in each ingredient in the pantry
  • [callback] - Optional Node.js callback

Relocating the ingredients base directory

The pantry path will always be given as the path to the root directory of the module. To support better dev ergonomics and allow for more control of project structure, pantry authors may optionally specify a subdirectory to use as the base path for ingredients by supplying the roux.pantryRoot property in the pantry modules' package.json file.

Entry point predicates

Entry point predicates are the mechanism for discovering the entry points an ingredient exposes. For each predicate, every Ingredient instance in the pantry will have a corresponding property in their entryPoints map. The value of the property will be an object if the predicate matched a file in the ingredient and null otherwise. Predicates for several common entry points are provided by default.

For example, given an ingredient containing the following files:

- ingredient.md
- index.js
- index.hbs

The entryPoints map might look like:

{
  handlebars: {
    filename: 'index.hbs'
  },
  javaScript: {
    filename: 'index.js'
  },
  model: null,
  preview: null,
  previewScript: null,
  sass: null
}

Predicates may be functions or regular expressions (RegExp instances). The predicate will be tested against each file in the root of each ingredient until either a match is found or all files have been checked.

Function predicates are passed the name of the file to be checked as their only argument. If the predicate can decide synchronously, it should return true if the file matches and false otherwise. If the predicate cannot decide synchronously, it should return a promise that will be resolved to true if the file matches and false otherwise.

Default predicates

The following predicates are configured by default:

  • assets - /^assets$/
  • handlebars - /^index.hbs$/
  • javaScript - /^index.js$/
  • model - /^model.js$/
  • preview - /^preview.hbs$/
  • previewScript - /^preview.js$/
  • sass - /^index.scss$/

Pantry

Instances of this class represent a pantry of Roux ingredients. They have the following properties:

  • name - the name of the pantry
  • path - the path to the pantry
  • ingredients - an object mapping from the name of each ingredient in the pantry to a corresponding Ingredient instance

Ingredient

Instances of this class represent a Roux ingredient. They have the following properties:

  • name - the name of the ingredient
  • path - the path to the ingredient
  • pantryName - the name of the pantry this ingredient belongs to
  • entryPoints - an object mapping from the name of a logical entry point ('sass', e.g.) to an object describing the entry point as provided by the ingredient or null if the ingredient does not provide it

entryPoints

The properties of this object are either null or an object with the following properties:

  • filename: the name of the file the ingredient provides for this entry point

parseIngredientPath

Parse the pantry and ingredient names out of an ingredient path. If passed a valid Roux ingredient path, this function returns an object with the pantry and ingredient names:

  • pantry - the name of the pantry, possibly including a namespace
  • ingredient the name of the ingredient

If passed a string that is not a valid path, it returns null. If passed anything else, it throws an Error.

resolve

Resolve a pantry or ingredient to an instance or an entry point to an absolute path to the corresponding file.

If passed a valid pantry name, this function returns a promise of the corresponding Pantry instance. If passed valid names of a pantry and ingredient, it returns a promise of the corresponding Ingredient instance. If passed valid names of a pantry, ingredient, and entry point, it returns a promise of the absolute path to the corresponding entry point file. In all of these cases, an optional configuration object can be passed as the last argument.

If passed invalid names, it throws an error. If the pantry, ingredient, or entry point cannot be found, the returned promise is rejected with an error.

  • pantry: pantry name
  • ingredient - optional ingredient name
  • entryPoint - optional entry point name
  • config - optional configuration object
  • config.pantries - a cache of Pantry instances
  • config.pantrySearchPaths - the paths to search for pantries in if not found in the cache