What is broccoli-file-creator?
The broccoli-file-creator npm package is a Broccoli plugin that allows you to create files with specific content during the build process. It is useful for generating files dynamically based on the build configuration or other inputs.
What are broccoli-file-creator's main functionalities?
Create a simple file
This feature allows you to create a simple file with specified content. In this example, a file named 'file.txt' is created with the content 'Hello, world!'.
const fileCreator = require('broccoli-file-creator');
const tree = fileCreator('path/to/file.txt', 'Hello, world!');
Create a file with dynamic content
This feature allows you to create a file with dynamic content. In this example, a file named 'build-info.txt' is created with the current build time as its content.
const fileCreator = require('broccoli-file-creator');
const dynamicContent = `Build time: ${new Date().toISOString()}`;
const tree = fileCreator('path/to/build-info.txt', dynamicContent);
Create multiple files
This feature allows you to create multiple files with different content. In this example, two files 'file1.txt' and 'file2.txt' are created with their respective content.
const fileCreator = require('broccoli-file-creator');
const tree1 = fileCreator('path/to/file1.txt', 'Content for file 1');
const tree2 = fileCreator('path/to/file2.txt', 'Content for file 2');
Other packages similar to broccoli-file-creator
broccoli-static-site-json
The broccoli-static-site-json package is used to generate JSON files from static site data. It is similar to broccoli-file-creator in that it generates files during the build process, but it is specifically focused on creating JSON files for static sites.
broccoli-funnel
The broccoli-funnel package is used to filter and move files around in a Broccoli build pipeline. While it does not create files from scratch like broccoli-file-creator, it is often used in conjunction with file creation to manage the file structure of the build output.
broccoli-merge-trees
The broccoli-merge-trees package is used to merge multiple Broccoli trees into a single tree. It complements broccoli-file-creator by allowing you to combine the generated files with other parts of your build output.
Broccoli's File Creator
Usage
Create a file named app/main.js
with "some content goes here":
let writeFile = require('broccoli-file-creator');
let tree = writeFile('/app/main.js', 'some content goes here');
Documentation
writeFile(filename, content, fileOptions)
filename
{String}
The path of the file to create.
content
{String|Function|Promise}
The contents to write into the file.
writeFile('filename.txt', 'the-content');
writeFile('filename.txt', Promise.resolve('the-content'));
writeFile('filename.txt', () => 'the-content');
writeFile('filename.txt', () => Promise.resolve('the-content'));
note: If a function is provided, it will only be invoked once, on first build
ZOMG!!! TESTS?!?!!?
I know, right?
Running the tests:
npm install
npm test
License
This project is distributed under the MIT license.