Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add compatibility with the new Vite build pipeline #175

Merged
merged 3 commits into from
Jul 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion app/Actions/Concerns/InteractsWithNpm.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,30 @@ trait InteractsWithNpm
{
use AbortsCommands;

/**
* @throws \App\LamboException
*/
protected function installAndCompileNodeDependencies(): void
{
$this->installNodeDependencies();
$this->compileNodeDependencies();
}

/**
* @throws \App\LamboException
*/
public function installNodeDependencies(): void
{
$process = app(Shell::class)->execInProject('npm install' . (config('lambo.store.with_output') ? '' : ' --silent'));
$this->abortIf(! $process->isSuccessful(), 'Installation of npm dependencies did not complete successfully', $process);
}

/**
* @throws \App\LamboException
*/
protected function compileNodeDependencies(): void
{
$process = app(Shell::class)->execInProject('npm run dev' . (config('lambo.store.with_output') ? '' : ' --silent'));
$process = app(Shell::class)->execInProject('npm run build' . (config('lambo.store.with_output') ? '' : ' --silent'));
$this->abortIf(! $process->isSuccessful(), 'Compilation of project assets did not complete successfully', $process);
}
}
12 changes: 9 additions & 3 deletions app/Actions/InstallJetstream.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,19 @@ class InstallJetstream
'Livewire' => 'livewire',
];

private $consoleWriter;
private $shell;
private ConsoleWriter $consoleWriter;
private Shell $shell;

public function __construct(Shell $shell, ConsoleWriter $consoleWriter)
{
$this->shell = $shell;
$this->consoleWriter = $consoleWriter;
}

public function __invoke()
/**
* @throws LamboException
*/
public function __invoke(): void
{
if (($stack = config('lambo.store.jetstream')) === false) {
return;
Expand All @@ -56,6 +59,9 @@ public function __invoke()
$this->consoleWriter->success('Successfully installed Laravel Jetstream.');
}

/**
* @throws LamboException
*/
protected function installJetstream(string $stack): void
{
$configuration = explode(',', $stack);
Expand Down
23 changes: 11 additions & 12 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ lambo new myNextProject
# What exactly does it do?

- `laravel new $PROJECTNAME`
- Initialize a git repo, add all of the files, and, after some changes below, make a commit with the text "Initial commit."
- Initialize a git repo, add all the files, and, after some changes below, make a commit with the text "Initial commit."
- Replace the `.env` (and `.env.example`) database credentials with the default macOS MySQL credentials: database of `$PROJECTNAME`, user `root`, and empty password
- Replace the `.env` (and `.env.example`) `APP_URL` with `$PROJECTNAME.$YOURVALETTLD`
- Generate an app key
Expand Down Expand Up @@ -205,23 +205,22 @@ You can optionally pass one or more of these parameters every time you use Lambo
lambo new superApplication --dbhost=127.0.0.1
```


- `--inertia` to install Jetstream using Inertia.
- `--breeze=STACK` to use the Laravel Breeze starter kit. `STACK` may be either `blade`, `vue` or `react`.

```bash
lambo new superApplication --inertia
lambo new superApplication --breeze=blade
lambo new superApplication --breeze=vue
lambo new superApplication --breeze=react
```

- `--livewire` to install Jetstream using Livewire.

```bash
lambo new superApplication --livewire
```

- `--teams` to install Jetstream using teams.
- `--jetstream=STACK[,teams]` to use the Laravel Jetstream starter kit. `STACK` may be either `inertia` or `livewire`.

```bash
lambo new superApplication --teams
lambo new superApplication --jetstream=inertia
lambo new superApplication --jetstream=inertia,teams
lambo new superApplication --jetstream=livewire
lambo new superApplication --jetstream=livewire,teams
```

- `--full` to use `--create-db`, `--migrate-db`, `--link`, and `-secure`.

Expand Down
18 changes: 12 additions & 6 deletions tests/Feature/InstallBreezeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,18 @@
*/
class InstallBreezeTest extends TestCase
{
/** @test */
/**
* @test
* @throws LamboException
*/
function it_installs_laravel_breeze()
{
foreach ([false, true] as $withOutput) {
foreach (array_values(InstallBreeze::VALID_STACKS) as $stack) {
foreach (InstallBreeze::VALID_STACKS as $stack) {
config(['lambo.store.breeze' => $stack]);
config(['lambo.store.with_output' => $withOutput]);

if ($this->isDebug()) {
if ($this->isVerbose()) {
$this->logUseCase($stack, $withOutput);
}

Expand All @@ -38,7 +41,10 @@ function it_installs_laravel_breeze()
}
}

/** @test */
/**
* @test
* @throws LamboException
*/
function it_skips_breeze_installation()
{
$this->spy(Shell::class);
Expand Down Expand Up @@ -114,7 +120,7 @@ private function getNpmInstallCommand($showOutput): string

private function getCompileAssetsCommand($withOutput): string
{
return 'npm run dev' . ($withOutput ? '' : ' --silent');
return 'npm run build' . ($withOutput ? '' : ' --silent');
}

private function logUseCase(string $stack, $showOutput): void
Expand All @@ -124,7 +130,7 @@ private function logUseCase(string $stack, $showOutput): void
$this->toSTDOUT("────────────────────────────\n");
$this->toSTDOUT(implode(PHP_EOL, [
sprintf(' lambo new <project> %s--breeze=%s', $showOutput ? '-v(vv) ' : '', $stack),
]), ' USECASE');
]), ' USE CASE');
$this->toSTDOUT(implode(PHP_EOL, [
" 1. {$this->getComposerCommand($showOutput)}",
" 2. {$this->getBreezeInstallCommand($stack, $showOutput)}",
Expand Down
16 changes: 11 additions & 5 deletions tests/Feature/InstallJetstreamTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,15 @@
*/
class InstallJetstreamTest extends TestCase
{
/** @test */
/**
* @test
* @throws LamboException
*/
function it_installs_laravel_jetstream()
{
foreach ([false, true] as $withOutput) {
foreach ([false, true] as $useTeams) {
foreach (array_values(InstallJetstream::VALID_STACKS) as $stack) {
foreach (InstallJetstream::VALID_STACKS as $stack) {
config(['lambo.store.jetstream' => $stack]);
config(['lambo.store.with_output' => $withOutput]);

Expand All @@ -40,7 +43,10 @@ function it_installs_laravel_jetstream()
}
}

/** @test */
/**
* @test
* @throws LamboException
*/
function it_skips_jetstream_installation()
{
$this->spy(Shell::class);
Expand Down Expand Up @@ -111,7 +117,7 @@ private function getComposerCommand(bool $withOutput = false): string

private function getCompileAssetsCommand($withOutput): string
{
return 'npm run dev' . ($withOutput ? '' : ' --silent');
return 'npm run build' . ($withOutput ? '' : ' --silent');
}

private function logUseCase(string $stack, $useTeams, $showOutput): void
Expand All @@ -124,7 +130,7 @@ private function logUseCase(string $stack, $useTeams, $showOutput): void

$this->toSTDOUT("────────────────────────────\n");
$this->toSTDOUT(sprintf(
" USECASE\n lambo new <project> %s--jetstream=%s%s",
" USE CASE\n lambo new <project> %s--jetstream=%s%s",
$showOutput ? '-v[vv] ' : '',
$stack,
$useTeams ? ',teams' : ''
Expand Down
5 changes: 5 additions & 0 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@ protected function shouldExecInProjectAndFail(string $command)
$this->shouldExecInProject($command, false);
}

protected function isVerbose(): bool
{
return $this->isDebug() || in_array('--verbose', $_SERVER['argv'], true);
}

protected function isDebug(): bool
{
return in_array('--debug', $_SERVER['argv'], true);
Expand Down