Skip to content

Commit e3e50e1

Browse files
Updates
1 parent 3faff01 commit e3e50e1

File tree

6 files changed

+133
-24
lines changed

6 files changed

+133
-24
lines changed

data/codes.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
},
5151
{
5252
"code": "0111",
53-
"message": "Invalid value of property \"type\" in just.config.js. It must be one of: \"postprocessor\", \"redirect\".",
53+
"message": "Invalid value of property \"type\" in just.config.js. It must be one of: \"postprocessor\", \"redirector\", \"compressor\".",
5454
"crashed": true,
5555
"link": ""
5656
},

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "just",
3-
"version": "0.0.25",
3+
"version": "0.0.27",
44
"description": "Just an Ultimate Site Tool (W.I.P.)",
55
"main": "index.sh",
66
"scripts": {

src/compress.js

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
/*
2+
3+
MIT License
4+
5+
Copyright (c) 2025 JustDeveloper <https://justdeveloper.is-a.dev/>
6+
7+
Permission is hereby granted, free of charge, to any person obtaining a copy
8+
of this software and associated documentation files (the "Software"), to deal
9+
in the Software without restriction, including without limitation the rights
10+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11+
copies of the Software, and to permit persons to whom the Software is
12+
furnished to do so, subject to the following conditions:
13+
14+
The above copyright notice and this permission notice shall be included in all
15+
copies or substantial portions of the Software.
16+
17+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23+
SOFTWARE.
24+
25+
*/
26+
27+
const fs = require('fs');
28+
const path = require('path');
29+
30+
const deployDir = process.argv[2] || __dirname;
31+
32+
function compressFile(filePath) {
33+
let content = fs.readFileSync(filePath, 'utf8');
34+
35+
if (filePath.endsWith('.js')) {
36+
content = content.replace(/\/\/.*\n/g, '\n');
37+
}
38+
39+
content = content.replace(/(\s*["'`])([^"'\n`]*)(["'`]\s*)/g, (match, p1, p2, p3) => {
40+
return p1 + p2.replace(/\s+/g, ' ') + p3;
41+
});
42+
43+
content = content.replace(/\n\s*/g, ' ').replace(/\s+/g, ' ');
44+
45+
if (filePath.endsWith('.css') || filePath.endsWith('.js')) {
46+
content = content.replace(/;\s*}/g, '}').replace(/;\s*$/, '');
47+
}
48+
49+
if (filePath.endsWith('.js') || filePath.endsWith('.json') || filePath.endsWith('.webmanifest')) {
50+
content = content.replace(/,\s*}/g, '}').replace(/,\s*]}/g, ']');
51+
}
52+
53+
fs.writeFileSync(filePath, content, 'utf8');
54+
}
55+
56+
function findAndCompressFiles(dir) {
57+
fs.readdirSync(dir).forEach(file => {
58+
const filePath = path.join(dir, file);
59+
const stat = fs.statSync(filePath);
60+
if (stat.isDirectory()) {
61+
findAndCompressFiles(filePath);
62+
} else if (
63+
file.endsWith('.html') ||
64+
file.endsWith('.svg') ||
65+
file.endsWith('.css') ||
66+
file.endsWith('.js') ||
67+
file.endsWith('.json') ||
68+
file.endsWith('.webmanifest')
69+
) {
70+
compressFile(filePath);
71+
}
72+
});
73+
}
74+
75+
findAndCompressFiles(deployDir);

src/modules/errmsg.sh

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#!/bin/bash
2424
ERRORS_FILE="$GITHUB_ACTION_PATH/data/codes.json"
2525
ERROR_PREFIX="Just an Ultimate Site Tool"
26+
_N_="\n\n\n\n"
2627

2728
ErrorMessage() {
2829
local ERROR_CODE=$2
@@ -32,7 +33,12 @@ ErrorMessage() {
3233
if [[ $ERROR_CODE == 02* ]]; then
3334
ERROR_TYPE="Warning"
3435
fi
35-
echo -e "\n\n\n\n$ERROR_PREFIX: $ERROR_TYPE $ERROR_CODE: $ERROR_MESSAGE $ERROR_LINK\n\n\n\n"
36+
echo -e "$_N_ $ERROR_PREFIX: $ERROR_TYPE $ERROR_CODE: $ERROR_MESSAGE $ERROR_LINK $_N_"
37+
}
38+
39+
Message() {
40+
local MESSAGE=$1
41+
echo -e "$_N_ $ERROR_PREFIX: INFO: $MESSAGE $_N_"
3642
}
3743

3844
export -f ErrorMessage

src/redirect/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/*
2+
23
MIT License
34
45
Copyright (c) 2025 JustDeveloper <https://justdeveloper.is-a.dev/>
@@ -20,6 +21,7 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
2021
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
2122
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2223
SOFTWARE.
24+
2325
*/
2426

2527
const template = {

src/run.sh

Lines changed: 47 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,31 @@
2424
ERRORS_FILE="$GITHUB_ACTION_PATH/data/codes.json"
2525
CONFIG_FILE="just.config.js"
2626
CONFIG_DATA="just.config.json"
27-
2827
source $GITHUB_ACTION_PATH/src/modules/errmsg.sh
2928

29+
VERSION=$(echo "$GITHUB_ACTION_PATH" | grep -oP '(?<=/v)[0-9]+\.[0-9]+\.[0-9]+(-[a-zA-Z0-9]+)?')
30+
msg1=($(Message "Running Just an Ultimate Site Tool v$VERSION"))
31+
msg2=($(Message "Installing Node.js"))
32+
msg3=($(Message "Installed Node.js"))
33+
msg4=($(Message "Postprocessing completed"))
34+
msg5=($(Message "Generating completed"))
35+
msg6=($(Message "Compressing completed"))
36+
echo $msg1
37+
38+
installNodejs() {
39+
echo $msg2
40+
sudo apt update -qq && sudo apt install -y nodejs npm > /dev/null 2>&1
41+
if [ $? -ne 0 ]; then
42+
local ERROR_MESSAGE=($(ErrorMessage "run.sh" "0205"))
43+
echo $ERROR_MESSAGE
44+
sudo apt update
45+
sudo apt install -y nodejs npm && \
46+
echo $msg3
47+
elif
48+
echo $msg3
49+
fi
50+
}
51+
3052
if [ -f "$CONFIG_DATA" ]; then
3153
local ERROR_MESSAGE=($(ErrorMessage "run.sh" "0113"))
3254
echo $ERROR_MESSAGE && exit 1
@@ -56,21 +78,23 @@ if [ -z "$TYPE" ]; then
5678
echo $ERROR_MESSAGE && exit 1
5779
fi
5880

59-
if [[ "$TYPE" != "postprocessor" && "$TYPE" != "redirect" ]]; then
81+
if [[ "$TYPE" != "postprocessor" && "$TYPE" != "redirector" && "$TYPE" != "compressor" ]]; then
6082
local ERROR_MESSAGE=($(ErrorMessage "run.sh" "0111"))
6183
echo $ERROR_MESSAGE && exit 1
6284
fi
6385

64-
if [ -d "deploy" ]; then
65-
local ERROR_MESSAGE=($(ErrorMessage "important_dirs" "0106"))
66-
echo $ERROR_MESSAGE && exit 1
67-
fi
68-
if [ -d "_just_data" ]; then
69-
local ERROR_MESSAGE=($(ErrorMessage "important_dirs" "0107"))
70-
echo $ERROR_MESSAGE && exit 1
86+
if [ "$TYPE" != "compressor" ]; then
87+
if [ -d "deploy" ]; then
88+
local ERROR_MESSAGE=($(ErrorMessage "important_dirs" "0106"))
89+
echo $ERROR_MESSAGE && exit 1
90+
fi
91+
if [ -d "_just_data" ]; then
92+
local ERROR_MESSAGE=($(ErrorMessage "important_dirs" "0107"))
93+
echo $ERROR_MESSAGE && exit 1
94+
fi
95+
mkdir -p deploy
96+
mkdir -p _just_data
7197
fi
72-
mkdir -p deploy
73-
mkdir -p _just_data
7498

7599
if [ "$TYPE" == "postprocessor" ]; then
76100
set -e
@@ -88,15 +112,17 @@ if [ "$TYPE" == "postprocessor" ]; then
88112
bash $GITHUB_ACTION_PATH/src/postprocessor/create_api_endpoints.sh && \
89113
bash $GITHUB_ACTION_PATH/src/postprocessor/modify_deployment.sh && \
90114
bash $GITHUB_ACTION_PATH/src/postprocessor/override_deployment.sh && \
91-
bash $GITHUB_ACTION_PATH/src/postprocessor/build_map.sh
92-
elif [ "$TYPE" == "redirect" ]; then
115+
installNodejs && \
116+
node $GITHUB_ACTION_PATH/src/compress.js "deploy" && \
117+
bash $GITHUB_ACTION_PATH/src/postprocessor/build_map.sh && \
118+
echo $msg4
119+
elif [ "$TYPE" == "redirector" ]; then
93120
mkdir -p deploy/_just
94-
sudo apt update -qq && sudo apt install -y nodejs npm > /dev/null 2>&1
95-
if [ $? -ne 0 ]; then
96-
local ERROR_MESSAGE=($(ErrorMessage "run.sh" "0205"))
97-
echo $ERROR_MESSAGE
98-
sudo apt update
99-
sudo apt install -y nodejs npm
100-
fi
101-
node $GITHUB_ACTION_PATH/src/redirect/index.js
121+
installNodejs && \
122+
node $GITHUB_ACTION_PATH/src/redirect/index.js && \
123+
echo $msg5
124+
elif [ "$TYPE" == "compressor" ]; then
125+
installNodejs && \
126+
node $GITHUB_ACTION_PATH/src/compress.js && \
127+
echo $msg6
102128
fi

0 commit comments

Comments
 (0)