Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(examples): add new mechanism for api key in examples #162

Merged
merged 4 commits into from
Jan 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion .github/workflows/deploy-website.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,20 @@ jobs:
working-directory: ./website
run: npm ci


- name: Build website
working-directory: ./website
run: |
npm run build
env:
GOOGLE_MAPS_API_KEY: ${{ secrets.GOOGLE_MAPS_API_KEY }}

- name: Find and Replace - Examples API Key
uses: jacobtomlinson/gha-find-replace@v3
with:
find: 'process.env.GOOGLE_MAPS_API_KEY'
replace: ${{ secrets.GOOGLE_MAPS_API_KEY_EXAMPLES }}
include: './website/build/scripts/examples.js'

- name: Upload artifact
uses: actions/upload-pages-artifact@v2
with:
Expand Down
1 change: 1 addition & 0 deletions examples/basic-map/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
<div id="app"></div>
<script type="module">
import '@vis.gl/react-google-maps/examples.css';
import '@vis.gl/react-google-maps/examples.js';
import {renderToDom} from './src/app';

renderToDom(document.querySelector('#app'));
Expand Down
3 changes: 2 additions & 1 deletion examples/basic-map/src/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import {createRoot} from 'react-dom/client';
import {APIProvider, Map} from '@vis.gl/react-google-maps';
import ControlPanel from './control-panel';

const API_KEY = process.env.GOOGLE_MAPS_API_KEY as string;
const API_KEY =
globalThis.GOOGLE_MAPS_API_KEY ?? (process.env.GOOGLE_MAPS_API_KEY as string);

const App = () => (
<APIProvider apiKey={API_KEY}>
Expand Down
6 changes: 6 additions & 0 deletions examples/basic-map/vite.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ export default defineConfig(({mode}) => {
return {
define: {
'process.env.GOOGLE_MAPS_API_KEY': JSON.stringify(GOOGLE_MAPS_API_KEY)
},
resolve: {
alias: {
'@vis.gl/react-google-maps/examples.js':
'https://visgl.github.io/react-google-maps/scripts/examples.js'
}
}
};
});
5 changes: 5 additions & 0 deletions examples/global.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export declare global {
// const or let does not work in this case, it has to be var
// eslint-disable-next-line no-var
var GOOGLE_MAPS_API_KEY: string | undefined;
}
3 changes: 3 additions & 0 deletions examples/vite.config.local.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ export default defineConfig(({mode}) => {
},
resolve: {
alias: {
'@vis.gl/react-google-maps/examples.js': resolve(
'../../website/static/scripts/examples.js'
),
'@vis.gl/react-google-maps/examples.css': resolve(
'../../examples/examples.css'
),
Expand Down
4 changes: 4 additions & 0 deletions website/static/scripts/examples.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// For the codesandbox examples, the 'process.env.GOOGLE_MAPS_API_KEY'
// gets replaced in the deploy task in the github action
// to contain the valid key for the examples
globalThis.GOOGLE_MAPS_API_KEY = process.env.GOOGLE_MAPS_API_KEY;
Loading