Skip to content

Commit

Permalink
fix: ensure react/next/vue sdks get the right cdn path from env (reve…
Browse files Browse the repository at this point in the history
  • Loading branch information
jatinsandilya authored and hrutik7 committed Nov 9, 2023
1 parent 7d42b5f commit b6da832
Show file tree
Hide file tree
Showing 9 changed files with 43 additions and 9 deletions.
2 changes: 1 addition & 1 deletion packages/js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"description": "Client side javascript sdk",
"scripts": {
"dev": "concurrently --kill-others \"yarn run watch:ts\" \"yarn workspace @revertdotdev/revert-react dev\"",
"watch:ts": "nodemon -w src/index.ts --exec \"yarn run build && cp dist/revert.js ../react/src/lib/build/revert-dev.js\"",
"watch:ts": "nodemon -w src/index.ts --exec \"yarn run build && cp dist/revert.js ../react/src/lib/build/revert-dev.js && cp dist/revert.js ../vue/src/lib/build/revert-dev.js\"",
"test": "npm test",
"build": "npm run prebuild && vite build",
"prebuild": "tsc && babel src -d lib && browserify lib/index.js -o lib/bundle.js",
Expand Down
7 changes: 7 additions & 0 deletions packages/react/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# locally
#
# CDN_PATH=src/lib/build/revert-dev.js

# While building for deployment
#
# CDN_PATH=https://cdn.revert.dev/revert.js
4 changes: 2 additions & 2 deletions packages/react/package.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"name": "@revertdotdev/revert-react",
"version": "0.0.17",
"version": "0.0.17-rc2",
"repository": {
"type": "git",
"url": "https://github.com/revertinc/Revert.git"
"url": "https://github.com/revertinc/revert.git"
},
"scripts": {
"dev": "vite",
Expand Down
5 changes: 3 additions & 2 deletions packages/react/src/lib/useRevertConnect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,14 @@ if (typeof window !== 'undefined') {
window.Revert = window.Revert || {};
}

declare var __CDN_PATH__: string;

export function useRevertConnectScript() {
const [loading, setLoading] = useState(true);
const [error, setError] = useState<Error | null>(null);

useEffect(() => {
const src =
process.env.NODE_ENV === 'development' ? 'src/lib/build/revert-dev.js' : 'https://cdn.revert.dev/revert.js';
const src = `${__CDN_PATH__}`;
const script = document.createElement('script');
script.src = src;
script.async = true;
Expand Down
9 changes: 9 additions & 0 deletions packages/react/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,17 @@ import react from '@vitejs/plugin-react';
import path from 'node:path';
import { defineConfig } from 'vite';
import dts from 'vite-plugin-dts';
import dotenv from 'dotenv';

dotenv.config(); // load env vars from .env

export default defineConfig({
/**
* This injects the environment variables into the code.
*/
define: {
__CDN_PATH__: `"${process.env.CDN_PATH || 'src/lib/build/revert-dev.js'}"`,
},
server: {
port: 3001,
},
Expand Down
7 changes: 7 additions & 0 deletions packages/vue/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# locally
#
# CDN_PATH=src/lib/build/revert-dev.js

# While building for deployment
#
# CDN_PATH=https://cdn.revert.dev/revert.js
4 changes: 2 additions & 2 deletions packages/vue/package.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
"name": "@revertdotdev/revert-vue",
"version": "0.0.8",
"version": "0.0.8-rc",
"publishConfig": {
"access": "public"
},
"repository": {
"type": "git",
"url": "https://github.com/revertinc/Revert.git"
"url": "https://github.com/revertinc/revert.git"
},
"scripts": {
"dev": "vite --host",
Expand Down
5 changes: 3 additions & 2 deletions packages/vue/src/lib/useRevertConnect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,14 @@ if (typeof window !== 'undefined') {
window.Revert = window.Revert || {};
}

declare const __CDN_PATH__: string;

export const useRevertConnectScript = () => {
const loading = ref(true);
const error = ref('');

onMounted(() => {
const src =
process.env.NODE_ENV === 'development' ? 'src/lib/revert-dev.js' : 'https://cdn.revert.dev/revert.js';
const src = `${__CDN_PATH__}`;
const script = document.createElement('script');
script.src = src;
script.async = true;
Expand Down
9 changes: 9 additions & 0 deletions packages/vue/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,17 @@ import { defineConfig } from 'vite';
import vue from '@vitejs/plugin-vue';
import dts from 'vite-plugin-dts';
import { resolve } from 'path';
import dotenv from 'dotenv';

dotenv.config(); // load env vars from .env

export default defineConfig({
/**
* This injects the environment variables into the code.
*/
define: {
__CDN_PATH__: `"${process.env.CDN_PATH || 'src/lib/build/revert-dev.js'}"`,
},
plugins: [vue(), dts({ insertTypesEntry: true })],
build: {
sourcemap: true,
Expand Down

0 comments on commit b6da832

Please sign in to comment.