From 919f6a01888357b61fc2b53a4313a5bd6d6c9a43 Mon Sep 17 00:00:00 2001 From: Alexander Popov Date: Wed, 13 Apr 2022 16:05:32 +0300 Subject: [PATCH] dist builder --- .editorconfig | 4 ++++ .gitignore | 1 + mkdist.py | 47 ++++++++++++++++++++++++++++++++++++++++++++ requirements-dev.txt | 1 + 4 files changed, 53 insertions(+) create mode 100755 mkdist.py diff --git a/.editorconfig b/.editorconfig index a1383fe..6a44699 100644 --- a/.editorconfig +++ b/.editorconfig @@ -19,3 +19,7 @@ indent_size = 2 [*.js] indent_style = space indent_size = 2 + +[*.py] +indent_style = space +indent_size = 4 diff --git a/.gitignore b/.gitignore index 1a1f875..ded0345 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ src/assets/ +dist/ diff --git a/mkdist.py b/mkdist.py new file mode 100755 index 0000000..c013a32 --- /dev/null +++ b/mkdist.py @@ -0,0 +1,47 @@ +#!/bin/env python3 +import os +import minify_html + + +if __name__ == '__main__': + HTML_SRC = '' + CSS_SRC = '' + + # Preparing, check dirs + if not os.path.isdir('dist'): + os.mkdir('dist') + + # Build HTML + with open('src/index.html') as file: + HTML_SRC = file.read() + + minified = minify_html.minify(HTML_SRC, minify_js=True, do_not_minify_doctype=True, ensure_spec_compliant_unquoted_attribute_values=False, remove_processing_instructions=True) + + # Fix minify_html bugs for W3C validator + minified = minified.replace('content=width=device-width,initial-scale=1', 'content="width=device-width, initial-scale=1"') + minified = minified.replace('icon"href', 'icon" href') + minified = minified.replace('«', '«') + minified = minified.replace('»', '»') + HTML_SRC = minified + + # Save HTML + with open('dist/index.html', 'w') as file: + file.write(HTML_SRC) + + # Build CSS + with open('src/styles.css') as file: + CSS_SRC = file.read() + + minified = minify_html.minify(CSS_SRC, minify_css=True, remove_processing_instructions=True) + CSS_SRC = minified + + # Save CSS + with open('dist/styles.css', 'w') as file: + file.write(CSS_SRC) + + # Copy other files + os.popen('cp src/favicon.ico src/humans.txt dist/' ) + + # Make archive + os.popen('cd ./dist/; tar -czf ../dist.tar.gz *') + # os.popen('rm -rf ./dist/') diff --git a/requirements-dev.txt b/requirements-dev.txt index 70f0a51..8e4735e 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -1 +1,2 @@ editorconfig-checker==2.4.0 +minify_html==0.8.0