tienvx / composer-downloads-plugin
Composer plugin for downloading additional files within any composer package.
Installs: 122 343
Dependents: 1
Suggesters: 0
Security: 0
Stars: 1
Watchers: 1
Forks: 8
Type:composer-plugin
Requires
- php: ^8.0
- composer-plugin-api: ^1.1 || ^2.0
- leongrdic/smplang: ^1.0.2
- symfony/filesystem: ^5.4 || ^6.0
- symfony/finder: ^4.4.23 || ^5.4 || ^6.0
Requires (Dev)
- composer/composer: ^1.10.26 || ^2.2
- php-vfs/php-vfs: ^1.4
- phpunit/phpunit: ^9.5.10
- symfony/process: ^4.4 || ^5.4 || ^6.0
This package is auto-updated.
Last update: 2024-04-15 14:04:27 UTC
README
This plugin allows you to download extra files and extract them within your package.
This is an updated version of civicrm/composer-downloads-plugin. It adds support for more archive files and allow custom variables.
Example
Suppose your PHP package foo/bar
relies on an external archive file (examplelib-1.1.0-windows-amd64.zip
on Windows, or examplelib-1.1.0-linux-x86_64.tar.gz
on Linux, or examplelib-1.1.0-darwin-x86_64.tar.gz
on MacOS):
{ "name": "foo/bar", "require": { "tienvx/composer-downloads-plugin": "^1.0" }, "extra": { "downloads": { "examplelib": { "url": "https://example.com/examplelib-{$version}-{$os}-{$architecture}.{$extension}", "path": "extern/{$id}", "version": "1.1.0", "variables": { "{$os}": "strtolower(PHP_OS_FAMILY)", "{$architecture}": "strtolower(php_uname('m'))", "{$extension}": "PHP_OS_FAMILY === 'Windows' ? 'zip' : 'tar.gz'", }, "ignore": ["tests", "doc", "*.md"] } } } }
When a downstream user of foo/bar
runs composer require foo/bar
, it will download and extract the archive file to vendor/foo/bar/extern/examplelib
.
Attribute:
-
url
: The URL to the extra file. -
path
: The releative path where content will be extracted. -
type
: (Optional) Determines how the download is handled. If omit, the extension inurl
will be used to detect.- Archive types (The archive file
url
will be downloaded and extracted topath
):zip
: . Support extension*.zip
rar
: Support extension*.rar
xz
: Support extension*.tar.xz
tar
: Support extensions*.tar.gz
,*.tar.bz2
,*.tar
,*.tgz
- File types (The file
url
will be downloaded and placed atpath
):file
phar
: The file will be mark as executable.gzip
: The*.gz
file will be extracted to a file that will be placed atpath
.
- Archive types (The archive file
-
ignore
: (Optional) A list of a files that should be omited from the extracted folder.- This supports a subset of
.gitignore
notation. - Only useful with archive types.
- This supports a subset of
-
executable
: (Optional) Indicate list of files should be mark as executable.- For archive types: the value should be a list of extracted files
- For file types: the value should be boolean (true/false)
-
version
: (Optional) A version number for the downloaded artifact.- This has no functional impact on the lifecycle of the artifact.
- It can affect the console output.
- It can be used as a variable.
-
variables
: (Optional) List of custom variables.
Variables
Supported Attribute
Only following attribute support variables:
url
path
ignore
Default Variables
{$id}
: The identifier of the download. (In the example, it would beexamplelib
.){$version}
: Just a text defined in theversion
attribute, if not defined, the value will be empty string (""
).
Custom Variables
- The format will be
"{$variable-name}": "EXPRESSION-SYNTAX-EVALUATED-TO-STRING"
- More about the syntax at Expression Syntax.
- The syntax must be evaluated into a
string
.
Methods
Custom variable support these methods:
range
strtolower
php_uname
in_array
str_contains
str_starts_with
str_ends_with
matches
Constants
Custom variable support these constants:
PHP_OS
PHP_OS_FAMILY
PHP_SHLIB_SUFFIX
DIRECTORY_SEPARATOR
Default Attributes
You may set default attributes for all downloads. Place them under *
, as in:
{ "extra": { "downloads": { "*": { "path": "bower_components/{$id}", "ignore": ["test", "tests", "doc", "docs"], "variables": { "{$extension}": "zip" } }, "jquery": { "url": "https://github.com/jquery/jquery-dist/archive/1.12.4.{$extension}" }, "jquery-ui": { "url": "https://github.com/components/jqueryui/archive/1.12.1.{$extension}" } } } }
Document
See more at Doc
Contributing
Pull requests are welcome, please send pull requests.
If you found any bug, please report issues.
Authors
- Rob Bayliss - Composer Extra Files
- Tim Otten and contributors - Composer Download Plugin
- Tien Vo and contributors - this project
License
This package is available under the MIT license.