| 116 | | case 'js' : |
|---|
| 117 | | $this->js_files[] = $path . "/" . $entry; |
|---|
| 118 | | //$this->js_packed_files[] = $this->target_dir . "/" . $path_parts['filename'] . ".pack.js"; |
|---|
| 119 | | $this->js_packed_files[] = $path . "/" . $path_parts['filename'] . ".pack.js"; |
|---|
| | 138 | case 'js': |
|---|
| | 139 | $clean_filename = str_replace('.src', '', $path_parts['filename']); |
|---|
| | 140 | $clean_filename = str_replace('.pack', '', $clean_filename); |
|---|
| | 141 | |
|---|
| | 142 | if (! in_array($path_parts['filename'], $this->js_file_names)) |
|---|
| | 143 | { |
|---|
| | 144 | if ( strpos($path_parts['filename'], '.src') === false |
|---|
| | 145 | && strpos($path_parts['filename'], '.pack') === false) |
|---|
| | 146 | { |
|---|
| | 147 | $this->js_file_names[$clean_filename] = $path_parts['filename']; |
|---|
| | 148 | $this->js_files[$clean_filename] = $path . "/" . $entry; |
|---|
| | 149 | } |
|---|
| | 150 | } |
|---|
| | 151 | if (strpos($path_parts['filename'], '.pack') !== false) |
|---|
| | 152 | { |
|---|
| | 153 | $this->js_packed_files[$clean_filename] = $path . "/" . $entry; |
|---|
| | 154 | } |
|---|
| | 155 | if (strpos($path_parts['filename'], '.src') !== false) |
|---|
| | 156 | { |
|---|
| | 157 | $this->js_src_files[$clean_filename] = $path . "/" . $entry; |
|---|
| | 158 | } |
|---|
| | 173 | function prepare_files() |
|---|
| | 174 | { |
|---|
| | 175 | foreach ($this->js_file_names as $clean_name => $file) |
|---|
| | 176 | { |
|---|
| | 177 | $old_packed = $this->js_packed_files[$clean_name]; |
|---|
| | 178 | $src_file = $this->js_src_files[$clean_name]; |
|---|
| | 179 | $sel_source = ''; |
|---|
| | 180 | //echo "\nClean name: {$clean_name}, file: {$file}\n"; |
|---|
| | 181 | //echo "\nPacked: {$old_packed}\n"; |
|---|
| | 182 | //echo "\nSource: {$src_file}\n"; |
|---|
| | 183 | |
|---|
| | 184 | $orig_file_parts = pathinfo($this->js_files[$clean_name]); |
|---|
| | 185 | $new_packed_file = $orig_file_parts['dirname'] . "/" . $orig_file_parts['filename'] . ".pack.js"; |
|---|
| | 186 | $new_source_file = $orig_file_parts['dirname'] . "/" . $orig_file_parts['filename'] . ".src.js"; |
|---|
| | 187 | |
|---|
| | 188 | if (empty($src_file)) |
|---|
| | 189 | { |
|---|
| | 190 | //echo "\nWe have no separate source file, assume the original is the source.\n"; |
|---|
| | 191 | $this->no_source = true; |
|---|
| | 192 | $sel_source = $this->js_files[$clean_name]; |
|---|
| | 193 | } |
|---|
| | 194 | else |
|---|
| | 195 | { |
|---|
| | 196 | //echo "\nWe have source file. Then we also must have either packed file, and/or the original is packed.\n"; |
|---|
| | 197 | $this->no_source = false; |
|---|
| | 198 | $sel_source = $src_file; |
|---|
| | 199 | |
|---|
| | 200 | if (! empty($old_packed)) |
|---|
| | 201 | { |
|---|
| | 202 | //echo "\nWe have old packed file. Delete this.\n"; |
|---|
| | 203 | unlink($old_packed); |
|---|
| | 204 | } |
|---|
| | 205 | } |
|---|
| | 206 | |
|---|
| | 207 | //echo "\nSelected source file {$sel_source}\n"; |
|---|
| | 208 | |
|---|
| | 209 | if (! $this->no_source) |
|---|
| | 210 | { |
|---|
| | 211 | //Separate source file |
|---|
| | 212 | //echo "\nRename current packed file {$this->js_files[$clean_name]} to .pack\n"; |
|---|
| | 213 | rename($this->js_files[$clean_name], $new_packed_file); |
|---|
| | 214 | //echo "\nRename current source file {$sel_source} to {$this->js_files[$clean_name]}\n"; |
|---|
| | 215 | rename($sel_source, $this->js_files[$clean_name]); |
|---|
| | 216 | } |
|---|
| | 217 | } |
|---|
| | 218 | } |
|---|
| | 219 | |
|---|
| 142 | | $trgt_file = $this->js_packed_files[$key]; |
|---|
| 143 | | $this->statistics .= "Packing file: {$src_file} to {$trgt_file}... "; |
|---|
| | 228 | |
|---|
| | 229 | $src_file_parts = pathinfo($src_file); |
|---|
| | 230 | $src_new_file = $src_file_parts['dirname'] . "/" . $src_file_parts['filename'] . ".src.js"; |
|---|
| | 231 | $trgt_file = $src_file; |
|---|
| | 232 | |
|---|
| | 233 | if (file_exists($src_file)) |
|---|
| | 234 | { |
|---|
| | 235 | rename($src_file, $src_new_file); |
|---|
| | 236 | //echo "\nRename source file {$src_file} to {$src_new_file}\n"; |
|---|
| | 237 | $this->statistics .= "\nrename {$src_file} to {$src_new_file}\n"; |
|---|
| | 238 | } |
|---|
| | 239 | else |
|---|
| | 240 | { |
|---|
| | 241 | echo "\nFATAL ERROR: Could not find source file {$src_file}\n"; |
|---|
| | 242 | continue; |
|---|
| | 243 | } |
|---|
| | 244 | |
|---|
| | 245 | $this->js_src_files[$key] = $src_new_file; |
|---|
| | 246 | $this->js_packed_files[$key] = $trgt_file; |
|---|
| | 247 | |
|---|
| | 248 | $this->statistics .= "Packing file: {$src_new_file} to {$trgt_file}... "; |
|---|
| | 262 | |
|---|
| | 263 | function unpack_files() |
|---|
| | 264 | { |
|---|
| | 265 | $t1 = microtime(true); |
|---|
| | 266 | |
|---|
| | 267 | $file_count = count($this->js_files); |
|---|
| | 268 | foreach ($this->js_files as $key => $file) |
|---|
| | 269 | { |
|---|
| | 270 | $file_parts = pathinfo($file); |
|---|
| | 271 | $src_file = $this->js_src_files[$key]; |
|---|
| | 272 | $packed_file = $this->js_packed_files[$key]; |
|---|
| | 273 | $new_src_file = $file; |
|---|
| | 274 | $new_packed_file = $file_parts['dirname'] . "/" . $file_parts['filename'] . ".pack.js"; |
|---|
| | 275 | |
|---|
| | 276 | if (file_exists($packed_file)) |
|---|
| | 277 | { |
|---|
| | 278 | if ( file_exists($new_packed_file) |
|---|
| | 279 | && $packed_file != $new_packed_file) |
|---|
| | 280 | { |
|---|
| | 281 | //echo "\nWe have old packed file. Delete this.\n"; |
|---|
| | 282 | unlink($new_packed_file); |
|---|
| | 283 | $this->statistics .= "\nunlink {$new_packed_file}\n"; |
|---|
| | 284 | } |
|---|
| | 285 | |
|---|
| | 286 | //echo "\nrename {$packed_file} to {$new_packed_file}\n"; |
|---|
| | 287 | rename($packed_file, $new_packed_file); |
|---|
| | 288 | $this->statistics .= "\nrename {$packed_file} to {$new_packed_file}\n"; |
|---|
| | 289 | } |
|---|
| | 290 | |
|---|
| | 291 | if (file_exists($src_file)) |
|---|
| | 292 | { |
|---|
| | 293 | //echo "\nrename {$src_file} to {$new_src_file}\n"; |
|---|
| | 294 | rename($src_file, $new_src_file); |
|---|
| | 295 | $this->statistics .= "\nrename {$src_file} to {$new_src_file}\n"; |
|---|
| | 296 | } |
|---|
| | 297 | } |
|---|
| | 298 | |
|---|
| | 299 | $t2 = microtime(true); |
|---|
| | 300 | $time = sprintf('%.4f', ($t2 - $t1) ); |
|---|
| | 301 | $this->statistics .= "\nunpacked {$file_count} files in {$time} seconds. \n"; |
|---|
| | 302 | } |
|---|