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.
composer require cpsit/setup-helper
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.
{
"extra": {
"setup-helper": [
{
"copy": {
"path/to/file/or/folder": "path/to/target",
"other/file": "other/target"
}
}
]
}
}
{
"extra": {
"setup-helper": [
{
"unlink": [
"path/to/file/or/folder",
"other file"
]
}
]
}
}
- there is no confirmation request. Any existing file or folder will be removed!
{
"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.
{
"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.
{
"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.
{
"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 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 charactera
,b
orc
[a-c]
matches a single charactera
,b
orc
[^abc]
matches any character buta
,b
orc
[^a-c]
matches any character buta
,b
orc
{ab,cd}
matchesab
orcd
E.g. "path": /path/to/dir/*.css
will select all files ending in .css
in that directory.
See documentation of glob library for details.
Currently we rely on a the fork cpsit/glob of webmozart/glob
since the original doesn't allow
recent PHP versions.