An extension for voral/version-increment to update version strings in custom files using regular expressions.
This tool allows you to automatically update version numbers in arbitrary files (e.g., PHP, JSON, XML) during the
versioning process. It integrates seamlessly with the voral/version-increment
package and listens to
the BEFORE_VERSION_SET
event to perform replacements based on a provided regular expression.
- Custom File Support: Update version strings in any file format using flexible regular expressions.
- Event-Based Integration: Listens to the
BEFORE_VERSION_SET
event fromvoral/version-increment
. - Error Handling with Unique Codes: Prevents conflicts between multiple extensions by supporting error code deltas.
- Flexible Configuration: Define custom regular expressions to match version strings in various formats.
- Extensibility: Easily integrate into existing workflows with minimal configuration.
Install the package via Composer:
composer require --dev voral/vinc-file-version-regexp
To use this extension, configure it in your .vs-version-increment.php
file by adding a listener for
the BEFORE_VERSION_SET
event. Here's an example:
use Vasoft\VersionIncrement\Config;
use Vasoft\VersionIncrement\Events\EventType;
use Vasoft\VersionIncrement\Extension\RegexpFileModifier;
$config = (new Config());
$config->getEventBus()->addListener(
EventType::BEFORE_VERSION_SET,
new RegexpFileModifier(
'./src/version.php',
'#(\$version\s*=\s*\'|"v)\d+\.\d+\.\d+(\'|";)#s'
)
);
return $config;
- File Path: Specify the path to the file where the version string should be updated (e.g.,
./src/version.php
). - Regular Expression: Provide a regex pattern to locate the version string. The pattern must include:
- Group 1: The part of the string before the version.
- Group 2: The part of the string after the version.
- Error Code Delta: Optionally, specify a delta value to ensure unique error codes when using multiple extensions.
If your project contains a version.php
file like this:
<?php $version = "Version 1.0.0"; ?>
The extension will update it to:
<?php $version = "Version 2.0.0"; ?>
For a config.json
file:
{
"version": "1.0.0"
}
The extension can update it to:
{
"version": "2.0.0"
}
The extension provides detailed error messages and unique error codes to help diagnose issues:
- FileNotFoundException: Thrown if the specified file does not exist.
- FileNotWritableException: Thrown if the file is not writable.
- PatternNotFoundException: Thrown if the regular expression does not match any part of the file content.
Error codes are offset by a configurable errorCodeDelta
to avoid conflicts with other extensions.
You can customize the behavior of the extension by adjusting its parameters:
Parameter | Description |
---|---|
filePath |
The path to the file where the version will be updated. |
regexp |
The regular expression used to locate the version string. |
errorCodeDelta |
Optional delta value to ensure unique error codes across multiple modules. |
Contributions are welcome! Please follow these steps:
- Fork the repository.
- Create a new branch for your feature or bugfix.
- Submit a pull request with a clear description of your changes.
Ensure that your code adheres to the project's coding standards and includes appropriate tests.
Run the following commands to test the package:
composer test
Generate a code coverage report:
composer coverage
Perform static analysis:
composer stan
Check coding standards:
composer fixer
Run all checks at once:
composer check
This package is licensed under the MIT License. See the LICENSE file for details.
- voral/version-increment: The main package this extension integrates with.