Skip to content

Commit

Permalink
Merge branch 'melkati:development' into development
Browse files Browse the repository at this point in the history
  • Loading branch information
Coscolin authored Jun 8, 2024
2 parents 9be2a0a + 55b335c commit 893e60f
Show file tree
Hide file tree
Showing 38 changed files with 2,349 additions and 1,449 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/release3.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Release V2.93
name: Release V2.94

# # # # # # # # # # #
# To create new release, just push a new tag with the format v* (v1.0, v2.0, v2.1, v2.2, etc)
Expand Down Expand Up @@ -93,11 +93,12 @@ jobs:
run: |
# Define offset values based on env.CHIP_FAMILY
# SPIFFS at 0x370000 (3604480) for ESP32 and 0xc90000 (13172736) for ESP32-S3
if [[ "${{ env.CHIP_FAMILY }}" == "ESP32-S3" ]]; then
bootloader_offset=0
partitions_offset=32768
firmware_offset=65536
spiffs_offset=3604480
spiffs_offset=13172736
else
# Default values for ESP32 or other environments
bootloader_offset=4096
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/release3_beta.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Beta Release V2.93
name: Beta Release V2.94

# # # # # # # # # # #
# To create new Beta version and upload to the web server, just commit with a message with the format "Beta v*.*.*" (Beta v1.0.1, Beta v1.1.12, Beta v2.1.123, etc)
Expand Down Expand Up @@ -37,7 +37,6 @@ jobs:
- ttgo-t7-WEACT_GDEH0154D67
- ttgo-t7-WEACT_DEPG0213BN
- ttgo-t7-WEACT_GxEPD2_290_BS


env:
CHIP_FAMILY: ${{ matrix.environment == 'TDISPLAY_S3' && 'ESP32-S3' || 'ESP32' }}
Expand Down Expand Up @@ -112,11 +111,12 @@ jobs:
# spiffs, data, spiffs, 0x370000, 0x4B000, # spiffs partition at offset 3604480 with size 307200 bytes (476KB)
# Define offset values based on env.CHIP_FAMILY
# SPIFFS at 0x370000 (3604480) for ESP32 and 0xc90000 (13172736) for ESP32-S3
if [[ "${{ env.CHIP_FAMILY }}" == "ESP32-S3" ]]; then
bootloader_offset=0
partitions_offset=32768
firmware_offset=65536
spiffs_offset=3604480
spiffs_offset=13172736
else
# Default values for ESP32 or other environments
bootloader_offset=4096
Expand Down
2 changes: 1 addition & 1 deletion CO2_Gadget_Preferences.h
Original file line number Diff line number Diff line change
Expand Up @@ -587,7 +587,7 @@ String getActualSettingsAsJson(bool includePasswords = false) {
doc["firmBranch"] = firmBranch;
doc["firmFlavour"] = firmFlavour;
doc["customCalValue"] = customCalibrationValue;
doc["tempOffset"] = tempOffset;
doc["tempOffset"] = String(tempOffset, 1);
doc["altitudeMeters"] = altitudeMeters;
doc["autoSelfCal"] = autoSelfCalibration;
doc["co2OrangeRange"] = co2OrangeRange;
Expand Down
191 changes: 133 additions & 58 deletions CO2_Gadget_WIFI.h

Large diffs are not rendered by default.

150 changes: 150 additions & 0 deletions CompressCommonJavaScrip.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
param(
[switch]$DeleteMinifiedFiles
)

# Input and output directory paths
$sourceDirectory = "webserver"
$outputDirectory = "data"
$tempCombinedFileNew = "$sourceDirectory\temp_combined_new.js" # Temporary file for combined JavaScript
$javascriptCombinedOutputFileName = "combined.js.gz" # Compressed file name for the combined JavaScript

# Path to 7z.exe executable
$zipExecutable = "C:\Program Files\7-Zip\7z.exe"

Write-Host "Source Directory: $sourceDirectory"
Write-Host "Output Directory: $outputDirectory"

# Create the output directory if it doesn't exist
if (-not (Test-Path -Path $outputDirectory)) {
New-Item -ItemType Directory -Path $outputDirectory | Out-Null
}

Write-Host "Minifying HTML, CSS, and JavaScript files..."

# Initialize or clear the combined JavaScript file content
$combinedJavaScriptContent = @()

# Iterate over the files in the source directory
Get-ChildItem -Path $sourceDirectory | Where-Object { $_.Extension -in @(".html", ".css", ".js") -and $_.Name -notlike "*.gz" } | ForEach-Object {
$file = $_

switch -Wildcard ($file.Extension) {
"*.html" {
Write-Host "Processing HTML file: $($file.FullName)"
if ($file.Name -notlike "*.min.*") {
$intermediateFileName = "$($file.BaseName).min.html"
$outputFileName = "$($file.BaseName).html.gz"
html-minifier "$($file.FullName)" -o "$($sourceDirectory)\$intermediateFileName" --collapse-whitespace --minify-css true --minify-js true

if (Test-Path "$($outputDirectory)\$outputFileName") {
Remove-Item "$($outputDirectory)\$outputFileName" -ErrorAction SilentlyContinue
}

& $zipExecutable a -tgzip "$($outputDirectory)\$outputFileName" "$($sourceDirectory)\$intermediateFileName"
Remove-Item "$($sourceDirectory)\$intermediateFileName" -ErrorAction SilentlyContinue
} else {
Write-Host "File $($file.FullName) is already minified. Skipping..."
}
}
"*.css" {
Write-Host "Processing CSS file: $($file.FullName)"
if ($file.Name -notlike "*.min.*") {
$intermediateFileName = "$($file.BaseName).min.css"
$outputFileName = "$($file.BaseName).css.gz"
uglifycss "$($file.FullName)" --output "$($outputDirectory)\$intermediateFileName"

if (Test-Path "$($outputDirectory)\$outputFileName") {
Remove-Item "$($outputDirectory)\$outputFileName" -ErrorAction SilentlyContinue
}

& $zipExecutable a -tgzip "$($outputDirectory)\$outputFileName" "$($outputDirectory)\$intermediateFileName"
Remove-Item "$($outputDirectory)\$intermediateFileName" -ErrorAction SilentlyContinue
} else {
Write-Host "File $($file.FullName) is already minified. Skipping..."
}
}
"*.js" {
# Process JavaScript files
if ($file.Name -in @("common.js", "themes.js", "captiveportal.js", "captivePortalStatusBar.js", "serverStatusDot.js", "debugWindow.js") -and $file.Name -notlike "*.min.*") {
Write-Host "Adding JavaScript file: $($file.FullName)"
try {
# Add JavaScript content to the list
$combinedJavaScriptContent += Get-Content $file.FullName -Raw
} catch {
Write-Host "Error: Could not add JavaScript file $($file.FullName) to combined content: $_"
continue
}
} elseif ($file.Name -notlike "*.min.*") {
# Minify the JavaScript file
$minifiedFileName = "$($outputDirectory)\$($file.BaseName).min.js" # Full path to the minified file in the output directory
Write-Host "Minifying JavaScript file $($file.FullName) to $minifiedFileName..."
uglifyjs $file.FullName -o $minifiedFileName

if (Test-Path $minifiedFileName) {
# If minified file is created successfully, proceed with compression
$compressedFileName = "$($outputDirectory)\$($file.BaseName).js.gz"

Write-Host "Compressing minified JavaScript file to $compressedFileName..."

# Remove existing .gz file if it exists
if (Test-Path $compressedFileName) {
Remove-Item $compressedFileName -ErrorAction SilentlyContinue
}

# Compress the minified file using 7-Zip
& $zipExecutable a -tgzip $compressedFileName $minifiedFileName

Write-Host "Successfully compressed $($file.FullName) to $compressedFileName"

if ($DeleteMinifiedFiles) {
Remove-Item $minifiedFileName -ErrorAction SilentlyContinue
}
} else {
Write-Host "Failed to minify $($file.FullName) to $minifiedFileName"
}
}
else {
Write-Host "File $($file.FullName) is either already minified, not required, or is the combined file. Skipping..."
}
}
default {
Write-Host "File $($file.FullName) is not an HTML, CSS, or JavaScript file. Skipping..."
}
}
}

# Write the combined JavaScript content to the temporary file
try {
$combinedJavaScriptContent | Out-File -FilePath $tempCombinedFileNew -Encoding utf8 -ErrorAction Stop
} catch {
Write-Host "Error: Could not write combined JavaScript content to the temporary file: $_"
exit 1
}

# Minify the combined JavaScript
Write-Host "Minifying combined JavaScript file..."
uglifyjs $tempCombinedFileNew -o "$sourceDirectory\combined.min.js"

# Remove any existing .gz files for combined.js
if (Test-Path "$outputDirectory\$javascriptCombinedOutputFileName") {
Remove-Item "$outputDirectory\$javascriptCombinedOutputFileName" -ErrorAction SilentlyContinue
}

# Compress the minified JavaScript file directly to combined.js.gz
Write-Host "Compressing minified JavaScript file to $javascriptCombinedOutputFileName..."
& $zipExecutable a -tgzip "$outputDirectory\$javascriptCombinedOutputFileName" "$sourceDirectory\combined.min.js"

# Remove the temporary JavaScript file
Remove-Item $tempCombinedFileNew -ErrorAction SilentlyContinue

# Remove the combined.min.js file
Remove-Item "$sourceDirectory\combined.min.js" -ErrorAction SilentlyContinue

# If file exist, compress favicon.ico to the output directory
if (Test-Path "$sourceDirectory\favicon.ico") {
$outputFileName = "$outputDirectory\favicon.ico.gz"
Write-Host "Compressing favicon.ico to $outputFileName..."
& $zipExecutable a -tgzip "$outputFileName" "$sourceDirectory\favicon.ico"
}

Write-Host "Combination, minification, and compression process completed."
110 changes: 110 additions & 0 deletions CompressJavaScript.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
# Input and output directory paths
$sourceDirectory = "data"
$outputDirectory = "$sourceDirectory"
$tempCombinedFileNew = "$outputDirectory\temp_combined_new.js" # Temporary file for combined JavaScript
$javascriptCombinedOutputFileName = "combined.js.gz" # Compressed file name for the combined JavaScript

# Path to 7z.exe executable
$zipExecutable = "C:\Program Files\7-Zip\7z.exe"

Write-Host "Source Directory: $sourceDirectory"
Write-Host "Output Directory: $outputDirectory"

# Create the output directory if it doesn't exist
if (-not (Test-Path -Path $outputDirectory)) {
New-Item -ItemType Directory -Path $outputDirectory | Out-Null
}

Write-Host "Minifying HTML, CSS, and JavaScript files..."

# Initialize or clear the combined JavaScript file content
$combinedJavaScriptContent = @()

# Iterate over the files in the source directory
Get-ChildItem -Path $sourceDirectory | Where-Object { $_.Extension -in @(".html", ".css", ".js") -and $_.Name -notlike "*.gz" } | ForEach-Object {
$file = $_

switch -Wildcard ($file.Extension) {
"*.html" {
Write-Host "Processing HTML file: $($file.FullName)"
if ($file.Name -notlike "*.min.*") {
$intermediateFileName = "$($file.BaseName).min.html"
$outputFileName = "$($file.BaseName).html.gz"
html-minifier "$($file.FullName)" -o "$($outputDirectory)\$intermediateFileName" --collapse-whitespace --minify-css true --minify-js true

if (Test-Path "$($outputDirectory)\$outputFileName") {
Remove-Item "$($outputDirectory)\$outputFileName" -ErrorAction SilentlyContinue
}

& $zipExecutable a -tgzip "$($outputDirectory)\$outputFileName" "$($outputDirectory)\$intermediateFileName"
Remove-Item "$($outputDirectory)\$intermediateFileName" -ErrorAction SilentlyContinue
} else {
Write-Host "File $($file.FullName) is already minified. Skipping..."
}
}
"*.css" {
Write-Host "Processing CSS file: $($file.FullName)"
if ($file.Name -notlike "*.min.*") {
$intermediateFileName = "$($file.BaseName).min.css"
$outputFileName = "$($file.BaseName).css.gz"
uglifycss "$($file.FullName)" --output "$($outputDirectory)\$intermediateFileName"

if (Test-Path "$($outputDirectory)\$outputFileName") {
Remove-Item "$($outputDirectory)\$outputFileName" -ErrorAction SilentlyContinue
}

& $zipExecutable a -tgzip "$($outputDirectory)\$outputFileName" "$($outputDirectory)\$intermediateFileName"
Remove-Item "$($outputDirectory)\$intermediateFileName" -ErrorAction SilentlyContinue
} else {
Write-Host "File $($file.FullName) is already minified. Skipping..."
}
}
"*.js" {
# Process JavaScript files
if ($file.Name -notlike "*.min.*" -and $file.Name -ne "combined.js" -and $file.Name -ne "combined.min.js") {
Write-Host "Adding JavaScript file: $($file.FullName)"
try {
# Add JavaScript content to the list
$combinedJavaScriptContent += Get-Content $file.FullName -Raw
} catch {
Write-Host "Error: Could not add JavaScript file $($file.FullName) to combined content: $_"
continue
}
} else {
Write-Host "File $($file.FullName) is already minified or is the combined file. Skipping..."
}
}
default {
Write-Host "File $($file.FullName) is not an HTML, CSS, or JavaScript file. Skipping..."
}
}
}

# Write the combined JavaScript content to the temporary file
try {
$combinedJavaScriptContent | Out-File -FilePath $tempCombinedFileNew -Encoding utf8 -ErrorAction Stop
} catch {
Write-Host "Error: Could not write combined JavaScript content to the temporary file: $_"
exit 1
}

# Minify the combined JavaScript
Write-Host "Minifying combined JavaScript file..."
uglifyjs $tempCombinedFileNew -o "$outputDirectory\combined.min.js"

# Remove any existing .gz files for combined.js
if (Test-Path "$outputDirectory\$javascriptCombinedOutputFileName") {
Remove-Item "$outputDirectory\$javascriptCombinedOutputFileName" -ErrorAction SilentlyContinue
}

# Compress the minified JavaScript file directly to combined.js.gz
Write-Host "Compressing minified JavaScript file to $javascriptCombinedOutputFileName..."
& $zipExecutable a -tgzip "$outputDirectory\$javascriptCombinedOutputFileName" "$outputDirectory\combined.min.js"

# Remove the temporary JavaScript file
Remove-Item $tempCombinedFileNew -ErrorAction SilentlyContinue

# Remove the combined.min.js file
Remove-Item "$outputDirectory\combined.min.js" -ErrorAction SilentlyContinue

Write-Host "Combination, minification, and compression process completed."
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,16 @@ All the [contributors that helped improving CO2 Gadget](https://github.com/melka
<img src="https://contrib.rocks/image?repo=melkati/CO2-Gadget" />
</a>


# ⭐ Please star this project

If you like this project, please give it a star on GitHub!

[![GitHub stars](https://img.shields.io/github/stars/melkati/CO2-Gadget?style=social)](https://github.com/melkati/CO2-Gadget/stargazers)

If you read this far, would you please star this repository?
It will help other people find it. Thanks!

---
## License

Expand Down
Loading

0 comments on commit 893e60f

Please sign in to comment.