-
Notifications
You must be signed in to change notification settings - Fork 18
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 #22 from WebMamba/add_listener_to_pre_assets_compi…
…le_event Add Listener to PreAssetsCompileEvent
- Loading branch information
Showing
3 changed files
with
54 additions
and
0 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
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,40 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the SymfonyCasts SassBundle package. | ||
* Copyright (c) SymfonyCasts <https://symfonycasts.com/> | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfonycasts\SassBundle\Listener; | ||
|
||
use Symfony\Component\AssetMapper\Event\PreAssetsCompileEvent; | ||
use Symfony\Component\Console\Input\ArrayInput; | ||
use Symfony\Component\Console\Style\SymfonyStyle; | ||
use Symfonycasts\SassBundle\SassBuilder; | ||
|
||
class PreAssetsCompileEventListener | ||
{ | ||
public function __construct(private readonly SassBuilder $sassBuilder) | ||
{ | ||
} | ||
|
||
public function __invoke(PreAssetsCompileEvent $preAssetsCompileEvent): void | ||
{ | ||
$this->sassBuilder->setOutput( | ||
new SymfonyStyle( | ||
new ArrayInput([]), | ||
$preAssetsCompileEvent->getOutput() | ||
) | ||
); | ||
|
||
$process = $this->sassBuilder->runBuild(false); | ||
|
||
if ($process->isSuccessful()) { | ||
return; | ||
} | ||
|
||
throw new \RuntimeException(sprintf('Error compiling sass: "%s"', $process->getErrorOutput())); | ||
} | ||
} |