]> git.andy128k.dev Git - ipf.git/commitdiff
remove asset compiler
authorAndrey Kutejko <andy128k@gmail.com>
Sun, 7 Apr 2019 13:59:16 +0000 (15:59 +0200)
committerAndrey Kutejko <andy128k@gmail.com>
Sun, 7 Apr 2019 13:59:16 +0000 (15:59 +0200)
ipf/application.php
ipf/assets.php [deleted file]
ipf/command/collectstatic.php
ipf/middleware/serve_static.php

index 57f8aee916a9ab5c3c11a1681b6921ac5f71f440..44aa0c5a0a33217b067c19df2f1605c304cb8e98 100644 (file)
@@ -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 (file)
index b7896f3..0000000
+++ /dev/null
@@ -1,78 +0,0 @@
-<?php
-
-class IPF_Assets
-{
-    private $files = array();
-    private $dirs = array();
-
-    public function __construct($dir)
-    {
-        $this->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);
-    }
-}
-
index 2e3d46d82958a26765cdcbdfdb4dd7565f0af41f..487ca15e5ddf4262166929bcbdada70ad593bc78 100644 (file)
@@ -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);
-                }
             }
         }
     }
index d496b46a488d0ec4d759fdf0bbe1c059fbb76cbc..234e4e5698c0b0dcd2a49b82cae38c60fd43cb34 100644 (file)
@@ -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;