From: Andrey Kutejko Date: Sun, 7 Apr 2019 13:59:16 +0000 (+0200) Subject: remove asset compiler X-Git-Url: https://git.andy128k.dev/?a=commitdiff_plain;h=dcd8bb0510b8f9b356172a74007470381dea5d70;p=ipf.git remove asset compiler --- diff --git a/ipf/application.php b/ipf/application.php index 57f8aee..44aa0c5 100644 --- a/ipf/application.php +++ b/ipf/application.php @@ -53,14 +53,4 @@ abstract class IPF_Application { return array(); } - - /** - * Returns Dictionary of assets - * - * @return array Dictionary of asset entry points mapped to output file - */ - public function assets() - { - return array(); - } } diff --git a/ipf/assets.php b/ipf/assets.php deleted file mode 100644 index b7896f3..0000000 --- a/ipf/assets.php +++ /dev/null @@ -1,78 +0,0 @@ -dirs = array( - rtrim($dir, '/'), - IPF::get('project_root') . '/vendor/npm-asset', - IPF::get('project_root') . '/vendor/bower-asset', - ); - } - - public function compileFile($path) - { - $root = $this->path($path); - list($success, $data) = \PFF\TopSort::sort(array($root), array($this, 'following')); - if (!$success) - throw new Exception('Loop detected: '.implode(' -> ', $data)); - - $dump = array(); - foreach ($data as $path) { - $dump[] = $this->files[$path]; - } - return implode("\n", $dump); - } - - public static function compile($dir, $path) - { - $compiler = new IPF_Assets($dir); - return $compiler->compileFile($path); - } - - function following($path) - { - if (!array_key_exists($path, $this->files)) - $this->files[$path] = file_get_contents($path); - $content = $this->files[$path]; - - if (!preg_match_all('#^(//=\\s*require\\s*(\\S+)|/\\*=\\s*require\\s*(\\S+)\\s*\\*/)\\s*$#m', $content, $matches, PREG_SET_ORDER)) - return array(); - - $currentDir = dirname($path); - - $result = array(); - foreach ($matches as $m) { - $result[] = $this->path(@$m[2].@$m[3], $currentDir); - } - - return $result; - } - - private function possiblePaths($file, $currentDir=null) - { - $file = ltrim($file, '/'); - $paths = array(); - - if ($currentDir) - $paths[] = rtrim($currentDir, '/') . '/' . $file; - - foreach ($this->dirs as $base) - $paths[] = $base . '/' . $file; - - return $paths; - } - - function path($file, $currentDir=null) - { - $paths = array_filter(array_map('realpath', $this->possiblePaths($file, $currentDir))); - if (!$paths) - throw new Exception("File '$file' not found in '" . implode("', '", $this->dirs) . "'."); - return array_shift($paths); - } -} - diff --git a/ipf/command/collectstatic.php b/ipf/command/collectstatic.php index 2e3d46d..487ca15 100644 --- a/ipf/command/collectstatic.php +++ b/ipf/command/collectstatic.php @@ -23,22 +23,8 @@ class IPF_Command_CollectStatic foreach ($this->apps as $app) { $source = $app->getPath() . 'static'; - if (is_dir($source)) + if (is_dir($source)) { IPF_Utils::copyDirectory($source, $this->staticDir); - - foreach ($app->assets() as $asset => $output) { - $compiler = new IPF_Assets($app->getPath()); - - $src = $compiler->path($asset); - $dest = $this->staticDir . $output; - - if (is_dir($src)) { - IPF_Utils::copyDirectory($src, $dest); - } else { - $content = $compiler->compileFile($asset); - IPF_Utils::makeDirectories(dirname($dest)); - file_put_contents($dest, $content); - } } } } diff --git a/ipf/middleware/serve_static.php b/ipf/middleware/serve_static.php index d496b46..234e4e5 100644 --- a/ipf/middleware/serve_static.php +++ b/ipf/middleware/serve_static.php @@ -15,12 +15,6 @@ class IPF_Serve_Static_Middleware extends IPF_Middleware $static = $app->getPath() . $staticUrl . $query; if (is_file($static)) return new IPF_HTTP_Response_File($static, null, $this->mimetype($query)); - - $asset = array_search($query, $app->assets()); - if ($asset !== false) { - $content = IPF_Assets::compile($app->getPath(), $asset); - return new IPF_HTTP_Response($content, $this->mimetype($query)); - } } return false;