-
Notifications
You must be signed in to change notification settings - Fork 28
Adding a new themes:migrate command (undocumented as it not yet ready for primetime)
#310
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
04e818a
589fcd2
f744878
8d28778
331d19e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| import { Command } from '@oclif/core' | ||
| import * as path from 'path' | ||
| import migrate from '../../lib/migrate' | ||
|
|
||
| export default class Migrate extends Command { | ||
| static description = 'migrate theme to the latest version of the templating api' | ||
|
|
||
| static hidden = true | ||
|
|
||
| static args = [ | ||
| { name: 'themeDirectory', required: true, default: '.' } | ||
| ] | ||
|
|
||
| static examples = [ | ||
| '$ zcli themes:migrate ./copenhagen_theme' | ||
| ] | ||
|
|
||
| static strict = false | ||
|
|
||
| async run () { | ||
| const { flags, argv: [themeDirectory] } = await this.parse(Migrate) | ||
| const themePath = path.resolve(themeDirectory) | ||
|
|
||
| await migrate(themePath, flags) | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,104 @@ | ||
| import * as sinon from 'sinon' | ||
| import { expect } from '@oclif/test' | ||
| import * as validationErrorsToString from './validationErrorsToString' | ||
| import * as errors from '@oclif/core/lib/errors' | ||
| import handleTemplateError from './handleTemplateError' | ||
|
|
||
| describe('handleTemplateError', () => { | ||
| beforeEach(() => { | ||
| sinon.restore() | ||
| }) | ||
|
|
||
| it('transforms template identifiers to template paths and calls error', () => { | ||
| const validationErrorsToStringStub = sinon.stub(validationErrorsToString, 'default').returns('formatted errors') | ||
| const errorStub = sinon.stub(errors, 'error') | ||
|
|
||
| const templateErrors = { | ||
| home_page: [ | ||
| { | ||
| description: 'not possible to access `names`', | ||
| line: 1, | ||
| column: 45, | ||
| length: 5 | ||
| } | ||
| ], | ||
| article_page: [ | ||
| { | ||
| description: "'articles' does not exist", | ||
| line: 21, | ||
| column: 16, | ||
| length: 11 | ||
| } | ||
| ] | ||
| } | ||
|
|
||
| handleTemplateError('theme/path', templateErrors) | ||
|
|
||
| expect(validationErrorsToStringStub.calledOnce).to.equal(true) | ||
| expect(validationErrorsToStringStub.firstCall.args[0]).to.equal('theme/path') | ||
|
|
||
| const transformedErrors = validationErrorsToStringStub.firstCall.args[1] | ||
| expect(transformedErrors).to.have.property('templates/home_page.hbs') | ||
| expect(transformedErrors).to.have.property('templates/article_page.hbs') | ||
| expect(transformedErrors['templates/home_page.hbs']).to.deep.equal([ | ||
| { | ||
| description: 'not possible to access `names`', | ||
| line: 1, | ||
| column: 45, | ||
| length: 5 | ||
| } | ||
| ]) | ||
|
|
||
| expect(errorStub.calledOnce).to.equal(true) | ||
| expect(errorStub.firstCall.args[0]).to.contain('InvalidTemplates') | ||
| expect(errorStub.firstCall.args[0]).to.contain('Template(s) with syntax error(s)') | ||
| expect(errorStub.firstCall.args[0]).to.contain('formatted errors') | ||
| }) | ||
|
|
||
| it('handles empty template errors', () => { | ||
| const validationErrorsToStringStub = sinon.stub(validationErrorsToString, 'default').returns('') | ||
| const errorStub = sinon.stub(errors, 'error') | ||
|
|
||
| handleTemplateError('theme/path', {}) | ||
|
|
||
| expect(validationErrorsToStringStub.calledOnce).to.equal(true) | ||
| expect(validationErrorsToStringStub.firstCall.args[1]).to.deep.equal({}) | ||
| expect(errorStub.calledOnce).to.equal(true) | ||
| }) | ||
|
|
||
| it('handles single template with multiple errors', () => { | ||
| const validationErrorsToStringStub = sinon.stub(validationErrorsToString, 'default').returns('multiple errors') | ||
| sinon.stub(errors, 'error') | ||
|
|
||
| const templateErrors = { | ||
| new_request_page: [ | ||
| { | ||
| description: 'First error', | ||
| line: 1, | ||
| column: 1, | ||
| length: 5 | ||
| }, | ||
| { | ||
| description: 'Second error', | ||
| line: 10, | ||
| column: 5, | ||
| length: 3 | ||
| }, | ||
| { | ||
| description: 'Third error', | ||
| line: 20, | ||
| column: 10, | ||
| length: 7 | ||
| } | ||
| ] | ||
| } | ||
|
|
||
| handleTemplateError('/my/theme', templateErrors) | ||
|
|
||
| const transformedErrors = validationErrorsToStringStub.firstCall.args[1] | ||
| expect(transformedErrors['templates/new_request_page.hbs']).to.have.length(3) | ||
| expect(transformedErrors['templates/new_request_page.hbs'][0].description).to.equal('First error') | ||
| expect(transformedErrors['templates/new_request_page.hbs'][1].description).to.equal('Second error') | ||
| expect(transformedErrors['templates/new_request_page.hbs'][2].description).to.equal('Third error') | ||
| }) | ||
| }) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,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[] | ||
dmuneras marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| const title = `${chalk.bold('InvalidTemplates')} - Template(s) with syntax error(s)` | ||
| const details = validationErrorsToString(themePath, validationErrors) | ||
|
|
||
| error(`${title}\n${details}`) | ||
| } | ||
|
Comment on lines
+1
to
+19
|
||
Uh oh!
There was an error while loading. Please reload this page.