This repository has been archived by the owner on Dec 18, 2024. It is now read-only.
generated from communitiesuk/funding-service-design-TEMPLATE
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.py
67 lines (50 loc) · 2.15 KB
/
build.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import os
import shutil
import urllib.request
import zipfile
import static_assets
def build_govuk_assets(static_dist_root="frontend/static/dist"):
DIST_ROOT = "./" + static_dist_root
GOVUK_URL = "https://github.com/alphagov/govuk-frontend/releases/download/v4.8.0/release-v4.8.0.zip"
ZIP_FILE = "./govuk_frontend.zip"
DIST_PATH = DIST_ROOT
ASSETS_DIR = "/assets"
ASSETS_PATH = DIST_PATH + ASSETS_DIR
# Checks if GovUK Frontend Assets already built
if os.path.exists(DIST_PATH):
print("GovUK Frontend assets already built.If you require a rebuild manually run build.build_govuk_assets")
return True
# Download zips from GOVUK_URL
# There is a known problem on Mac where one must manually
# run the script "Install Certificates.command" found
# in the python application folder for this to work.
print("Downloading static file zip.")
urllib.request.urlretrieve(GOVUK_URL, ZIP_FILE) # nosec
# Attempts to delete the old files, states if
# one doesn't exist.
print("Deleting old " + DIST_PATH)
try:
shutil.rmtree(DIST_PATH)
except FileNotFoundError:
print("No old " + DIST_PATH + " to remove.")
# Extract the previously downloaded zip to DIST_PATH
print("Unzipping file to " + DIST_PATH + "...")
with zipfile.ZipFile(ZIP_FILE, "r") as zip_ref:
zip_ref.extractall(DIST_PATH)
# Move files from ASSETS_PATH to DIST_PATH
print("Moving files from " + ASSETS_PATH + " to " + DIST_PATH)
for file_to_move in os.listdir(ASSETS_PATH):
shutil.move("/".join([ASSETS_PATH, file_to_move]), DIST_PATH)
# Delete temp files
print("Deleting " + ASSETS_PATH)
shutil.rmtree(ASSETS_PATH)
os.remove(ZIP_FILE)
def build_all(static_dist_root="frontend/static/dist", remove_existing=False):
if remove_existing:
relative_dist_root = "./" + static_dist_root
if os.path.exists(relative_dist_root):
shutil.rmtree(relative_dist_root)
build_govuk_assets(static_dist_root=static_dist_root)
static_assets.build_bundles(static_folder=static_dist_root)
if __name__ == "__main__":
build_all(remove_existing=True)