@revealui/setup
v0.2.0
Published
Setup utilities for RevealUI projects - environment, database, and configuration management
Maintainers
Readme
@revealui/setup
Shared setup utilities for RevealUI projects. Provides environment variable management, database initialization, and configuration validation.
Features
- Environment Setup - Interactive and automated environment variable configuration
- Secret Generation - Cryptographically secure secret and password generation
- Validation - Type-safe validation for environment variables
- Logging - Consistent, colored console output with log levels
- Reusable - Used by both @revealui/cli and setup scripts
Installation
pnpm add @revealui/setupUsage
Environment Setup
import { setupEnvironment } from '@revealui/setup/environment'
// Interactive setup with prompts
const result = await setupEnvironment({
projectRoot: '/path/to/project',
interactive: true
})
if (result.success) {
console.log('Environment configured!')
} else {
console.log('Missing variables:', result.missing)
}Generate Secrets
import { generateSecret, generatePassword } from '@revealui/setup/environment'
const jwtSecret = generateSecret(32) // 64-char hex string
const password = generatePassword(16) // 16-char alphanumeric + specialValidate Environment
import { validateEnv, REQUIRED_ENV_VARS } from '@revealui/setup/validators'
const validation = validateEnv(REQUIRED_ENV_VARS, process.env)
if (!validation.valid) {
console.log('Missing:', validation.missing)
console.log('Invalid:', validation.invalid)
}Logging
import { createLogger } from '@revealui/setup/utils'
const logger = createLogger({
prefix: 'MyScript',
level: 'info',
timestamps: true
})
logger.info('Starting process')
logger.success('Completed!')
logger.error('Failed')
logger.header('Section Title')
logger.divider()
logger.progress(50, 100, 'Processing')API Reference
Environment
setupEnvironment(options)
Sets up environment variables for a project.
Options:
projectRoot: string- Project root directorytemplatePath?: string- Path to .env.template (default:{projectRoot}/.env.template)outputPath?: string- Output path (default:{projectRoot}/.env.development.local)force?: boolean- Overwrite existing file without promptinggenerateOnly?: boolean- Only generate secrets, skip promptsinteractive?: boolean- Enable interactive prompts (default: true)customVariables?: EnvVariable[]- Custom variable definitionslogger?: Logger- Custom logger instance
Returns: Promise<SetupEnvironmentResult>
success: boolean- Whether setup completed successfullyenvPath: string- Path to generated env filemissing: string[]- Variables still missinginvalid: string[]- Variables with invalid values
generateSecret(length?: number)
Generates cryptographically secure hex string.
generatePassword(length?: number)
Generates random password with alphanumeric + special characters.
updateEnvValue(content, key, value)
Updates or adds an environment variable in file content.
parseEnvContent(content)
Parses environment file content into key-value object.
Validators
validateEnv(required, env)
Validates environment variables against schema.
Parameters:
required: EnvVariable[]- Required variable definitionsenv: Record<string, string>- Environment to validate
Returns: ValidationResult
valid: booleanmissing: string[]invalid: string[]
validators
Pre-built validators:
postgresUrl- PostgreSQL connection stringstripeSecretKey- Stripe secret key formatstripePublishableKey- Stripe publishable key formaturl- Valid URL formatemail- Valid email formatminLength(n)- Minimum string length
REQUIRED_ENV_VARS
Default required environment variables for RevealUI:
REVEALUI_SECRET- JWT secret (min 32 chars)POSTGRES_URL- Database connection stringBLOB_READ_WRITE_TOKEN- Vercel Blob tokenSTRIPE_SECRET_KEY- Stripe secret keyNEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY- Stripe publishable key
OPTIONAL_ENV_VARS
Optional environment variables (Supabase, Sentry, admin config, etc.)
Utilities
createLogger(options)
Creates a logger instance with configurable options.
Options:
level?: 'debug' | 'info' | 'warn' | 'error' | 'silent'prefix?: string- Prefix for all log messagescolors?: boolean- Enable colors (auto-detected by default)timestamps?: boolean- Include timestamps
Methods:
debug(msg, ...args)- Debug messageinfo(msg, ...args)- Info messagewarn(msg, ...args)- Warning messageerror(msg, ...args)- Error messagesuccess(msg, ...args)- Success messageheader(msg)- Formatted headerdivider()- Visual dividertable(data)- Console tablegroup(label)- Start groupgroupEnd()- End groupprogress(current, total, label?)- Progress bar
Examples
Complete Setup Flow
import { setupEnvironment, createLogger } from '@revealui/setup'
const logger = createLogger({ prefix: 'Setup' })
logger.header('Project Setup')
const result = await setupEnvironment({
projectRoot: process.cwd(),
interactive: true,
logger
})
if (result.success) {
logger.success('Environment configured successfully!')
logger.info(`Config file: ${result.envPath}`)
} else {
logger.error('Setup failed')
logger.info('Missing variables:', result.missing.join(', '))
}Non-Interactive Setup
import { setupEnvironment } from '@revealui/setup'
// Generate secrets only, no prompts
const result = await setupEnvironment({
projectRoot: '/path/to/project',
interactive: false,
generateOnly: true
})Custom Validation
import { validateEnv, validators, type EnvVariable } from '@revealui/setup/validators'
const customVars: EnvVariable[] = [
{
name: 'API_KEY',
description: 'Third-party API key',
required: true,
validator: validators.minLength(20)
},
{
name: 'WEBHOOK_URL',
description: 'Webhook endpoint',
required: true,
validator: validators.url
}
]
const validation = validateEnv(customVars, process.env)Package Exports
// Main export
import { setupEnvironment, createLogger } from '@revealui/setup'
// Subpath exports
import { setupEnvironment } from '@revealui/setup/environment'
import { validateEnv } from '@revealui/setup/validators'
import { createLogger } from '@revealui/setup/utils'Integration
In @revealui/cli
import { setupEnvironment, createLogger } from '@revealui/setup'
const logger = createLogger({ prefix: '@revealui/cli' })
await setupEnvironment({
projectRoot: projectPath,
interactive: true,
logger
})In Setup Scripts
#!/usr/bin/env tsx
import { setupEnvironment } from '@revealui/setup'
await setupEnvironment({
projectRoot: process.cwd(),
force: process.argv.includes('--force')
})Development
# Build package
pnpm build
# Watch mode
pnpm dev
# Type check
pnpm typecheck
# Run tests
pnpm test
# Coverage
pnpm test:coverageLicense
MIT
