3

Anybody knows how to composer install for all subfolders too? Does the composer support it? Now I need to execute this command in each subfolder or add all subfolder's vendor folder to git.

I found solution in Linux: https://www.bram.us/2014/02/16/installing-dependencies-in-all-subfolder-organised-projects/

But how to do the same in Windows?

Example.

I have a project in C:\grav with composer.json in it. But also I have plugins folder C:\grav\user\plugins with composer.json in some of subfolders:

enter image description here

I want to execute composer install in C:\grav to install all dependencies in each C:\grav\user\plugins\* too.

Matt McCabe
  • 2,986
  • 2
  • 22
  • 29
Sogl
  • 782
  • 3
  • 9
  • 29
  • When you run `composer install` or `composer require` it will scan through your dependencies and install them all in `vendor` there is no need to run `composer install` in each directory. – Michael Mar 01 '16 at 02:14
  • 1
    If you do need to run a script (any script) in a sub folder you can make use of composer's [script hook—manual](https://getcomposer.org/doc/articles/scripts.md) – Michael Mar 01 '16 at 02:16
  • @Michael I mean I have `composer.json` in root and in each subfolder. – Sogl Mar 01 '16 at 02:16
  • Please update your question with an example. You don't need to run `composer install` on `vendor`-folders – Michael Mar 01 '16 at 02:17
  • @Michael Example added. – Sogl Mar 01 '16 at 02:30

1 Answers1

2

Grav plugin or theme

In order to support the correct installation folders for Grav plugins and themes, you would need to add the composer/installers to the require section of your plugins.

Normally the plugins would land in the vendor folder, too - but, the Grav Installer tells Composer the correct position inside a Grav project, see see https://github.com/composer/installers/blob/master/src/Composer/Installers/GravInstaller.php#L6

So, when writing plugins or themes for grav each composer.json must indicate the type as grav-plugin or grav-theme, else Composer can't match the package to the installer.

{
    "name": "your/some-grav-plugin",
    "type": "grav-plugin",
    "require": {
        "composer/installers": "^1.0.23"
    }
}

Grav main project

Now, in your main grav project's composer.json, just add the plugins.

Then run composer install. That means the package is fetched, the composer installer is fetched, based on the package type the matching installer is triggered and the grav installer drops the file into the correct folder....


But how to do the same in Windows?

Uhm... Composer works cross-platform. Not a problem.

Jens A. Koch
  • 39,862
  • 13
  • 113
  • 141
  • So I need to add `type: grav-plugin` and `composer/installers` to all my plugin's `composer.json`? Also can you add main project `composer.json` example? Thx! – Sogl Mar 01 '16 at 23:33
  • Yes, when you add the `type` and `composer/installers`, then all grav plugins and themes will be automatically identified and installed in the right folders. | Adding an example for main `composer.json`? There isn't much to show.. you basically add the plugins to the require section. That's it. – Jens A. Koch Mar 02 '16 at 10:43