From 14043768350d7bf4df50bc33c4c8bd3db7917007 Mon Sep 17 00:00:00 2001 From: sauravraw Date: Mon, 30 Sep 2024 11:36:04 +0530 Subject: [PATCH] create env file using command --- .gitignore | 1 + index.js | 60 ++++++++++++++++++++++++++++++++++++++++++++ package.json | 4 ++- ui/package-lock.json | 11 +++++++- upload-api/.env | 3 ++- 5 files changed, 76 insertions(+), 3 deletions(-) create mode 100644 index.js diff --git a/.gitignore b/.gitignore index bc013215..ae3e6cee 100644 --- a/.gitignore +++ b/.gitignore @@ -9,6 +9,7 @@ *.user *.userosscache *.sln.docstates +package-lock* # User-specific files (MonoDevelop/Xamarin Studio) *.userprefs diff --git a/index.js b/index.js new file mode 100644 index 00000000..92e49eb6 --- /dev/null +++ b/index.js @@ -0,0 +1,60 @@ +const fs = require('fs'); +const path = require('path'); + +const apiEnvContent = ` +APP_TOKEN_KEY=MIGRATION_V2 +PORT=5001 +`; + +const uiEnvContent = ` +REACT_APP_WEBSITE_BASE_URL="http://localhost:3000/" +REACT_APP_BASE_API_URL="http://localhost:5001/" +REACT_APP_API_VERSION=v2 +REACT_APP_HOST="http://localhost:3000" +REACT_APP_UPLOAD_SERVER="http://localhost:4002/" +REACT_APP_OFFLINE_CMS=true +`; + +const uploadAPIEnvContent = ` +PORT=4002 +NODE_BACKEND_API =http://localhost:5001 +`; + +const envFilePaths = { + API: path.join(__dirname, 'api', 'production.env'), + UI: path.join(__dirname, 'ui', '.env.local'), + 'Upload-API': path.join(__dirname, 'upload-api', '.env'), +}; + +// Define the contents for each file in an array +const envContents = { + API: apiEnvContent, + UI: uiEnvContent, + 'Upload-API': uploadAPIEnvContent, +}; + +// Function to create env files +const createEnvFiles = () => { + // Loop through each key in the envFilePaths object + Object.keys(envFilePaths).forEach((key) => { + const filePath = envFilePaths[key]; + const dir = path.dirname(filePath); + + // Ensure the directory exists, if not, create it + if (!fs.existsSync(dir)) { + fs.mkdirSync(dir, { recursive: true }); + } + + // Write the content to the env file corresponding to the key + fs.writeFile(filePath, envContents[key], (err) => { + if (err) { + console.error(`Error creating ${key} file at ${filePath}:`, err); + } else { + console.log(`${key} env file created successfully!`); + } + }); + }); +}; + +// Run the function to create the files +createEnvFiles(); diff --git a/package.json b/package.json index 1d2ae4cb..6b6a7666 100644 --- a/package.json +++ b/package.json @@ -5,9 +5,11 @@ "scripts": { "test": "echo \"Error: no test specified\" && exit 1", "postinstall": "(cd ./api && npm install --force) ; (cd ./ui && npm install --force) ; (cd ./upload-api && npm install --force)", + "env": "npm start", "api": "cd ./api && npm run dev", "upload": "cd ./upload-api && npm start", - "ui": "cd ./ui && npm start" + "ui": "cd ./ui && npm start", + "start": "node index.js" }, "repository": { "type": "git", diff --git a/ui/package-lock.json b/ui/package-lock.json index fdd23193..94eb9b77 100644 --- a/ui/package-lock.json +++ b/ui/package-lock.json @@ -20,7 +20,9 @@ "axios": "^1.5.1", "bootstrap": "5.1.3", "chokidar": "^3.6.0", + "final-form": "^4.20.10", "html-react-parser": "^4.2.9", + "jwt-decode": "^4.0.0", "react": "^18.2.0", "react-dom": "^18.2.0", "react-final-form": "^6.5.9", @@ -10883,7 +10885,6 @@ "version": "4.20.10", "resolved": "https://registry.npmjs.org/final-form/-/final-form-4.20.10.tgz", "integrity": "sha512-TL48Pi1oNHeMOHrKv1bCJUrWZDcD3DIG6AGYVNOnyZPr7Bd/pStN0pL+lfzF5BNoj/FclaoiaLenk4XUIFVYng==", - "peer": true, "dependencies": { "@babel/runtime": "^7.10.0" }, @@ -16449,6 +16450,14 @@ "node": ">=4.0" } }, + "node_modules/jwt-decode": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/jwt-decode/-/jwt-decode-4.0.0.tgz", + "integrity": "sha512-+KJGIyHgkGuIq3IEBNftfhW/LfWhXUIY6OmyVWjliu5KH1y0fw7VQ8YndE2O4qZdMSd9SqbnC8GOcZEy0Om7sA==", + "engines": { + "node": ">=18" + } + }, "node_modules/keyv": { "version": "4.5.4", "resolved": "https://registry.npmjs.org/keyv/-/keyv-4.5.4.tgz", diff --git a/upload-api/.env b/upload-api/.env index 2c50b649..13675414 100644 --- a/upload-api/.env +++ b/upload-api/.env @@ -1,2 +1,3 @@ + PORT=4002 -NODE_BACKEND_API =http://localhost:5001 \ No newline at end of file +NODE_BACKEND_API =http://localhost:5001