Skip to content
Open
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
34 changes: 24 additions & 10 deletions robo-components/ThemeTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ trait ThemeTrait {
* @param bool $optimize
* Indicate whether to optimize during compilation.
*/
private function doThemeCompile(bool $optimize = FALSE): void {
private function doThemeCompile(bool $optimize = FALSE): ResultData {
$directories = [
'js',
'images',
Expand All @@ -47,7 +47,10 @@ private function doThemeCompile(bool $optimize = FALSE): void {
$theme_dir = self::$themeBase;

// Make sure we have all the node packages.
$this->_exec("cd $theme_dir && npm install");
$result = $this->_exec("cd $theme_dir && npm install");
if ($result->getExitCode() !== 0) {
return new ResultData($result->getExitCode(), 'npm install failed.');
}

// Use Tailwind CLI to compile CSS and always minify for consistent output.
$tailwind_command = "cd $theme_dir && npx tailwindcss -i ./src/css/style.css -o ./dist/css/style.css --minify";
Expand All @@ -60,7 +63,7 @@ private function doThemeCompile(bool $optimize = FALSE): void {

if ($result->getExitCode() !== 0) {
$this->taskCleanDir(['dist/css']);
return;
return new ResultData($result->getExitCode(), 'Theme compilation failed.');
}

// Javascript.
Expand All @@ -71,7 +74,11 @@ private function doThemeCompile(bool $optimize = FALSE): void {
$from = str_replace('web/themes/custom/server_theme/', '', $js_file);
$to = str_replace('src/', 'dist/', $from);
// Minify the js.
$this->_exec("cd $theme_dir && npx minify $from > $to");
$result = $this->_exec("cd $theme_dir && npx minify --fail-on-error $from > $to");
$to_abs = self::$themeBase . '/' . $to;
if ($result->getExitCode() !== 0 || !file_exists($to_abs) || filesize($to_abs) === 0) {
return new ResultData(1, "JS minification failed for $from.");
}
}
}
else {
Expand All @@ -91,33 +98,40 @@ private function doThemeCompile(bool $optimize = FALSE): void {
self::$themeBase . '/src/images/*.png',
];

$this->taskImageMinify($input)
$result = $this->taskImageMinify($input)
->to(self::$themeBase . '/dist/images/')
->run();
if (!$result->wasSuccessful()) {
return new ResultData($result->getExitCode(), 'Image minification failed.');
}

// Compress all SVGs.
$this->themeSvgCompress();
$svgResult = $this->themeSvgCompress();
if ($svgResult !== NULL) {
return $svgResult;
}
}

$this->_exec('drush cache:rebuild');
return new ResultData(ResultData::EXITCODE_OK);
}

/**
* Compile the theme (optimized).
*/
public function themeCompile(): void {
public function themeCompile(): ResultData {
$this->say('Compiling (optimized).');
$this->doThemeCompile(TRUE);
return $this->doThemeCompile(TRUE);
}

/**
* Compile the theme.
*
* Non-optimized.
*/
public function themeCompileDebug(): void {
public function themeCompileDebug(): ResultData {
$this->say('Compiling (non-optimized).');
$this->doThemeCompile();
return $this->doThemeCompile();
}

/**
Expand Down
Loading
Loading