Component Downloader
The Component Downloader is a utility script designed to fetch and extract specific blocks, modules, and dependencies for use in your project from the Buro voor de Boeg Components Library.
What It Does
This script allows you to:
- Download blocks and modules directly from the components library.
- Extract and manage dependencies (such as Twig templates) for each downloaded component.
- Ensure that blocks and modules are downloaded only if they don't already exist in your project, preventing accidental overwrites.
Usage
Install
First, ensure the package is installed:
npm install @burovoordeboeg/component-downloader
Usage Command
You can invoke the downloader using npm scripts. Here’s an example of how to add it to your package.json
:
"scripts": {
"require": "component-downloader"
}
Once added, you can download blocks or modules using the following command:
npm run require blocks/block-name
or
npm run require modules/module-name
Replace block-name
or module-name
with the actual name of the block or module you want to download.
Example
To download a block named cta
, run the following command:
npm run require blocks/cta
This will fetch the cta
block and any of its dependencies, ensuring that no existing files are overwritten.
Features
- Prevents Overwrites: If a block or module already exists in your project, the script will abort the download to prevent overwriting files.
- Dependency Management: The script scans the Twig templates for
extends
and include
statements, downloading any missing dependencies.
- Automatic Cleanup: In the event of a failed download, the script will clean up any partially created files or directories.
Components Library
The blocks and modules are fetched from the Buro voor de Boeg Components Library. You can explore the available blocks and modules there.
Error Handling
The script handles a variety of errors, including:
- 404 Not Found: If the block or module doesn’t exist on the server, the script will report this and stop.
- Network Issues: If the server is unreachable, the script will report the issue.
- Extraction Errors: If there’s a problem during the extraction of the ZIP file, the script will clean up any incomplete downloads.
License
MIT License
Author
Justin Streuper (justin@burovoordeboeg.nl) - Buro voor de Boeg