$var) { $appVariables .= '$' . "$k:$var;" . PHP_EOL; } $appVariables .= ":root{" . PHP_EOL; foreach ($vars as $k => $var) { $appVariables .= "--$k:$var;" . PHP_EOL; } $appVariables .= "}" . PHP_EOL . PHP_EOL; file_put_contents(resource_path() . '/sass/client-custom/_app_variables.scss', $appVariables); // add custom scss and js $files = File::allFiles(resource_path() . '/sass/client-custom'); foreach ($files as $file) { if ($file->getType() == 'file' && $file->getExtension() == 'scss') { $variables .= '@use "client-custom/' . substr(trim($file->getBasename(), '_'), 0, -5) . '";' . PHP_EOL; } } $files = File::allFiles(resource_path() . '/js/client-custom'); foreach ($files as $file) { if ($file->getType() == 'file' && $file->getExtension() == 'js') { $js .= 'import "./client-custom/' . $file->getBasename() . '";' . PHP_EOL; } } // add parts scss & js foreach (Part::distinct()->get() as $part) { if (filesize(__DIR__ . '/../../../resources/views/segments/' . $part->segment . '/' . $part->part . '/' . $part->part . '.scss') > 10) { $variables .= '@use "../views/segments/' . $part->segment . '/' . $part->part . '/' . $part->part . '";' . PHP_EOL; } if (filesize(__DIR__ . '/../../../resources/views/segments/' . $part->segment . '/' . $part->part . '/' . $part->part . '.js') > 10) { $js .= 'import "../views/segments/' . $part->segment . '/' . $part->part . '/' . $part->part . '.js";' . PHP_EOL; } } // save scss file_put_contents(resource_path() . '/sass/client.scss', $this->removeDuplicateLines($variables)); file_put_contents(resource_path() . '/js/client.js', $this->removeDuplicateLines( $js )); } // remove duplicate lines private function removeDuplicateLines($text) { $lines = explode("\n", $text); $uniqueLines = array_unique($lines); $uniqueText = implode("\n", $uniqueLines); return $uniqueText; } }