Skip to content

Commit

Permalink
CDE-40 chore: Add build demo step
Browse files Browse the repository at this point in the history
  • Loading branch information
afonsobspinto committed Feb 22, 2024
1 parent 4bcf77a commit 945a233
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 2 deletions.
7 changes: 5 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
ARG PARENT=ubuntu/nginx
ARG NODE_PARENT=node:18.12.1
ARG VITE_API_KEY



FROM ${NODE_PARENT} as build
ENV APP_DIR=/app
ARG VITE_API_KEY
ENV VITE_API_KEY=$VITE_API_KEY
ENV APP_DIR=/app

WORKDIR ${APP_DIR}

Expand All @@ -15,6 +17,7 @@ RUN npm install

# user node
ADD --chown=node:node . ${APP_DIR}
RUN npm run build:demo
RUN npm run build

FROM ${PARENT}
Expand Down
38 changes: 38 additions & 0 deletions build_demo.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/* eslint-env node */

import dotenv from 'dotenv';
import replace from 'replace-in-file';

dotenv.config(); // Load environment variables

const getReplacements = () => {
// Filter only variables starting with VITE_
const viteEnvVars = Object.keys(process.env).filter(key => key.startsWith('VITE_'));

// Create replacement options for each VITE_ variable
return viteEnvVars.map(key => ({
from: new RegExp(`import.meta.env.${key}`, 'g'),
to: JSON.stringify(process.env[key]),
}));
};

const options = {
files: 'demo/*.js', // Target all .js files in dist directory
from: [],
to: [],
};

// Generate and apply replacements
const replacements = getReplacements();
replacements.forEach(replacement => {
options.from.push(replacement.from);
options.to.push(replacement.to);
});

replace(options)
.then(results => {
console.log(results.filter(r => r.hasChanged).length, 'files changed.')
})
.catch(error => {
console.error('Error occurred:', error);
});
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"scripts": {
"dev": "vite",
"build": "tsc --p ./tsconfig-build.json && vite build && cp -f dist/cde-mapper.js demo",
"build:demo": "node build_demo.js",
"lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
"preview": "vite preview",
"prepublishOnly": "npm run build"
Expand All @@ -32,10 +33,12 @@
"@typescript-eslint/eslint-plugin": "^6.14.0",
"@typescript-eslint/parser": "^6.14.0",
"@vitejs/plugin-react": "^4.2.1",
"dotenv": "^16.4.5",
"eslint": "^8.55.0",
"eslint-plugin-react-hooks": "^4.6.0",
"eslint-plugin-react-refresh": "^0.4.5",
"react-dropzone": "^14.2.3",
"replace-in-file": "^7.1.0",
"typescript": "^5.2.2",
"vite": "^5.0.8",
"vite-plugin-dts": "^3.6.4"
Expand Down

0 comments on commit 945a233

Please sign in to comment.