1
0
mirror of https://github.com/webstudio-is/webstudio.git synced 2025-03-15 09:45:09 +00:00
webstudio/apps/builder/env-check.js
Oleg Isonen cd0174807d chore: use console.info instead of console.log ()
## Description

We allow console.info (btw we should also allow warn/error/info), we
only disallow console.log in the linter because that's what we use for
debugging.

## Steps for reproduction

1. click button
2. expect xyz

## Code Review

- [ ] hi @TrySound , I need you to do
  - conceptual review (architecture, feature-correctness)
  - detailed review (read every line)
  - test it on preview

## Before requesting a review

- [ ] made a self-review
- [ ] added inline comments where things may be not obvious (the "why",
not "what")

## Before merging

- [ ] tested locally and on preview environment (preview dev login:
5de6)
- [ ] updated [test
cases](https://github.com/webstudio-is/webstudio/blob/main/apps/builder/docs/test-cases.md)
document
- [ ] added tests
- [ ] if any new env variables are added, added them to `.env.example`
and the `builder/env-check.js` if mandatory
2024-03-24 12:52:46 +01:00

71 lines
2.2 KiB
JavaScript

// @ts-check
/**
* This file is included in `/remix.config.js` which ensures the app isn't built with invalid env vars.
* It has to be a `.js`-file to be imported there.
*/
/**
* Remix does not read .env files when building for production so this would make it to that when you tried to run pnpm build locally
* you would get an error because your environment variables are in the .env file.
* `dot-env` makes it so that when you run this file the `process.env` is always populated with your `.env` file if it finds one,
* if not it will read the environment variables set by your hosting provider like remix does.
*/
require("dotenv/config");
const REQUIRED_ENVS = ["DATABASE_URL", "AUTH_SECRET"];
const S3_KEYS = [
"S3_ENDPOINT",
"S3_REGION",
"S3_SECRET_ACCESS_KEY",
"S3_ACCESS_KEY_ID",
"S3_BUCKET",
];
const errors = [];
REQUIRED_ENVS.map((env) => {
if (!process.env[env]) {
errors.push(`👉 The ${env} environment variable is required`);
}
});
if (process.env.DEPLOYMENT_ENVIRONMENT === "production") {
if (!process.env.DEPLOYMENT_URL) {
errors.push(
"👉 In production DEPLOYMENT_URL is required for website functionality. Please set it to your production URL."
);
}
if (!process.env.BUILDER_HOST) {
errors.push(
"👉 In production BUILDER_HOST is required for website functionality. Please set it to your production URL of the builder."
);
}
if (!process.env.PUBLISHER_HOST) {
errors.push(
"👉 In production PUBLISHER_HOST is required for website functionality. Please set it to your production URL of the builder."
);
}
}
// check for when user has some S3 env variables but not all required
if (
S3_KEYS.some((key) => Object.keys(process.env).includes(key)) &&
!S3_KEYS.every((key) => Object.keys(process.env).includes(key))
) {
const notIncluded = S3_KEYS.filter(
(key) => !Object.keys(process.env).includes(key)
);
errors.push(
`👉 You don't have all the necessary envriroment variables to have S3 asset hosting, you are missing ${notIncluded.join(
","
)}`
);
}
if (errors.length) {
console.error("❌ Invalid environment variables:");
console.error(errors.join("\n"));
process.exit(1);
}