From 864e73cdc75a2fb0e4fad500f649dae2343c10a8 Mon Sep 17 00:00:00 2001 From: Evgeny Zinoviev Date: Mon, 11 Jul 2022 02:59:35 +0300 Subject: rewrite css and js assets building --- build_static.php | 96 -------------------------------------------------------- 1 file changed, 96 deletions(-) delete mode 100755 build_static.php (limited to 'build_static.php') diff --git a/build_static.php b/build_static.php deleted file mode 100755 index 63c6e0e..0000000 --- a/build_static.php +++ /dev/null @@ -1,96 +0,0 @@ -#!/usr/bin/env php8.1 - '.escapeshellarg($output); - system($cmd); - - if (file_exists($output)) { - unlink($file); - rename($output, $file); - } else { - fwrite(STDERR, "error: could not cleancss $file\n"); - } -} - -function dark_diff(string $light_file, string $dark_file): void { - $temp_output = $dark_file.'.diff'; - $cmd = ROOT.'/dark-theme-diff.js '.escapeshellarg($light_file).' '.$dark_file.' > '.$temp_output; - exec($cmd, $output, $code); - if ($code != 0) { - fwrite(STDERR, "dark_diff failed with code $code\n"); - return; - } - - unlink($dark_file); - rename($temp_output, $dark_file); -} - -require __DIR__.'/init.php'; - -function build_static(): void { - $css_dir = ROOT.'/htdocs/css'; - $hashes = []; - - if (!file_exists($css_dir)) - mkdir($css_dir); - - // 1. scss -> css - $themes = ['light', 'dark']; - $entries = ['common', 'admin']; - foreach ($themes as $theme) { - foreach ($entries as $entry) { - $input = ROOT.'/htdocs/scss/entries/'.$entry.'/'.$theme.'.scss'; - $output = $css_dir.'/'.$entry.($theme == 'dark' ? '_dark' : '').'.css'; - if (sassc($input, $output) != 0) - fwrite(STDERR, "error: could not compile entries/$entry/$theme.scss\n"); - } - } - - // 2. generate dark theme diff - foreach ($entries as $entry) { - $light_file = $css_dir.'/'.$entry.'.css'; - $dark_file = str_replace('.css', '_dark.css', $light_file); - dark_diff($light_file, $dark_file); - - // 2.1. apply cleancss (must be done _after_ css-patch) - clean_css($light_file); - clean_css($dark_file); - } - - // 3. calculate hashes - foreach (['css', 'js'] as $type) { - $reldir = ROOT.'/htdocs/'; - $entries = glob_recursive($reldir.$type.'/*.'.$type); - if (empty($entries)) { - continue; - } - foreach ($entries as $file) { - $name = preg_replace('/^'.preg_quote($reldir, '/').'/', '', $file); - $hashes[$name] = gethash($file); - } - } - logInfo($hashes); - - // 4. write config-static.php - $scfg = "