Broccoli Metal
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 = ;var inputNode = 'src';moduleexports = ;
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:
;
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 = ; moduleexports = ;
...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 = ; moduleexports = ;
...Broccoli Metal will return the following Broccoli node:
└── src/ ├── foo.js // contents = 'alert("this is foo")' └── css/ └── bar.css // contents = "body {color: green;}"