JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 2
  • Score
    100M100P100Q48651F
  • License MIT

Build tools for Maropost storefront themes - includes asset compilation, Tailwind CSS processing, file watching, and development server

Package Exports

  • @maropost-tools/theme-cli
  • @maropost-tools/theme-cli/index.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@maropost-tools/theme-cli) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

Maropost Theme CLI

Professional build tools for Maropost storefront themes - includes asset compilation, Tailwind CSS processing, file watching, and integrated development server with theme preview functionality.

Features

🚀 All-in-One Development Server

  • Automatic asset building on startup and file changes
  • Local theme development server that proxies to remote Maropost storefront
  • Template preview functionality - sends local templates to storefront /preview endpoint
  • Intelligent static asset serving with manifest-based hash resolution
  • Route-based template matching using routes.json configuration
  • Real-time file watching with automatic rebuilds
  • Professional logging with categorized, colored output
  • Gzip compression for faster template transfers

🏗️ Asset Building

  • CSS/SCSS/SASS compilation with Sass
  • JavaScript/TypeScript bundling with esbuild
  • Tailwind CSS processing with v4 support
  • Image optimization with WebP conversion
  • PostCSS processing with autoprefixer and cssnano
  • CSS purging with PurgeCSS
  • Asset hashing with manifest generation

🔧 Developer Experience

  • Professional CLI interface with modern development workflow
  • Verbose debug mode for troubleshooting
  • Graceful error handling and recovery
  • Build timing and performance metrics
  • Template rendering status tracking

Installation

npm install @maropost-tools/theme-cli

Or install globally:

npm install -g @maropost-tools/theme-cli

Quick Start

The easiest way to start developing - builds, watches, and serves everything in one command:

# Start development server with automatic building and watching
maropost-serve --storefront-url="https://your-store.example.com"

# With custom options
maropost-serve --storefront-url="https://your-store.example.com" \
                --theme-path="./theme" \
                --port=3000 \
                --verbose

# Skip initial build (use existing assets)
maropost-serve --storefront-url="https://your-store.example.com" --no-build

# Server only (no file watching)
maropost-serve --storefront-url="https://your-store.example.com" --no-watch

🏗️ Standalone Asset Building

For CI/CD or when you only need to build assets:

# Build individual files (default)
maropost-build

# Build bundled files
maropost-build --bundle

# Clean and build
maropost-build --clean

# Build with CSS purging
maropost-build --purge

👀 Standalone File Watching

For custom workflows (not needed with serve command):

# Watch for changes and rebuild (legacy)
maropost-watch

Development Server

The development server replicates the functionality of the maropost-cli Go project, providing a local development environment for Maropost themes.

How It Works

  1. Route Matching: Reads config/routes.json to determine which template to use for each URL path
  2. Template Loading: Loads local template files from templates/[type]/default.json
  3. Asset Collection: Automatically collects all required sections, blocks, and snippets
  4. Preview Request: Sends the local template data to the storefront's /preview endpoint
  5. Response Proxying: Returns the storefront's response with local theme changes applied

Server Features

  • Static Assets: Serves /static and /public directories
  • Template Preview: Intercepts theme requests and sends to preview endpoint
  • Fallback Proxy: Routes unmatched requests directly to storefront
  • CORS Support: Full CORS headers for development
  • Request Logging: Comprehensive request logging with Morgan
  • Graceful Shutdown: Handles SIGINT and SIGTERM signals

Configuration

const { createDevServer } = require('@maropost-tools/theme-cli');

const server = createDevServer({
  port: 3333,                    // Server port (default: 3333)
  host: 'localhost',             // Host to bind to (default: localhost)
  storefrontURL: 'https://your-store.example.com',  // Required: Remote storefront URL
  themePath: './theme'           // Optional: Local theme directory path (default: current directory)
});

// Start the server
server.start().then(() => {
  console.log('Development server running');
});

// Stop the server
server.stop().then(() => {
  console.log('Development server stopped');
});

CLI Usage

maropost-serve [options]

Required Options:
  --storefront-url    Storefront store URL (e.g., https://your-store.example.com)

Optional Options:
  --theme-path        Path to local theme directory (default: current directory ".")
  --port              Port for local development server (default: 3333)
  --host              Host to bind to (default: localhost)
  --no-build          Skip initial build on startup
  --no-watch          Disable file watching and auto-rebuild
  --verbose           Enable verbose debug logging
  --help              Show help message

Examples:
  # Standard development workflow
  maropost-serve --storefront-url="https://your-store.example.com"

  # With custom theme directory and port
  maropost-serve --storefront-url="https://your-store.example.com" --theme-path="./theme" --port=3000

  # Debug mode with verbose logging
  maropost-serve --storefront-url="https://your-store.example.com" --verbose

  # Server only (no build/watch)
  maropost-serve --storefront-url="https://your-store.example.com" --no-build --no-watch

Theme Structure

The development server expects your theme to follow this structure:

theme/
├── config/
│   ├── routes.json           # Route definitions
│   ├── settings_data.json    # Theme settings
│   └── settings_schema.json  # Settings schema
├── templates/
│   ├── home/
│   │   └── default.json      # Home page template
│   ├── product/
│   │   └── default.json      # Product page template
│   └── collection/
│       └── default.json      # Collection page template
├── sections/
│   ├── default.html          # Default section
│   ├── header.html           # Header section
│   └── footer.html           # Footer section
├── blocks/
│   ├── button.html           # Button block
│   ├── image.html            # Image block
│   └── text.html             # Text block
├── snippets/
│   ├── product-card.html     # Product card snippet
│   └── collection-card.html  # Collection card snippet
├── layouts/
│   ├── main.html             # Main layout
│   └── auth.html             # Auth layout
├── assets/
│   ├── css/                  # CSS/SCSS files
│   ├── js/                   # JavaScript files
│   └── images/               # Image files
└── public/                   # Public assets

Routes Configuration

The config/routes.json file defines how URLs map to templates:

[
  {
    "id": "home",
    "label": "Home",
    "path": "/",
    "method": "GET",
    "target": "template",
    "template_type": "home"
  },
  {
    "id": "product",
    "label": "Product",
    "path": "/products/{handle}",
    "method": "GET",
    "target": "template",
    "template_type": "product"
  },
  {
    "id": "collection",
    "label": "Collection",
    "path": "/collections/{handle}",
    "method": "GET",
    "target": "template",
    "template_type": "collection"
  }
]

Template Structure

Templates in templates/[type]/default.json define the page structure:

{
  "id": "home",
  "label": "Home Page",
  "type": "home",
  "layout": "main",
  "sections": {
    "header": {
      "id": "header",
      "type": "header",
      "settings": {},
      "blocks": {}
    },
    "hero": {
      "id": "hero",
      "type": "hero",
      "settings": {},
      "blocks": {}
    }
  },
  "order": ["header", "hero"]
}

Asset Building

Build Modes

Individual Mode (Default)

  • Each CSS/SCSS/SASS file → separate .css file
  • Each JS/TS/JSX/TSX file → separate .js file
  • Good for: selective loading, debugging, modular themes

Bundle Mode

  • All CSS → single theme.css file
  • All JS → single theme.js file
  • Good for: performance, single HTTP request, production

Build Options

# Individual files (default)
maropost-build

# Bundle mode
maropost-build --bundle

# Clean output directories
maropost-build --clean

# CSS purging
maropost-build --purge

# Disable minification
maropost-build --no-minify

# Combine options
maropost-build --bundle --clean --purge

Configuration

Create a theme-cli.config.js file in your project root:

module.exports = {
  // Input directories
  cssDir: 'assets/css',
  jsDir: 'assets/js',
  imagesDir: 'assets/images',
  
  // Output directories
  outputCssDir: 'tmp/assets/css',
  outputJsDir: 'tmp/assets/js',
  outputImagesDir: 'tmp/assets/images',
  
  // Build options
  bundle: false,        // Bundle all files
  minify: true,         // Minify output
  purge: false,         // Run PurgeCSS
  
  // Tailwind CSS
  tailwindInput: 'assets/css/tailwind.css',
  
  // Theme directories for CSS purging
  themeDirs: [
    'templates',
    'sections',
    'blocks',
    'snippets',
    'layouts'
  ]
};

File Watching

# Watch for changes and rebuild
maropost-watch

# Watch with specific options
maropost-watch --bundle --purge

Programmatic Usage

Asset Building

const { build, config } = require('@maropost-tools/theme-cli');

// Use default configuration
build();

// Custom configuration
const customConfig = {
  ...config,
  bundle: true,
  purge: true
};

build(customConfig);

Development Server

const { createDevServer } = require('@maropost-tools/theme-cli');

const server = createDevServer({
  port: 3000,
  storefrontURL: 'https://your-store.example.com',
  themePath: './theme'
});

server.start().then(() => {
  console.log('Server running on port 3000');
});

Dependencies

Required

  • Node.js >= 18.0.0
  • npm >= 9.0.0

Build Tools

  • Sass for CSS/SCSS compilation
  • esbuild for JavaScript/TypeScript bundling
  • Tailwind CSS v4 for utility-first CSS
  • PostCSS for CSS processing
  • PurgeCSS for unused CSS removal

Development Server

  • Express.js for HTTP server
  • CORS for cross-origin requests
  • Morgan for request logging
  • http-proxy-middleware for proxying

Examples

Basic Theme Development

  1. Start the development server:

    maropost-serve --storefront-url="https://your-store.example.com"
  2. Make changes to your theme files

  3. View changes in real-time at http://localhost:3333

  4. Build production assets:

    maropost-build --bundle --clean

Advanced Configuration

// theme-cli.config.js
module.exports = {
  bundle: true,
  minify: true,
  purge: true,
  tailwindInput: 'assets/css/tailwind.css',
  themeDirs: ['templates', 'sections', 'blocks', 'snippets', 'layouts']
};

Integration with Build Tools

// package.json scripts
{
  "scripts": {
    "dev": "maropost-serve --storefront-url=\"https://your-store.example.com\"",
    "build": "maropost-build --bundle --clean",
    "watch": "maropost-watch --bundle",
    "build:prod": "maropost-build --bundle --clean --purge"
  }
}

Troubleshooting

Common Issues

  1. Port already in use: Change the port with --port option
  2. Template not found: Check your routes.json configuration
  3. Assets not loading: Ensure theme directory structure is correct
  4. Preview endpoint errors: Verify storefront URL and connectivity

Debug Mode

Enable verbose logging by setting the DEBUG environment variable:

DEBUG=* maropost-serve --storefront-url="..." --theme-path="..."

Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests if applicable
  5. Submit a pull request

License

MIT License - see LICENSE file for details.

Support