]> _ Git - fluidbook-toolbox.git/commitdiff
wait #5543 @0.75
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Tue, 25 Oct 2022 07:19:08 +0000 (09:19 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Tue, 25 Oct 2022 07:19:08 +0000 (09:19 +0200)
.docker/images/php/Dockerfile
app/Http/Controllers/Admin/Operations/Tools/SASSCompiler.php

index d59051dc951b9be9486610f4ab462b0f15b31b12..3a88b3a2d6afaaa7d43e8710ad962f5fab275016 100644 (file)
@@ -92,7 +92,7 @@ RUN apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* /usr/share/do
 
 RUN groupadd sudo;useradd -d /application -g www-data -G sudo -s /bin/bash -u 1001 toolbox
 ENV PUPPETEER_SKIP_CHROMIUM_DOWNLOAD true
-RUN npm install --unsafe-perm --global uglify-js less puppeteer favicons-compiled-cli
+RUN npm install --unsafe-perm --global uglify-js less sass puppeteer favicons-compiled-cli
 
 # PHP-FPM packages need a nudge to make them docker-friendly
 COPY overrides.conf /etc/php/8.1/fpm/pool.d/z-overrides.conf
index cf2ab73ffdbdc8c32e215b1f8d26c06b3e380044..2463bd72c096c9cc5366f9cdb827324eb272dc80 100644 (file)
@@ -4,6 +4,9 @@ namespace App\Http\Controllers\Admin\Operations\Tools;
 
 use Cubist\Backpack\Magic\Fields\DirectoryUpload;
 use Cubist\Backpack\Magic\Form;
+use Cubist\Util\CommandLine;
+use Cubist\Util\Files\Files;
+use Cubist\Util\Zip;
 
 trait SASSCompiler
 {
@@ -21,8 +24,31 @@ trait SASSCompiler
 
     public function dosasscompile()
     {
-        $files = $_FILES;
-        dd($files,request('directory'));
+        $temp = Files::tmpdir();
+        $css = Files::tmpdir();
+        foreach ($_FILES['directory']['full_path'] as $index => $path) {
+            $path = $this->_removeBasePath($path);
+            $dest = $temp . '/' . $path;
+            Files::mkdir(dirname($dest));
+            move_uploaded_file($_FILES['directory']['tmp_name'][$index], $dest);
+        }
+        $sass = new CommandLine('sass');
+        $sass->setArg(null, $temp . ':'.$css);
+        $sass->execute();
+
+        $zip = Files::tempnam() . '.zip';
+        Files::rmdir($temp);
+        Zip::archive($css, $zip);
+        Files::rmdir($css);
+
+        return response()->download($zip, 'sass.zip', ['Content-type' => 'application/zip'])->deleteFileAfterSend();
+    }
+
+    protected function _removeBasePath($path)
+    {
+        $e = explode('/', trim($path, '/'));
+        array_shift($e);
+        return implode('/', $e);
     }
 
 }