Composer `setup` Command

Share
Composer `setup` Command
Photo by Imagine Buddy / Unsplash

Did you know that composer has a setup command, in which you can define commands in your composer.json file to help users get started once they've pulled down your app for the first time?

Taylor Otwell recently added this to the Laravel composer.json file, which makes total sense to help new Laravel users get set up quickly. This is what was added:

"setup": [
    "composer install",
    "@php -r \"file_exists('.env') || copy('.env.example', '.env');\"",
    "@php artisan key:generate",
    "@php artisan migrate --force",
    "npm install",
    "npm run build"
]

These commands are all commands you can run individually in your command line, but why bother when you can just run composer setup and have them ran for you!

I've been thinking about bringing this into all of our Shopify apps, to make onboarding to a new app easier for the team. I'll make a future post about how I get on with this!