@@ -18,7 +18,7 @@ discard block |
||
18 | 18 | |
19 | 19 | echo "Running...".PHP_EOL; |
20 | 20 | |
21 | - if(is_dir($this->sass_directory)) { |
|
21 | + if (is_dir($this->sass_directory)) { |
|
22 | 22 | // Clean output folder |
23 | 23 | array_map('unlink', array_filter((array) glob($this->css_directory."*"))); |
24 | 24 | |
@@ -28,13 +28,13 @@ discard block |
||
28 | 28 | $this->updateMainFiles(); |
29 | 29 | |
30 | 30 | // Compile the files |
31 | - foreach($this->fileHashes as $file => $hash) { |
|
31 | + foreach ($this->fileHashes as $file => $hash) { |
|
32 | 32 | |
33 | 33 | $file = realpath($file); |
34 | 34 | $fileDependancies = $this->compileFile($file); |
35 | 35 | $this->fileHashes[$file] = filemtime($file); |
36 | 36 | $this->dependancyTree[$file] = $fileDependancies; |
37 | - foreach($fileDependancies as $dep) { |
|
37 | + foreach ($fileDependancies as $dep) { |
|
38 | 38 | $this->fileHashes[realpath($dep)] = filemtime($dep); |
39 | 39 | } |
40 | 40 | } |
@@ -43,7 +43,7 @@ discard block |
||
43 | 43 | echo "Dependancies tree built.".PHP_EOL.PHP_EOL; |
44 | 44 | |
45 | 45 | // Compute md5 hash for files |
46 | - foreach($this->dependancyTree as $file => $where) { |
|
46 | + foreach ($this->dependancyTree as $file => $where) { |
|
47 | 47 | $fileHashes[$file] = filemtime($file); |
48 | 48 | } |
49 | 49 | |
@@ -68,24 +68,24 @@ discard block |
||
68 | 68 | //Start the PHP built-in web server |
69 | 69 | $command = sprintf('php -S localhost:5555 -t %s %s/webserver.php', $this->application, $this->application); |
70 | 70 | $this->webServerProcess = proc_open($command, [STDIN, STDOUT, STDERR], $pipes); |
71 | - while(true) { |
|
72 | - if($this->compile_sass) { |
|
71 | + while (true) { |
|
72 | + if ($this->compile_sass) { |
|
73 | 73 | $this->cleanDeletedFiles(); |
74 | 74 | $this->updateMainFiles(); |
75 | - foreach($this->fileHashes as $file => $hash) { |
|
75 | + foreach ($this->fileHashes as $file => $hash) { |
|
76 | 76 | $file = realpath($file); |
77 | - if(file_exists($file)) { |
|
77 | + if (file_exists($file)) { |
|
78 | 78 | $newHash = filemtime($file); |
79 | - if($newHash != $hash) { |
|
79 | + if ($newHash != $hash) { |
|
80 | 80 | echo "\e[93mFile $file modified!\e[39m".PHP_EOL; |
81 | 81 | $this->fileHashes[$file] = $newHash; |
82 | 82 | |
83 | 83 | // if it's a main file |
84 | - if(key_exists($file, $this->dependancyTree)) { |
|
84 | + if (key_exists($file, $this->dependancyTree)) { |
|
85 | 85 | $this->dependancyTree[$file] = $this->compileFile($file); |
86 | 86 | } else { // if it's an included file |
87 | - foreach($this->dependancyTree as $main => $dependancies) { |
|
88 | - if(in_array($file, $dependancies)) { |
|
87 | + foreach ($this->dependancyTree as $main => $dependancies) { |
|
88 | + if (in_array($file, $dependancies)) { |
|
89 | 89 | $this->dependancyTree[$main] = $this->compileFile($main); |
90 | 90 | } |
91 | 91 | } |
@@ -113,14 +113,14 @@ discard block |
||
113 | 113 | public function cleanDeletedFiles() |
114 | 114 | { |
115 | 115 | |
116 | - foreach($this->fileHashes as $file => $hash) { |
|
117 | - if(!file_exists($file)) { |
|
116 | + foreach ($this->fileHashes as $file => $hash) { |
|
117 | + if (!file_exists($file)) { |
|
118 | 118 | unset($fileHashes[$file]); |
119 | - foreach($this->dependancyTree as $main => $dependancies) { |
|
120 | - if($main == $file) { |
|
119 | + foreach ($this->dependancyTree as $main => $dependancies) { |
|
120 | + if ($main == $file) { |
|
121 | 121 | unset($this->dependancyTree[$main]); |
122 | 122 | } |
123 | - if(in_array($file, $dependancies)) { |
|
123 | + if (in_array($file, $dependancies)) { |
|
124 | 124 | $key = array_search($file, $dependancies); |
125 | 125 | unset($this->dependancyTree[$main][$key]); |
126 | 126 | } |
@@ -140,7 +140,7 @@ discard block |
||
140 | 140 | if (is_file($inputFile)) { |
141 | 141 | // Set the path to the output CSS file |
142 | 142 | $outputFile = preg_replace('/(.*)\.(sass|scss)$/', '$1.css', basename($inputFile)); |
143 | - $outputFile = $this->css_directory.$outputFile; |
|
143 | + $outputFile = $this->css_directory.$outputFile; |
|
144 | 144 | // Compile the SCSS code into CSS |
145 | 145 | try { |
146 | 146 | $result = $compiler->compileString(file_get_contents($inputFile)); |
@@ -175,14 +175,14 @@ discard block |
||
175 | 175 | |
176 | 176 | public function updateMainFiles() |
177 | 177 | { |
178 | - $files = glob($this->sass_directory . '/*'); // Get all files in the directory |
|
178 | + $files = glob($this->sass_directory.'/*'); // Get all files in the directory |
|
179 | 179 | |
180 | 180 | |
181 | 181 | foreach ($files as $file) { |
182 | 182 | $file = realpath($file); |
183 | - $pattern = '/^\/.+\/[^_]*[.](scss|sass)/'; // Specify the regex pattern for file names |
|
184 | - if(preg_match($pattern, $file)) { |
|
185 | - if(! array_key_exists($file, $this->fileHashes)) { |
|
183 | + $pattern = '/^\/.+\/[^_]*[.](scss|sass)/'; // Specify the regex pattern for file names |
|
184 | + if (preg_match($pattern, $file)) { |
|
185 | + if (!array_key_exists($file, $this->fileHashes)) { |
|
186 | 186 | $this->fileHashes[$file] = 0; |
187 | 187 | } |
188 | 188 | } |
@@ -83,7 +83,8 @@ |
||
83 | 83 | // if it's a main file |
84 | 84 | if(key_exists($file, $this->dependancyTree)) { |
85 | 85 | $this->dependancyTree[$file] = $this->compileFile($file); |
86 | - } else { // if it's an included file |
|
86 | + } else { |
|
87 | +// if it's an included file |
|
87 | 88 | foreach($this->dependancyTree as $main => $dependancies) { |
88 | 89 | if(in_array($file, $dependancies)) { |
89 | 90 | $this->dependancyTree[$main] = $this->compileFile($main); |