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

rosmaro-tools

v0.0.4

Published

CLI utilities for [Rosmaro](https://rosmaro.js.org).

Downloads

5

Readme

rosmaro-tools

CLI utilities for Rosmaro.

To get started, get npm and then simply type the following command in your terminal:

$ npx rosmaro-tools

Available commands are described below.

npx rosmaro-tools bindings:build path/to/the/bindings/folder

Generates a JavaScript file exporting a factory function that takes an object and returns another object which is meant to be used as Rosmaro bindings.

Let's say we have a Rosmaro model which consists of the following nodes:

  • main
  • main:A
  • main:B
  • main:B:A
  • main:B:B

Rosmaro expects the bindings object to reflect the node hierarchy, like this:

{
  'main': {handler, lens, nodes},
  'main:A': {handler, lens, nodes},
  'main:B': {handler, lens, nodes},
  'main:B:A': {handler, lens, nodes},
  'main:B:B': {handler, lens, nodes},
}

As soon as the number of nodes grows, writing this by hand may be cumbersome. rosmaro-tools solves this problem by utilizing a directory-based convention.

Instead of manually building the bindings object, we create a directory which structure reflects the hierarchy of nodes of our graph:

$ tree -U
.
└── main
    ├── index.js
    ├── A
    │   └── index.js
    └── B
        ├── anotherFile.js
        ├── index.js
        ├── A
        │   └── index.js
        └── B
            └── index.js

The main/index.js file contains code related to the main binding. The main/A/index.js file contains code related to the main:A binding and so on. Files named differently are ignored by the generator. However, they may still be imported by index.js files.

Every index.js file is meant to have one default export - a binding factory. It looks like this:

export default (options) => ({

  // Somehow define these three.
  handler,
  lens,
  nodes
  
});

It's basically exporting a function that takes an arbitrary value and returns an object which is a Rosmaro binding. The options object is explained below.

As soon as we run $ npx rosmaro-tools bindings:build path/to/the/bindings/folder, it's going to generate an index.js file in the root directory:

$ npx rosmaro-tools bindings:build .
Generated index.js!
$ tree -U
.
├── index.js
└── main
    ├── index.js
    ├── A
    │   └── index.js
    └── B
        ├── anotherFile.js
        ├── index.js
        ├── A
        │   └── index.js
        └── B
            └── index.js

This automatically generated file exports a function taking an arbitrary value and returning an object with keys named after graph nodes. It follows this pattern:

export default (options) => ({
  'main': <the function exported from the main/index.js file>(options),
  'main:A': <the function exported from the main/A/index.js file>(options),
  'main:B': <the function exported from the main/B/index.js file>(options),
  'main:B:A': <the function exported from the main/B/A/index.js file>(options),
  'main:B:B': <the function exported from the main/B/B/index.js file>(options),
});

As we can see, it calls binding factories from each index.js file and builds an object which may be used as bindings for Rosmaro:

import rosmaro from 'rosmaro';
// ...
// This will import the generated index.js file.
import makeBindings from './bindings';

const bindings = makeBindings({parameters, passed, to, bindings, factories});
const model = rosmaro({graph, bindings});

Please remember that you can use symlinks in order to reuse bindings:

$ ln -s ToReuse Reused