From 1fbd2dfd2dd216a25c914881debf8dc987dae378 Mon Sep 17 00:00:00 2001 From: Cutieguwu Date: Mon, 21 Jul 2025 22:42:45 -0400 Subject: [PATCH] Add AIO build script. --- balloon.py | 16 +++++++++--- build.sh | 73 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 85 insertions(+), 4 deletions(-) create mode 100755 build.sh diff --git a/balloon.py b/balloon.py index 2e53aa1..a465ad3 100644 --- a/balloon.py +++ b/balloon.py @@ -13,7 +13,7 @@ from typing import TYPE_CHECKING if TYPE_CHECKING: from _typeshed import StrPath -WORK_DIR: StrPath = os.getcwd() +WORK_DIR: StrPath = os.getcwd() + '/' @dataclass class Tag: @@ -104,16 +104,24 @@ def main() -> None: # Incorrect number of arguments # Long help flag # Short help flag - if len(sys.argv) != 1 or ( + if len(sys.argv) != 2 or ( sys.argv[0] == '--help' or sys.argv[0] == '-h' ): help() return - with open(str(WORK_DIR) + 'src' + sys.argv[0], 'rt') as f: + file_name = sys.argv[1].removeprefix('src/') + + with open(str(WORK_DIR) + 'src/' + file_name, 'rt') as f: html_src = HTML(f.read()) - with open(str(WORK_DIR) + 'target' + sys.argv[0], 'w') as f: + + try: + os.makedirs(str(WORK_DIR) + 'target/' + os.path.dirname(file_name)) + except FileExistsError: + pass + + with open(str(WORK_DIR) + 'target/' + file_name, 'w') as f: f.write(html_src.write()) def help() -> None: diff --git a/build.sh b/build.sh new file mode 100755 index 0000000..bde7c4f --- /dev/null +++ b/build.sh @@ -0,0 +1,73 @@ +#! /usr/bin/bash +# +# I'm new to bash scripting, so give me a break. +# I know that this is probably crap, but it's cheap, dirty, and does the job. + +python=~/.pyenv/versions/3.12.9/bin/python +green='\e[32m' +cyan='\e[36m' + +# The "a" is just to make this work if no characters are present in $@ +args=$@ +args+=('a') + +if [ $(expr length "$args") -gt 1 ] +then + args=$@ +else + args='inflate style copy' +fi + +for x in $args +do + if [ "$x" == 'inflate' ] + then + echo -e "$green"Inflating... + + files=(`ls src/*.html`) + files+=(`ls src/errors/*.html`) + + for html in "${files[@]}" + do + echo -e " $cyan$html -> target/" + + eval $python 'balloon.py' $html + done + + elif [ "$x" == 'style' ] + then + echo -e "$green"Styling... + + sass src/style.scss target/style.css + + echo -e "$cyan"' src/style.scss -> target/style.css' + + elif [ "$x" == 'copy' ] + then + echo -e "$green"Copying... + + files=( + '.well-known/security.txt' + 'img' + 'robots.txt' + ) + + for item in "${files[@]}" + do + echo -e "$cyan src/$item -> target/$item" + + cp -R src/$item target/$item + done + elif [ "$x" == '-h' -o "$x" == '--help' ] + then + echo -e "$green"Usage:"$cyan" build.sh [OPTIONS] [COMMAND] + echo + echo -e "$green"Options:"$cyan" + echo ' -h, --help Print help' + echo + echo -e "$green"Commands:"$cyan" + echo ' inflate Inflate the HTML source' + echo ' style Compile SCSS to CSS' + echo ' copy Copy assets to target' + fi +done