mirror of
https://github.com/chylex/Discord-History-Tracker.git
synced 2025-04-13 15:27:16 +03:00
Redo renderer file building and reorganize build script a bit
This commit is contained in:
parent
874fe42701
commit
f4814b88f4
50
build.py
50
build.py
@ -5,6 +5,12 @@ import glob
|
||||
import os
|
||||
|
||||
|
||||
def combine_files(input_pattern, output_file):
|
||||
with fileinput.input(sorted(glob.glob(input_pattern))) as stream:
|
||||
for line in stream:
|
||||
output_file.write(line)
|
||||
|
||||
|
||||
def build_tracker():
|
||||
output_file = "bld/track.js"
|
||||
output_file_tmp = "bld/track.tmp.js"
|
||||
@ -12,11 +18,7 @@ def build_tracker():
|
||||
|
||||
with open(output_file, "w") as out:
|
||||
out.write("(function(){")
|
||||
|
||||
with fileinput.input(sorted(glob.glob(input_pattern))) as stream:
|
||||
for line in stream:
|
||||
out.write(line)
|
||||
|
||||
combine_files(input_pattern, out)
|
||||
out.write("})()")
|
||||
|
||||
os.system("java -jar lib/closure-compiler-v20160911.jar --js \"{0}\" --js_output_file=\"{1}\"".format(output_file, output_file_tmp))
|
||||
@ -34,30 +36,44 @@ def build_tracker():
|
||||
|
||||
def build_renderer():
|
||||
output_file = "bld/render.html"
|
||||
input_file = "src/renderer/index.html"
|
||||
tmp_file = "bld/.tmp"
|
||||
input_html = "src/renderer/index.html"
|
||||
|
||||
input_css_pattern = "src/renderer/*.css"
|
||||
tmp_css_file_combined = "bld/render.tmp.css"
|
||||
tmp_css_file_minified = "bld/render.min.css"
|
||||
|
||||
with open(tmp_css_file_combined, "w") as out:
|
||||
combine_files(input_css_pattern, out)
|
||||
|
||||
os.system("java -jar lib/yuicompressor-2.4.8.jar --charset utf-8 --line-break 160 --type css -o \"{1}\" \"{0}\"".format(tmp_css_file_combined, tmp_css_file_minified))
|
||||
os.remove(tmp_css_file_combined)
|
||||
|
||||
input_js_pattern = "src/renderer/*.js"
|
||||
tmp_js_file_combined = "bld/render.tmp.js"
|
||||
tmp_js_file_minified = "bld/render.min.js"
|
||||
|
||||
with open(tmp_js_file_combined, "w") as out:
|
||||
combine_files(input_js_pattern, out)
|
||||
|
||||
os.system("java -jar lib/closure-compiler-v20160911.jar --js \"{0}\" --js_output_file=\"{1}\"".format(tmp_js_file_combined, tmp_js_file_minified))
|
||||
os.remove(tmp_js_file_combined)
|
||||
|
||||
tokens = {
|
||||
"/*{js}*/": "src/renderer/script.js",
|
||||
"/*{css}*/": "src/renderer/style.css"
|
||||
"/*{js}*/": tmp_js_file_minified,
|
||||
"/*{css}*/": tmp_css_file_minified
|
||||
}
|
||||
|
||||
with open(output_file, "w") as out:
|
||||
with open(input_file, "r") as fin:
|
||||
with open(input_html, "r") as fin:
|
||||
for line in fin:
|
||||
token = None
|
||||
|
||||
for token in (token for token in tokens if token in line):
|
||||
token_path = tokens[token]
|
||||
file_type = token_path.split("/")[-1].split(".")[-1]
|
||||
|
||||
os.system("java -jar lib/yuicompressor-2.4.8.jar --charset utf-8 --line-break 160 --type {2} -o \"{0}\" \"{1}\"".format(tmp_file, token_path, file_type))
|
||||
|
||||
with open(tmp_file, "r") as token_file:
|
||||
with open(tokens[token], "r") as token_file:
|
||||
embedded = token_file.read()
|
||||
|
||||
out.write(embedded)
|
||||
os.remove(tmp_file)
|
||||
os.remove(tokens[token])
|
||||
|
||||
if token is None:
|
||||
out.write(line)
|
||||
|
Loading…
x
Reference in New Issue
Block a user