-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #14 from gwleuverink/feature/install-command
Feature/install command
- Loading branch information
Showing
15 changed files
with
356 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
name: browser-tests | ||
|
||
on: | ||
workflow_dispatch: | ||
pull_request: | ||
branches: [development, main] | ||
workflow_run: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
name: tests | ||
|
||
on: | ||
workflow_dispatch: | ||
pull_request: | ||
branches: [development, main] | ||
workflow_run: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
<?php | ||
|
||
namespace Leuverink\Bundle\Commands; | ||
|
||
use Illuminate\Console\Command; | ||
use Illuminate\Support\Facades\Process; | ||
|
||
use function Laravel\Prompts\note; | ||
use function Laravel\Prompts\intro; | ||
use function Laravel\Prompts\outro; | ||
use function Laravel\Prompts\select; | ||
use function Laravel\Prompts\confirm; | ||
use function Laravel\Prompts\warning; | ||
use function Laravel\Prompts\progress; | ||
|
||
class Install extends Command | ||
{ | ||
protected $signature = 'bundle:install'; | ||
protected $description = 'Installs Bun, LightningCSS & Sass'; | ||
|
||
protected $installCommands = []; | ||
|
||
public function handle(): int | ||
{ | ||
$this->callSilent('bundle:clear'); | ||
|
||
$this->printAscii(); | ||
$this->printIntro(); | ||
|
||
$this->promptToInstallBun(); | ||
$this->promptToInstallCssLoading(); | ||
|
||
$this->install(); | ||
|
||
$this->call('bundle:version'); | ||
|
||
$this->printOutro(); | ||
|
||
return static::SUCCESS; | ||
} | ||
|
||
protected function printAscii() | ||
{ | ||
note(<<< TEXT | ||
____ __ __ _ __ ____ __ ______ | ||
/ __ ) / / / // | / // __ \ / / / ____/ | ||
/ __ |/ / / // |/ // / / // / / __/ | ||
/ /_/ // /_/ // /| // /_/ // /___ / /___ | ||
/_____/ \____//_/ |_//_____//_____//_____/ | ||
TEXT); | ||
} | ||
|
||
protected function printIntro() | ||
{ | ||
intro(PHP_EOL . ' Thank you for installing Bundle! This wizard will set everything up for you. ' . PHP_EOL); | ||
} | ||
|
||
protected function promptToInstallBun() | ||
{ | ||
$confirmed = confirm( | ||
default: true, | ||
label: 'Do you want to install Bun?', | ||
hint: 'Bun needs to be installed in order to use Bundle. Skip this if you\'ve installed it manually.' | ||
); | ||
|
||
if ($confirmed) { | ||
$this->installCommands[] = 'npm install bun@^1 --save-dev'; | ||
} | ||
} | ||
|
||
protected function promptToInstallCssLoading() | ||
{ | ||
$choice = select( | ||
label: 'Would you like to use CSS loading?', | ||
options: [ | ||
'css' => 'CSS (installs LightningCSS)', | ||
'sass' => 'Sass (installs Sass & LightningCSS)', | ||
'none' => 'None', | ||
], | ||
default: 'css', | ||
); | ||
|
||
match ($choice) { | ||
'css' => $this->installCommands[] = 'npm install lightningcss --save-dev', | ||
'sass' => $this->installCommands = array_merge($this->installCommands, [ | ||
'npm install lightningcss --save-dev', | ||
'npm install sass --save-dev', | ||
]), | ||
default => null, | ||
}; | ||
} | ||
|
||
protected function install() | ||
{ | ||
if (empty($this->installCommands)) { | ||
warning('Nothing to install.'); | ||
|
||
return; | ||
} | ||
|
||
progress( | ||
label: 'Installing dependencies.', | ||
steps: $this->installCommands, | ||
callback: function ($command, $progress) { | ||
$progress->hint($command); | ||
|
||
Process::run($command); | ||
}, | ||
hint: 'This may take some time.', | ||
); | ||
} | ||
|
||
protected function printOutro() | ||
{ | ||
outro(PHP_EOL . " You're all set! Check out https://laravel-bundle.dev/ to get started! " . PHP_EOL); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?php | ||
|
||
namespace Leuverink\Bundle\Commands; | ||
|
||
use Illuminate\Console\Command; | ||
use Illuminate\Support\Facades\Process; | ||
|
||
class Version extends Command | ||
{ | ||
protected $signature = 'bundle:version'; | ||
protected $description = 'Lists Bundle and it\'s dependencies versions.'; | ||
|
||
public function handle(): int | ||
{ | ||
$this->components->twoColumnDetail(' <fg=green;options=bold>Back-end</>'); | ||
$this->components->twoColumnDetail('Bundle', $this->composerPackageVersion('leuverink/bundle')); | ||
$this->components->twoColumnDetail('Laravel', phpversion()); | ||
$this->components->twoColumnDetail('PHP', $this->laravel->version()); | ||
|
||
$this->newLine(); | ||
$this->components->twoColumnDetail(' <fg=green;options=bold>Front-end</>'); | ||
$this->components->twoColumnDetail('Bun', $this->npmPackageVersion('bun')); | ||
$this->components->twoColumnDetail('LightningCSS', $this->npmPackageVersion('lightningcss')); | ||
$this->components->twoColumnDetail('Sass', $this->npmPackageVersion('sass')); | ||
|
||
return static::SUCCESS; | ||
} | ||
|
||
protected function composerPackageVersion(string $name): string | ||
{ | ||
$packageInfo = json_decode(Process::run("composer show {$name} --format=json")->output()); | ||
$versions = data_get($packageInfo, 'versions', ['Not installed']); | ||
|
||
return head($versions); | ||
} | ||
|
||
protected function npmPackageVersion(string $name): string | ||
{ | ||
$packageInfo = json_decode(Process::run("npm list {$name} --json")->output()); | ||
|
||
return data_get($packageInfo, "dependencies.{$name}.version", 'Not installed'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
<?php | ||
|
||
use Illuminate\Process\PendingProcess; | ||
use Illuminate\Support\Facades\Process; | ||
|
||
beforeEach(function () { | ||
Process::fake(); | ||
}); | ||
|
||
it('follows the happy path') | ||
->artisan('bundle:install') | ||
->expectsQuestion('Do you want to install Bun?', true) | ||
->expectsQuestion('Would you like to use CSS loading?', 'none') | ||
->assertSuccessful(); | ||
|
||
it('installs Bun when selected', function () { | ||
$this->artisan('bundle:install') | ||
->expectsQuestion('Do you want to install Bun?', true) | ||
->expectsQuestion('Would you like to use CSS loading?', 'none') | ||
->assertSuccessful(); | ||
|
||
Process::assertRan('npm install bun@^1 --save-dev'); | ||
}); | ||
|
||
it('doesnt install Bun when not selected', function () { | ||
$this->artisan('bundle:install') | ||
->expectsQuestion('Do you want to install Bun?', false) | ||
->expectsQuestion('Would you like to use CSS loading?', 'none') | ||
->assertSuccessful(); | ||
|
||
Process::assertDidntRun('npm install bun@^1 --save-dev'); | ||
}); | ||
|
||
it('installs LightningCSS when selected', function () { | ||
$this->artisan('bundle:install') | ||
->expectsQuestion('Do you want to install Bun?', false) | ||
->expectsQuestion('Would you like to use CSS loading?', 'css') | ||
->assertSuccessful(); | ||
|
||
Process::assertRan('npm install lightningcss --save-dev'); | ||
}); | ||
|
||
it('doesnt install LightningCSS when not selected', function () { | ||
$this->artisan('bundle:install') | ||
->expectsQuestion('Do you want to install Bun?', false) | ||
->expectsQuestion('Would you like to use CSS loading?', 'none') | ||
->assertSuccessful(); | ||
|
||
Process::assertDidntRun('npm install lightningcss --save-dev'); | ||
}); | ||
|
||
it('installs Sass when selected', function () { | ||
$this->artisan('bundle:install') | ||
->expectsQuestion('Do you want to install Bun?', false) | ||
->expectsQuestion('Would you like to use CSS loading?', 'sass') | ||
->assertSuccessful(); | ||
|
||
Process::assertRan('npm install lightningcss --save-dev'); | ||
Process::assertRan('npm install sass --save-dev'); | ||
}); | ||
|
||
it('doesnt install Sass when not selected', function () { | ||
$this->artisan('bundle:install') | ||
->expectsQuestion('Do you want to install Bun?', false) | ||
->expectsQuestion('Would you like to use CSS loading?', 'none') | ||
->assertSuccessful(); | ||
|
||
Process::assertDidntRun('npm install lightningcss --save-dev'); | ||
Process::assertDidntRun('npm install sass --save-dev'); | ||
}); | ||
|
||
it('doesnt install anything when nothing selected', function () { | ||
$this->artisan('bundle:install') | ||
->expectsQuestion('Do you want to install Bun?', false) | ||
->expectsQuestion('Would you like to use CSS loading?', 'none') | ||
->assertSuccessful(); | ||
|
||
// Assert for absence of npm install commands | ||
Process::assertDidntRun(function (PendingProcess $process) { | ||
return str($process->command)->startsWith('npm install'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?php | ||
|
||
it('runs without crashing') | ||
->artisan('bundle:version') | ||
->expectsOutputToContain('Bundle') | ||
->expectsOutputToContain('Laravel') | ||
->expectsOutputToContain('PHP') | ||
->expectsOutputToContain('Bun') | ||
->expectsOutputToContain('LightningCSS') | ||
->expectsOutputToContain('Sass') | ||
->assertSuccessful(); |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.