mirror of
https://github.com/umami-software/umami.git
synced 2026-02-06 21:57:16 +01:00
feat: enhance existing validation scripts with better error messages
- Improve check-env.js with color-coded output and detailed solutions - Enhance check-db.js with comprehensive troubleshooting steps - Add variable descriptions and examples - Include PostgreSQL installation and connection guidance
This commit is contained in:
parent
ddc005625d
commit
06422fb65f
2 changed files with 202 additions and 34 deletions
|
|
@ -1,5 +1,32 @@
|
|||
/* eslint-disable no-console */
|
||||
import 'dotenv/config';
|
||||
import chalk from 'chalk';
|
||||
|
||||
/**
|
||||
* Variable descriptions and examples
|
||||
*/
|
||||
const variableInfo = {
|
||||
DATABASE_URL: {
|
||||
description: 'PostgreSQL database connection string',
|
||||
example: 'postgresql://username:password@localhost:5432/umami',
|
||||
required: true,
|
||||
},
|
||||
CLOUD_URL: {
|
||||
description: 'Umami Cloud URL',
|
||||
example: 'https://cloud.umami.is',
|
||||
required: false,
|
||||
},
|
||||
CLICKHOUSE_URL: {
|
||||
description: 'ClickHouse database URL (required when CLOUD_URL is set)',
|
||||
example: 'https://clickhouse.example.com',
|
||||
required: false,
|
||||
},
|
||||
REDIS_URL: {
|
||||
description: 'Redis connection URL (required when CLOUD_URL is set)',
|
||||
example: 'redis://localhost:6379',
|
||||
required: false,
|
||||
},
|
||||
};
|
||||
|
||||
function checkMissing(vars) {
|
||||
const missing = vars.reduce((arr, key) => {
|
||||
|
|
@ -10,14 +37,37 @@ function checkMissing(vars) {
|
|||
}, []);
|
||||
|
||||
if (missing.length) {
|
||||
console.log(`The following environment variables are not defined:`);
|
||||
console.log(chalk.red.bold('\n❌ Environment Configuration Error\n'));
|
||||
console.log(chalk.yellow('The following environment variables are not defined:\n'));
|
||||
|
||||
for (const item of missing) {
|
||||
console.log(' - ', item);
|
||||
const info = variableInfo[item] || {};
|
||||
console.log(chalk.red(` ✗ ${item}`));
|
||||
|
||||
if (info.description) {
|
||||
console.log(chalk.gray(` Description: ${info.description}`));
|
||||
}
|
||||
|
||||
if (info.example) {
|
||||
console.log(chalk.cyan(` Example: ${info.example}`));
|
||||
}
|
||||
|
||||
console.log('');
|
||||
}
|
||||
|
||||
console.log(chalk.yellow.bold('💡 Solution:\n'));
|
||||
console.log(" 1. Create a .env file in the project root if it doesn't exist");
|
||||
console.log(' 2. Copy the template from .env.example:');
|
||||
console.log(chalk.cyan(' cp .env.example .env'));
|
||||
console.log(' 3. Add the missing variables to your .env file\n');
|
||||
|
||||
console.log(chalk.blue('📖 For more information, see .env.example or SETUP.md\n'));
|
||||
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
// Check required variables based on configuration
|
||||
if (!process.env.SKIP_DB_CHECK && !process.env.DATABASE_TYPE) {
|
||||
checkMissing(['DATABASE_URL']);
|
||||
}
|
||||
|
|
@ -25,3 +75,6 @@ if (!process.env.SKIP_DB_CHECK && !process.env.DATABASE_TYPE) {
|
|||
if (process.env.CLOUD_URL) {
|
||||
checkMissing(['CLOUD_URL', 'CLICKHOUSE_URL', 'REDIS_URL']);
|
||||
}
|
||||
|
||||
// Success message
|
||||
console.log(chalk.green('✓ Environment variables validated successfully\n'));
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue