Skip to content

Instantly share code, notes, and snippets.

@polyrand
Last active November 17, 2022 12:15
Show Gist options
  • Select an option

  • Save polyrand/3bed83897658806bd490e1d44df4cd91 to your computer and use it in GitHub Desktop.

Select an option

Save polyrand/3bed83897658806bd490e1d44df4cd91 to your computer and use it in GitHub Desktop.

Revisions

  1. polyrand revised this gist Sep 14, 2022. 1 changed file with 0 additions and 1 deletion.
    1 change: 0 additions & 1 deletion build.py
    Original file line number Diff line number Diff line change
    @@ -10,7 +10,6 @@

    print("Downloading tailwindcss binary")
    # https://tailwindcss.com/blog/standalone-cli
    # chmod +x tailwindcss-macos-arm64
    subprocess.run(
    [
    "curl",
  2. polyrand revised this gist Sep 14, 2022. 1 changed file with 10 additions and 9 deletions.
    19 changes: 10 additions & 9 deletions build.py
    Original file line number Diff line number Diff line change
    @@ -10,19 +10,20 @@

    print("Downloading tailwindcss binary")
    # https://tailwindcss.com/blog/standalone-cli
    # chmod +x tailwindcss-macos-arm64
    subprocess.run(
    """
    set -euo pipefail
    curl -sLO https://github.com/tailwindlabs/tailwindcss/releases/latest/download/tailwindcss-macos-arm64
    chmod +x tailwindcss-macos-arm64
    mv tailwindcss-macos-arm64 tailwindcss
    """.strip(),
    shell=True,
    [
    "curl",
    "-SsL",
    "https://github.com/tailwindlabs/tailwindcss/releases/latest/download/tailwindcss-macos-arm64",
    "-o",
    "tailwindcss",
    ],
    check=True,
    )

    subprocess.run(["chmod", "+x", "tailwindcss"], check=True)


    if "alpine.js" not in os.listdir():
    print("Downloading alpine.js")
  3. polyrand revised this gist Sep 14, 2022. 1 changed file with 6 additions and 3 deletions.
    9 changes: 6 additions & 3 deletions build.py
    Original file line number Diff line number Diff line change
    @@ -26,7 +26,9 @@

    if "alpine.js" not in os.listdir():
    print("Downloading alpine.js")
    subprocess.run(["curl", "-SsL", "https://unpkg.com/alpinejs", "-o", "alpine.js"])
    subprocess.run(
    ["curl", "-SsL", "https://unpkg.com/alpinejs", "-o", "alpine.js"], check=True
    )


    tailwind_config = tempfile.NamedTemporaryFile()
    @@ -70,7 +72,8 @@
    tailwind_config.name,
    "--output",
    "./output.css",
    ]
    ],
    check=True,
    )

    tailwind_config.close()
    @@ -101,4 +104,4 @@
    )


    print("done")
    print("done")
  4. polyrand revised this gist Sep 14, 2022. 1 changed file with 7 additions and 2 deletions.
    9 changes: 7 additions & 2 deletions build.py
    Original file line number Diff line number Diff line change
    @@ -8,7 +8,7 @@

    if "tailwindcss" not in os.listdir():

    print("downloading tailwind bin")
    print("Downloading tailwindcss binary")
    # https://tailwindcss.com/blog/standalone-cli
    subprocess.run(
    """
    @@ -24,6 +24,11 @@
    )


    if "alpine.js" not in os.listdir():
    print("Downloading alpine.js")
    subprocess.run(["curl", "-SsL", "https://unpkg.com/alpinejs", "-o", "alpine.js"])


    tailwind_config = tempfile.NamedTemporaryFile()
    tailwind_css = tempfile.NamedTemporaryFile()

    @@ -96,4 +101,4 @@
    )


    print("done")
    print("done")
  5. polyrand created this gist Sep 14, 2022.
    99 changes: 99 additions & 0 deletions build.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,99 @@
    from jinja2 import Environment, FileSystemLoader, select_autoescape
    from pathlib import Path
    import shutil
    import tempfile
    import subprocess
    import os


    if "tailwindcss" not in os.listdir():

    print("downloading tailwind bin")
    # https://tailwindcss.com/blog/standalone-cli
    subprocess.run(
    """
    set -euo pipefail
    curl -sLO https://github.com/tailwindlabs/tailwindcss/releases/latest/download/tailwindcss-macos-arm64
    chmod +x tailwindcss-macos-arm64
    mv tailwindcss-macos-arm64 tailwindcss
    """.strip(),
    shell=True,
    check=True,
    )


    tailwind_config = tempfile.NamedTemporaryFile()
    tailwind_css = tempfile.NamedTemporaryFile()

    tailwind_config.write(
    b"""
    module.exports = {
    content: ["./**/*.{html,js}"],
    theme: {
    extend: {},
    },
    plugins: [
    require('@tailwindcss/typography'),
    require('@tailwindcss/forms'),
    require('@tailwindcss/aspect-ratio'),
    ]
    }
    """.strip()
    )
    tailwind_config.flush()


    tailwind_css.write(
    b"""
    @tailwind base;
    @tailwind components;
    @tailwind utilities;
    """.strip()
    )
    tailwind_css.flush()


    subprocess.run(
    [
    "./tailwindcss",
    "--minify",
    "--input",
    tailwind_css.name,
    "--config",
    tailwind_config.name,
    "--output",
    "./output.css",
    ]
    )

    tailwind_config.close()
    tailwind_css.close()


    loader = FileSystemLoader(".")

    t = Environment(loader=loader, autoescape=select_autoescape())

    for file in Path.cwd().glob("*.html.j2"):
    rendered = t.get_template(file.name).render()
    with open(file.stem, "w") as f:
    f.write(rendered)
    with open(f"drop/{file.stem}", "w") as f:
    f.write(rendered)

    shutil.copyfile("./alpine.js", (Path.cwd() / "drop" / "alpine.js").resolve())
    shutil.copyfile("./main.js", (Path.cwd() / "drop" / "main.js").resolve())
    shutil.copyfile("./output.css", (Path.cwd() / "drop" / "output.css").resolve())


    # Copy folder with static assets
    shutil.copytree(
    (Path.cwd() / "s").resolve(),
    (Path.cwd() / "drop" / "s").resolve(),
    dirs_exist_ok=True,
    )


    print("done")