# Image Generator for Power of Dark CMS

Automated CLI tool to capture full-page screenshots of CMS themes via Playwright and optionally sync them into WordPress CMS Theme posts as Gutenberg image galleries.

## Requirements

- Node.js >= 20.12.2
- Playwright Chromium engine

## Installation

```bash
# 1. Clone/navigate to directory and install dependencies
npm install

# 2. Install Playwright browser engine
npx playwright install chromium

# 3. Configure environment variables
cp .env.example .env
```

## CLI Help

```
Usage: node index.js [options]

Options:
  -u, --url <url>        Target URL template (env: URL / DEMOS_URL, e.g. "https://{theme}.cms.powerofdark.com/{pageURL}")
  -t, --theme <theme>    Single theme name (env: THEME, mandatory if URL lacks {theme})
      --themes <list>    Comma-separated themes list (env: THEMES, overrides default themes)
  -p, --preset <name>    Preset name from presets/ directory without extension (env: PRESET, default: "store")
      --skip-wp          Skip WordPress media upload and theme update (env: SKIP_WP)
  -h, --help             Show help

Examples:
  # 1. Full run: 2 themes with WordPress upload
  node index.js --url "https://{theme}.cms.powerofdark.com/{pageURL}" --themes "arg2019,cotowers" --preset store

  # 2. Single theme: static URL without {theme} and developer preset (skip WP)
  node index.js --url "http://localhost:8080/{pageURL}" --theme mytheme --preset develop --skip-wp
```

## Usage Examples

### 1. Full Run: 2 Themes with WordPress Upload
Crawl `arg2019` and `cotowers` against templated demo URL using the `store` preset, then upload images to WordPress and update post Gutenberg layout:

```bash
node index.js \
  --url "https://{theme}.cms.powerofdark.com/{pageURL}" \
  --themes "arg2019,cotowers" \
  --preset store
```

### 2. Single Theme: Static URL without `{theme}` and Developer Preset
Crawl a local/staging environment where the URL does not contain `{theme}`. Uses `develop` preset, stores screenshots in `screenshots/mytheme/`, and skips WordPress sync:

```bash
node index.js \
  --url "http://localhost:8080/{pageURL}" \
  --theme mytheme \
  --preset develop \
  --skip-wp
```

## Docker

```bash
# Build image
docker build -t node-20-playwright .

# Run container
docker run -it --rm --privileged \
  -v $(pwd):/app \
  -w /app \
  node-20-playwright npm start
```