Drupal Composer scaffold file prepending and appending

The file-mapping configuration setting consists of a map from the destination path of the file to scaffold to a set of properties that control how the file should be scaffolded.

The available properties are as follows:

  • mode: One of “replace”, “append” or “skip”.
  • path: The path to the source file to write over the destination file.
  • prepend: The path to the source file to prepend to the destination file, which must always be a scaffold file provided by some other project.
  • append: Like prepend, but appends content rather than prepends.
  • overwrite: If false, prevents a replace from happening if the destination already exists.

The mode may be inferred from the other properties. If the mode is not specified, then the following defaults will be supplied:

  • replace: Selected if a path property is present, or if the entry’s value is a string rather than a property set.
  • append: Selected if a prepend or append property is present.
  • skip: Selected if the entry’s value is a boolean false.

Examples:

"file-mapping": {
  "[web-root]/sites/default/default.settings.php": {
    "mode": "replace",
    "path": "assets/sites/default/default.settings.php",
    "overwrite": true
  },
  "[web-root]/sites/default/settings.php": {
    "mode": "replace",
    "path": "assets/sites/default/settings.php",
    "overwrite": false
  },
  "[web-root]/robots.txt": {
    "mode": "append",
    "prepend": "assets/robots-prequel.txt",
    "append": "assets/robots-append.txt"
  },
  "[web-root]/.htaccess": {
    "mode": "skip",
  }
}