LoginSignup
6
6

More than 5 years have passed since last update.

任意のコマンドやスクリプトをComposerから実行

Last updated at Posted at 2015-06-20

Composerはインストールなどのタイミングで任意のPHP処理を実行する事が出来るが、実はPHP関係なくシェルコマンドも実行できる。

ポータビリティを保つのは難しいかもしれないが、シェルスクリプトを同梱するよりは統一感がある。具体的にはcomposer.jsonの"scripts"に任意に名前とコマンドを定義する。

{
    "scripts": {
        "test": "phpunit"
    }
}

phpunitとあるが、別にどんなコマンドでも良い。定義されたコマンドはcomposerのサブコマンドのように実行できる。

composer test

手元では下記のようなコマンドでgettextの起動をショートカットしている。

{
    "scripts": {
        "i18n-extract": "xgettext.pl -D src/ -D templates/ -D towers/ -o i18n/default.pot"
    }
}




この場合も次のようにしてコマンドを実行できる。オプションを覚えなくていいので便利。

composer i18n-extract
6
6
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
6