Skip to content

Commit

Permalink
fix: CSS/Less assets not recompiling in debug mode (#60)
Browse files Browse the repository at this point in the history
  • Loading branch information
davwheat authored Jun 3, 2022
1 parent 6abc192 commit 9aaa098
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions src/Content/Assets.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

namespace FoF\NightMode\Content;

use Flarum\Foundation\Application;
use Flarum\Frontend\Compiler\CompilerInterface;
use Flarum\Frontend\Document;
use Flarum\User\User;
Expand Down Expand Up @@ -47,16 +46,16 @@ public function __invoke(Document $document, Request $request)
$nightCss = $this->assets->makeDarkCss();
$dayCss = $this->assets->makeCss();

$preference = $this->getPreference($request);
$preference = $this->getThemePreference($request);

$compilers = [
'js' => [$this->assets->makeJs(), $this->assets->makeLocaleJs($locale)],
'css' => [$this->assets->makeLocaleCss($locale)],
];

if (resolve(Application::class)->inDebugMode()) {
$this->commit(Arr::flatten($compilers));
$this->commit([$dayCss, $nightCss]);
if ($this->config->inDebugMode()) {
$this->forceCommit(Arr::flatten($compilers));
$this->forceCommit([$dayCss, $nightCss]);
}

$isAuto = $preference === 0;
Expand Down Expand Up @@ -98,7 +97,7 @@ protected function generateTag(?string $url, string $type, string $auto)
*
* @return int
*/
protected function getPreference(Request $request)
protected function getThemePreference(Request $request)
{
/**
* @var User $actor
Expand All @@ -114,14 +113,18 @@ protected function getPreference(Request $request)
}

// --- original ---
// these are private methods so we have to redefine them :(

/**
* Force compilation of assets when in debug mode.
*
* @param array $compilers
*/
private function commit(array $compilers)
private function forceCommit(array $compilers)
{
/** @var CompilerInterface $compiler */
foreach ($compilers as $compiler) {
$compiler->commit();
$compiler->commit(true);
}
}

Expand Down

0 comments on commit 9aaa098

Please sign in to comment.