Skip to content

Conversation

@luis-almeida
Copy link
Contributor

@luis-almeida luis-almeida commented Jan 29, 2026

Description

First iteration of a new themes:migrate command.
We are not adding documentation for it as it is not yet ready for "primetime". Once it becomes stable we will document it and announce it.

Nonetheless, the idea behind this new command is to help migrate a theme to the latest templating api version.
The end goal for this command is to automate all required changes to make a theme compatible with templating api v4.

As part of this work I have also addressed a regression: after migrating axios to use the fetch adapter, we stopped seeing well formatted errors. That should be fixes now.

Checklist

  • 💂‍♂️ includes new unit and functional tests

@luis-almeida luis-almeida force-pushed the luis.themes_migrate_command branch from 1a60fc3 to 8d28778 Compare January 29, 2026 16:01
@luis-almeida luis-almeida marked this pull request as ready for review January 29, 2026 16:16
@luis-almeida luis-almeida requested a review from a team as a code owner January 29, 2026 16:16
Copilot AI review requested due to automatic review settings January 29, 2026 16:16
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR introduces a new undocumented themes:migrate command to help migrate themes to the latest templating API version, and addresses a regression in error formatting after migrating axios to use the fetch adapter.

Changes:

  • Added new themes:migrate command with core migration logic and supporting utilities
  • Fixed axios fetch adapter error formatting by introducing parseAxiosError utility
  • Extracted common template error handling into handleTemplateError function
  • Updated test files to properly type-cast error objects as CLIError

Reviewed changes

Copilot reviewed 18 out of 18 changed files in this pull request and generated 8 comments.

Show a summary per file
File Description
packages/zcli-themes/src/commands/themes/migrate.ts New command entry point for theme migration
packages/zcli-themes/src/lib/migrate.ts Core migration logic that calls internal API and rewrites theme files
packages/zcli-themes/src/lib/rewriteManifest.ts Utility to update manifest.json api_version field
packages/zcli-themes/src/lib/rewriteTemplates.ts Utility to rewrite template files with migrated content
packages/zcli-themes/src/lib/parseAxiosError.ts Utility to normalize axios errors from fetch adapter
packages/zcli-themes/src/lib/handleTemplateError.ts Extracted error handling for template validation errors
packages/zcli-themes/src/lib/handleThemeApiError.ts Updated to use parseAxiosError for proper error formatting
packages/zcli-themes/src/lib/preview.ts Refactored to use extracted handleTemplateError function
packages/zcli-themes/tests/functional/migrate.test.ts Functional tests for migrate command
packages/zcli-themes/src/lib/migrate.test.ts Unit tests for migrate function
packages/zcli-themes/src/lib/rewriteManifest.test.ts Unit tests for manifest rewriting
packages/zcli-themes/src/lib/rewriteTemplates.test.ts Unit tests for template rewriting
packages/zcli-themes/tests/functional/update.test.ts Updated error type casting to CLIError
packages/zcli-themes/tests/functional/publish.test.ts Updated error type casting to CLIError
packages/zcli-themes/tests/functional/preview.test.ts Added type annotation for server variable
packages/zcli-themes/tests/functional/list.test.ts Updated error type casting to CLIError
packages/zcli-themes/tests/functional/import.test.ts Updated error type casting to CLIError
packages/zcli-themes/tests/functional/delete.test.ts Updated error type casting to CLIError

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +1 to +19
import { ValidationError, ValidationErrors } from '../types'
import validationErrorsToString from './validationErrorsToString'
import * as chalk from 'chalk'
import { error } from '@oclif/core/lib/errors'

export default function handleTemplateError (themePath: string, templateErrors: ValidationErrors) {
const validationErrors: ValidationErrors = {}
for (const [template, errors] of Object.entries(templateErrors)) {
// the theming endpoints return the template identifier as the 'key' instead of
// the template path. We must fix this so we can reuse `validationErrorsToString`
// and align with the job import error handling
validationErrors[`templates/${template}.hbs`] = errors as ValidationError[]
}

const title = `${chalk.bold('InvalidTemplates')} - Template(s) with syntax error(s)`
const details = validationErrorsToString(themePath, validationErrors)

error(`${title}\n${details}`)
}
Copy link

Copilot AI Jan 29, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The handleTemplateError function lacks unit tests. This is an extracted function used by both preview and migrate commands, and verifying its behavior in isolation would improve maintainability. Tests should verify that it correctly transforms template identifiers to file paths and properly formats error messages.

Copilot uses AI. Check for mistakes.
@luis-almeida luis-almeida merged commit 5c31cc8 into master Feb 2, 2026
7 checks passed
@luis-almeida luis-almeida deleted the luis.themes_migrate_command branch February 2, 2026 09:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants