{"id":15726686,"url":"https://github.com/grasmash/composer-scaffold","last_synced_at":"2025-05-13T10:40:46.035Z","repository":{"id":66224301,"uuid":"180418827","full_name":"grasmash/composer-scaffold","owner":"grasmash","description":"Allows Composer to copy files around after package installation.","archived":false,"fork":false,"pushed_at":"2019-07-23T01:10:25.000Z","size":265,"stargazers_count":5,"open_issues_count":0,"forks_count":9,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-04-20T23:32:34.426Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/grasmash.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-04-09T17:38:12.000Z","updated_at":"2021-01-13T19:58:00.000Z","dependencies_parsed_at":null,"dependency_job_id":"18270e81-3b8a-44c0-afe6-30cc2175bd4f","html_url":"https://github.com/grasmash/composer-scaffold","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/grasmash%2Fcomposer-scaffold","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/grasmash%2Fcomposer-scaffold/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/grasmash%2Fcomposer-scaffold/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/grasmash%2Fcomposer-scaffold/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/grasmash","download_url":"https://codeload.github.com/grasmash/composer-scaffold/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253924819,"owners_count":21985179,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-03T22:40:21.618Z","updated_at":"2025-05-13T10:40:46.007Z","avatar_url":"https://github.com/grasmash.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# composer-scaffold\n\nThis project provides a composer plugin for placing scaffold files (like `index.php`, `update.php`, …) from the `drupal/core` project into their desired location inside the web root. Only individual files may be scaffolded with this plugin.\n\nThe purpose of scaffolding files is to allow Drupal sites to be fully managed by Composer, and still allow individual asset files to be placed in arbitrary locations. The goal of doing this is to enable a properly configured composer template to produce a file layout that exactly matches the file layout of a Drupal 8.7.x and earlier tarball distribution. Other file layouts will also be possible; for example, a project layout very similar to the current [drupal-composer/drupal-project](https://github.com/drupal-composer/drupal-scaffold) template will also be provided. When one of these projects is used, the user should be able to use `composer require` and `composer update` on a Drupal site immediately after untarring the downloaded archive.\n\nNote that the dependencies of a Drupal site are only able to scaffold files if explicitly granted that right in the top-level composer.json file. See [allowed packages](#allowed-packages), below.\n\n## Usage\n\nComposer-scaffold is used by requiring `grasmash/composer-scaffold` in your project, and providing configuration settings in the `extra` section of your project's composer.json file. Additional configuration from the composer.jon file of your project's dependencies is also consulted in order to scaffold the files a project needs. Additional information may be added to the beginning or end of scaffold files, as is commonly done to `.htaccess` and `robots.txt` files. See [altering scaffold files](#altering-scaffold-files) for more information.\n\n### Allowed Packages\n\nScaffold files are stored inside of projects that are required from the main project's composer.json file as usual. The scaffolding operation happens after `composer install`, and involves copying or symlinking the desired assets to their destination location. In order to prevent arbitrary dependencies from copying files via the scaffold mechanism, only those projects that are specifically permitted by the top-level project will be used to scaffold files.\n\nExample: Permit scaffolding from the project `drupal/core`\n```\n  \"name\": \"my/project\",\n  ...\n  \"extra\": {\n    \"composer-scaffold\": {\n      \"allowed-packages\": [\n        \"drupal/core\",\n      ],\n      ...\n    }\n  }\n``` \nAllowing a package to scaffold files also permits it to delegate permission to scaffold to any project that it requires itself. This allows a package to organize its scaffold assets as it sees fit. For example, the project `drupal/core` may choose to store its assets in a subproject `drupal/assets`.\n\nIt is possible for a project to obtain scaffold files from multiple projects. For example, a Drupal project using a distribution, and installing on a specific web hosting service provider might take its scaffold files from:\n\n- Drupal core\n- Its distribution\n- A project provided by the hosting provider\n- The project itself\n\nEach project allowed to scaffold by the top-level project will be used in turn, with projects declared later in the `allowed-packages` list taking precidence over the projects named before. The top-level composer.json itself is always implicitly allowed to scaffold files, and its scaffold files have highest priority.\n\n### Defining Project Locations\n\nThe top-level project in turn must define where the web root is located. It does so via the `locations` mapping, as shown below:\n```\n  \"name\": \"my/project\",\n  ...\n  \"extra\": {\n    \"composer-scaffold\": {\n      \"locations\": {\n        \"web-root\": \"./docroot\"\n      },\n      ...\n    }\n  }\n``` \nThis makes it possible to configure a project with different file layouts; for example, either the `drupal/drupal` file layout or the `drupal-composer/drupal-project` file layout could be used to set up a project.\n\nIf a web-root is not explicitly defined, then it will default to `./`.\n\n### Altering Scaffold Files\n\nSometimes, a project might wish to use a scaffold file provided by a dependency, but alter it in some way. Two forms of alteration are supported: appending and patching.\n\nThe example below shows a project that appends additional entries onto the end of the `robots.txt` file provided by `drupal/core`:\n```\n  \"name\": \"my/project\",\n  ...\n  \"extra\": {\n    \"composer-scaffold\": {\n      \"file-mapping\": {\n        \"[web-root]/robots.txt\": {\n          \"append\": \"assets/my-robots-additions.txt\",\n        }\n      }\n    }\n  }\n``` \nIt is also possible to prepend to a scaffold file instead of, or in addition to appending by including a \"prepend\" entry that provides the relative path to the file to prepend to the scaffold file.\n\nThe example below demonstrates the use of the `post-composer-scaffold-cmd` hook to patch the `.htaccess` file using a patch.\n```\n  \"name\": \"my/project\",\n  ...\n  \"scripts\": {\n    \"post-composer-scaffold-cmd\": [\n      \"cd docroot \u0026\u0026 patch -p1 \u003c../patches/htaccess-ssl.patch\"\n    ]\n  }\n``` \n\n### Defining Scaffold Files\n\nThe placement of scaffold assets is under the control of the project that provides them, but the location is always relative to some directory defined by the root project -- usually the web root. For example, the scaffold file `robots.txt` is copied from its source location, `assets/robots.txt` into the web root in the snippet below.\n```\n{\n  \"name\": \"drupal/assets\",\n  ...\n  \"extra\": {\n    \"composer-scaffold\": {\n      \"file-mapping\": {\n        \"[web-root]/robots.txt\": \"assets/robots.txt\",\n        ...\n      }\n    }\n  }\n}\n```\n\n### Excluding Scaffold Files\n\nSometimes, a project might prefer to entirely replace a scaffold file provided by a dependency, and receive no further updates for it. This can be done by setting the value for the scaffold file to exclude to `false`:\n```\n  \"name\": \"my/project\",\n  ...\n  \"extra\": {\n    \"composer-scaffold\": {\n      \"file-mapping\": {\n        \"[web-root]/robots.txt\": false\n      }\n    }\n  }\n``` \nIf possible, use the `append` and `prepend` directives as explained in [altering scaffold files](#altering-scaffold-files), above. Excluding a file means that your project will not get any bug fixes or other updates to files that are modified locally.\n\n### Overwrite\n\nBy default, scaffold files overwrite whatever content exists at the target location. Sometimes a project may wish to provide the initial contents for a file that will not be changed in subsequent updates. This can be done by setting the `overwrite` flag to `false`, as shown in the example below:\n```\n{\n  \"name\": \"service-provider/d8-scaffold-files\",\n  \"extra\": {\n    \"composer-scaffold\": {\n      \"file-mapping\": {\n        \"[web-root]/sites/default/settings.php\": {\n          \"mode\": \"replace\",\n          \"path\": \"assets/sites/default/settings.php\",\n          \"overwrite\": false\n        }\n      }\n    }\n  }\n}\n```\nNote that the `overwrite` directive is intended to be used by starter kits, service providers, and so on. Individual Drupal sites should [exclude the file by setting its value to false](https://github.com/grasmash/composer-scaffold#excluding-scaffold-files) instead.\n\n## Specifications\n\nReference section for the configuration directives for the \"composer-scaffold\" section of the \"extra\" section of a `composer.json` file appear below.\n\n### allowed-packages\n\nThe `allowed-packages` configuration setting contains an orderd list of package names that will be used during the scaffolding phase.\n```\n\"allowed-packages\": [\n  \"drupal/core\",\n],\n```\n### file-mapping\n\nThe `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.\n\nThe available properties are as follows:\n\n- mode: One of \"replace\", \"append\" or \"skip\". \n- path: The path to the source file to write over the destination file.\n- 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.\n- append: Like `prepend`, but appends content rather than prepends.\n- overwrite: If `false`, prevents a `replace` from happening if the destination already exists.\n\nThe mode may be inferred from the other properties. If the mode is not specified, then the following defaults will be supplied:\n\n- replace: Selected if a `path` property is present, or if the entry's value is a string rather than a property set.\n- append: Selected if a `prepend` or `append` property is present.\n- skip: Selected if the entry's value is a boolean `false`.\n\nExamples:\n```\n\"file-mapping\": {\n  \"[web-root]/sites/default/default.settings.php\": {\n    \"mode\": \"replace\",\n    \"path\": \"assets/sites/default/default.settings.php\",\n    \"overwrite\": true\n  },\n  \"[web-root]/sites/default/settings.php\": {\n    \"mode\": \"replace\",\n    \"path\": \"assets/sites/default/settings.php\",\n    \"overwrite\": false\n  },\n  \"[web-root]/robots.txt\": {\n    \"mode\": \"append\",\n    \"prepend\": \"assets/robots-prequel.txt\",\n    \"append\": \"assets/robots-append.txt\"\n  },\n  \"[web-root]/.htaccess\": {\n    \"mode\": \"skip\",\n  }\n}\n```\nThe short-form of the above example would be:\n```\n\"file-mapping\": {\n  \"[web-root]/sites/default/default.settings.php\": \"assets/sites/default/default.settings.php\",\n  \"[web-root]/sites/default/settings.php\": {\n    \"path\": \"assets/sites/default/settings.php\",\n    \"overwrite\": false\n  },\n  \"[web-root]/robots.txt\": {\n    \"prepend\": \"assets/robots-prequel.txt\",\n    \"append\": \"assets/robots-append.txt\"\n  },\n  \"[web-root]/.htaccess\": false\n}\n```\nNote that there is no distinct \"prepend\" mode; \"append\" mode is used to both append and prepend to scaffold files. The reason for this is that scaffold file entries are identified in the file-mapping section keyed by their destination path, and it is not possible for multiple entries to have the same key. If \"prepend\" were a separate mode, then it would not be possible to both prepend and append to the same file.\n\n### gitignore\n\nThe `gitignore` configuration setting controls whether or not this plugin will manage `.gitignore` files for files written during the scaffold operation.\n\n- true: `.gitignore` files will be updated when scaffold files are written.\n- false: `.gitignore` files will never be modified.\n- Not set: `.gitignore` files will be updated if the target directory is a local working copy of a git repository, and the `vendor` directory is not committed in that repository.\n \n### locations\n\nThe `locations` configuration setting contains a list of named locations that may be used in placing scaffold files. The only required location is `web-root`. Other locations may also be defined if desired.\n```\n\"locations\": {\n  \"web-root\": \"./docroot\"\n},\n```\n### symlink\n\nThe `symlink` property causes `replace` operations to make a symlink to the source file rather than copying it. This is useful when doing core development, as the symlink files themselves should not be edited. Note that `append` operations override the `symlink` option, to prevent the original scaffold assets from being altered.\n```\n\"symlink\": true,\n```\n## Managing Scaffold Files\n\nScaffold files should be treated the same way that the `vendor` directory is handled. If you need to commit `vendor` (e.g. in order to deploy your site), then you should also commit your scaffold files. You should not commit your `vendor` directory or scaffold files unless it is necessary.\n\nIf a dependency provides a scaffold file with `overwrite` set to `false`, that file should be committed to your repository.\n\nBy default, `.gitignore` files will be automatically updated if needed when scaffold files are written. See the `gitignore` setting in the Specifications section above.\n\n## Examples\n\nSome full-length examples appear below.\n\nSample composer.json for a project that relies on packages that use composer-scaffold:\n```\n{\n  \"name\": \"my/project\",\n  \"require\": {\n    \"drupal/composer-scaffold\": \"*\",\n    \"composer/installers\": \"^1.2\",\n    \"cweagans/composer-patches\": \"^1.6.5\",\n    \"drupal/core\": \"^8.8.x-dev\",\n    \"service-provider/d8-scaffold-files\": \"^1\"\n  },\n  \"config\": {\n    \"optimize-autoloader\": true,\n    \"sort-packages\": true\n  },\n  \"extra\": {\n    \"composer-scaffold\": {\n      \"allowed-packages\": [\n        \"drupal/core\",\n      ],\n      \"locations\": {\n        \"web-root\": \"./docroot\"\n      },\n      \"symlink\": true,\n      \"overwrite\": true,\n      \"file-mapping\": {\n        \"[web-root]/.htaccess\": false,\n        \"[web-root]/robots.txt\": \"assets/robots-default.txt\"\n      }\n    }\n  }\n}\n```\n\nSample composer.json for drupal/core, with assets placed in a different project:\n\n```\n{\n  \"name\": \"drupal/core\",\n  \"extra\": {\n    \"composer-scaffold\": {\n      \"allowed-packages\": [\n        \"drupal/assets\",\n      ]\n    }\n  }\n}\n```\n\nSample composer.json for composer-scaffold files in drupal/assets:\n\n```\n{\n  \"name\": \"drupal/assets\",\n  \"extra\": {\n    \"composer-scaffold\": {\n      \"file-mapping\": {\n        \"[web-root]/.csslintrc\": \"assets/.csslintrc\",\n        \"[web-root]/.editorconfig\": \"assets/.editorconfig\",\n        \"[web-root]/.eslintignore\": \"assets/.eslintignore\",\n        \"[web-root]/.eslintrc.json\": \"assets/.eslintrc.json\",\n        \"[web-root]/.gitattributes\": \"assets/.gitattributes\",\n        \"[web-root]/.ht.router.php\": \"assets/.ht.router.php\",\n        \"[web-root]/.htaccess\": \"assets/.htaccess\",\n        \"[web-root]/sites/default/default.services.yml\": \"assets/default.services.yml\",\n        \"[web-root]/sites/default/default.settings.php\": \"assets/default.settings.php\",\n        \"[web-root]/sites/example.settings.local.php\": \"assets/example.settings.local.php\",\n        \"[web-root]/sites/example.sites.php\": \"assets/example.sites.php\",\n        \"[web-root]/index.php\": \"assets/index.php\",\n        \"[web-root]/robots.txt\": \"assets/robots.txt\",\n        \"[web-root]/update.php\": \"assets/update.php\",\n        \"[web-root]/web.config\": \"assets/web.config\"\n      }\n    }\n  }\n}\n```\n\nSample composer.json for a library that implements composer-scaffold:\n\n```\n{\n  \"name\": \"service-provider/d8-scaffold-files\",\n  \"extra\": {\n    \"composer-scaffold\": {\n      \"file-mapping\": {\n        \"[web-root]/sites/default/settings.php\": \"assets/sites/default/settings.php\"\n      }\n    }\n  }\n}\n```\n\nAppend to robots.txt:\n\n```\n{\n  \"name\": \"service-provider/d8-scaffold-files\",\n  \"extra\": {\n    \"composer-scaffold\": {\n      \"file-mapping\": {\n        \"[web-root]/robots.txt\": {\n          \"append\": \"assets/my-robots-additions.txt\",\n        }\n      }\n    }\n  }\n}\n```\n\nPatch a file after it's copied:\n\n```\n\"post-composer-scaffold-cmd\": [\n  \"cd docroot \u0026\u0026 patch -p1 \u003c../patches/htaccess-ssl.patch\"\n]\n```\n\n## Related Plugins\n\n### drupal-composer/drupal-scaffold\n\nPrevious versions of drupal-scaffold (see community project, [drupal-composer/drupal-scaffold](https://github.com/drupal-composer/drupal-project)) downloaded each scaffold file directly from its distribution server (e.g. `https://cgit.drupalcode.org`) to the desired destination directory. This was necessary, because there was no subtree split of the scaffold files available. Copying the scaffold assets from projects already downloaded by Composer is more effective, as downloading and unpacking archive files is more efficient than downloading each scaffold file individually.\n\n### composer/installers\n\nThe [composer/installers](https://github.com/composer/installers) plugin is similar to this plugin in that it allows dependencies to be installed in locations other than the `vendor` directory. However, Composer and the `composer/installers` plugin have a limitation that one project cannot be moved inside of another project. Therefore, if you use `composer/installers` to place Drupal modules inside the directory `web/modules/contrib`, then you cannot also use `composer/installers` to place files such as `index.php` and `robots.txt` into the `web` directory. The drupal-scaffold plugin was created to work around this limitation.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgrasmash%2Fcomposer-scaffold","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgrasmash%2Fcomposer-scaffold","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgrasmash%2Fcomposer-scaffold/lists"}