update buildscript
This commit is contained in:
parent
b4177c9b0f
commit
f966f2df14
1
Software/.gitignore
vendored
1
Software/.gitignore
vendored
@ -1,5 +1,6 @@
|
||||
data/
|
||||
data_src/version
|
||||
node_modules/
|
||||
.pio
|
||||
.vscode/.browse.c_cpp.db*
|
||||
.vscode/c_cpp_properties.json
|
||||
|
@ -1,4 +1,3 @@
|
||||
import glob
|
||||
import shutil
|
||||
import gzip
|
||||
import os
|
||||
@ -8,23 +7,40 @@ from os import popen
|
||||
Import("env")
|
||||
Import("projenv")
|
||||
|
||||
# Überprüfe die Betriebssystemplattform
|
||||
if platform.system() == "Windows":
|
||||
# Setze die Pfade zu den Tools für Windows
|
||||
html_minifier_path = os.path.join(os.getenv("APPDATA"), "npm", "html-minifier.cmd")
|
||||
uglifyjs_path = os.path.join(os.getenv("APPDATA"), "npm", "uglifyjs.cmd")
|
||||
terser_path = os.path.join(os.getenv("APPDATA"), "npm", "terser.cmd")
|
||||
cssnano_path = os.path.join(os.getenv("APPDATA"), "npm", "cssnano.cmd")
|
||||
elif platform.system() == "Linux":
|
||||
# Setze die Namen der Tools für Linux
|
||||
html_minifier_path = "html-minifier"
|
||||
uglifyjs_path = "uglifyjs"
|
||||
terser_path = "terser"
|
||||
cssnano_path = "cssnano"
|
||||
else:
|
||||
# Hier könntest du weitere Bedingungen für andere Betriebssysteme hinzufügen
|
||||
raise Exception("Unterstütztes Betriebssystem nicht erkannt")
|
||||
def resolve_tool(name):
|
||||
local_bin = os.path.join(env['PROJECT_DIR'], 'node_modules', '.bin', name)
|
||||
if platform.system() == "Windows":
|
||||
local_bin += ".cmd"
|
||||
if os.path.exists(local_bin):
|
||||
return local_bin
|
||||
|
||||
found = shutil.which(name)
|
||||
if found:
|
||||
return found
|
||||
|
||||
raise FileNotFoundError(f"{name} wurde nicht gefunden. Bitte `npm install` ausführen.")
|
||||
|
||||
def ensure_npm_dependencies():
|
||||
node_modules_bin = os.path.join(env['PROJECT_DIR'], 'node_modules', '.bin')
|
||||
required_tools = ["html-minifier", "terser", "cleancss"]
|
||||
missing = False
|
||||
|
||||
for tool in required_tools:
|
||||
path = os.path.join(node_modules_bin, tool + ('.cmd' if platform.system() == "Windows" else ''))
|
||||
if not os.path.exists(path):
|
||||
missing = True
|
||||
break
|
||||
|
||||
if missing:
|
||||
print("NPM-Abhängigkeiten fehlen – führe `npm install` aus...")
|
||||
subprocess.run(["npm", "install"], cwd=env['PROJECT_DIR'], check=True)
|
||||
|
||||
|
||||
ensure_npm_dependencies()
|
||||
|
||||
html_minifier_path = resolve_tool("html-minifier")
|
||||
terser_path = resolve_tool("terser")
|
||||
cleancss_path = resolve_tool("cleancss")
|
||||
|
||||
def minify_html(input_path, output_path):
|
||||
subprocess.run([html_minifier_path, '--collapse-whitespace', '--remove-comments', input_path, '-o', output_path])
|
||||
@ -33,7 +49,7 @@ def minify_js(input_path, output_path):
|
||||
subprocess.run([terser_path, input_path, '-o', output_path, '-c', '-m'])
|
||||
|
||||
def minify_css(input_path, output_path):
|
||||
subprocess.run([cssnano_path, '--no-discardUnused', input_path, output_path])
|
||||
subprocess.run([cleancss_path, '--no-discardUnused', input_path, output_path])
|
||||
|
||||
def process_file(src_path, dest_path):
|
||||
_, file_extension = os.path.splitext(src_path)
|
||||
@ -152,7 +168,8 @@ def gzip_webfiles(source, target, env):
|
||||
target_file_path = data_dir_path + filename_subdir
|
||||
os.makedirs(os.path.dirname(target_file_path), exist_ok=True)
|
||||
print('GZIP: Compressed... ' + target_file_path)
|
||||
gzip_file(source_file_path, target_file_path + ".gz")
|
||||
gzip_target_path = target_file_path + ".gz"
|
||||
gzip_file(source_file_path, gzip_target_path)
|
||||
except IOError as e:
|
||||
was_error = True
|
||||
print('GZIP: Failed to compress file: ' + source_file_path)
|
||||
|
9
Software/package.json
Normal file
9
Software/package.json
Normal file
@ -0,0 +1,9 @@
|
||||
{
|
||||
"name": "pio-build-tools",
|
||||
"private": true,
|
||||
"devDependencies": {
|
||||
"html-minifier": "^4.0.0",
|
||||
"terser": "^5.0.0",
|
||||
"clean-css-cli": "^5.0.0"
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user