This directory contains utility scripts and modules that support the Craft CMS development workflow. These utilities handle environment configuration, project setup, and asset optimization.
A robust environment variable parser and validator built with Zod schema validation. This module ensures that all required environment variables are present and properly formatted.
- Schema Validation: Uses Zod to define and validate environment variable types
- Type Coercion: Automatically converts string values to appropriate types (numbers, booleans, etc.)
- Graceful Error Handling: Exits with clear error messages if validation fails
- Default Values: Provides sensible defaults for optional variables
import { parse } from './utility/env.js'
// Parse and validate current environment
const { VITE_BASE, VITE_PORT, PRIMARY_SITE_URL } = env.parse()
// Parse and validate custom environment object
const { VITE_BASE, VITE_PORT, PRIMARY_SITE_URL } = env.parse(customEnvObject)The schema validates the following environment variables:
Vite Configuration:
VITE_BASE(required): Base URL for ViteVITE_TEMP(optional): Temporary directory pathVITE_PORT(default: 5173): Development server port
External Services:
TINYPNG_KEY(required): API key for TinyPNG image optimization
Craft CMS Configuration:
CRAFT_ENVIRONMENT(required): Environment type (dev/staging/production)CRAFT_SECURITY_KEY(required): Craft security keyCRAFT_APP_ID(required): Craft application IDPRIMARY_SITE_NAME(required): Primary site namePRIMARY_SITE_URL(required): Primary site URL (must be valid URL)CRAFT_ENABLE_TEMPLATE_CACHING(optional): Enable template caching
Database Configuration:
CRAFT_DB_DRIVER(required): Database driverCRAFT_DB_SERVER(required): Database serverCRAFT_DB_USER(required): Database usernameCRAFT_DB_PASSWORD(required): Database passwordCRAFT_DB_DATABASE(required): Database nameCRAFT_DB_SCHEMA(required): Database schemaCRAFT_DB_TABLE_PREFIX(optional): Table prefixCRAFT_DB_PORT(default: 3306): Database port
Email Configuration:
SYSTEM_EMAIL_TEST_ADDRESS(optional): Test email addressSYSTEM_EMAIL_ADDRESS(required): System email address
An automated setup script that initializes a new Craft CMS project with all necessary dependencies and configuration. This script streamlines the development environment setup process.
-
Environment Setup:
- Copies
.env.exampleto.env - Automatically configures
PRIMARY_SITE_URLbased on current directory name - Sets up
IMGIX_URLfor image optimization service with a sensible default
- Copies
-
DDEV Configuration:
- Configures DDEV project with directory-based naming
- Starts the DDEV environment
- Updates Composer dependencies
- Runs
bun installon the host and lets the Bun postinstall hook refresh container dependencies automatically when DDEV is running - Uses DDEV configuration that keeps container
node_modulesseparate from the host tree
-
Craft CMS Installation:
- Generates security keys
- Runs Craft installation process
- Uses the host install as the standard JavaScript dependency step for IDEs and local tooling
-
API Key Integration (if 1Password CLI is available):
- Retrieves API keys from 1Password vault
- Automatically configures
TINYPNG_KEY - Triggers initial build process
-
Fallback Handling:
- Provides helpful instructions if 1Password CLI is not installed
- Continues setup process without API keys
- Keeps manual container refresh available via
ddev bun installif the background sync is skipped or needs to be rerun later
- DDEV installed and configured
- Bun package manager
- Composer
- 1Password CLI (optional, for automatic API key setup)
The install script includes automatic API key retrieval using the 1Password CLI for a streamlined development setup experience. This integration eliminates the need to manually copy and paste API keys from the 1Password vault.
Requirements:
- 1Password CLI installed and authenticated
- Access to the Mostly Serious team account (
mostlyserious.1password.com) - Read access to the default
Employeevault - An item named
ENVIRONMENT_DEFAULTSwith the required API key fields - Field with label
TINYPNG_KEYcontaining the TinyPNG API key
Installation Process:
- If 1Password CLI is detected, the script automatically retrieves and sets the API keys
- After setting the keys, it runs
bun run buildto perform the initial asset build inside DDEV - If 1Password CLI is not available, the script provides installation instructions and continues without the API keys
This template supports two valid JavaScript install contexts from the same package.json and bun.lock:
bun installon the host as the standard dependency-management pathddev bun installas a manual recovery command when you need to prune and refresh container dependencies explicitly
When DDEV is running, host bun install, bun update, bun add, and bun remove schedule an asynchronous background sync that waits for package.json and bun.lock to settle, runs ddev mutagen sync, prunes the container node_modules volume, and then runs ddev bun install --frozen-lockfile.
These installs are expected to be separate platform-specific node_modules trees. The project does not require a shared host/container dependency directory.
The DDEV configuration supports this by excluding /node_modules from Mutagen sync and by mounting container-side node_modules on its own Docker volume.
Benefits:
- Eliminates manual API key configuration
- Ensures consistent key management across team members
- Reduces setup friction for new developers
- Maintains security by keeping API keys in the team vault
Installing 1Password CLI: If you don't have the 1Password CLI installed, visit: https://developer.1password.com/docs/cli/get-started/
A Vite plugin that automatically optimizes SVG files during the build process using SVGO. Reduces file sizes while maintaining visual quality.
A Vite plugin that compresses PNG and JPEG images using the TinyPNG service. Features intelligent caching to avoid reprocessing unchanged images and requires a TINYPNG_KEY environment variable.