cpsit/setup-helper

Helps setting up a project bundle. This is a composer plugin. It performs predefined tasks on composer after update or install command.

Installs: 2 170

Dependents: 0

Suggesters: 0

Security: 0

Stars: 1

Watchers: 8

Forks: 1

Open Issues: 3

Type:composer-plugin

2.0.0 2021-06-10 22:30 UTC

README

Build Status Quality Gate Status

Setup Helper

Helps setting up project bundles based on configuration and templates.

This is a composer plugin. It performs predefined tasks on composer after update or install command.

Usage

composer require cpsit/setup-helper

Configuration

Add a key setup-helper to to the extra section of your composer.json. Note: Paths must be relative to your composer root directory or absolute.

Copy files or folder

{
  "extra": {
    "setup-helper": [
      {
        "copy": {
          "path/to/file/or/folder": "path/to/target",
          "other/file": "other/target"
        }
      }
    ]
  }
}

Unlink files or folders

{
  "extra": {
    "setup-helper": [
      {
        "unlink": [
          "path/to/file/or/folder",
          "other file"
        ]
      }
    ]
  }
}
  • there is no confirmation request. Any existing file or folder will be removed!

Move files or folders

{
  "extra": {
    "setup-helper": [
      {
        "move": {
          "path/to/old/file/or/folder": "path/to/new/folder",
          "other/file": "new/path"
        }
      }
    ]
  }
}

Note: Move does not rename a file or folder. If required combine it with a Rename task.

Rename files or folders

{
  "extra": {
    "setup-helper": [
      {
        "rename": {
          "path/to/old/file/or/folder": "newName",
          "other/file": "otherName"
        }
      }
    ]
  }
}

The source path is relative to the current working directory. This should always be the composer root directory, if the Installer is called via composer plugin API as expected.

Make directory

{
  "extra": {
    "setup-helper": [
      {
        "makeDirectory": [
          "path/to/new/folder"
        ]
      }
    ]
  }
}

The directory path is relative to the current working directory. This should always be the composer root directory, if the Installer is called via composer plugin API as expected. Any missing directory will be created recursively.

Symlink from source to target

{
  "extra": {
    "setup-helper": [
      {
        "symlink": {
          "path/to/source/file": "target",
          "file": "even/deeper/path/to/target"
        }
      }
    ]
  }
}

The source path is relative to the current working directory. This should always be the composer root directory, if the Installer is called via composer plugin API as expected. On existing source or target no symlink is created.

Replace

  • Replace a string with another string:
{
  "extra": {
    "setup-helper": [
      {
        "replace": [
          {
            "path": "path/to/file",
            "search": "string-to-replace", 
            "replace": "replacement string"
           }           
        ]
      }
    ]
  }
}
  • Replace a string with a string given as answer to a question (interactively)
{
  "extra": {
    "setup-helper": [
      {
        "replace": [
           {
             "path": "path/to/file",
             "search": "string-or-pattern-to-replace", 
             "ask": "Question to ask for (Answer replaces pattern)"
           }           
        ]
      }
    ]
  }
}

The path key respects Ant-like globbing.

Syntax:

  • ? matches any character
  • * matches zero or more characters, except /
  • /**/ matches zero or more directory names
  • [abc] matches a single character a, b or c
  • [a-c] matches a single character a, b or c
  • [^abc] matches any character but a, b or c
  • [^a-c] matches any character but a, b or c
  • {ab,cd} matches ab or cd

E.g. "path": /path/to/dir/*.css will select all files ending in .css in that directory.

See documentation of glob library for details.

Caveats

Currently we rely on a the fork cpsit/glob of webmozart/glob since the original doesn't allow recent PHP versions.