aboutsummaryrefslogtreecommitdiff
path: root/deploy/gen_static_config.php
diff options
context:
space:
mode:
authorEvgeny Zinoviev <me@ch1p.io>2022-07-11 02:59:35 +0300
committerEvgeny Zinoviev <me@ch1p.io>2022-07-11 02:59:40 +0300
commit864e73cdc75a2fb0e4fad500f649dae2343c10a8 (patch)
tree6ce6762c6be72c98592a32fe0bed4f2ce751d544 /deploy/gen_static_config.php
parentcb13ea239b9f1ca6aea43125d5694d5a55dcd287 (diff)
rewrite css and js assets building
Diffstat (limited to 'deploy/gen_static_config.php')
-rwxr-xr-xdeploy/gen_static_config.php57
1 files changed, 57 insertions, 0 deletions
diff --git a/deploy/gen_static_config.php b/deploy/gen_static_config.php
new file mode 100755
index 0000000..09058ad
--- /dev/null
+++ b/deploy/gen_static_config.php
@@ -0,0 +1,57 @@
+#!/usr/bin/env php8.1
+<?php
+
+require __DIR__.'/../init.php';
+
+if ($argc <= 1) {
+ usage();
+ exit(1);
+}
+
+$input_dir = null;
+
+array_shift($argv);
+while (count($argv) > 0) {
+ switch ($argv[0]) {
+ case '-i':
+ array_shift($argv);
+ $input_dir = array_shift($argv);
+ break;
+
+ default:
+ cli::die('unsupported argument: '.$argv[0]);
+ }
+}
+
+if (is_null($input_dir))
+ cli::die("input directory has not been specified");
+
+$hashes = [];
+foreach (['css', 'js'] as $type) {
+ $entries = glob_recursive($input_dir.'/dist-'.$type.'/*.'.$type);
+ if (empty($entries)) {
+ cli::error("warning: no files found in $input_dir/dist-$type");
+ continue;
+ }
+
+ foreach ($entries as $file)
+ $hashes[$type.'/'.basename($file)] = get_hash($file);
+}
+
+echo "<?php\n\n";
+echo "return ".var_export($hashes, true).";\n";
+
+function usage(): void {
+ global $argv;
+ echo <<<EOF
+usage: {$argv[0]} [OPTIONS]
+
+Options:
+ -i input htdocs directory
+
+EOF;
+}
+
+function get_hash(string $path): string {
+ return substr(sha1(file_get_contents($path)), 0, 8);
+} \ No newline at end of file