|
2 | 2 |
|
3 | 3 | namespace BrushCSS\CLI; |
4 | 4 |
|
5 | | -use BrushCSS\CLI\Commands\AddCommand; |
| 5 | +use Symfony\Component\Console\Application as SymfonyApplication; |
| 6 | +use BrushCSS\CLI\BuildCommand; |
| 7 | +use BrushCSS\Config\ConfigLoader; |
6 | 8 |
|
7 | | -final class Application |
| 9 | +final class Application extends SymfonyApplication |
8 | 10 | { |
9 | | - public function run(array $argv): void |
10 | | - { |
11 | | - $cmd = $argv[1] ?? null; |
12 | | - |
13 | | - match ($cmd) { |
14 | | - |
15 | | - 'add' => (new AddCommand()) |
16 | | - ->handle($argv[2] ?? ''), |
17 | | - |
18 | | - 'build' => $this->build(), |
19 | | - |
20 | | - default => $this->help() |
21 | | - }; |
22 | | - } |
| 11 | + private array $config = []; |
23 | 12 |
|
24 | | - private function builds(): void |
| 13 | + public function __construct() |
25 | 14 | { |
26 | | - echo "🔍 Scanning files...\n"; |
27 | | - |
28 | | - $paths = ['examples']; // change to 'views' in real app |
29 | | - |
30 | | - $extractor = new \BrushCSS\JIT\ClassExtractor(); |
31 | | - $resolver = new \BrushCSS\JIT\Resolver(); |
32 | | - $engine = new \BrushCSS\JIT\JITEngine($resolver); |
33 | | - |
34 | | - $classes = []; |
35 | | - |
36 | | - foreach ($paths as $path) { |
37 | | - foreach (glob($path . '/*.php') as $file) { |
38 | | - $content = file_get_contents($file); |
39 | | - |
40 | | - $found = $extractor->extract($content); |
41 | | - |
42 | | - echo "📄 {$file} → " . implode(', ', $found) . "\n"; |
43 | | - |
44 | | - $classes = array_merge($classes, $found); |
45 | | - } |
46 | | - } |
47 | | - |
48 | | - $classes = array_unique($classes); |
49 | | - |
50 | | - echo "⚙️ Generating CSS...\n"; |
51 | | - |
52 | | - $css = $engine->build($classes); |
53 | | - |
54 | | - if (!is_dir('public')) { |
55 | | - mkdir('public', 777, true); |
| 15 | + parent::__construct('BrushCSS', '1.0.0'); |
56 | 16 | } |
57 | 17 |
|
58 | | - file_put_contents('public/style.css', $css); |
59 | | - |
60 | | - echo "✅ CSS written to public/style.css\n"; |
61 | | - echo "Building CSS...\n"; |
62 | | - } |
63 | | - |
64 | | - private function help(): void |
| 18 | + // ----------------------------- |
| 19 | + // BOOTSTRAP SYSTEM |
| 20 | + // ----------------------------- |
| 21 | + public function boot(): void |
65 | 22 | { |
66 | | - echo "brushcss add <plugin>\nbrushcss build\n"; |
| 23 | + $this->loadConfig(); |
| 24 | + $this->registerCommands(); |
67 | 25 | } |
68 | 26 |
|
69 | | - private function build(): void |
70 | | -{ |
71 | | - echo "🚀 Build started\n"; |
72 | | - |
73 | | - $paths = ['examples']; |
74 | | - |
75 | | - $extractor = new \BrushCSS\JIT\ClassExtractor(); |
76 | | - $resolver = new \BrushCSS\JIT\Resolver(); |
77 | | - $engine = new \BrushCSS\JIT\JITEngine($resolver); |
78 | | - |
79 | | - $classes = []; |
80 | | - |
81 | | - foreach ($paths as $path) { |
82 | | - |
83 | | - echo "📂 Scanning: {$path}\n"; |
84 | | - |
85 | | - $files = glob($path . '/*.php'); |
86 | | - |
87 | | - if (!$files) { |
88 | | - echo "❌ No files found in {$path}\n"; |
89 | | - } |
90 | | - |
91 | | - foreach ($files as $file) { |
92 | | - |
93 | | - echo "📄 Reading: {$file}\n"; |
94 | | - |
95 | | - $content = file_get_contents($file); |
96 | | - |
97 | | - if (!$content) { |
98 | | - echo "❌ Empty file: {$file}\n"; |
99 | | - } |
100 | | - |
101 | | - $found = $extractor->extract($content); |
102 | | - |
103 | | - echo "🎯 Classes: " . json_encode($found) . "\n"; |
104 | | - |
105 | | - $classes = array_merge($classes, $found); |
106 | | - } |
| 27 | + // ----------------------------- |
| 28 | + // CONFIG LOADING |
| 29 | + // ----------------------------- |
| 30 | + private function loadConfig(): void |
| 31 | + { |
| 32 | + $this->config = ConfigLoader::load(); |
107 | 33 | } |
108 | 34 |
|
109 | | - $classes = array_unique($classes); |
110 | | - |
111 | | - echo "📦 Final classes: " . json_encode($classes) . "\n"; |
112 | | - |
113 | | - $css = $engine->build($classes); |
114 | | - |
115 | | - echo "🧾 Generated CSS:\n$css\n"; |
116 | | - |
117 | | - if (!is_dir('public')) { |
118 | | - echo "📁 Creating public directory...\n"; |
119 | | - mkdir('public', 0777, true); |
| 35 | + public function config(): array |
| 36 | + { |
| 37 | + return $this->config; |
120 | 38 | } |
121 | 39 |
|
122 | | - $result = file_put_contents('public/style.css', $css); |
123 | | - |
124 | | - if ($result === false) { |
125 | | - echo "❌ Failed to write CSS file\n"; |
126 | | - } else { |
127 | | - echo "✅ CSS written to public/style.css\n"; |
| 40 | + // ----------------------------- |
| 41 | + // COMMAND REGISTRATION |
| 42 | + // ----------------------------- |
| 43 | + private function registerCommands(): void |
| 44 | + { |
| 45 | + $this->add(new BuildCommand()); |
128 | 46 | } |
129 | 47 | } |
130 | | -} |
0 commit comments