Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: add ensure-cloudflare-pages-exists script
- Loading branch information
Showing
2 changed files
with
39 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#!/bin/bash | ||
|
||
set -e | ||
|
||
CLOUDFLARE_PAGES_PROJECT_NAME=$1 | ||
|
||
function check_requirements() { | ||
if [[ -z "$(command -v node)" ]]; then | ||
echo "Please install 'node' program before running this script" | ||
exit 1 | ||
elif [[ -z "$CLOUDFLARE_ACCOUNT_ID" ]]; then | ||
echo "Please ensure environment variable 'CLOUDFLARE_ACCOUNT_ID' exists before running this script" | ||
exit 1 | ||
elif [[ -z "$CLOUDFLARE_API_TOKEN" ]]; then | ||
echo "Please ensure environment variable 'CLOUDFLARE_API_TOKEN' exists before running this script" | ||
exit 1 | ||
elif [[ -z "$CLOUDFLARE_PAGES_PROJECT_NAME" ]]; then | ||
echo "Arg 1 for script 'CLOUDFLARE_PAGES_PROJECT_NAME' was not given..." | ||
exit 1 | ||
fi | ||
} | ||
|
||
function main() { | ||
check_requirements | ||
|
||
if ./node_modules/.bin/wrangler pages project list | grep -q "$CLOUDFLARE_PAGES_PROJECT_NAME"; then | ||
echo "Cloudflare pages project '$CLOUDFLARE_PAGES_PROJECT_NAME' exists..." | ||
else | ||
echo "Cloudflare pages project '$CLOUDFLARE_PAGES_PROJECT_NAME' does not exist..." | ||
./node_modules/.bin/wrangler pages project create "$CLOUDFLARE_PAGES_PROJECT_NAME" --production-branch main | ||
fi | ||
} | ||
|
||
main |