or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

build-system.mdcli-engine.mdconfiguration-management.mdindex.mdpackage-management.mdproject-management.mduser-interface.md
tile.json

configuration-management.mddocs/

Configuration Management

Configuration system for managing project settings, environment-specific options, and conditional property resolution with support for nested configurations and environment matching.

Capabilities

Configuration Class

Main configuration management class providing environment-aware property resolution and option management.

/**
 * Configuration management with environment-aware property resolution
 */
class Configuration {
  /**
   * Initialize configuration with options and environment
   * @param options - Configuration options object
   * @param defaultOptions - Default configuration values
   * @param environment - Target environment (defaults to CLIOptions.getEnvironment())
   */
  constructor(options: object, defaultOptions?: object, environment?: string);
  
  /**
   * Get all configuration options
   * @returns Complete configuration object
   */
  getAllOptions(): object;
  
  /**
   * Get configuration value by property path
   * @param propPath - Dot-separated property path
   * @returns Configuration value with environment resolution
   */
  getValue(propPath: string): any;
  
  /**
   * Check if property path is applicable for current environment
   * @param propPath - Dot-separated property path
   * @returns True if property is applicable
   */
  isApplicable(propPath: string): boolean;
  
  /**
   * Check if environment matches configuration value
   * @param environment - Environment to check
   * @param value - Environment value or pattern
   * @returns True if environment matches
   */
  matchesEnvironment(environment: string, value: string): boolean;
  
  // Properties
  options: object;
  environment: string;
}

Usage Examples:

const { Configuration, CLIOptions } = require("aurelia-cli");

// Basic configuration
const config = new Configuration({
  server: {
    port: 3000,
    host: "localhost"
  },
  database: {
    host: "localhost",
    port: 5432
  }
});

// Get simple values
const serverPort = config.getValue("server.port"); // 3000
const dbHost = config.getValue("database.host"); // "localhost"

// Get all options
const allOptions = config.getAllOptions();
console.log(JSON.stringify(allOptions, null, 2));

Environment-Specific Configuration

Advanced configuration with environment-specific values and conditional resolution.

/**
 * Environment-specific configuration structure
 * Values can be objects with environment keys for conditional resolution
 */
interface EnvironmentConfig {
  [key: string]: any | {
    default?: any;
    dev?: any;
    prod?: any;
    test?: any;
    [environment: string]: any;
  };
}

Usage Examples:

// Environment-specific configuration
const envConfig = new Configuration({
  database: {
    host: {
      default: "localhost",
      prod: "prod-db.example.com",
      test: "test-db.example.com"
    },
    port: {
      default: 5432,
      prod: 5433
    },
    ssl: {
      default: false,
      prod: true
    }
  },
  api: {
    baseUrl: {
      dev: "http://localhost:3001",
      prod: "https://api.example.com",
      test: "http://test-api.example.com"
    },
    timeout: 5000 // Simple value used for all environments
  }
}, {}, "prod"); // Production environment

// Resolved values for production
const dbHost = envConfig.getValue("database.host"); // "prod-db.example.com"
const dbPort = envConfig.getValue("database.port"); // 5433
const dbSsl = envConfig.getValue("database.ssl"); // true
const apiUrl = envConfig.getValue("api.baseUrl"); // "https://api.example.com"
const apiTimeout = envConfig.getValue("api.timeout"); // 5000

console.log("Database config:", {
  host: dbHost,
  port: dbPort,
  ssl: dbSsl
});

Default Configuration Merging

Configuration merging with default values and environment-specific overrides.

/**
 * Configuration merging process:
 * 1. Start with defaultOptions
 * 2. Merge with provided options
 * 3. Resolve environment-specific values
 * 4. Return final configuration
 */

Usage Examples:

// Default configuration
const defaultConfig = {
  server: {
    port: 3000,
    host: "0.0.0.0",
    cors: true
  },
  logging: {
    level: "info",
    file: "app.log"
  }
};

// User configuration
const userConfig = {
  server: {
    port: 8080, // Override default
    // host inherited from default
    https: true // New property
  },
  database: {
    host: "localhost",
    port: 5432
  }
  // logging inherited from default
};

const config = new Configuration(userConfig, defaultConfig, "dev");

// Merged result
const serverPort = config.getValue("server.port"); // 8080 (user override)
const serverHost = config.getValue("server.host"); // "0.0.0.0" (default)
const serverHttps = config.getValue("server.https"); // true (user addition)
const logLevel = config.getValue("logging.level"); // "info" (default)
const dbHost = config.getValue("database.host"); // "localhost" (user)

Environment Pattern Matching

Advanced environment matching with pattern support for flexible configuration.

/**
 * Environment pattern matching supports:
 * - Exact match: "prod"
 * - Multiple environments: "dev&test" (matches dev OR test)
 * - Case-insensitive matching
 */

Usage Examples:

const config = new Configuration({
  features: {
    debugging: {
      "dev&test": true,
      "prod": false
    },
    analytics: {
      "prod&staging": true,
      "default": false
    },
    hotReload: {
      "dev": true,
      "default": false
    }
  }
});

// Test different environments
const devConfig = new Configuration(config.options, {}, "dev");
const prodConfig = new Configuration(config.options, {}, "prod");
const testConfig = new Configuration(config.options, {}, "test");

// Development environment
console.log("Dev debugging:", devConfig.getValue("features.debugging")); // true
console.log("Dev analytics:", devConfig.getValue("features.analytics")); // false
console.log("Dev hotReload:", devConfig.getValue("features.hotReload")); // true

// Production environment
console.log("Prod debugging:", prodConfig.getValue("features.debugging")); // false
console.log("Prod analytics:", prodConfig.getValue("features.analytics")); // true
console.log("Prod hotReload:", prodConfig.getValue("features.hotReload")); // false

// Test environment
console.log("Test debugging:", testConfig.getValue("features.debugging")); // true
console.log("Test analytics:", testConfig.getValue("features.analytics")); // false

Configuration Validation

Property applicability checking and configuration validation.

/**
 * Configuration validation and applicability checking
 */
interface ConfigurationValidation {
  /** Check if property exists and is applicable */
  isApplicable(propPath: string): boolean;
  
  /** Validate configuration structure */
  validate(schema: ConfigSchema): ValidationResult;
  
  /** Get configuration warnings */
  getWarnings(): string[];
}

interface ValidationResult {
  isValid: boolean;
  errors: string[];
  warnings: string[];
}

Usage Examples:

const config = new Configuration({
  server: {
    enabled: true,
    port: 3000,
    ssl: {
      dev: false,
      prod: true
    }
  },
  cache: {
    enabled: {
      dev: false,
      prod: true
    },
    ttl: 3600
  }
}, {}, "prod");

// Check property applicability
console.log("Server enabled:", config.isApplicable("server.enabled")); // true
console.log("SSL enabled:", config.isApplicable("server.ssl")); // true (resolves to true for prod)
console.log("Cache enabled:", config.isApplicable("cache.enabled")); // true (resolves to true for prod)
console.log("Non-existent:", config.isApplicable("server.nonexistent")); // false

// Check specific values
const sslEnabled = config.getValue("server.ssl"); // true (for prod environment)
const cacheEnabled = config.getValue("cache.enabled"); // true (for prod environment)

if (config.isApplicable("server.ssl") && config.getValue("server.ssl")) {
  console.log("SSL is enabled for this environment");
}

Nested Configuration Access

Deep property access with dot notation and complex object handling.

/**
 * Deep property access with dot notation
 * Supports nested objects and array indices
 */
interface NestedAccess {
  /** Access nested properties with dot notation */
  getValue(path: string): any;
  
  /** Set nested property values */
  setValue(path: string, value: any): void;
  
  /** Check if nested path exists */
  hasPath(path: string): boolean;
}

Usage Examples:

const complexConfig = new Configuration({
  app: {
    name: "My App",
    version: "1.0.0",
    modules: {
      auth: {
        enabled: true,
        providers: ["local", "oauth2"],
        oauth2: {
          clientId: "abc123",
          scopes: ["read", "write"]
        }
      },
      api: {
        version: "v1",
        endpoints: {
          users: "/api/v1/users",
          posts: "/api/v1/posts"
        }
      }
    }
  }
});

// Deep nested access
const appName = complexConfig.getValue("app.name"); // "My App"
const authEnabled = complexConfig.getValue("app.modules.auth.enabled"); // true
const oauthClientId = complexConfig.getValue("app.modules.auth.oauth2.clientId"); // "abc123"
const usersEndpoint = complexConfig.getValue("app.modules.api.endpoints.users"); // "/api/v1/users"

// Non-existent paths return undefined
const nonExistent = complexConfig.getValue("app.modules.auth.ldap.server"); // undefined

// Working with arrays
const providers = complexConfig.getValue("app.modules.auth.providers"); // ["local", "oauth2"]
const scopes = complexConfig.getValue("app.modules.auth.oauth2.scopes"); // ["read", "write"]

Integration with CLIOptions

Configuration integration with command-line options and environment detection.

/**
 * Configuration integrates with CLIOptions for environment detection
 * Falls back to CLIOptions.getEnvironment() if no environment specified
 */

Usage Examples:

const { Configuration, CLIOptions } = require("aurelia-cli");

// Configuration uses CLIOptions environment automatically
const cliOptions = new CLIOptions();
// Assume CLI was run with --env prod

const config = new Configuration({
  build: {
    minify: {
      dev: false,
      prod: true
    },
    sourcemaps: {
      dev: true,
      prod: false
    }
  }
}); // Environment automatically detected from CLIOptions

// Values resolved based on CLI environment
const shouldMinify = config.getValue("build.minify"); // true (because --env prod)
const useSourcemaps = config.getValue("build.sourcemaps"); // false (because --env prod)

// Explicit environment override
const devConfig = new Configuration(config.options, {}, "dev");
const devMinify = devConfig.getValue("build.minify"); // false
const devSourcemaps = devConfig.getValue("build.sourcemaps"); // true