Commit e8577d98fa
Unsigned
Layout: unified · split
build.py +11 −6
| @@ -5,11 +5,13 @@ import subprocess | |||
| 5 | import sys | 5 | import sys |
| 6 | from pathlib import Path | 6 | from pathlib import Path |
| 7 | 7 | ||
| 8 | |||
| 8 | def prompt(prompt_text): | 9 | def prompt(prompt_text): |
| 9 | try: | 10 | try: |
| 10 | return input(prompt_text).strip() | 11 | return input(prompt_text).strip() |
| 11 | except EOFError: | 12 | except EOFError: |
| 12 | return '' | 13 | return "" |
| 14 | |||
| 13 | 15 | ||
| 14 | def remove_build_directory(build_dir): | 16 | def remove_build_directory(build_dir): |
| 15 | if build_dir.exists(): | 17 | if build_dir.exists(): |
| @@ -17,6 +19,7 @@ def remove_build_directory(build_dir): | |||
| 17 | shutil.rmtree(build_dir) | 19 | shutil.rmtree(build_dir) |
| 18 | build_dir.mkdir(parents=True, exist_ok=True) | 20 | build_dir.mkdir(parents=True, exist_ok=True) |
| 19 | 21 | ||
| 22 | |||
| 20 | def minify_css(src_css, dest_css): | 23 | def minify_css(src_css, dest_css): |
| 21 | print(f"Minifying CSS: {src_css} → {dest_css}") | 24 | print(f"Minifying CSS: {src_css} → {dest_css}") |
| 22 | result = subprocess.run( | 25 | result = subprocess.run( |
| @@ -30,6 +33,7 @@ def minify_css(src_css, dest_css): | |||
| 30 | print(result.stderr, file=sys.stderr) | 33 | print(result.stderr, file=sys.stderr) |
| 31 | sys.exit(1) | 34 | sys.exit(1) |
| 32 | 35 | ||
| 36 | |||
| 33 | def run_emacs_publish(dev_mode=True): | 37 | def run_emacs_publish(dev_mode=True): |
| 34 | if dev_mode: | 38 | if dev_mode: |
| 35 | print("Running Emacs publish script (development)...") | 39 | print("Running Emacs publish script (development)...") |
| @@ -53,6 +57,7 @@ def run_emacs_publish(dev_mode=True): | |||
| 53 | print(result.stderr, file=sys.stderr) | 57 | print(result.stderr, file=sys.stderr) |
| 54 | sys.exit(1) | 58 | sys.exit(1) |
| 55 | 59 | ||
| 60 | |||
| 56 | def deploy_to_server(build_dir, server): | 61 | def deploy_to_server(build_dir, server): |
| 57 | remote_path = f"{server}:/var/www/cleberg.net/" | 62 | remote_path = f"{server}:/var/www/cleberg.net/" |
| 58 | print(f"Deploying .build/ → {remote_path}") | 63 | print(f"Deploying .build/ → {remote_path}") |
| @@ -67,21 +72,20 @@ def deploy_to_server(build_dir, server): | |||
| 67 | print(result.stderr, file=sys.stderr) | 72 | print(result.stderr, file=sys.stderr) |
| 68 | sys.exit(1) | 73 | sys.exit(1) |
| 69 | 74 | ||
| 75 | |||
| 70 | def start_dev_server(build_dir): | 76 | def start_dev_server(build_dir): |
| 71 | print(f"Starting development HTTP server from {build_dir}/ on port 8000") | 77 | print(f"Starting development HTTP server from {build_dir}/ on port 8000") |
| 72 | os.chdir(build_dir) | 78 | os.chdir(build_dir) |
| 73 | # This will run until interrupted (Ctrl+C) | 79 | # This will run until interrupted (Ctrl+C) |
| 74 | try: | 80 | try: |
| 75 | subprocess.run( | 81 | subprocess.run([sys.executable, "-m", "http.server", "8000"], check=True) |
| 76 | [sys.executable, "-m", "http.server", "8000"], | ||
| 77 | check=True | ||
| 78 | ) | ||
| 79 | except KeyboardInterrupt: | 82 | except KeyboardInterrupt: |
| 80 | print("\nDevelopment server stopped.") | 83 | print("\nDevelopment server stopped.") |
| 81 | except subprocess.CalledProcessError as e: | 84 | except subprocess.CalledProcessError as e: |
| 82 | print(f"Error starting development server: {e}", file=sys.stderr) | 85 | print(f"Error starting development server: {e}", file=sys.stderr) |
| 83 | sys.exit(1) | 86 | sys.exit(1) |
| 84 | 87 | ||
| 88 | |||
| 85 | def main(): | 89 | def main(): |
| 86 | build_dir = Path(".build") | 90 | build_dir = Path(".build") |
| 87 | theme_dir = Path("theme/static") | 91 | theme_dir = Path("theme/static") |
| @@ -132,5 +136,6 @@ def main(): | |||
| 132 | # Launch development web server | 136 | # Launch development web server |
| 133 | start_dev_server(build_dir) | 137 | start_dev_server(build_dir) |
| 134 | 138 | ||
| 139 | |||
| 135 | if __name__ == "__main__": | 140 | if __name__ == "__main__": |
| 136 | main()\ No newline at end of file | 141 | main() |