dist builder

This commit is contained in:
Alexander Popov 2022-04-13 16:05:32 +03:00
parent 0f6f4170db
commit 919f6a0188
Signed by: iiiypuk
GPG Key ID: 3F76816AEE08F908
4 changed files with 53 additions and 0 deletions

View File

@ -19,3 +19,7 @@ indent_size = 2
[*.js]
indent_style = space
indent_size = 2
[*.py]
indent_style = space
indent_size = 4

1
.gitignore vendored
View File

@ -1 +1,2 @@
src/assets/
dist/

47
mkdist.py Executable file
View File

@ -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('&amp#xab;', '«')
minified = minified.replace('&amp#xbb;', '»')
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/')

View File

@ -1 +1,2 @@
editorconfig-checker==2.4.0
minify_html==0.8.0