/** * Delete Manifest file(s) in the application's assets path * * @return void */ protected function deleteManifest() { $manifests = find_paths(public_path('assets/') . 'manifest-*.json'); foreach ($manifests as $manifest) { File::delete($manifest); } }
public function __construct($args = null) { $args = is_array($args) ? $args : func_get_args(); if (count($args) < 2) { $args = array_merge($args, [null]); } list($this->dir, $this->path) = $args; $this->dir = $this->normalizePath($this->dir); $this->path = $this->normalizePath($this->path); $basePath = $this->normalizePath(base_path()); // Windows support: Convert backslash to slash // Expand paths if ($this->dir) { $this->dir = $this->normalizePath(realpath($this->dir)); } if ($this->path) { $this->path = $this->normalizePath(realpath($this->path)); } // If path is given as the second arg if ($this->dir && File::extension($this->dir) != "") { list($this->dir, $this->path) = [null, $this->dir]; } // Default dir to the directory of the path if ($this->path) { $this->dir = $this->dir ?: dirname($this->path); } // If directory is given w/o path, pick a random manifest.json location if ($this->dir && !$this->path) { // Find the first manifest.json in the directory $paths = find_paths($this->dir . "/manifest*.json"); if (!empty($paths)) { $this->path = head($paths); } else { $this->path = $this->dir . "/manifest-" . md5(uniqid(mt_rand(), true)) . ".json"; } } if (!$this->dir && !$this->path) { throw new Exception("manifest requires output path", 1); } $data = []; try { if (File::exists($this->path)) { // \Log::info("Load manifest !");//debug $data = json_decode(File::get($this->path), true); } } catch (Exception $e) { \Log::error($this->path . " is invalid: " . get_classname($e) . " " . $e->getMessage()); } $this->data = $data; }
function find_paths($all_locations, $direct, $from, $paths = array()) { // reset keys & pick the new 'from' array_values($all_locations); if (!isset($paths['total'])) { $paths['total'] = 0; } // exclude the current 'from' and create new set $temp = $all_locations; if (($key = array_search($from, $temp)) !== false) { unset($temp[$key]); } //else{ var_dump($temp); var_dump($from); } $temp = array_values($temp); $possible = array(); $to = ''; foreach ($direct as $k => $v) { if (strpos($k, $from) !== false && in_array(str_replace(array($from, ' to '), "", $k), $temp)) { $to = str_replace(array($from, ' to '), "", $k); $possible[$from . ' to ' . $to] = $v; } } if (!empty($possible)) { //var_dump(array_keys($possible, min($possible))); $smallest_key = array_keys($possible, max($possible)); $smallest_value = $possible[$smallest_key[0]]; $paths[$smallest_key[0]] = $smallest_value; $paths['total'] += $smallest_value; $to = trim(str_replace(array($from, ' to '), "", $smallest_key[0])); if (count($temp) > 0) { return find_paths($temp, $direct, $to, $paths); } } else { return $paths; } }
<?php return ['prefix' => '/assets', 'host' => null, 'paths' => array_merge(find_paths(base_path() . '/vendor/*/*/resources/assets/*/'), [base_path() . '/resources/assets/images', base_path() . '/resources/assets/js', base_path() . '/resources/assets/css', base_path() . '/lib/assets/images', base_path() . '/lib/assets/js', base_path() . '/lib/assets/css', base_path() . '/provider/assets/images', base_path() . '/provider/assets/js', base_path() . '/provider/assets/css']), 'precompile' => ['app.css', 'app.js'], 'sourceMaps' => true];