Skip to content

Commit

Permalink
changed build and deploy script to use content hashes
Browse files Browse the repository at this point in the history
  • Loading branch information
niftyvictor committed Oct 7, 2024
1 parent fa477e3 commit c92943b
Show file tree
Hide file tree
Showing 14 changed files with 32 additions and 47 deletions.
55 changes: 20 additions & 35 deletions addReleaseTag
Original file line number Diff line number Diff line change
Expand Up @@ -98,51 +98,36 @@ git push --delete origin $currTag
git tag v$version
git push --tags


response=`curl -s -X GET \
"https://api.supertokens.io/0/frontend/latest/check?password=$password&version=$version&name=web-js" \
-H 'api-version: 0'`
response=`echo $response | jq .isLatest`


# all files in the bundle directory have the same hash
# so we can just take the first one and extract the hash

# List files in the ./bundle directory
files=$(ls ./bundle)

# Get the first file name
first_file=$(echo "$files" | head -n 1)

# Extract the hash from the file name
if [[ $first_file =~ \.([a-zA-Z0-9]+)\.js$ ]]; then
hash="${BASH_REMATCH[1]}"
else
RED='\033[0;31m'
NC='\033[0m'
printf "${RED}Unable to extract hash from file name${NC}\n"
exit 1
fi
# Initialize an empty JSON object string
jsonPayload="{\"password\": \"$releasePassword\""
# Iterate through all files in the ./bundle directory
for file in ./bundle/*; do
# Extract the filename without the path
filename=$(basename "$file")
# Extract the name part (before the first dot)
name="${filename%%.*}"
# Add the key-value pair to the JSON object string
if [ -n "$jsonPayload" ] && [ "$jsonPayload" != "{" ]; then
jsonPayload+=","
fi
jsonPayload+="\"$name\":\"https://cdn.jsdelivr.net/gh/supertokens/supertokens-web-js@v${version}/bundle/$filename\""
done
# Close the JSON object
jsonPayload+="}"

responseStatus=`curl -s -o /dev/null -w "%{http_code}" -X PUT \
https://api.supertokens.io/0/frontend/web-js \
http://localhost:9000/0/frontend/web-js \
-H 'Content-Type: application/json' \
-H 'api-version: 0' \
-d "{
\"password\": \"$releasePassword\",
\"dateprovider\": \"https://cdn.jsdelivr.net/gh/supertokens/supertokens-web-js@v${version}/bundle/dateprovider.${hash}.js\",
\"emailpassword\": \"https://cdn.jsdelivr.net/gh/supertokens/supertokens-web-js@v${version}/bundle/emailpassword.${hash}.js\",
\"emailverification\": \"https://cdn.jsdelivr.net/gh/supertokens/supertokens-web-js@v${version}/bundle/emailverification.${hash}.js\",
\"multifactorauth\": \"https://cdn.jsdelivr.net/gh/supertokens/supertokens-web-js@v${version}/bundle/multifactorauth.${hash}.js\",
\"multitenancy\": \"https://cdn.jsdelivr.net/gh/supertokens/supertokens-web-js@v${version}/bundle/multitenancy.${hash}.js\",
\"passwordless\": \"https://cdn.jsdelivr.net/gh/supertokens/supertokens-web-js@v${version}/bundle/passwordless.${hash}.js\",
\"session\": \"https://cdn.jsdelivr.net/gh/supertokens/supertokens-web-js@v${version}/bundle/session.${hash}.js\",
\"supertokens\": \"https://cdn.jsdelivr.net/gh/supertokens/supertokens-web-js@v${version}/bundle/supertokens.${hash}.js\",
\"thirdparty\": \"https://cdn.jsdelivr.net/gh/supertokens/supertokens-web-js@v${version}/bundle/thirdparty.${hash}.js\",
\"totp\": \"https://cdn.jsdelivr.net/gh/supertokens/supertokens-web-js@v${version}/bundle/totp.${hash}.js\",
\"userroles\": \"https://cdn.jsdelivr.net/gh/supertokens/supertokens-web-js@v${version}/bundle/userroles.${hash}.js\",
\"website\": \"https://cdn.jsdelivr.net/gh/supertokens/supertokens-web-js@v${version}/bundle/website.${hash}.js\"
}"`
-d "${jsonPayload}"`
if [ "$responseStatus" -ne 200 ]
then
echo "failed PUT API to update js deliver uri on server with status code: $responseStatus. You need to manually call this API with the right url!"
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
24 changes: 12 additions & 12 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,52 +16,52 @@ var config = {
entry: {
supertokens: {
import: APP_DIR + "/lib/build/bundleEntry.js",
filename: "supertokens.[hash].js",
filename: "supertokens.[contenthash].js",
dependOn: "supertokensWebsite",
},
supertokensSession: {
import: APP_DIR + "/lib/build/recipe/session/index.js",
filename: "session.[hash].js",
filename: "session.[contenthash].js",
dependOn: "supertokensWebsite",
},
supertokensEmailVerification: {
import: APP_DIR + "/lib/build/recipe/emailverification/index.js",
filename: "emailverification.[hash].js",
filename: "emailverification.[contenthash].js",
dependOn: "supertokensWebsite",
},
supertokensEmailPassword: {
import: APP_DIR + "/lib/build/recipe/emailpassword/index.js",
filename: "emailpassword.[hash].js",
filename: "emailpassword.[contenthash].js",
dependOn: "supertokensWebsite",
},
supertokensThirdParty: {
import: APP_DIR + "/lib/build/recipe/thirdparty/index.js",
filename: "thirdparty.[hash].js",
filename: "thirdparty.[contenthash].js",
dependOn: "supertokensWebsite",
},
supertokensPasswordless: {
import: APP_DIR + "/lib/build/recipe/passwordless/index.js",
filename: "passwordless.[hash].js",
filename: "passwordless.[contenthash].js",
dependOn: "supertokensWebsite",
},
supertokensUserRoles: {
import: APP_DIR + "/lib/build/recipe/userroles/index.js",
filename: "userroles.[hash].js",
filename: "userroles.[contenthash].js",
dependOn: "supertokensWebsite",
},
supertokensMultitenancy: {
import: APP_DIR + "/lib/build/recipe/multitenancy/index.js",
filename: "multitenancy.[hash].js",
filename: "multitenancy.[contenthash].js",
dependOn: "supertokensWebsite",
},
supertokensMultiFactorAuth: {
import: APP_DIR + "/lib/build/recipe/multifactorauth/index.js",
filename: "multifactorauth.[hash].js",
filename: "multifactorauth.[contenthash].js",
dependOn: "supertokensWebsite",
},
supertokensTOTP: {
import: APP_DIR + "/lib/build/recipe/totp/index.js",
filename: "totp.[hash].js",
filename: "totp.[contenthash].js",
dependOn: "supertokensWebsite",
},
/**
Expand All @@ -71,7 +71,7 @@ var config = {
*/
supertokensDateProvider: {
import: APP_DIR + "/utils/dateProvider/index.js",
filename: "dateprovider.[hash].js",
filename: "dateprovider.[contenthash].js",
dependOn: "supertokensWebsite",
},
/**
Expand All @@ -84,7 +84,7 @@ var config = {
*/
supertokensWebsite: {
import: "supertokens-website",
filename: "website.[hash].js",
filename: "website.[contenthash].js",
},
},
output: {
Expand Down

0 comments on commit c92943b

Please sign in to comment.