statamic / cli

Install and manage your Statamic projects from the command line.
71 stars 19 forks source link

Feature Request: Option to install npm dependencies? #50

Closed duncanmcclean closed 2 years ago

duncanmcclean commented 2 years ago

Like how the CLI asks if you want to create a user when creating a fresh site with the Statamic CLI, it could be nice if it also asked you if you wanted it to run npm install for you.

Feel free to transfer this to statamic/ideas if that's a better place for this kind of thing - wasn't sure as it's CLI related, not Core related (I assume anyways).

robdekort commented 2 years ago

Hey Duncan. This should be possible with the new starter kit install hooks.

<?php

use Symfony\Component\Process\Process;
use Symfony\Component\Process\Exception\ProcessFailedException;

class StarterKitPostInstall
{
    public function handle($console)
    {
        if ($console->confirm('Do you want to install npm dependencies?', true)) {
            $process = new Process(['npm', 'i']);
            try {
                $process->mustRun();
                $console->info('Dependencies installed.');
            } catch (ProcessFailedException $exception) {
                $console->info($exception->getMessage());
            }
        }
    }
}
duncanmcclean commented 2 years ago

Ooh, that's nice - exactly what I needed! Thanks for noticing 🎉