Skip to main content

Add a nice deploy script

ID
c2b5b65
date
2025-01-29 21:03:39+00:00
author
Alex Chan <alex@alexwlchan.net>
parent
1501023
message
Add a nice deploy script
changed files
3 files, 46 additions, 24 deletions

Changed files

README.md (962 → 903)

diff --git a/README.md b/README.md
index ac9e25c..731db03 100644
--- a/README.md
+++ b/README.md
@@ -18,6 +18,5 @@ You need to use an HTTP server rather than opening the file because it needs to 
 
 ## Deployment
 
-Run the `build.py` script to create the version of the site for deployment.
-
-This inlines the two JavaScript files, so we get a single HTML file which contains the entire tool.
+Run the `deploy.py` script.
+This will compile the app into a single JavaScript file, then upload it to my web server.

build.py (603 → 0)

diff --git a/build.py b/build.py
deleted file mode 100755
index 009a748..0000000
--- a/build.py
+++ /dev/null
@@ -1,21 +0,0 @@
-#!/usr/bin/env python3
-
-from pathlib import Path
-
-
-if __name__ == '__main__':
-    out_dir = Path("dist")
-    out_dir.mkdir(exist_ok=True)
-    
-    html = Path("index.html").read_text()
-    html = html.replace(
-        '<script src="static/app.js"></script>',
-        '<script id="app">' + Path("static/app.js").read_text() + '</script>'
-    )
-    html = html.replace(
-        '<script src="static/jszip.min.js"></script>',
-        '<script id="jsmin">' + Path("static/jszip.min.js").read_text() + '</script>'
-    )
-    assert '<script src' not in html
-    
-    (out_dir / "index.html").write_text(html)

deploy.py (0 → 1205)

diff --git a/deploy.py b/deploy.py
new file mode 100755
index 0000000..f24abe2
--- /dev/null
+++ b/deploy.py
@@ -0,0 +1,44 @@
+#!/usr/bin/env python3
+"""
+This script builds and deploys the app to my web server, which means:
+
+1.  Compiling everything into a single HTML file
+2.  Uploading that HTML file to my web server
+
+"""
+
+from pathlib import Path
+import subprocess
+
+
+if __name__ == "__main__":
+    out_dir = Path("dist")
+    out_dir.mkdir(exist_ok=True)
+
+    html = Path("index.html").read_text()
+    html = html.replace(
+        '<script src="static/app.js"></script>',
+        '<script id="app">' + Path("static/app.js").read_text() + "</script>",
+    )
+    html = html.replace(
+        '<script src="static/jszip.min.js"></script>',
+        '<script id="jsmin">' + Path("static/jszip.min.js").read_text() + "</script>",
+    )
+    assert "<script src" not in html
+
+    (out_dir / "index.html").write_text(html)
+
+    subprocess.check_call(
+        [
+            "ssh",
+            "alexwlchan@alexwlchan.net",
+            "mkdir -p repos/alexwlchan.net/_site/tools/add-cover-to-ao3-epubs",
+        ]
+    )
+    subprocess.check_call(
+        [
+            "scp",
+            str(out_dir / "index.html"),
+            "alexwlchan@alexwlchan.net:repos/alexwlchan.net/_site/tools/add-cover-to-ao3-epubs/index.html",
+        ]
+    )