Skip to content

Commit 7e2cfc9

Browse files
Updates
1 parent 48bd064 commit 7e2cfc9

File tree

9 files changed

+123
-81
lines changed

9 files changed

+123
-81
lines changed

data/codes.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
{
22
"README": {
33
" CODES ": {
4-
" OK ": " 0000 - 0099 ",
5-
" CRASH ": " 0100 - 0199 ",
6-
" WARNING ": " 0200 - 0299 "
4+
" OK ": " 0000 - 0099 ",
5+
" CRASH ": " 0100 - 0199 ",
6+
" WARNING ": " 0200 - 0299 ",
7+
" RESERVED ": " 0299 - 9999 "
78
}
89
},
910
"important_dirs": [

src/modules/errmsg.sh

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
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+
ERRORS_FILE="$GITHUB_ACTION_PATH/data/codes.json"
25+
26+
ErrorMessage() {
27+
local ERROR_CODE=$2
28+
local ERROR_MESSAGE=${3:-$(jq -r ".[\"$1\"][] | select(.code==\"$ERROR_CODE\") | .message" "$ERRORS_FILE")}
29+
local ERROR_LINK=$(jq -r ".[\"$1\"][] | select(.code==\"$ERROR_CODE\") | .link" "$ERRORS_FILE")
30+
echo -e "\n\n\n\nError $ERROR_CODE: $ERROR_MESSAGE $ERROR_LINK"
31+
}
32+
33+
export -f ErrorMessage

src/modules/string.sh

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
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+
generate_strings() {
25+
local count=$1
26+
local length=$2
27+
local chars="qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM1234567890-_"
28+
for ((i=0; i<count; i++)); do
29+
local random_string=""
30+
for ((j=0; j<length; j++)); do
31+
random_string+="${chars:RANDOM%32:1}"
32+
done
33+
echo "$random_string"
34+
done
35+
}
36+
37+
export -f generate_strings

src/postprocessor/build_map.sh

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,18 +27,7 @@ mkdir -p deploy/_just/static/
2727
mkdir -p deploy/_just/static/$BUILD_ID/
2828
mkdir -p deploy/_just/static/chunks/
2929

30-
generate_strings() {
31-
local count=$1
32-
local length=$2
33-
local chars="qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM1234567890-_"
34-
for ((i=0; i<count; i++)); do
35-
local random_string=""
36-
for ((j=0; j<length; j++)); do
37-
random_string+="${chars:RANDOM%32:1}"
38-
done
39-
echo "$random_string"
40-
done
41-
}
30+
source $GITHUB_ACTION_PATH/src/modules/string.sh
4231

4332
random_strings=($(generate_strings 1 16))
4433
clearCache_name=${random_strings[0]}c

src/postprocessor/checks.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ for dir in "_just" "_just/js" "_just/style"; do
3131
echo -e " ? (root)/_just/404.html\n"
3232
echo -e "End _just Checks\n"
3333
echo -e "----------------\n"
34-
echo "Error: The $dir directory is missing. Please create it to proceed." >&2
34+
echo "The $dir directory is missing." >&2
3535
exit 1
3636
fi
3737
done
@@ -44,7 +44,7 @@ if [ ! -f "_just/404.html" ]; then
4444
echo -e " ✕ (root)/_just/404.html\n"
4545
echo -e "End _just Checks\n"
4646
echo -e "----------------\n"
47-
echo "Error: The _just/404.html file is missing." >&2
47+
echo "0101" >&2
4848
exit 1
4949
fi
5050

src/postprocessor/modify_deployment.sh

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,6 @@
2222

2323
# Modify Deployment
2424

25-
if [ -d "deploy/_just" ]; then
26-
echo "Error: Your website has a _just directory in the root. Please remove it to proceed." >&2
27-
exit 1
28-
fi
2925
if [ -d "_just/dangerously-insert-files/_just" ]; then
3026
echo "Error: Inserting files in _just directory is not allowed." >&2
3127
exit 1
@@ -35,21 +31,9 @@ if [ -d "_just/dangerously-insert-files/_next" ]; then
3531
exit 1
3632
fi
3733

38-
mkdir -p deploy/_just/
3934
echo -e "\n----------------\n\n_just Chunks:\n"
4035

41-
generate_strings() {
42-
local count=$1
43-
local length=$2
44-
local chars="qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM1234567890-_"
45-
for ((i=0; i<count; i++)); do
46-
local random_string=""
47-
for ((j=0; j<length; j++)); do
48-
random_string+="${chars:RANDOM%32:1}"
49-
done
50-
echo "$random_string"
51-
done
52-
}
36+
source $GITHUB_ACTION_PATH/src/modules/string.sh
5337

5438
mkdir -p _just/dangerously-insert-files/_just/
5539
merged_data=($(generate_strings 1 16))

src/postprocessor/prepare_deployment.sh

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,6 @@
2222

2323
# Prepare Deployment
2424

25-
if [ -d "deploy" ]; then
26-
echo "Error: Your repository has a deploy directory in the root. Please remove it to proceed." >&2
27-
exit 1
28-
fi
29-
if [ -d "_just_data" ]; then
30-
echo "Error: Your repository has a _just_data directory in the root. Please remove it to proceed." >&2
31-
exit 1
32-
fi
33-
mkdir -p deploy
34-
mkdir -p _just_data
3525
cp -r .next/server/pages/* deploy/
3626
mkdir -p deploy/_next/static/
3727
cp -r .next/static/* deploy/_next/static/

src/redirect/index.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,11 @@ const generatePage = (url, title, path_) => {
3737
<meta charset="UTF-8">
3838
<meta name="viewport" content="width=device-width, initial-scale=1.0">
3939
<title>${title}</title>
40-
<link rel="stylesheet" href="${page}.css">
40+
<link rel="stylesheet" href="/_just/${page}.css">
4141
</head>
4242
<body>
4343
<h1>${title}</h1>
44-
<script src="${page}.js"></script>
44+
<script src="/_just/${page}.js"></script>
4545
</body>
4646
</html>
4747
`;
@@ -55,14 +55,14 @@ const generatePage = (url, title, path_) => {
5555
}
5656
`;
5757

58-
fs.writeFileSync(`deploy/${page}.css`, cssContent);
58+
fs.writeFileSync(`deploy/_just/${page}.css`, cssContent);
5959

6060
const jsContent = `
6161
console.log('Redirecting to ${url}');
6262
window.location.href = '${url}';
6363
`;
6464

65-
fs.writeFileSync(`deploy/${page}.js`, jsContent);
65+
fs.writeFileSync(`deploy/_just/${page}.js`, jsContent);
6666
};
6767

6868
generatePage(redirectConfig.url, redirectConfig.title);

src/run.sh

Lines changed: 41 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -25,63 +25,71 @@ ERRORS_FILE="$GITHUB_ACTION_PATH/data/codes.json"
2525
CONFIG_FILE="just.config.js"
2626
CONFIG_DATA="just.config.json"
2727

28-
ErrorMessage() {
29-
local ERROR_CODE=$1
30-
local ERROR_MESSAGE=$(jq -r ".[\"run.sh\"][] | select(.code==\"$ERROR_CODE\") | .message" "$ERRORS_FILE")
31-
local ERROR_LINK=$(jq -r '.["run.sh"][] | select(.code=="0108") | .link' "$ERRORS_FILE")
32-
echo -e "\n\n\n\nError $ERROR_CODE: $ERROR_MESSAGE $ERROR_LINK"
33-
}
28+
source $GITHUB_ACTION_PATH/src/modules/errmsg.sh
3429

3530
if [ -f "$CONFIG_DATA" ]; then
36-
local ERROR_MESSAGE=($(ErrorMessage "0113"))
31+
local ERROR_MESSAGE=($(ErrorMessage "run.sh" "0113"))
3732
echo $ERROR_MESSAGE && exit 1
3833
fi
3934

4035
if [ ! -f "$CONFIG_FILE" ]; then
41-
ERROR_CODE="0108"
42-
ERROR_MESSAGE=$(jq -r ".[\"run.sh\"][] | select(.code==\"$ERROR_CODE\") | .message" "$ERRORS_FILE")
43-
ERROR_LINK=$(jq -r '.["run.sh"][] | select(.code=="0108") | .link' "$ERRORS_FILE")
44-
echo "Error $ERROR_CODE: $ERROR_MESSAGE $ERROR_LINK"
45-
exit 1
36+
local ERROR_MESSAGE=($(ErrorMessage "run.sh" "0108"))
37+
echo $ERROR_MESSAGE && exit 1
4638
fi
4739

4840
CONFIG_JSON=$(node -e "console.log(JSON.stringify(require('./just.config.js')));")
4941
if [ $? -ne 0 ]; then
50-
ERROR_MESSAGE=$(jq -r '.["run.sh"][] | select(.code=="0109") | .message' "$ERRORS_FILE")
51-
ERROR_CODE="0109"
52-
ERROR_LINK=$(jq -r '.["run.sh"][] | select(.code=="0109") | .link' "$ERRORS_FILE")
53-
echo "Error $ERROR_CODE: $ERROR_MESSAGE $ERROR_LINK"
54-
exit 1
42+
local ERROR_MESSAGE=($(ErrorMessage "run.sh" "0109"))
43+
echo $ERROR_MESSAGE && exit 1
5544
fi
5645
echo "Parsed CONFIG_JSON: $CONFIG_JSON" # debug
46+
echo "$CONFIG_JSON" > "$CONFIG_DATA"
5747

5848
if [ -z "$(echo "$CONFIG_JSON" | jq -r '.module.exports')" ]; then
59-
ERROR_MESSAGE=$(jq -r '.["run.sh"][] | select(.code=="0112") | .message' "$ERRORS_FILE")
60-
ERROR_CODE="0112"
61-
ERROR_LINK=$(jq -r '.["run.sh"][] | select(.code=="0112") | .link' "$ERRORS_FILE")
62-
echo "Error $ERROR_CODE: $ERROR_MESSAGE $ERROR_LINK"
63-
exit 1
49+
local ERROR_MESSAGE=($(ErrorMessage "run.sh" "0112"))
50+
echo $ERROR_MESSAGE && exit 1
6451
fi
6552

6653
TYPE=$(echo "$CONFIG_JSON" | jq -r '.type')
6754
if [ -z "$TYPE" ]; then
68-
ERROR_MESSAGE=$(jq -r '.["run.sh"][] | select(.code=="0110") | .message' "$ERRORS_FILE")
69-
ERROR_CODE="0110"
70-
ERROR_LINK=$(jq -r '.["run.sh"][] | select(.code=="0110") | .link' "$ERRORS_FILE")
71-
echo "Error $ERROR_CODE: $ERROR_MESSAGE $ERROR_LINK"
72-
exit 1
55+
local ERROR_MESSAGE=($(ErrorMessage "run.sh" "0110"))
56+
echo $ERROR_MESSAGE && exit 1
7357
fi
7458

7559
if [[ "$TYPE" != "postprocessor" && "$TYPE" != "redirect" ]]; then
76-
ERROR_MESSAGE=$(jq -r '.["run.sh"][] | select(.code=="0111") | .message' "$ERRORS_FILE")
77-
ERROR_CODE="0111"
78-
ERROR_LINK=$(jq -r '.["run.sh"][] | select(.code=="0111") | .link' "$ERRORS_FILE")
79-
echo "Error $ERROR_CODE: $ERROR_MESSAGE $ERROR_LINK (Got \"$TYPE\")"
80-
exit 1
60+
local ERROR_MESSAGE=($(ErrorMessage "run.sh" "0111"))
61+
echo $ERROR_MESSAGE && exit 1
62+
fi
63+
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
71+
fi
72+
mkdir -p deploy
73+
mkdir -p _just_data
74+
75+
if [ -d "deploy/_just" ]; then
76+
local ERROR_MESSAGE=($(ErrorMessage "postprocessor/modify_deployment.sh" "0103"))
77+
echo $ERROR_MESSAGE && exit 1
8178
fi
79+
mkdir -p deploy/_just/
8280

8381
if [ "$TYPE" == "postprocessor" ]; then
84-
bash $GITHUB_ACTION_PATH/src/postprocessor/checks.sh && \
82+
set -e
83+
postprocessor_checks=$(bash $GITHUB_ACTION_PATH/src/postprocessor/checks.sh 2>&1) || {
84+
local error_code=$?
85+
if [ $error_code -eq 1 ]; then
86+
local ERROR_MESSAGE=($(ErrorMessage "postprocessor/checks.sh" "0100" "$postprocessor_checks"))
87+
if [ "$postprocessor_checks" == "0101" ]; then
88+
ERROR_MESSAGE=($(ErrorMessage "postprocessor/checks.sh" "0101"))
89+
fi
90+
echo $ERROR_MESSAGE && exit 1
91+
fi
92+
} && \
8593
bash $GITHUB_ACTION_PATH/src/postprocessor/prepare_deployment.sh && \
8694
bash $GITHUB_ACTION_PATH/src/postprocessor/create_api_endpoints.sh && \
8795
bash $GITHUB_ACTION_PATH/src/postprocessor/modify_deployment.sh && \

0 commit comments

Comments
 (0)