2 min read

Theme Bundling Script (scripts/bundle.ps1)

This document details the functionality of the bundle.ps1 PowerShell script used to package the theme for production.

Overview

The bundle.ps1 script automates the creation of a production-ready WordPress theme ZIP file. It handles versioning, asset compilation, cleanup of development files, and ensures cross-platform compatibility.

Key Features

1. Version Management

  • Automatically increments the patch version in src/input.css (e.g., 1.0.0 -> 1.0.1).
  • Runs npm run build to compile Tailwind CSS and propagate the version to style.css.

2. Clean Build Generation

  • Creates a temporary distribution folder.
  • Excludes development assets such as:
    • node_modules
    • .git / .github
    • src folder
    • scripts folder
    • Configuration files (tailwind.config.js, package.json, etc.)

3. Cross-Platform Compatibility

  • Issue: Windows-generated zip files often use backslashes (\) for paths, which can break directory structures when uploaded to Linux servers (cPanel, FTP).
  • Solution: This script manually constructs the zip archive using .NET libraries to enforce forward-slash (/) path separators.
  • Reference: See ZIP_COMPATIBILITY.md for a deep dive into this issue and the solution implemented.

4. Validation

  • Verifies the existence of critical WordPress files (style.css, index.php, functions.php).
  • Checks style.css for the required "Theme Name" header.

Usage & Parameters

Run the script from the project root or the scripts directory.

.\scripts\bundle.ps1 [parameters]
Parameter Description
-ThemeName "slug" Sets the theme slug used for the zip filename and the internal root folder. Default: wp-scratch.
-SkipVersionBump Skips the automatic version increment in src/input.css.
-NoVersionSuffix Removes the version number from the output filename (e.g., wp-scratch.zip) and skips version bump.
-SkipBuild Skips the npm run build step and critical file validation. Useful for quick zipping of current state.
-DryRun Simulates the process without modifying files or creating a zip. Lists files to be included.

Examples

Standard Production Build:

.\scripts\bundle.ps1

Build with Custom Theme Name:

.\scripts\bundle.ps1 -ThemeName "client-project"

Quick Export (No version bump, no build step):

.\scripts\bundle.ps1 -NoVersionSuffix -SkipBuild