Skip to content

Commit

Permalink
Merge pull request #27 from remarkablemark/build/cloudflare-pages
Browse files Browse the repository at this point in the history
build: generate 404 page in docs and fix Cloudflare Pages deployment
  • Loading branch information
remarkablemark authored Dec 11, 2022
2 parents 2bfcb22 + f962d7f commit 6adc0f3
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 2 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ jobs:
run: npm run build

- name: Build docs
run: npm run docs
run: scripts/docs.sh
env:
BASE_URL: /${{ github.event.repository.name }}/

- name: Deploy
if: github.ref == 'refs/heads/master'
Expand Down
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
<!-- readme-start -->

<!-- readme-content-start -->

# cypress-cucumber-steps

[![NPM](https://nodei.co/npm/cypress-cucumber-steps.png)](https://nodei.co/npm/cypress-cucumber-steps/)
Expand Down Expand Up @@ -77,3 +81,9 @@ Release is automated with [Release Please](https://github.com/googleapis/release
## License

[MIT](https://github.com/remarkablemark/cypress-cucumber-steps/blob/master/LICENSE)

<!-- readme-content-end -->

<!-- readme-content-placeholder -->

<!-- readme-end -->
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"clean": "rm -rf docs lib",
"cypress:open": "cypress open",
"docs": "typedoc",
"docs:watch": "typedoc --watch",
"docs:watch": "npm run docs -- --watch",
"lint": "eslint --ignore-path .gitignore --ext .js,.ts .",
"lint:fix": "npm run lint -- --fix",
"lint:tsc": "tsc --noEmit",
Expand Down
56 changes: 56 additions & 0 deletions scripts/docs.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#!/bin/bash

DOCS_DIRECTORY='docs'
NOT_FOUND_PATH="$DOCS_DIRECTORY/404.html"

npm run docs

# https://developers.cloudflare.com/pages/platform/serving-pages/#single-page-app-spa-rendering
cp $DOCS_DIRECTORY/index.html $NOT_FOUND_PATH

README_START='<!-- readme-content-start -->'
README_END='<!-- readme-content-end -->'
README_PLACEHOLDER='<!-- readme-content-placeholder -->'
README_REPLACEMENT='<h1>Not Found</h1>'

if [[ $CF_PAGES == '1' ]]; then
BASE_URL='/'
fi

if [[ $(uname) == 'Linux' ]]; then
sed -i "/$README_START/,/$README_END/d" $NOT_FOUND_PATH
sed -i "s|$README_PLACEHOLDER|$README_REPLACEMENT|" $NOT_FOUND_PATH

for path in 'assets/' 'functions/' 'interfaces/' 'modules/' 'types/'; do
sed -i "s|$path|${BASE_URL}${path}|g" $NOT_FOUND_PATH
done
elif [[ $(uname) == 'Darwin' ]]; then
sed -i '' "/$README_START/,/$README_END/d" $NOT_FOUND_PATH
sed -i '' "s|$README_PLACEHOLDER|$README_REPLACEMENT|" $NOT_FOUND_PATH

for path in 'assets/' 'functions/' 'interfaces/' 'modules/' 'types/'; do
sed -i '' "s|$path|${BASE_URL}${path}|g" $NOT_FOUND_PATH
done
fi

echo "Created $NOT_FOUND_PATH"

# https://developers.cloudflare.com/pages/platform/build-configuration/#environment-variables
if [[ $CF_PAGES == '1' ]]; then
# https://community.cloudflare.com/t/functions-dir-is-ignored-in-deploy/438211
# https://github.com/cloudflare/wrangler2/issues/2240#issuecomment-1343406897
FUNCTIONS='functions'
RENAMED_FUNCTIONS='function'
FUNCTIONS_DIRECTORY="$DOCS_DIRECTORY/$FUNCTIONS"
RENAMED_FUNCTIONS_DIRECTORY="$DOCS_DIRECTORY/$RENAMED_FUNCTIONS"

mv $FUNCTIONS_DIRECTORY $RENAMED_FUNCTIONS_DIRECTORY

if [[ $(uname) == 'Linux' ]]; then
sed -i "s|$FUNCTIONS/|$RENAMED_FUNCTIONS/|g" $DOCS_DIRECTORY/*.html
elif [[ $(uname) == 'Darwin' ]]; then
sed -i '' "s|$FUNCTIONS/|$RENAMED_FUNCTIONS/|g" $DOCS_DIRECTORY/*.html
fi

echo "Renamed $FUNCTIONS_DIRECTORY to $RENAMED_FUNCTIONS_DIRECTORY"
fi

0 comments on commit 6adc0f3

Please sign in to comment.