From bfc07dd13637995192311003b34aa3f697c483fd Mon Sep 17 00:00:00 2001 From: kovacsv Date: Fri, 6 Aug 2021 13:49:50 +0200 Subject: [PATCH] Compress website css. --- package.json | 8 ++++++-- tools/build.py | 27 +++++++++++++++++++++------ 2 files changed, 27 insertions(+), 8 deletions(-) diff --git a/package.json b/package.json index 7c0e07a..9bbc450 100644 --- a/package.json +++ b/package.json @@ -5,6 +5,7 @@ "repository": "github:kovacsv/Online3DViewer", "license": "MIT", "devDependencies": { + "clean-css-cli": "^5.3.3", "eslint": "^7.30.0", "google-closure-compiler": "^20210302.0.0", "http-server": "^0.12.3", @@ -51,7 +52,10 @@ "no-multiple-empty-lines": "error", "comma-spacing": "error", "prefer-arrow-callback": "error", - "quotes": ["error", "single"], + "quotes": [ + "error", + "single" + ], "block-scoped-var": "error", "no-loop-func": "error", "no-undef": "error", @@ -59,5 +63,5 @@ "eqeqeq": "error", "no-unused-vars": "off" } - } + } } diff --git a/tools/build.py b/tools/build.py index a00fea7..dd3b51c 100644 --- a/tools/build.py +++ b/tools/build.py @@ -24,7 +24,18 @@ def ESLintFolder (folder): return False return True -def CompressFiles (inputFiles, outputFile): +def CompressCssFiles (inputFiles, outputFile): + parameters = ['-o', outputFile] + for inputFile in inputFiles: + extension = os.path.splitext (inputFile)[1] + if extension == '.css': + parameters.append (inputFile) + result = Tools.RunCommand ('cleancss', parameters) + if result != 0: + return False + return True + +def CompressJavascriptFiles (inputFiles, outputFile): parameters = [] for inputFile in inputFiles: extension = os.path.splitext (inputFile)[1] @@ -47,7 +58,6 @@ def CreateDestinationDir (config, rootDir, websiteDir, version, testBuild): shutil.copy2 (os.path.join (rootDir, 'website', 'index.html'), websiteDir) shutil.copy2 (os.path.join (rootDir, 'website', 'embed.html'), websiteDir) shutil.copy2 (os.path.join (rootDir, 'website', 'robots.txt'), websiteDir) - shutil.copy2 (os.path.join (rootDir, 'website', 'o3dv', 'website.css'), os.path.join (webSourcesDir, 'o3dv.website.css')) shutil.copytree (os.path.join (rootDir, 'libs'), os.path.join (websiteDir, 'libs')) shutil.copytree (os.path.join (rootDir, 'website', 'assets'), os.path.join (websiteDir, 'assets')) shutil.copytree (os.path.join (rootDir, 'website', 'info'), os.path.join (websiteDir, 'info')) @@ -55,7 +65,7 @@ def CreateDestinationDir (config, rootDir, websiteDir, version, testBuild): libFiles = config['lib_files'] importerFiles = ['o3dv/o3dv.min.js'] websiteFiles = [ - 'o3dv/o3dv.website.css', + 'o3dv/o3dv.website.min.css', 'o3dv/o3dv.website.min.js' ] @@ -97,7 +107,6 @@ def CreatePackage (rootDir, websiteDir, packageDir, version): libs = [ 'three.min-129.js', 'three.license.md' - ] externalLibs = [ 'draco_decoder.js', @@ -156,17 +165,23 @@ def Main (argv): CreateDestinationDir (config, rootDir, websiteDir, version, testBuild) PrintInfo ('Compress importer sources.') - compressResult = CompressFiles (config['engine_files'], os.path.join (websiteDir, 'o3dv', 'o3dv.min.js')) + compressResult = CompressJavascriptFiles (config['engine_files'], os.path.join (websiteDir, 'o3dv', 'o3dv.min.js')) if not compressResult: PrintError ('Compress importer sources failed.') return 1 PrintInfo ('Compress website sources.') - compressResult = CompressFiles (config['website_files_js'], os.path.join (websiteDir, 'o3dv', 'o3dv.website.min.js')) + compressResult = CompressJavascriptFiles (config['website_files_js'], os.path.join (websiteDir, 'o3dv', 'o3dv.website.min.js')) if not compressResult: PrintError ('Compress website sources failed.') return 1 + PrintInfo ('Compress website css sources.') + compressResult = CompressCssFiles (config['website_files_css'], os.path.join (websiteDir, 'o3dv', 'o3dv.website.min.css')) + if not compressResult: + PrintError ('Compress website css sources failed.') + return 1 + PrintInfo ('Create package.') packageResult = CreatePackage (rootDir, websiteDir, packageDir, version) if not packageResult: