or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

dmg-building.mddmg-customization.mderror-handling.mdindex.mdlicense-management.mdvolume-operations.md
tile.json

dmg-building.mddocs/

DMG Building

Main DMG creation functionality using the DmgTarget class. Handles the complete build process from app packaging to final DMG generation with customization options, code signing, and metadata generation.

Capabilities

DmgTarget Class

The main class for building DMG files within the electron-builder ecosystem. Extends the base Target class and orchestrates the complete DMG creation process.

/**
 * Main DMG target class for building DMG files
 * Extends Target from app-builder-lib
 */
class DmgTarget extends Target {
  /** DMG configuration options from packager config */
  readonly options: DmgOptions;
  /** Indicates this target does not support async operations during build */
  readonly isAsyncSupported: boolean;
  
  /**
   * Create a new DMG target instance
   * @param packager - MacPackager instance for the build
   * @param outDir - Output directory for the generated DMG
   */
  constructor(packager: MacPackager, outDir: string);
  
  /**
   * Build the DMG file for the specified app and architecture
   * @param appPath - Path to the .app bundle to package
   * @param arch - Target architecture (x64, arm64, universal)
   * @returns Promise that resolves when DMG creation is complete
   */
  build(appPath: string, arch: Arch): Promise<void>;
  
  /**
   * Compute the volume name for the DMG
   * @param arch - Target architecture
   * @param custom - Optional custom volume name template with variable substitution
   * @returns Computed volume name string
   */
  computeVolumeName(arch: Arch, custom?: string | null): string;
  
  /**
   * Compute and validate DMG options from configuration
   * @param appPath - Path to the app bundle
   * @returns Promise resolving to validated DmgOptions
   */
  computeDmgOptions(appPath: string): Promise<DmgOptions>;
}

Usage Examples:

import { DmgTarget } from "dmg-builder";
import { MacPackager, Arch } from "app-builder-lib";

// Create packager and DMG target
const packager = new MacPackager(info, platform, cleanupTasks);
const dmgTarget = new DmgTarget(packager, "/output/directory");

// Build DMG for x64 architecture
await dmgTarget.build("/path/to/MyApp.app", Arch.x64);

// Custom volume name with variables
const volumeName = dmgTarget.computeVolumeName(
  Arch.x64, 
  "${productName} ${version} ${arch}"
);
// Result: "MyApp 1.0.0 x64"

Volume Name Computation

Generates appropriate volume names for DMG files with support for variable substitution.

/**
 * Compute the volume name for the DMG with variable substitution
 * @param arch - Target architecture for arch suffix
 * @param custom - Custom template with variables: ${arch}, ${shortVersion}, ${version}, ${name}, ${productName}
 * @returns Computed volume name
 */
computeVolumeName(arch: Arch, custom?: string | null): string;

Available Variables:

  • ${arch} - Architecture suffix (e.g., " x64", " arm64", "")
  • ${shortVersion} - Bundle short version or app version
  • ${version} - Full app version
  • ${name} - App name
  • ${productName} - Product name from app info

DMG Options Computation

Validates and computes final DMG configuration options with intelligent defaults.

/**
 * Compute and validate DMG options from packager configuration
 * Applies defaults for icon, background, format, and contents
 * @param appPath - Path to the app bundle for content configuration
 * @returns Promise resolving to complete DmgOptions configuration
 * @throws InvalidConfigurationError for invalid configuration combinations
 */
computeDmgOptions(appPath: string): Promise<DmgOptions>;

Default Behaviors:

  • Icon: Uses packager icon if not specified
  • Background: Auto-detects background.tiff or background.png, falls back to default
  • Format: Chooses UDZO (compressed), UDRO (uncompressed), or UDBZ (maximum compression) based on settings
  • Contents: Creates default layout with app at (130, 220) and Applications link at (410, 220)

Usage Example:

const dmgTarget = new DmgTarget(packager, outDir);
const options = await dmgTarget.computeDmgOptions("/path/to/MyApp.app");

// Options will include validated configuration with defaults applied
console.log(options.format); // "UDZO" (default compressed)
console.log(options.contents); // Default app + Applications link layout

Types

Architecture Enumeration

enum Arch {
  x64 = "x64",
  arm64 = "arm64", 
  universal = "universal"
}

DMG Options Interface

/**
 * Complete DMG configuration options interface
 * Extended from app-builder-lib DmgOptions
 */
interface DmgOptions {
  /** Background image path or null to use backgroundColor */
  background?: string | null;
  /** Background color (hex) when no background image */
  backgroundColor?: string | null;
  /** DMG icon path */
  icon?: string | null;
  /** Icon size in pixels (default: platform default) */
  iconSize?: number;
  /** Icon text size (10-16, default: 12) */
  iconTextSize?: number;
  /** Window configuration for DMG appearance */
  window?: {
    x?: number;
    y?: number; 
    width?: number;
    height?: number;
  };
  /** DMG compression format (UDZO, UDRO, UDBZ) */
  format?: string;
  /** Enable internet-enabled DMG (deprecated) */
  internetEnabled?: boolean;
  /** Code sign the DMG file */
  sign?: boolean;
  /** Custom DMG title template */
  title?: string;
  /** Write update info for auto-updater */
  writeUpdateInfo?: boolean;
  /** Contents layout configuration */
  contents?: Array<{
    /** Path to file/directory or special paths like /Applications */
    path?: string;
    /** X position in DMG window */
    x: number;
    /** Y position in DMG window */
    y: number;
    /** Display name (optional) */
    name?: string;
    /** Type of content item */
    type?: "file" | "link" | "dir";
  }>;
}

Error Handling

The build process includes comprehensive error handling for common DMG creation issues:

  • Invalid Configuration: Throws InvalidConfigurationError for conflicting options
  • Missing Resources: Handles missing icons, backgrounds, or app bundles gracefully
  • Code Signing Failures: Gracefully handles missing certificates or keychain issues
  • hdiutil Errors: Automatic retry for transient hdiutil failures
  • Python Execution: Falls back from python3 to python if needed

Code Signing Integration

DMG files can be automatically code signed during the build process:

// Enable DMG signing in configuration
const dmgOptions = {
  sign: true, // Enable code signing
  // Other options...
};

Requirements:

  • Valid Developer ID Application certificate
  • Proper keychain configuration
  • Code signing identity in packager configuration