Skip to content

Commit c7ce630

Browse files
Updates
1 parent 3ab757d commit c7ce630

File tree

6 files changed

+98
-15
lines changed

6 files changed

+98
-15
lines changed

src/_justManifest_end.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
window._justManifest = _justManifest_;

src/_justManifest_start.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
const _justManifest_ = [];

src/buildManifest_end.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,14 @@
11
window._just_Manifest = _just_buildManifest;
2+
3+
/* Example usage:
4+
5+
6+
let buildManifestString = '';
7+
const pathToCurrentSite = `${window.location.protocol}//${window.location.hostname}`
8+
_just_Manifest.forEach((item) => {
9+
buildManifestString += `\n${pathToCurrentSite}/${item.path} - ${item.type} - ${item.size.string}`
10+
})
11+
console.log(`%c${buildManifestString}`, `color: #6e3bf3; background-color: #161616; padding-left: 5px; padding-right: 5px; border-radius: 5px;`);
12+
13+
14+
*/

src/build_map.sh

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,17 @@ mkdir -p deploy/_just/static/
2727
mkdir -p deploy/_just/static/$BUILD_ID/
2828

2929
echo "$(cat $GITHUB_ACTION_PATH/src/buildManifest_start.js)" > deploy/_just/static/$BUILD_ID/buildManifest.js
30+
echo "$(cat $GITHUB_ACTION_PATH/src/_justManifest_start.js)" > deploy/_just/static/$BUILD_ID/_justManifest.js
31+
find _just_data -mindepth 1 -print | while read -r path; do
32+
relative_path=${path#_just_data/}
33+
first_line=$(head -n 1 "$path")
34+
if [ -f "$path" ]; then
35+
if [[ "$first_line" != "// _just hide" ||
36+
"$first_line" != "// _just doNotModify+hide" ]]; then
37+
echo " _just_buildManifest.push($relative_path);" >> deploy/_just/static/$BUILD_ID/buildManifest.js
38+
fi
39+
fi
40+
done
3041

3142
# Convert bytes to human-readable format
3243
function human_readable_size {
@@ -48,7 +59,7 @@ TOTAL_FILES=$(find deploy -mindepth 1 -print | wc -l)
4859
TOTAL_SIZE=0
4960
find deploy -mindepth 1 -print | while read -r path; do
5061
relative_path=${path#deploy/}
51-
62+
first_line=$(head -n 1 "$path")
5263
if [ -f "$path" ]; then
5364
case "${path##*.}" in
5465

@@ -97,7 +108,7 @@ find deploy -mindepth 1 -print | while read -r path; do
97108

98109
esac
99110
file_size=$(stat -c%s "$path")
100-
TOTAL_SIZE=$((TOTAL_SIZE + file_size))
111+
TOTAL_SIZE=$((TOTAL_SIZE + $file_size))
101112

102113
# Output formatting
103114
if [ "$FILE_ID" -eq 1 ]; then
@@ -124,8 +135,13 @@ echo -e "_just/static/$BUILD_ID/buildManifest.js size: $(human_readable_size $ma
124135
echo -e " Total build size: $(human_readable_size $TOTAL_SIZE)\n\n"
125136
echo -e "----------------\n"
126137
echo "$(cat $GITHUB_ACTION_PATH/src/buildManifest_end.js)" >> deploy/_just/static/$BUILD_ID/buildManifest.js
138+
echo "$(cat $GITHUB_ACTION_PATH/src/_justManifest_end.js)" >> deploy/_just/static/$BUILD_ID/_justManifest.js
127139

128-
# Override Deployment
140+
# Override Pages
129141
for html_file in deploy/*.html; do
130-
echo "<script src=\"_just/static/$BUILD_ID/buildManifest.js\"></script>" >> "$html_file"
142+
sed -i.bak '/<\/body>/d' "$html_file"
143+
sed -i.bak '/<\/html>/d' "$html_file"
144+
echo "<script src=\"_just/static/$BUILD_ID/buildManifest.js\"></script>" >> "$html_file"
145+
echo "<script src=\"_just/static/$BUILD_ID/_justManifest.js\"></script>" >> "$html_file"
146+
echo "</body></html>" >> "$html_file"
131147
done

src/modify_deployment.sh

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

2323
# Modify Deployment
2424

25+
# Checks
2526
if [ -d "deploy/_just" ]; then
2627
echo "Error: Your website has a _just directory in the root. Please remove it to proceed." >&2
2728
exit 1
2829
fi
30+
if [ -d "_just/dangerously-insert-files/_just" ]; then
31+
echo "Error: Inserting files in _just directory is not allowed." >&2
32+
exit 1
33+
fi
34+
if [ -d "_just/dangerously-insert-files/_next" ]; then
35+
echo "Error: Inserting files in _next directory is not allowed." >&2
36+
exit 1
37+
fi
2938

3039
mkdir -p deploy/_just/
3140
echo -e "\n----------------\n\n_just Chunks:\n"
3241

42+
generate_strings() {
43+
local count=$1
44+
local length=$2
45+
local chars="qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM1234567890-_"
46+
for ((i=0; i<count; i++)); do
47+
local random_string=""
48+
for ((j=0; j<length; j++)); do
49+
random_string+="${chars:RANDOM%32:1}"
50+
done
51+
echo "$random_string"
52+
done
53+
}
54+
3355
# Merging logic
34-
merged_file="deploy/_just/merged.js"
56+
mkdir -p _just/dangerously-insert-files/_just/
57+
merged_data=($(generate_strings 1 16))
58+
merged_name=${merged_data[0]}
59+
mkdir -p _just/dangerously-insert-files/_just/$merged_name/
60+
merged_file="_just/dangerously-insert-files/_just/$merged_name/merged.js"
3561
> "$merged_file"
3662
for file in _just/js/*; do
3763
file_size=$(stat -c%s "$file")
@@ -41,8 +67,6 @@ for file in _just/js/*; do
4167
fi
4268
done
4369

44-
echo "t1"
45-
4670
# Check if merged file is less than 128KB
4771
while [[ $(stat -c%s "$merged_file") -lt 131072 ]]; do
4872
largest_file=$(ls -S _just/js/* | head -n 1) # Get the largest original file
@@ -56,8 +80,6 @@ while [[ $(stat -c%s "$merged_file") -lt 131072 ]]; do
5680
fi
5781
done
5882

59-
echo "t2"
60-
6183
# Move unmerged files to _just/js/
6284
for file in _just/js/*; do
6385
first_line=$(head -n 1 "$file")
@@ -69,25 +91,41 @@ for file in _just/js/*; do
6991
fi
7092
done
7193

72-
echo "t3"
94+
mkdir -p _just_data/_just/
7395

7496
# Move js files to deploy/_just/
97+
TOTAL_FILES_JS=0
98+
for file in _just/js/*; do
99+
TOTAL_FILES_JS=$((TOTAL_FILES_JS + 1))
100+
done
101+
random_strings_js=($(generate_strings $TOTAL_FILES_JS 14))
75102
FILE_ID=1
76103
for file in _just/js/*; do
77104
first_line=$(head -n 1 "$file")
78105
if [[ $first_line == "// _just ignore"* ]]; then
79106
continue
80107
fi
81-
cp "$file" "deploy/_just/${FILE_ID}.js"
82-
echo "_just/${FILE_ID}.js"
108+
FILE_ID_M1=$((FILE_ID - 1))
109+
FILE_NAME=${random_strings_js[$FILE_ID_M1]}
110+
cp "$file" "deploy/_just/${FILE_NAME}${FILE_ID}.js"
111+
cp "$file" "_just_data/_just/${FILE_NAME}${FILE_ID}.js"
112+
echo "_just/${FILE_NAME}${FILE_ID}.js"
83113
FILE_ID=$((FILE_ID + 1))
84114
done
85115

86116
# Move css files to deploy/_just/
117+
TOTAL_FILES_CSS=0
118+
for file in _just/style/*; do
119+
TOTAL_FILES_CSS=$((TOTAL_FILES_CSS + 1))
120+
done
121+
random_strings_css=($(generate_strings $TOTAL_FILES_CSS 14))
87122
FILE_ID=1
88123
for file in _just/style/*; do
89-
cp "$file" "deploy/_just/${FILE_ID}.css"
90-
echo "_just/${FILE_ID}.css"
124+
FILE_ID_M1=$((FILE_ID - 1))
125+
FILE_NAME=${random_strings_css[$FILE_ID_M1]}
126+
cp "$file" "deploy/_just/${FILE_NAME}${FILE_ID}.css"
127+
cp "$file" "_just_data/_just/${FILE_NAME}${FILE_ID}.css"
128+
echo "_just/${FILE_NAME}${FILE_ID}.css"
91129
FILE_ID=$((FILE_ID + 1))
92130
done
93131

@@ -99,12 +137,15 @@ echo -e "\n----------------\n\nDangerously Inserted Files:\n"
99137
find _just/dangerously-insert-files/ -type f | while read -r file; do
100138
relative_path="${file#_just/dangerously-insert-files/}"
101139
target_dir="deploy/$(dirname "$relative_path")"
140+
target_dir2="_just_data/$(dirname "$relative_path")"
102141
mkdir -p "$target_dir"
142+
mkdir -p "$target_dir2"
103143
if [ -f "$target_dir/$(basename "$file")" ]; then
104144
echo "Warning: Failed to insert file \"$target_dir/$(basename "$file")\"."
105145
fi
106146
if [ ! -f "$target_dir/$(basename "$file")" ]; then
107147
cp "$file" "$target_dir/$(basename "$file")"
148+
cp "$file" "$target_dir2/$(basename "$file")"
108149
echo "$target_dir/$(basename "$file")"
109150
fi
110151
done

src/prepare_deployment.sh

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,19 @@
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
2533
mkdir -p deploy
34+
mkdir -p _just_data
2635
cp -r .next/server/pages/* deploy/
2736
mkdir -p deploy/_next/static/
2837
cp -r .next/static/* deploy/_next/static/
29-
cp .next/server/pages/en.html deploy/index.html
38+
if [ -f ".next/server/pages/en.html" ]; then
39+
cp .next/server/pages/en.html deploy/index.html
40+
fi

0 commit comments

Comments
 (0)