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

broccoli-metal

v1.0.0

Published

Easily iterate through and modify all the files in your Broccoli node (tree).

Downloads

28

Readme

Broccoli Metal

Build Status

Easily iterate through and modify all the files in your Broccoli node (tree)

Documentation

Given an input node and a callback function, Broccoli Metal will return a new node based any changes that were performed to the input node within the callback function.

Example Usage

var metal = require('broccoli-metal');
var inputNode = 'src';
module.exports = metal(inputNode, function(files) {
  // `files` is a plain JavaScript object.
  // Each object key is the file name/path and the
  // property values are the string contents of the
  // file.  File paths are relative to the input node.
  //
  // Broccoli Metal will return a new node based on
  // any additions/modifications/deletions performed
  // on the above `files` object.
});

If your project contains the following structure:

├── Brocfile.js
└── src/
    ├── index.js
    ├── css/
    │   ├── reset.css
    │   └── todos.css
    └── javascript/
        ├── app.js
        └── todo.js

then the files object passed to your Broccoli Metal callback function will consist of the following:

metal('src', function(files) {
  console.log(files); //outputs the following:
  /*
  {
    'index.js':           '<string contents of index.js>',
    'css/reset.css':      '<string contents of reset.css>',
    'css/todos.css':      '<string contents of todos.css>',
    'javascript/app.js':  '<string contents of app.js>',
    'javascript/todo.js': '<string contents of todo.js>'
  }
   */
});

The new Broccoli node generated by Broccoli Metal will be based on the modified files object. Deleting an item from the files object results in removing the file from the output node. Adding a new item to the files object results in creating a new file within the output node. And modifying the string contents of an item in the files object will result in modifying the file's contents within the output node.

Given the following project structure (and file contents):

├── Brocfile.js
└── src/
    ├── index.js      // contents = "alert('index.js')"
    ├── css/
    │   ├── reset.css // contents = "body {color: red;}"
    │   └── todos.css // contents = "p {font-size: 12px;}"
    └── javascript/
        ├── app.js    // contents = "alert('app.js')"
        └── todo.js   // contents = "alert('todo.js')"

and when the Brocfile.js contents consists of the following:

var metal = require('broccoli-metal');

module.exports = metal('src', function(files) {
  files['javascript/foo.js'] = "console.log('this is foo.js')";

  delete files['javascript/app.js'];

  delete files['css/todos.css'];
  
  files['css/reset'] = files['css/reset.css'].replace('red', 'blue');

  files['index.js'] = files['index.js'].replace('alert', 'console.log');
});

...then the following new project structure will be created:

└── src/
    ├── index.js      // contents = "console.log('index.js')"
    ├── css/
    │   └── reset.css // contents = "body {color: blue;}"
    └── javascript/
        ├── foo.js    // contents = "console.log('this is foo.js')"
        └── todo.js   // contents = "alert('todo.js')"

In your callback function, you can alternatively return a different object (instead of modifying the provided files object). The new object you return will result in creating a new file structure (relative to the input node).

For example, with the following Brocfile.js:

var metal = require('broccoli-metal');

module.exports = metal('src', function(files) {
  
  return {
    'foo.js': 'alert("this is foo")',
    'css/bar.css': 'body {color: green;}'
  };

});

...Broccoli Metal will return the following Broccoli node:

└── src/
    ├── foo.js      // contents = 'alert("this is foo")'
    └── css/
        └── bar.css // contents = "body {color: green;}"