Changing the name of a Composer Package upon Install

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 tecnick.com/tcpdf 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

{
  "config":{
    "cache-dir":"/var/lib/jenkins/.composer/cache"
  },
  "require": {
      "php": ">=5.4.0",
      "yiisoft/yii": "1.1.14",
      "tecnick.com/tcpdf":"6.0.057",
      "lib-curl": "*",
      "elasticsearch/elasticsearch": "~1.0"
  },
  "require-dev" :{
      "codeception/codeception":"~2.0",
      "phpunit/php-invoker": "*"
  },
  "scripts":{
      "post-install-cmd":[
          "[ -e `pwd`/vendor/tecnickcom ] || mkdir -p `pwd`/vendor/tecnickcom ",
          "[ -L `pwd`/vendor/tecnickcom/tcpdf ] || ln -s `pwd`/vendor/tecnick.com/tcpdf `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"
      ]
  }
}