Skip to content

Commit

Permalink
launch depending on the installed bundler webpack/vite anoterh yarn c…
Browse files Browse the repository at this point in the history
…li command
  • Loading branch information
indivisualvj committed Jun 18, 2024
1 parent 0db1367 commit 8e3ac29
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/Subroutine/Initialize.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
use Enhavo\Component\Cli\Task\DumpRoutes;
use Enhavo\Component\Cli\Task\EnhavoInit;
use Enhavo\Component\Cli\Task\ExecuteMigrations;
use Enhavo\Component\Cli\Task\YarnEncore;
use Enhavo\Component\Cli\Task\YarnBundler;
use Enhavo\Component\Cli\Task\YarnInstall;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Helper\QuestionHelper;
Expand Down Expand Up @@ -46,7 +46,7 @@ public function __invoke(): int
(new DoctrineFixtures($this->input, $this->output, $this->questionHelper))();
(new EnhavoInit($this->input, $this->output, $this->questionHelper))();
(new \Enhavo\Component\Cli\Task\CreateUser($this->input, $this->output, $this->questionHelper, $this->configuration))();
(new YarnEncore($this->input, $this->output, $this->questionHelper))();
(new YarnBundler($this->input, $this->output, $this->questionHelper))();
(new DumpRoutes($this->input, $this->output, $this->questionHelper))();

return Command::SUCCESS;
Expand Down
4 changes: 2 additions & 2 deletions src/Subroutine/Update.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
use Enhavo\Component\Cli\Task\DumpRoutes;
use Enhavo\Component\Cli\Task\EnhavoInit;
use Enhavo\Component\Cli\Task\ExecuteMigrations;
use Enhavo\Component\Cli\Task\YarnEncore;
use Enhavo\Component\Cli\Task\YarnBundler;
use Enhavo\Component\Cli\Task\YarnInstall;
use Symfony\Component\Console\Command\Command;

Expand All @@ -22,7 +22,7 @@ public function __invoke(): int
(new ExecuteMigrations($this->input, $this->output, $this->questionHelper))();
(new DoctrineFixtures($this->input, $this->output, $this->questionHelper))();
(new EnhavoInit($this->input, $this->output, $this->questionHelper))();
(new YarnEncore($this->input, $this->output, $this->questionHelper))();
(new YarnBundler($this->input, $this->output, $this->questionHelper))();
(new DumpRoutes($this->input, $this->output, $this->questionHelper))();

return Command::SUCCESS;
Expand Down
25 changes: 25 additions & 0 deletions src/Task/YarnBuild.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

namespace Enhavo\Component\Cli\Task;

use Enhavo\Component\Cli\AbstractSubroutine;
use Enhavo\Component\Cli\ExecuteTrait;
use Symfony\Component\Console\Command\Command;

class YarnBuild extends AbstractSubroutine
{
use ExecuteTrait;

public function __invoke()
{
while(true) {
$option = $this->askYesNo($this->input, $this->output, 'vite build?', self::ANSWER_YES);

if (strtolower($option) === self::ANSWER_NO) {
return Command::SUCCESS;
} elseif (strtolower($option) === self::ANSWER_YES) {
return $this->execute(['yarn', 'build'], $this->output);
}
}
}
}
26 changes: 26 additions & 0 deletions src/Task/YarnBundler.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

namespace Enhavo\Component\Cli\Task;

use Enhavo\Component\Cli\AbstractSubroutine;

class YarnBundler extends AbstractSubroutine
{
public function __invoke()
{
if ($this->isVite()) {
return (new YarnBuild($this->input, $this->output, $this->questionHelper))();
}

return (new YarnEncore($this->input, $this->output, $this->questionHelper))();
}

private function isVite(): bool
{
if (getcwd() === false) {
return false;
}
$configFile = sprintf('%s/node_modules/@vitejs', getcwd());
return file_exists($configFile);
}
}

0 comments on commit 8e3ac29

Please sign in to comment.