Changing the name of a Composer Package upon Install

Last updated:

Composer allows you to define shell scripts to be run at specified times and/or events such as before or after installing a package.

A very common use for it is to modify a project folder once it's been installed.

In this example case, shell scripts were defined to:

  • Make a copy of a project folder called under another name tecnickcom/tcpdf.

    • Note the use of bash constructs such as pwd to make commands work with relative paths ( pwd refers to the current path, or the directory where composer.json is located)
  • Run PHP scripts to add fonts to the target system

Sample composer.json file

  "require": {
      "php": ">=5.4.0",
      "yiisoft/yii": "1.1.14",
      "lib-curl": "*",
      "elasticsearch/elasticsearch": "~1.0"
  "require-dev" :{
      "phpunit/php-invoker": "*"
          "[ -e `pwd`/vendor/tecnickcom ] || mkdir -p `pwd`/vendor/tecnickcom ",
          "[ -L `pwd`/vendor/tecnickcom/tcpdf ] || ln -s `pwd`/vendor/ `pwd`/vendor/tecnickcom ",
          "php `pwd`/vendor/tecnickcom/tcpdf/tools/tcpdf_addfont.php -i `pwd`/pdf/ttfs/arial.ttf",
          "php `pwd`/vendor/tecnickcom/tcpdf/tools/tcpdf_addfont.php -i `pwd`/pdf/ttfs/arialb.ttf",
          "php `pwd`/vendor/tecnickcom/tcpdf/tools/tcpdf_addfont.php -i `pwd`/pdf/ttfs/arialbi.ttf",
          "php `pwd`/vendor/tecnickcom/tcpdf/tools/tcpdf_addfont.php -i `pwd`/pdf/ttfs/ariali.ttf",
          "php `pwd`/vendor/tecnickcom/tcpdf/tools/tcpdf_addfont.php -i `pwd`/pdf/ttfs/ariblk.ttf",
          "php `pwd`/vendor/tecnickcom/tcpdf/tools/tcpdf_addfont.php -i `pwd`/pdf/ttfs/verdana.ttf",
          "php `pwd`/vendor/tecnickcom/tcpdf/tools/tcpdf_addfont.php -i `pwd`/pdf/ttfs/verdanab.ttf",
          "php `pwd`/vendor/tecnickcom/tcpdf/tools/tcpdf_addfont.php -i `pwd`/pdf/ttfs/verdanai.ttf",
          "php `pwd`/vendor/tecnickcom/tcpdf/tools/tcpdf_addfont.php -i `pwd`/pdf/ttfs/verdanaz.ttf"

Dialogue & Discussion