devuri / zipit
A simple and flexible tool for creating zip archives.
Requires
- php: ^7.4 || ^8.0
- composer/ca-bundle: ^1.5
- symfony/console: ^5.4
- symfony/filesystem: ^5.4
- symfony/var-dumper: ^5.4
Requires (Dev)
- fakerphp/faker: ^1.23
- phpstan/phpstan: ^1.8
- phpstan/phpstan-strict-rules: ^1.3
- phpunit/phpunit: ^9.5
- vimeo/psalm: ^4.24 || ^5.0
README
ZipIt is a simple, flexible PHP CLI tool for creating zip archives, providing features like progress bars, customizable output locations, and recursive file archiving.
Features
- Configurable: Define the base directory, files to include, and exclusions in a
.zipit-conf.php
file. - Customizable Output: Optionally specify the output file name and path in the configuration file.
- Recursive Archiving: Automatically includes directories and their contents.
- Styled Output: Uses color-coded messages for warnings, errors, and success feedback.
- Progress Bar: Visual progress for long-running operations.
- Custom Config Path: Option to specify a custom configuration file path.
Installation
Add ZipIt to your project with Composer:
composer require devuri/zipit
Configuration
Create a .zipit-conf.php
file in your project root directory. This file should return an array with the following configuration keys:
<?php return [ 'baseDir' => __DIR__, // The base directory where files are located 'files' => [ // List of files and directories to include 'file1.txt', 'directory1', 'file2.txt', ], 'exclude' => [ // List of files and directories to exclude 'directory1/exclude-this.txt', 'file-to-exclude.txt', ], 'outputFile' => __DIR__ . '/project-archive.zip', // Optional: Custom output file path ];
Configuration Details
- baseDir: The root directory for all files to be zipped. Paths in
files
andexclude
are relative to this directory. - files: Array of files and directories to include in the zip archive.
- exclude: Array of files and directories to exclude. Paths are also relative to
baseDir
. - outputFile: (Optional) Specify a custom path and name for the output zip file. If not provided, the file name passed as a command argument will be used.
Usage
After setting up the .zipit-conf.php
file, use the zipit
command to create a zip archive. The zipit
executable will be available in vendor/bin
after installation.
Running ZipIt
Run ZipIt from your project’s root directory:
vendor/bin/zipit output.zip
- output.zip: The name of the zip file to create. If
outputFile
is set in the configuration file, that path will override this argument.
Specifying a Custom Config File
You can specify a custom configuration file path:
vendor/bin/zipit output.zip /path/to/.zipit-conf.php
Example
Suppose you have the following directory structure:
/my-project
|-- file1.txt
|-- file2.txt
|-- /directory1
|-- file3.txt
|-- exclude-this.txt
|-- .zipit-conf.php
In .zipit-conf.php
:
<?php return [ 'baseDir' => __DIR__, 'files' => [ 'file1.txt', 'file2.txt', 'directory1', ], 'exclude' => [ 'directory1/exclude-this.txt', ], 'outputFile' => __DIR__ . '/project-archive.zip', // Optional: Custom output file name ];
Running vendor/bin/zipit archive.zip
will create project-archive.zip
in the project root if outputFile
is set. Otherwise, it will create archive.zip
with file1.txt
, file2.txt
, and directory1/file3.txt
, while excluding directory1/exclude-this.txt
.
Output
- Styled Messages: Errors, warnings, and notes are shown in color for easy readability.
- Progress Bar: Tracks the zipping process to keep you informed.
Requirements
- PHP 7.4 or higher
- Composer
License
This project is licensed under the MIT License. See the LICENSE file for details.
Enjoy easy archiving with ZipIt!