Skip to content

Commit 291da42

Browse files
Updates
1 parent 447c111 commit 291da42

File tree

6 files changed

+100
-5
lines changed

6 files changed

+100
-5
lines changed

data/codes.json

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,5 +140,25 @@
140140
"crashed": false,
141141
"link": ""
142142
}
143+
],
144+
"redirect/checks.sh": [
145+
{
146+
"code": "0114",
147+
"message": "Missing \"url\" in \"redirect_config\" in \"module.exports\" at \"just.config.js\" file.",
148+
"crashed": true,
149+
"link": ""
150+
},
151+
{
152+
"code": "0115",
153+
"message": "( MISSING URL IN {} IN PATHS[] IN REDIRECT_CONFIG{} IN MODULE.EXPORTS AT JUST.CONFIG.JS )",
154+
"crashed": true,
155+
"link": ""
156+
},
157+
{
158+
"code": "0116",
159+
"message": "( MISSING PATH_ IN {} IN PATHS[] IN REDIRECT_CONFIG{} IN MODULE.EXPORTS AT JUST.CONFIG.JS )",
160+
"crashed": true,
161+
"link": ""
162+
}
143163
]
144164
}

src/compress.js

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,20 @@ const deployDir = process.argv[2] || __dirname;
3232
function compressFile(filePath) {
3333
let content = fs.readFileSync(filePath, 'utf8');
3434

35-
if (filePath.endsWith('.js')) {
35+
if (filePath.endsWith('.js') || filePath.endsWith('.css')) {
3636
content = content.replace(/(?<!["'`][\s\S]*)\/\/.*\n/g, '\n')
37-
.replace(/(?<!['"`][\s\S]*)\btrue\b(?!['"`][\s\S]*)/g, '!![]')
38-
.replace(/(?<!['"`][\s\S]*)\bfalse\b(?!['"`][\s\S]*)/g, '![]')
39-
.replace(/(?<!['"`][\s\S]*)\bundefined\b(?!['"`][\s\S]*)/g, '[][[]]');
37+
.replace(/\/\*[\s\S]*?\*\//g, '');
38+
}
39+
40+
if (filePath.endsWith('.html') || filePath.endsWith('.svg')) {
41+
content = content.replace(/<!--[\s\S]*?-->/g, '');
42+
}
43+
44+
if (filePath.endsWith('.js')) {
45+
content = content
46+
.replace(/(?<!['"`][\s\S]*)\btrue\b(?!['"`][\s\S]*)/g, '!![]')
47+
.replace(/(?<!['"`][\s\S]*)\bfalse\b(?!['"`][\s\S]*)/g, '![]')
48+
.replace(/(?<!['"`][\s\S]*)\bundefined\b(?!['"`][\s\S]*)/g, '[][[]]');
4049
}
4150

4251
content = content.replace(/(\s*["'`])([^"'\n`]*)(["'`]\s*)/g, (match, p1, p2, p3) => {

src/modules/errmsg.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,5 +41,9 @@ _justMessage() {
4141
echo -e "$NEWLINES $ERROR_PREFIX: INFO: $MESSAGE $NEWLINES"
4242
}
4343

44+
customErrorMessage() {
45+
echo -e "$NEWLINES $ERROR_PREFIX: $1 $2: $3 $NEWLINES"
46+
}
47+
4448
export -f ErrorMessage
4549
export -f _justMessage

src/postprocessor/build_map.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ find deploy -mindepth 1 -print | while read -r path; do
121121

122122
esac
123123
file_size=$(stat -c%s "$path")
124-
TOTAL_SIZE=$((TOTAL_SIZE + $file_size))
124+
TOTAL_SIZE=$((TOTAL_SIZE + $((file_size))))
125125

126126
if [ "$FILE_ID" -eq 1 ]; then
127127
printf "┌ %s | %s\n" "$(human_readable_size $file_size)" "$relative_path"

src/redirect/checks.sh

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# MIT License
2+
#
3+
# Copyright (c) 2025 JustDeveloper <https://justdeveloper.is-a.dev/>
4+
#
5+
# Permission is hereby granted, free of charge, to any person obtaining a copy
6+
# of this software and associated documentation files (the "Software"), to deal
7+
# in the Software without restriction, including without limitation the rights
8+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
# copies of the Software, and to permit persons to whom the Software is
10+
# furnished to do so, subject to the following conditions:
11+
#
12+
# The above copyright notice and this permission notice shall be included in all
13+
# copies or substantial portions of the Software.
14+
#
15+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
# SOFTWARE.
22+
23+
#!/bin/bash
24+
source $GITHUB_ACTION_PATH/src/modules/errmsg.sh
25+
config=$(cat just.config.json)
26+
27+
local redirect_config_=$(echo "$config" | jq -r '.redirect_config')
28+
if ! echo "$config" | jq -e '.redirect_config' > /dev/null; then
29+
local ERROR_MESSAGE=($(ErrorMessage "redirect/checks.sh" "0117"))
30+
echo $ERROR_MESSAGE && exit 1
31+
fi
32+
33+
validate_redirect_config() {
34+
local url=$(echo "$config" | jq -r '.redirect_config.url' > /dev/null)
35+
if [[ -z "$url" ]]; then
36+
local ERROR_MESSAGE=($(ErrorMessage "redirect/checks.sh" "0114"))
37+
echo $ERROR_MESSAGE && exit 1
38+
fi
39+
}
40+
41+
validate_paths() {
42+
local paths=$(echo "$config" | jq -c '.redirect_config.paths[]?')
43+
if [[ -n "$paths" ]]; then
44+
local countt=0
45+
for path in $paths; do
46+
local url=$(echo "$path" | jq -r '.url')
47+
local path_=$(echo "$path" | jq -r '.path_')
48+
if [[ -z "$url"]]; then
49+
local ERROR_MESSAGE=($(customErrorMessage "Error" "0115" "Missing \"url\" in item #$countt in \"paths\" in \"redirect_config\" in \"module.exports\" at \"just.config.js\" file."))
50+
echo $ERROR_MESSAGE && exit 1
51+
elif [[ -z "$path_" ]]; then
52+
local ERROR_MESSAGE=($(customErrorMessage "Error" "0116" "Missing \"path_\" in item #$countt in \"paths\" in \"redirect_config\" in \"module.exports\" at \"just.config.js\" file."))
53+
echo $ERROR_MESSAGE && exit 1
54+
fi
55+
countt=$((countt + 1))
56+
done
57+
fi
58+
}
59+
60+
validate_redirect_config
61+
validate_paths

src/run.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ if [ "$TYPE" == "postprocessor" ]; then
117117
elif [ "$TYPE" == "redirector" ]; then
118118
mkdir -p deploy/_just
119119
installNodejs && \
120+
bash $GITHUB_ACTION_PATH/src/redirect/checks.sh && \
120121
node $GITHUB_ACTION_PATH/src/redirect/index.js && \
121122
echo $msg5
122123
elif [ "$TYPE" == "compressor" ]; then

0 commit comments

Comments
 (0)