Add interactive environment setup script (npm run setup)#25
Add interactive environment setup script (npm run setup)#25Codewithpabitra wants to merge 1 commit intoZenYukti:mainfrom
Conversation
|
Yay! You're officially a Contributor! 🎉Huge thanks for opening this Pull Request. Being a contributor to ZenYukti is a big deal, and we’re excited to have you on board. Next Steps:
|
|
@ayushHardeniya If you tell I can Update the documentation as well. Let me know if further work is required on this issue . |
|
Hi, thank you for the contribution - we appreciate your effort. Just a small request: please avoid tagging maintainers imediately after opening an issue or PR. Thanks for your patience and for contributing to the project. |
|
Okay, didn't aware of, Thank u! |
There was a problem hiding this comment.
Pull request overview
This PR adds an interactive CLI-based environment setup script to simplify the initial project configuration for OpenMindWell. Users can now run npm run setup to interactively provide credentials and automatically generate .env files for both backend and frontend from their respective .env.example templates. The script uses the inquirer library for an interactive CLI experience and includes validation for Supabase URLs and API keys.
Changes:
- Added
scripts/setup-env.jsto create an interactive environment setup workflow - Added
inquirerdependency for interactive CLI prompts - Added
"type": "module"to root package.json to enable ES module syntax in the setup script - Updated
.gitignoreto explicitly include generated.envfiles
Reviewed changes
Copilot reviewed 2 out of 4 changed files in this pull request and generated 7 comments.
| File | Description |
|---|---|
| scripts/setup-env.js | New interactive setup script that prompts for Supabase and HuggingFace credentials and generates .env files |
| package.json | Added inquirer dependency, "type": "module" configuration, and new "setup" script command |
| package-lock.json | Lockfile updates for inquirer v13.2.2 and all its dependencies |
| .gitignore | Explicitly added backend/.env and frontend/.env to ignored files |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| "concurrently": "^8.2.2" | ||
| }, | ||
| "dependencies": { | ||
| "inquirer": "^13.2.2" |
There was a problem hiding this comment.
The inquirer package version 13.2.2 requires Node.js >= 23.5.0 || ^22.13.0 || ^21.7.0 || ^20.12.0, but the backend/package.json specifies "engines": {"node": ">=18.0.0"}. This creates a version mismatch where users on Node.js 18 or 19 (which are valid for the backend) won't be able to run npm install successfully at the root level. Consider either downgrading to inquirer version 9 or 10 (which support Node 18+), or explicitly documenting the Node 20.12+ requirement in the root package.json engines field.
| "inquirer": "^13.2.2" | |
| "inquirer": "^10.0.0" |
| frontendEnv | ||
| ); | ||
|
|
||
| console.log("\n🎊Environment setup complete!"); |
There was a problem hiding this comment.
Missing space after emoji. Should be "🎊 Environment setup complete!" for consistency with the warning emoji format on line 18.
| console.log("\n🎊Environment setup complete!"); | |
| console.log("\n🎊 Environment setup complete!"); |
| let backendEnv = readTemplate( | ||
| resolvePath("backend/.env.example") | ||
| ); | ||
|
|
||
| backendEnv = replaceValue( | ||
| backendEnv, | ||
| "SUPABASE_URL", | ||
| answers.SUPABASE_URL | ||
| ); | ||
|
|
||
| backendEnv = replaceValue( | ||
| backendEnv, | ||
| "SUPABASE_ANON_KEY", | ||
| answers.SUPABASE_ANON_KEY | ||
| ); | ||
|
|
||
| backendEnv = replaceValue( | ||
| backendEnv, | ||
| "SUPABASE_SERVICE_ROLE_KEY", | ||
| answers.SUPABASE_SERVICE_ROLE_KEY | ||
| ); | ||
|
|
||
| backendEnv = replaceValue( | ||
| backendEnv, | ||
| "HUGGINGFACE_API_TOKEN", | ||
| answers.HUGGINGFACE_API_TOKEN || "" | ||
| ); | ||
|
|
||
| writeEnv( | ||
| resolvePath("backend/.env"), | ||
| backendEnv | ||
| ); | ||
|
|
||
| // frontend | ||
| let frontendEnv = readTemplate( | ||
| resolvePath("frontend/.env.example") | ||
| ); | ||
|
|
||
| frontendEnv = replaceValue( | ||
| frontendEnv, | ||
| "VITE_SUPABASE_URL", | ||
| answers.SUPABASE_URL | ||
| ); | ||
|
|
||
| frontendEnv = replaceValue( | ||
| frontendEnv, | ||
| "VITE_SUPABASE_ANON_KEY", | ||
| answers.SUPABASE_ANON_KEY | ||
| ); | ||
|
|
||
| writeEnv( | ||
| resolvePath("frontend/.env"), | ||
| frontendEnv | ||
| ); |
There was a problem hiding this comment.
The script doesn't handle or copy other required environment variables from the .env.example files. For backend, it's missing FRONTEND_URL, PORT, RATE_LIMIT_WINDOW_MS, and RATE_LIMIT_MAX_REQUESTS. For frontend, it's missing VITE_API_BASE_URL and VITE_WS_URL. Users will need to manually add these after running the script, which defeats the purpose of automated setup. Consider either prompting for these values or preserving all non-sensitive defaults from the .env.example files when generating the .env files.
| validate: (v) => | ||
| v.length > 40 ? true : "Key looks too short", | ||
| }, | ||
| { | ||
| type: "input", | ||
| name: "SUPABASE_SERVICE_ROLE_KEY", | ||
| message: "Supabase Service Role Key:", | ||
| filter: (v) => v.trim(), | ||
| validate: (v) => | ||
| v.length > 40 ? true : "Key looks too short", |
There was a problem hiding this comment.
The validation for Supabase keys (length > 40) is too simplistic and may give users a false sense of security. Valid Supabase JWT tokens are typically 200+ characters long. Consider either removing this validation (since invalid keys will fail at runtime anyway) or making it more strict (e.g., length > 100) to catch obvious mistakes while avoiding false positives.
| const replaceValue = (env, key, value) => { | ||
| const regex = new RegExp(`^${key}=.*$`, "m"); |
There was a problem hiding this comment.
The regex replacement doesn't escape special regex characters in the key parameter. If a key contains regex special characters like dots, brackets, or dollar signs, the regex could fail or behave unexpectedly. While current environment variable names don't contain such characters, this could cause issues if the template format changes. Consider escaping the key using a utility like key.replace(/[.*+?^${}()|[]\]/g, '\$&') before creating the regex.
| const replaceValue = (env, key, value) => { | |
| const regex = new RegExp(`^${key}=.*$`, "m"); | |
| const escapeRegex = (str) => str.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"); | |
| const replaceValue = (env, key, value) => { | |
| const escapedKey = escapeRegex(key); | |
| const regex = new RegExp(`^${escapedKey}=.*$`, "m"); |
| "concurrently": "^8.2.2" | ||
| }, | ||
| "dependencies": { | ||
| "inquirer": "^13.2.2" | ||
| } | ||
| } |
There was a problem hiding this comment.
Adding inquirer as a production dependency rather than a devDependency may not be ideal since it's only used during setup/development, not at runtime. Consider moving it to devDependencies to keep the production installation leaner.
| "concurrently": "^8.2.2" | |
| }, | |
| "dependencies": { | |
| "inquirer": "^13.2.2" | |
| } | |
| } | |
| "concurrently": "^8.2.2", | |
| "inquirer": "^13.2.2" | |
| }, | |
| "dependencies": {} | |
| } |
|
|
||
| (async () => { | ||
| try { | ||
| console.log("\nOpenMindWell environment setup\n"); |
There was a problem hiding this comment.
The console message refers to "OpenMindWell" but based on the PR description and title, this PR was submitted for "ZenYukti". This inconsistency could be confusing for users running the setup script. The project is named "OpenMindWell" according to the package.json and README.md, so this appears to be correct, but the PR description references ZenYukti as if that's the project name.

Description
Adds an interactive environment setup script to simplify initial project configuration. Users can now run npm run setup to generate backend/.env and frontend/.env from existing .env.example files by providing required credentials.
Type of Change
How Has This Been Tested?
Screenshots
N/A (CLI-based change)
Checklist
Additional Information
Learning Outcomes
Let me know if any further improvement is needed on this issue. Thank you !