Skip to content

Commit 7858c0a

Browse files
committed
[ADD] Multiply Tailwind css files compile.
1 parent 8d05f7c commit 7858c0a

2 files changed

Lines changed: 22 additions & 19 deletions

File tree

core/src/Console/TailwindBuildCommand.php

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,16 @@ public function handle(): int
2929
$compiler = app(TailwindService::class);
3030

3131
foreach ($packages as $pkg) {
32-
try {
33-
$url = $compiler->compile($pkg, $force);
34-
$this->info("{$pkg}: built → {$url}");
35-
} catch (\Throwable $e) {
36-
$this->error("{$pkg}: " . $e->getMessage());
32+
$styles = glob(EVO_BASE_PATH . $pkg . '/*tailwind.css');
33+
if (!empty($styles)) {
34+
foreach ($styles as $style) {
35+
try {
36+
$url = $compiler->compile($style, $force);
37+
$this->info("{$pkg}: built → {$url}");
38+
} catch (\Throwable $e) {
39+
$this->error("{$pkg}: " . $e->getMessage());
40+
}
41+
}
3742
}
3843
}
3944

@@ -55,7 +60,7 @@ private function discoverPackages(): array
5560
if ($dir[0] === '.') continue;
5661

5762
$base = "{$root}/{$dir}/";
58-
if (is_file($base.'tailwind.css')) {
63+
if (is_file($base . 'tailwind.css')) {
5964
$pretty = $this->guessPrettyName(realpath($base));
6065
$labels[] = $pretty;
6166
$map[strtolower($pretty)] = "assets/{$dir}";

core/src/Services/TailwindService.php

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,34 +21,32 @@ class TailwindService
2121
/**
2222
* Build CSS or return cached file.
2323
*
24-
* @param string $package Relative package path (e.g. packages/sSeo)
24+
* @param string $input Relative package file of style (e.g. packages/sSeo/css/tailwind.css)
2525
* @param bool $forceRebuild Ignore cache
2626
* @return string Public URL to compiled CSS
2727
*/
28-
public function compile(string $package, bool $forceRebuild = false): string
28+
public function compile(string $input, bool $forceRebuild = false): string
2929
{
30-
$base = EVO_BASE_PATH . $package . '/';
31-
$input = $base . 'tailwind.css';
32-
$output = $base . "{$this->buildDir}tailwind.min.css";
30+
$output = str_replace('.css', '.min.css', $input);
3331

3432
if (!$forceRebuild && is_file($output)) {
35-
$hash = Cache::get("tw:{$package}");
33+
$hash = Cache::get("tw:{$input}");
3634
$cur = md5_file($input);
3735
if ($hash === $cur) {
38-
return "/{$package}/{$this->buildDir}tailwind.min.css";
36+
return str_replace(EVO_BASE_PATH, '/', $output);
3937
}
4038
}
4139

4240
if (!is_file($input)) {
43-
throw new RuntimeException("Tailwind sources not found for «{$package}».");
41+
throw new RuntimeException("Tailwind sources not found for «{$input}».");
4442
}
4543

4644
$this->ensureBinary();
4745

4846
if (!is_dir(dirname($output))
4947
&& !mkdir(dirname($output), 0775, true)
5048
&& !is_dir(dirname($output))) {
51-
throw new RuntimeException("Cannot create build dir for «{$package}».");
49+
throw new RuntimeException("Cannot create build dir for «{$input}».");
5250
}
5351

5452
$tmpPath = EVO_CORE_PATH . 'storage/tmp';
@@ -68,9 +66,9 @@ public function compile(string $package, bool $forceRebuild = false): string
6866
}
6967

7068
$hash = md5_file($input);
71-
Cache::put("tw:{$package}", $hash, $this->ttl);
69+
Cache::put("tw:{$input}", $hash, $this->ttl);
7270

73-
return "/{$package}/{$this->buildDir}tailwind.min.css";
71+
return str_replace(EVO_BASE_PATH, '/', $output);
7472
}
7573

7674
/**
@@ -86,8 +84,8 @@ protected function ensureBinary(): void
8684

8785
// Determine a platform (basic)
8886
[$os, $arch] = $this->detectPlatform(); // linux/macos/windows | x64/arm64
89-
$ext = $os === 'windows' ? '.exe' : '';
90-
$url = sprintf(
87+
$ext = $os === 'windows' ? '.exe' : '';
88+
$url = sprintf(
9189
'https://github.com/tailwindlabs/tailwindcss/releases/latest/download/'
9290
.'tailwindcss-%s-%s%s',
9391
$os, $arch, $ext

0 commit comments

Comments
 (0)