The composer.json file schema contains a script section that allows projects to define actions that are executed under certain circumstances. The most recognizable use for this section is to define events that happen at defined times during the execution of Composer commands; for example, the post-update-cmd runs at the end of every composer update command.
However, Composer also allows custom commands to be defined in this same section; an example of this is shown in the composer.json schema documentation:
{
"scripts": {
"test": "phpunit"
}
}
Example how to add custom command
"scripts": {
"post-autoload-dump": [
"Illuminate\\Foundation\\ComposerScripts::postAutoloadDump",
"@php artisan package:discover --ansi"
],
"post-root-package-install": [
"@php -r \"file_exists('.env') || copy('.env.example', '.env');\""
],
"post-create-project-cmd": [
"@php artisan key:generate --ansi"
],
"pull": [
"composer install",
"composer dump-autoload",
"npm install",
"npm run dev"
]
}