-
Notifications
You must be signed in to change notification settings - Fork 0
/
inline-build.sh
executable file
·37 lines (26 loc) · 1.26 KB
/
inline-build.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#!/bin/bash
# Move to the build directory.
cd build || { echo "Failed to change directory to build"; exit 1; }
# Backup the original file
cp index.html index.html.bak
# Split the file around the script tag
awk '/<script defer="defer"/ {print; nextfile} {print}' index.html > part1.html
awk '/<script defer="defer"/,0' index.html > part2.html
# Combine the files so that the script is before </body>
cat part1.html part2.html > index.html || { echo "Failed to recombine HTML parts"; exit 1; }
# Remove the temporary files
rm part1.html part2.html
# Add 'inline' attributes to the tags using sed
sed -i '' 's/<script defer="defer" src="/<script inline defer="defer" src="/g' index.html
sed -i '' 's/<link href="/<link inline href="/g' index.html
sed -i '' 's/<img src=".*\.svg"/& inline/g' index.html
# Inline the assets using inline-source
npx inline-source index.html > index_inlined.html || { echo "Failed to inline sources"; exit 1; }
# Rename the inlined file back to index.html
mv index_inlined.html index.html
## Build Plugin File
# Move back to the project root.
cd ..
# Compile the TypeScript file.
npx tsc plugin.ts --outDir build --esModuleInterop || { echo "Failed to compile plugin.ts"; }
# The file will already be named plugin.js, so there's no need to rename it.