Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Heroku: composer.json in sub folder

Lets take the following folder structure:

www/
www/composer.json
www/index.php
www/vendor
www/backend/
www/backend/composer.json
www/backend/index.php
www/backend/vendor

As you can see I have 2 projects, 1 project being a subfolder in the main folder. The main folder gets deployed with heroku and heroku installs the packages from composer.json automatically. Is there a way to instruct heroku or composer.json to also install the www/backend/composer.json packages inside the www/backend/vendor folder?

Or can I specify some of the packages inside the www/compposer.json (not all) to install under the www/backend/vendor folder? Also to generate 2 autoloads file in both www/vendor/ and www/backend/vendor/ ?

like image 301
keepwalking Avatar asked May 23 '16 06:05

keepwalking


2 Answers

Afterall, i was able to do this adding the following in the main composer.json:

"scripts" : { "post-install-cmd" : "cd api;composer install;composer update" }

like image 176
keepwalking Avatar answered Sep 24 '22 18:09

keepwalking


For people looking for this in the future: As indicated by the answer from keepwalking you can use the "scripts" key in the "composer.json", as described in the "Scripts" section of the Composer documentation. Interestingly, you can also use arrays for individual events.

You can use bash commands, such as cd and mv but you can also use && to chain commands. So, my example would be:

{
  ...
  "scripts": {
    "post-install-cmd": [
      "cd www && composer install",
      "cd www/backend && composer install"
    ]
  }
  ...
}

This has the following flow:

  1. You run composer install in the project root
  2. Composer finishes installing the dependencies and emits the "post-install-cmd" event
  3. Composer runs the first command in the "post-install-cmd" array
  4. Composer finishes the first command in the "post-install-cmd" array
  5. Composer runs the second command in the "post-install-cmd" array
like image 20
Brandon Oldenhof Avatar answered Sep 23 '22 18:09

Brandon Oldenhof