babymarkt/composer-cleaner-plugin

A composer plugin to clean up your project directory

v1.0.0-beta.3 2020-09-23 17:33 UTC

This package is auto-updated.

Last update: 2024-11-24 03:45:46 UTC


README

Build Status Packagist PHP Version Support version GitHub GitHub All Releases

Install

To install the plugin use Composer:

composer require --dev babymarkt/composer-plugin-cleaner

Configure

The configuration must be placed in the extra section in composer.json. An example is:

{
  "name": "company/your-project",
  "type": "project",
  "extra": {
    "babymarkt:cleaner": {
      "context-name": {
        "pattern": [
          "README*",
          ".git*"
        ],
        "paths": [
          "test",
          "artifacts"
        ],
        "exclude": [
          "test/important"
        ]
      }
    }
  },
  "require-dev": {
    "babymarkt/composer-plugin-cleaner": "*"
  }
}

The program contains a default configuration under the context default (Surprise surprise!). More detailed information can be found in the class AbstractCommand. Run

composer babymarkt:cleaner:clean default

to use it.

Configuration options

context

Each configuration set is wrapped in a cleaning context. A context is a simple string which can be used on terminal to select the configuration.

{
  "extra": {
    "babymarkt:cleaner": {
      "context-name": {
        "your cleaner options": "..."
      }
    }
  }
}

pattern

pattern contains a list of glob pattern to select files in the project directory tree. Consult the PHP documentation or Wikipedia for more information about the glob function and patterns.

{
  "extra": {
    "babymarkt:cleaner": {
      "context-name": {
        "pattern": [
          "README*",
          ".git*"
        ]
      }
    }
  }
}

This example searches for files starting with README or .git in the complete project tree.

paths

By default the cleaner command use the project root directory to search files (the directory that contains the composer.json file). With the option paths you can set multiple paths to search for files in instead of the default root directory. All paths are relative to the root directory, also such starting with an /. Paths outside the root are being ommited.

{
  "extra": {
    "babymarkt:cleaner": {
      "context-name": {
        "pattern": [
          ".git*"
        ],
        "paths": [
          "src",
          "vendor"
        ]
      }
    }
  }
}

This example searches for files starting with .git in ./src and ./vendor, nowhere else.

exclude

This option allows you to exclude files from deletion. The list consists of RegEx patterns, without specifying the delimiter characters. The pattern is applied to the entire path and not only to the file name. The used delimiter character is the #. If you need to use it in you pattern, you must escape it.

{
  "extra": {
    "babymarkt:cleaner": {
      "context-name": {
        "pattern": [
          "data/*"
        ],
        "exclude": [
          ".*\\.important"
        ]
      }
    }
  }
}

This example searches for paths starting with data/ and NOT ends with .important.

Run

To run the command use composer:

composer babymarkt:cleaner:clean your-context-name

or add a custom script to your composer.json:

{
  "scripts": {
    "cleanup:dev": [
      "@composer babymarkt:cleaner:clean your-context-name"
    ]
  }
}