Skip to content

Commit

Permalink
feat: cache buffer + improve site build script
Browse files Browse the repository at this point in the history
  • Loading branch information
yeojz committed Aug 25, 2019
1 parent dee0b49 commit d7d72a9
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 15 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test-browser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
OTPLIB_BUILD_CLEAN=true
OTPLIB_BUILD_MODULE=false
OTPLIB_BUILD_BUNDLE=true
OTPLIB_BUILD_DOWNLOAD_BUFFER=true
OTPLIB_BUILD_INCLUDE_BUFFER=true
OTPLIB_BUILD_COPY_META=false
npm run build
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test-module.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ jobs:
OTPLIB_BUILD_CLEAN=true
OTPLIB_BUILD_MODULE=true
OTPLIB_BUILD_BUNDLE=true
OTPLIB_BUILD_DOWNLOAD_BUFFER=false
OTPLIB_BUILD_INCLUDE_BUFFER=false
OTPLIB_BUILD_COPY_META=false
npm run build
Expand Down
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@
"packages/**/*.{js,ts}",
"!**/node_modules/**",
"!packages/tests-*/*",
"!packages/otplib-preset-browser/*"
"!packages/otplib-preset-browser/*",
"!packages/package-cache/*"
],
"coverageDirectory": "./coverage/",
"modulePaths": [
Expand All @@ -98,7 +99,8 @@
"testPathIgnorePatterns": [
"/node_modules/",
"/packages/tests-data/",
"/packages/tests-suites/"
"/packages/tests-suites/",
"/packages/package-cache/"
],
"testURL": "http://localhost",
"transform": {
Expand Down
1 change: 1 addition & 0 deletions packages/package-cache/buffer.js

Large diffs are not rendered by default.

33 changes: 29 additions & 4 deletions scripts/build-site.sh
Original file line number Diff line number Diff line change
@@ -1,18 +1,43 @@
#!/bin/bash

echo "\n--- cleaning prev builds ---"
if [ "$OTPLIB_BUILD_SITE_PACKAGE" == "true" ]; then
echo "\n--- installing and build npm package ---"
OTPLIB_SETUP_EXTRAS=skip \
OTPLIB_BUILD_REINSTALL=true \
OTPLIB_BUILD_CLEAN=true \
OTPLIB_BUILD_MODULE=false \
OTPLIB_BUILD_BUNDLE=true \
OTPLIB_BUILD_INCLUDE_BUFFER=true \
OTPLIB_BUILD_COPY_META=false \
npm run build
fi

echo "\n--- cleaning prev site builds ---"
npx rimraf \
./builds/typedocs \
./website/static/otplib-browser \
./website/static/docs \
./website/static/api \
./website/public

echo "\n--- building docs ---"
echo "\n--- copying bundle to website ---"
cp -r ./builds/otplib/preset-browser/. ./website/static/otplib-browser

echo "\n--- building api docs ---"
npx typedoc \
--hideGenerator \
--options ./configs/typedoc.json \
--out ./builds/typedocs

echo "\n--- copying statics to website ---"
cp -r ./builds/otplib/preset-browser/. ./website/static/otplib-browser
echo "\n--- copying api docs to website ---"
cp -r ./builds/typedocs/. ./website/static/api

echo "\n--- changing to website folder ---"
cd website

if [ "$OTPLIB_BUILD_SITE_REINSTALL" == "true" ]; then
echo "\n--- install website node_modules ---"
npm ci;
fi

npm run build
16 changes: 10 additions & 6 deletions scripts/build.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
#!/bin/bash

if [ "$OTPLIB_BUILD_REINSTALL" == "true" ]; then
echo "\n--- installing node_modules ---"
npm run setup;
fi

if [ -z "$OTPLIB_BUILD_CLEAN" ] || [ "$OTPLIB_BUILD_CLEAN" == "true" ]; then
echo "\n--- cleaning prev builds ---"
npx rimraf \
Expand All @@ -18,21 +23,20 @@ if [ -z "$OTPLIB_BUILD_MODULE" ] || [ "$OTPLIB_BUILD_MODULE" == "true" ]; then
typedef \
./builds/otplib/**/*.d.ts

echo "\n--- build modules ---"
echo "\n--- building modules ---"
NODE_ENV=production npx rollup \
-c ./configs/rollup.config.js
fi

if [ -z "$OTPLIB_BUILD_BUNDLE" ] || [ "$OTPLIB_BUILD_BUNDLE" == "true" ]; then
echo "\n--- build bundles ---"
echo "\n--- building bundles ---"
NODE_ENV=production npx webpack \
--config ./configs/webpack.config.js
fi

if [ -z "$OTPLIB_BUILD_DOWNLOAD_BUFFER" ] || [ "$OTPLIB_BUILD_DOWNLOAD_BUFFER" == "true" ]; then
echo "\n--- downloading buffer module ---"
curl https://bundle.run/buffer@5.3.0 \
--output ./builds/otplib/preset-browser/buffer.js
if [ -z "$OTPLIB_BUILD_INCLUDE_BUFFER" ] || [ "$OTPLIB_BUILD_INCLUDE_BUFFER" == "true" ]; then
echo "\n--- copying buffer module ---"
cp ./packages/package-cache/buffer.js ./builds/otplib/preset-browser/buffer.js
fi

if [ -z "$OTPLIB_BUILD_COPY_META" ] || [ "$OTPLIB_BUILD_COPY_META" == "true" ]; then
Expand Down
4 changes: 3 additions & 1 deletion website/src/components/Layout.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ const Layout = ({ children }) => (
</Link>

<nav className={styles.navlinks}>
<Link to="/docs/getting-started">Docs</Link>
<a href="https://github.com/yeojz/otplib/blob/master/README.md">
Docs
</a>
<a href="/api">API</a>
<a href="https://github.com/yeojz/otplib">Github</a>
</nav>
Expand Down

0 comments on commit d7d72a9

Please sign in to comment.