markocupic/composer-file-copier-plugin

Copy files or mirroring folders from a package dist directory to the filesystem during 'composer-install-cmd' or 'composer-update-cmd'.

0.2.1 2023-08-18 13:50 UTC

This package is auto-updated.

Last update: 2024-11-18 16:41:36 UTC


README

Logo

Composer File Copier Plugin

Let's assume you have developed a composer package. Now you want selected files inside your package to be copied to a defined location on your local file system after each post-install-cmd and post-update-cmd event. With a bit of configuration this composer plugin can do this job for you.

The configuration is made inside the extra key of the composer.json file of your freshly programmed composer package.

Installation

composer require markocupic/composer-file-copier-plugin

Build your composer package

<project_root>/
├── app/
├── public/
└── vendor/
    └── code4nix/
        └── super-package/
            ├── .github/
            ├── src/
            ├── tests/
            ├── data/
            │   ├── foo.txt
            │   ├── style.css
            │   ├── config.yaml
            │   └── test1/
            │       ├── foo1.txt
            │       ├── style1.css
            │       ├── config1.yaml
            │       └── test2/
            │           ├── foo2.txt
            │           ├── style2.css
            │           └── config2.yaml
            └── composer.json    # configuration goes here!

Big thanks to https://tree.nathanfriend.io for sharing this fancy tree generator. ❤️

Configuration

The configuration is made inside the extra key of the composer.json file inside your composer package.

Note, that source paths are always relative to the installation directory of your package.

Note, that target paths are always relative to the project root.

Inside the composer.json of your package:

{
    "name": "code4nix/super-package",
    "type": "symfony-bundle",
    "require": {
        "php": "^8.1",
        "markocupic/composer-file-copier-plugin": "^0.1"
    },
    "autoload": {
        "psr-4": {
            "code4nix\\SuperPackage\\": "src/"
        }
    },
    "extra": {
        "composer-file-copier-plugin": [
            {
                "source": "data/foo.txt",
                "target": "foo.txt"
            },
            {
                "source": "data/foo.txt",
                "target": "foo.txt",
                "options": {
                    "OVERRIDE": true
                }
            },
            {
                "source": "data/test1",
                "target": "files/test1",
                "options": {
                    "OVERRIDE": true,
                    "DELETE": true
                }
            },
            {
                "source": "data",
                "target": "files/data",
                "options": {
                    "OVERRIDE": true
                },
                "filter": {
                    "NAME": [
                        "*.css",
                        "*.yaml"
                    ],
                    "DEPTH": [
                        "> 1",
                        "< 3"
                    ]
                }
            }
        ]
    }
}

Options

Filters

Additional configuration

By default this package will not process the following package types: library','metapackage','composer-plugin','project'.
This can be overridden in your composer.json by specifying which package to exclude:

{
    "extra": {
        "composer-file-copier-excluded": ["library", "metapackage", "composer-plugin"]
    }
}

⚠️ Last but not least!

Note, that this is a very powerful but also dangerous tool that can OVERRIDE/DELETE files/folders and DESTROY/DAMAGE your installation if wrongly applied.