diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9f7b685..cf9f383 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,5 +1,5 @@ name: Run CI jobs -on: [push, pull_request] +on: [push] jobs: lint: diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index b3ac13f..e768e9f 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -19,4 +19,14 @@ jobs: uses: softprops/action-gh-release@v2 if: startsWith(github.ref, 'refs/tags/') with: - files: '*.vsix' \ No newline at end of file + files: '*.vsix' + deploy: + runs-on: ubuntu-latest + needs: build + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Publish + run: npm run deploy + env: + VSCE_PAT: ${{ secrets.VSCE_PAT }} diff --git a/CHANGELOG.md b/CHANGELOG.md index a15ffb9..40f8733 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,22 @@ All notable changes to the "magento-toolbox" extension will be documented in thi Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how to structure this file. +## [1.2.0] + +- Added: Generator command for sample Layout XML file +- Added: Generator command for sample page_types.xml file +- Added: Generator command for sample crontab.xml file +- Added: Generator command for sample email_templates.xml file +- Added: Generator command for sample sections.xml file +- Added: Generator command for sample fieldset.xml file +- Added: Generator command for sample view.xml file +- Added: Generator command for sample indexer.xml file +- Added: Generator command for sample mview.xml file +- Added: Generator command for sample widget.xml file +- Added: Generator command for sample extension_attributes.xml file +- Added: Generator command for sample system.xml file +- Added: Generator command for sample config.xml file + ## [1.1.3] - 3/12/2025 - Fixed: Block, observer, plugin and preference class generation fails if class name includes backslashes @@ -11,7 +27,7 @@ Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how - Fixed: Module generation module.xml sequence elements are not added - Fixed: Observer XML generation fails if file header comment is not configured - Fixed: Preference type attribute does not include full class namespace -- Chore: added unit tests for generator commands +- Chore: Added unit tests for generator commands ## [1.1.2] - 2/27/2025 diff --git a/package.json b/package.json index 29c1f3a..badc522 100644 --- a/package.json +++ b/package.json @@ -110,6 +110,58 @@ { "command": "magento-toolbox.generatePreference", "title": "Magento Toolbox: Generate Preference" + }, + { + "command": "magento-toolbox.generateLayoutXmlFile", + "title": "Magento Toolbox: Generate Layout XML" + }, + { + "command": "magento-toolbox.generatePageTypesXmlFile", + "title": "Magento Toolbox: Generate Page Types XML" + }, + { + "command": "magento-toolbox.generateCrontabXmlFile", + "title": "Magento Toolbox: Generate Crontab XML" + }, + { + "command": "magento-toolbox.generateEmailTemplatesXmlFile", + "title": "Magento Toolbox: Generate Email Templates XML" + }, + { + "command": "magento-toolbox.generateSectionsXmlFile", + "title": "Magento Toolbox: Generate Sections XML" + }, + { + "command": "magento-toolbox.generateFieldsetXmlFile", + "title": "Magento Toolbox: Generate Fieldset XML" + }, + { + "command": "magento-toolbox.generateViewXmlFile", + "title": "Magento Toolbox: Generate View XML" + }, + { + "command": "magento-toolbox.generateIndexerXmlFile", + "title": "Magento Toolbox: Generate Indexer XML" + }, + { + "command": "magento-toolbox.generateMviewXmlFile", + "title": "Magento Toolbox: Generate MVIEW XML" + }, + { + "command": "magento-toolbox.generateWidgetXmlFile", + "title": "Magento Toolbox: Generate Widget XML" + }, + { + "command": "magento-toolbox.generateExtensionAttributesXmlFile", + "title": "Magento Toolbox: Generate Extension Attributes XML" + }, + { + "command": "magento-toolbox.generateSystemXmlFile", + "title": "Magento Toolbox: Generate System XML" + }, + { + "command": "magento-toolbox.generateConfigXmlFile", + "title": "Magento Toolbox: Generate Config XML" } ], "menus": { @@ -183,6 +235,58 @@ { "command": "magento-toolbox.generateWebapiXmlFile", "when": "resourcePath =~ /app\\/code\\/.+\\/.+/i" + }, + { + "command": "magento-toolbox.generateLayoutXmlFile", + "when": "resourcePath =~ /app\\/code\\/.+\\/.+/i" + }, + { + "command": "magento-toolbox.generatePageTypesXmlFile", + "when": "resourcePath =~ /app\\/code\\/.+\\/.+/i" + }, + { + "command": "magento-toolbox.generateCrontabXmlFile", + "when": "resourcePath =~ /app\\/code\\/.+\\/.+/i" + }, + { + "command": "magento-toolbox.generateEmailTemplatesXmlFile", + "when": "resourcePath =~ /app\\/code\\/.+\\/.+/i" + }, + { + "command": "magento-toolbox.generateSectionsXmlFile", + "when": "resourcePath =~ /app\\/code\\/.+\\/.+/i" + }, + { + "command": "magento-toolbox.generateFieldsetXmlFile", + "when": "resourcePath =~ /app\\/code\\/.+\\/.+/i" + }, + { + "command": "magento-toolbox.generateViewXmlFile", + "when": "resourcePath =~ /app\\/code\\/.+\\/.+/i" + }, + { + "command": "magento-toolbox.generateIndexerXmlFile", + "when": "resourcePath =~ /app\\/code\\/.+\\/.+/i" + }, + { + "command": "magento-toolbox.generateMviewXmlFile", + "when": "resourcePath =~ /app\\/code\\/.+\\/.+/i" + }, + { + "command": "magento-toolbox.generateWidgetXmlFile", + "when": "resourcePath =~ /app\\/code\\/.+\\/.+/i" + }, + { + "command": "magento-toolbox.generateExtensionAttributesXmlFile", + "when": "resourcePath =~ /app\\/code\\/.+\\/.+/i" + }, + { + "command": "magento-toolbox.generateSystemXmlFile", + "when": "resourcePath =~ /app\\/code\\/.+\\/.+/i" + }, + { + "command": "magento-toolbox.generateConfigXmlFile", + "when": "resourcePath =~ /app\\/code\\/.+\\/.+/i" } ] } @@ -201,7 +305,8 @@ "test": "vscode-test", "format": "prettier --write \"src/**/*.{ts,tsx,js,jsx,json,css,scss,md}\"", "format:check": "prettier --check \"src/**/*.{ts,tsx,js,jsx,json,css,scss,md}\"", - "package-vsix": "vsce package" + "package-vsix": "vsce package", + "deploy": "vsce publish" }, "devDependencies": { "@types/ejs": "^3.1.5", diff --git a/src/command/GenerateAclXmlFileCommand.ts b/src/command/GenerateAclXmlFileCommand.ts index 687ee7a..c2ba402 100644 --- a/src/command/GenerateAclXmlFileCommand.ts +++ b/src/command/GenerateAclXmlFileCommand.ts @@ -10,7 +10,7 @@ export default class GenerateAclXmlFileCommand extends SimpleTemplateGeneratorCo return 'ACL XML File'; } - getTemplatePath(data: TemplateWizardData): string { + getFilePath(data: TemplateWizardData): string { const [vendor, module] = data.module.split('_'); return `app/code/${vendor}/${module}/etc/acl.xml`; diff --git a/src/command/GenerateConfigXmlFileCommand.ts b/src/command/GenerateConfigXmlFileCommand.ts new file mode 100644 index 0000000..c2d4a2a --- /dev/null +++ b/src/command/GenerateConfigXmlFileCommand.ts @@ -0,0 +1,27 @@ +import { SimpleTemplateGeneratorCommand } from './SimpleTemplateGeneratorCommand'; +import { TemplateWizardData } from 'wizard/SimpleTemplateWizard'; +import FileHeader from 'common/xml/FileHeader'; + +export default class GenerateConfigXmlFileCommand extends SimpleTemplateGeneratorCommand { + constructor() { + super('magento-toolbox.generateConfigXmlFile'); + } + + getWizardTitle(): string { + return 'Config XML File'; + } + + getFileHeader(data: TemplateWizardData): string | undefined { + return FileHeader.getHeader(data.module); + } + + getFilePath(data: TemplateWizardData): string { + const [vendor, module] = data.module.split('_'); + + return `app/code/${vendor}/${module}/etc/config.xml`; + } + + getTemplateName(data: TemplateWizardData): string { + return 'xml/blank-config'; + } +} diff --git a/src/command/GenerateCrontabXmlCommand.ts b/src/command/GenerateCrontabXmlCommand.ts new file mode 100644 index 0000000..d964e6f --- /dev/null +++ b/src/command/GenerateCrontabXmlCommand.ts @@ -0,0 +1,27 @@ +import { SimpleTemplateGeneratorCommand } from './SimpleTemplateGeneratorCommand'; +import { TemplateWizardData } from 'wizard/SimpleTemplateWizard'; +import FileHeader from 'common/xml/FileHeader'; + +export default class GenerateCrontabXmlCommand extends SimpleTemplateGeneratorCommand { + constructor() { + super('magento-toolbox.generateCrontabXmlFile'); + } + + getWizardTitle(): string { + return 'Crontab XML File'; + } + + getFileHeader(data: TemplateWizardData): string | undefined { + return FileHeader.getHeader(data.module); + } + + getFilePath(data: TemplateWizardData): string { + const [vendor, module] = data.module.split('_'); + + return `app/code/${vendor}/${module}/etc/crontab.xml`; + } + + getTemplateName(data: TemplateWizardData): string { + return 'xml/blank-crontab'; + } +} diff --git a/src/command/GenerateDiXmlFileCommand.ts b/src/command/GenerateDiXmlFileCommand.ts index e0f6c9a..a806a4b 100644 --- a/src/command/GenerateDiXmlFileCommand.ts +++ b/src/command/GenerateDiXmlFileCommand.ts @@ -23,7 +23,7 @@ export default class GenerateDiXmlFileCommand extends SimpleTemplateGeneratorCom return 'DI XML File'; } - getTemplatePath(data: TemplateWizardData): string { + getFilePath(data: TemplateWizardData): string { const [vendor, module] = data.module.split('_'); if (data.area && data.area !== MagentoScope.Global) { diff --git a/src/command/GenerateEmailTemplatesXmlCommand.ts b/src/command/GenerateEmailTemplatesXmlCommand.ts new file mode 100644 index 0000000..79bf69d --- /dev/null +++ b/src/command/GenerateEmailTemplatesXmlCommand.ts @@ -0,0 +1,27 @@ +import { SimpleTemplateGeneratorCommand } from './SimpleTemplateGeneratorCommand'; +import { TemplateWizardData } from 'wizard/SimpleTemplateWizard'; +import FileHeader from 'common/xml/FileHeader'; + +export default class GenerateEmailTemplatesXmlCommand extends SimpleTemplateGeneratorCommand { + constructor() { + super('magento-toolbox.generateEmailTemplatesXmlFile'); + } + + getWizardTitle(): string { + return 'Email Templates XML File'; + } + + getFileHeader(data: TemplateWizardData): string | undefined { + return FileHeader.getHeader(data.module); + } + + getFilePath(data: TemplateWizardData): string { + const [vendor, module] = data.module.split('_'); + + return `app/code/${vendor}/${module}/etc/email_templates.xml`; + } + + getTemplateName(data: TemplateWizardData): string { + return 'xml/blank-email-templates'; + } +} diff --git a/src/command/GenerateEventsXmlCommand.ts b/src/command/GenerateEventsXmlCommand.ts index 5a18fa1..4d88a74 100644 --- a/src/command/GenerateEventsXmlCommand.ts +++ b/src/command/GenerateEventsXmlCommand.ts @@ -28,7 +28,7 @@ export default class GenerateEventsXmlCommand extends SimpleTemplateGeneratorCom return FileHeader.getHeader(data.module); } - getTemplatePath(data: TemplateWizardData): string { + getFilePath(data: TemplateWizardData): string { const [vendor, module] = data.module.split('_'); if (data.area && data.area !== MagentoScope.Global) { diff --git a/src/command/GenerateExtensionAttributesXmlFileCommand.ts b/src/command/GenerateExtensionAttributesXmlFileCommand.ts new file mode 100644 index 0000000..967ca07 --- /dev/null +++ b/src/command/GenerateExtensionAttributesXmlFileCommand.ts @@ -0,0 +1,27 @@ +import { SimpleTemplateGeneratorCommand } from './SimpleTemplateGeneratorCommand'; +import { TemplateWizardData } from 'wizard/SimpleTemplateWizard'; +import FileHeader from 'common/xml/FileHeader'; + +export default class GenerateExtensionAttributesXmlFileCommand extends SimpleTemplateGeneratorCommand { + constructor() { + super('magento-toolbox.generateExtensionAttributesXmlFile'); + } + + getWizardTitle(): string { + return 'Extension Attributes XML File'; + } + + getFileHeader(data: TemplateWizardData): string | undefined { + return FileHeader.getHeader(data.module); + } + + getFilePath(data: TemplateWizardData): string { + const [vendor, module] = data.module.split('_'); + + return `app/code/${vendor}/${module}/etc/extension_attributes.xml`; + } + + getTemplateName(data: TemplateWizardData): string { + return 'xml/blank-extension-attributes'; + } +} diff --git a/src/command/GenerateFieldsetXmlCommand.ts b/src/command/GenerateFieldsetXmlCommand.ts new file mode 100644 index 0000000..0917bc7 --- /dev/null +++ b/src/command/GenerateFieldsetXmlCommand.ts @@ -0,0 +1,27 @@ +import { SimpleTemplateGeneratorCommand } from './SimpleTemplateGeneratorCommand'; +import { TemplateWizardData } from 'wizard/SimpleTemplateWizard'; +import FileHeader from 'common/xml/FileHeader'; + +export default class GenerateFieldsetXmlCommand extends SimpleTemplateGeneratorCommand { + constructor() { + super('magento-toolbox.generateFieldsetXmlFile'); + } + + getWizardTitle(): string { + return 'Fieldset XML File'; + } + + getFileHeader(data: TemplateWizardData): string | undefined { + return FileHeader.getHeader(data.module); + } + + getFilePath(data: TemplateWizardData): string { + const [vendor, module] = data.module.split('_'); + + return `app/code/${vendor}/${module}/etc/fieldset.xml`; + } + + getTemplateName(data: TemplateWizardData): string { + return 'xml/blank-fieldset'; + } +} diff --git a/src/command/GenerateGraphqlSchemaFile.ts b/src/command/GenerateGraphqlSchemaFile.ts index 7b430fc..7c82b06 100644 --- a/src/command/GenerateGraphqlSchemaFile.ts +++ b/src/command/GenerateGraphqlSchemaFile.ts @@ -10,7 +10,7 @@ export default class GenerateGraphqlSchemaFileCommand extends SimpleTemplateGene return 'GraphQL Schema File'; } - getTemplatePath(data: TemplateWizardData): string { + getFilePath(data: TemplateWizardData): string { const [vendor, module] = data.module.split('_'); return `app/code/${vendor}/${module}/etc/schema.graphqls`; diff --git a/src/command/GenerateIndexerXmlFileCommand.ts b/src/command/GenerateIndexerXmlFileCommand.ts new file mode 100644 index 0000000..5db3be7 --- /dev/null +++ b/src/command/GenerateIndexerXmlFileCommand.ts @@ -0,0 +1,27 @@ +import { SimpleTemplateGeneratorCommand } from './SimpleTemplateGeneratorCommand'; +import { TemplateWizardData } from 'wizard/SimpleTemplateWizard'; +import FileHeader from 'common/xml/FileHeader'; + +export default class GenerateIndexerXmlFileCommand extends SimpleTemplateGeneratorCommand { + constructor() { + super('magento-toolbox.generateIndexerXmlFile'); + } + + getWizardTitle(): string { + return 'Indexer XML File'; + } + + getFileHeader(data: TemplateWizardData): string | undefined { + return FileHeader.getHeader(data.module); + } + + getFilePath(data: TemplateWizardData): string { + const [vendor, module] = data.module.split('_'); + + return `app/code/${vendor}/${module}/etc/indexer.xml`; + } + + getTemplateName(data: TemplateWizardData): string { + return 'xml/blank-indexer'; + } +} diff --git a/src/command/GenerateLayoutXmlCommand.ts b/src/command/GenerateLayoutXmlCommand.ts new file mode 100644 index 0000000..d78826e --- /dev/null +++ b/src/command/GenerateLayoutXmlCommand.ts @@ -0,0 +1,56 @@ +import { MagentoScope } from 'types'; +import { SimpleTemplateGeneratorCommand } from './SimpleTemplateGeneratorCommand'; +import { TemplateWizardData } from 'wizard/SimpleTemplateWizard'; +import { WizardField, WizardValidationRule } from 'webview/types'; +import { WizardFieldBuilder } from 'webview/WizardFieldBuilder'; +import FileHeader from 'common/xml/FileHeader'; + +export default class GenerateLayoutXmlCommand extends SimpleTemplateGeneratorCommand { + constructor() { + super('magento-toolbox.generateLayoutXmlFile'); + } + + getAreas(): MagentoScope[] { + return [ + MagentoScope.Global, + MagentoScope.Adminhtml, + MagentoScope.Frontend, + MagentoScope.Cron, + MagentoScope.WebapiRest, + MagentoScope.WebapiSoap, + MagentoScope.Graphql, + ]; + } + + getFileHeader(data: TemplateWizardData): string | undefined { + return FileHeader.getHeader(data.module); + } + + getWizardTitle(): string { + return 'Layout XML File'; + } + + getFilePath(data: TemplateWizardData): string { + const [vendor, module] = data.module.split('_'); + + if (data.area && data.area !== MagentoScope.Global) { + return `app/code/${vendor}/${module}/view/${data.area}/layout/${data.name}.xml`; + } + + return `app/code/${vendor}/${module}/view/base/layout/${data.name}.xml`; + } + + getTemplateName(data: TemplateWizardData): string { + return 'xml/blank-layout'; + } + + getWizardFields(): WizardField[] { + return [WizardFieldBuilder.text('name', 'Layout Name').build()]; + } + + getWizardValidation(): Record { + return { + name: 'required', + }; + } +} diff --git a/src/command/GenerateMviewXmlFileCommand.ts b/src/command/GenerateMviewXmlFileCommand.ts new file mode 100644 index 0000000..7439a64 --- /dev/null +++ b/src/command/GenerateMviewXmlFileCommand.ts @@ -0,0 +1,27 @@ +import { SimpleTemplateGeneratorCommand } from './SimpleTemplateGeneratorCommand'; +import { TemplateWizardData } from 'wizard/SimpleTemplateWizard'; +import FileHeader from 'common/xml/FileHeader'; + +export default class GenerateMviewXmlFileCommand extends SimpleTemplateGeneratorCommand { + constructor() { + super('magento-toolbox.generateMviewXmlFile'); + } + + getWizardTitle(): string { + return 'MVIEW XML File'; + } + + getFileHeader(data: TemplateWizardData): string | undefined { + return FileHeader.getHeader(data.module); + } + + getFilePath(data: TemplateWizardData): string { + const [vendor, module] = data.module.split('_'); + + return `app/code/${vendor}/${module}/etc/mview.xml`; + } + + getTemplateName(data: TemplateWizardData): string { + return 'xml/blank-mview'; + } +} diff --git a/src/command/GeneratePageTypesXmlCommand.ts b/src/command/GeneratePageTypesXmlCommand.ts new file mode 100644 index 0000000..d504a09 --- /dev/null +++ b/src/command/GeneratePageTypesXmlCommand.ts @@ -0,0 +1,27 @@ +import { SimpleTemplateGeneratorCommand } from './SimpleTemplateGeneratorCommand'; +import { TemplateWizardData } from 'wizard/SimpleTemplateWizard'; +import FileHeader from 'common/xml/FileHeader'; + +export default class GeneratePageTypesXmlCommand extends SimpleTemplateGeneratorCommand { + constructor() { + super('magento-toolbox.generatePageTypesXmlFile'); + } + + getWizardTitle(): string { + return 'Page Types XML File'; + } + + getFileHeader(data: TemplateWizardData): string | undefined { + return FileHeader.getHeader(data.module); + } + + getFilePath(data: TemplateWizardData): string { + const [vendor, module] = data.module.split('_'); + + return `app/code/${vendor}/${module}/etc/frontend/page_types.xml`; + } + + getTemplateName(data: TemplateWizardData): string { + return 'xml/blank-page-types'; + } +} diff --git a/src/command/GenerateRoutesXmlFileCommand.ts b/src/command/GenerateRoutesXmlFileCommand.ts index e42e4fb..1df986b 100644 --- a/src/command/GenerateRoutesXmlFileCommand.ts +++ b/src/command/GenerateRoutesXmlFileCommand.ts @@ -22,7 +22,7 @@ export default class GenerateRoutesXmlFileCommand extends SimpleTemplateGenerato return FileHeader.getHeader(data.module); } - getTemplatePath(data: TemplateWizardData): string { + getFilePath(data: TemplateWizardData): string { const [vendor, module] = data.module.split('_'); return `app/code/${vendor}/${module}/etc/${data.area}/routes.xml`; diff --git a/src/command/GenerateSectionsXmlCommand.ts b/src/command/GenerateSectionsXmlCommand.ts new file mode 100644 index 0000000..75cfd68 --- /dev/null +++ b/src/command/GenerateSectionsXmlCommand.ts @@ -0,0 +1,27 @@ +import { SimpleTemplateGeneratorCommand } from './SimpleTemplateGeneratorCommand'; +import { TemplateWizardData } from 'wizard/SimpleTemplateWizard'; +import FileHeader from 'common/xml/FileHeader'; + +export default class GenerateSectionsXmlCommand extends SimpleTemplateGeneratorCommand { + constructor() { + super('magento-toolbox.generateSectionsXmlFile'); + } + + getWizardTitle(): string { + return 'Sections XML File'; + } + + getFileHeader(data: TemplateWizardData): string | undefined { + return FileHeader.getHeader(data.module); + } + + getFilePath(data: TemplateWizardData): string { + const [vendor, module] = data.module.split('_'); + + return `app/code/${vendor}/${module}/etc/frontend/sections.xml`; + } + + getTemplateName(data: TemplateWizardData): string { + return 'xml/blank-sections'; + } +} diff --git a/src/command/GenerateSystemXmlFileCommand.ts b/src/command/GenerateSystemXmlFileCommand.ts new file mode 100644 index 0000000..bb2ea5c --- /dev/null +++ b/src/command/GenerateSystemXmlFileCommand.ts @@ -0,0 +1,27 @@ +import { SimpleTemplateGeneratorCommand } from './SimpleTemplateGeneratorCommand'; +import { TemplateWizardData } from 'wizard/SimpleTemplateWizard'; +import FileHeader from 'common/xml/FileHeader'; + +export default class GenerateSystemXmlFileCommand extends SimpleTemplateGeneratorCommand { + constructor() { + super('magento-toolbox.generateSystemXmlFile'); + } + + getFileHeader(data: TemplateWizardData): string | undefined { + return FileHeader.getHeader(data.module); + } + + getWizardTitle(): string { + return 'System XML File'; + } + + getFilePath(data: TemplateWizardData): string { + const [vendor, module] = data.module.split('_'); + + return `app/code/${vendor}/${module}/etc/adminhtml/system.xml`; + } + + getTemplateName(data: TemplateWizardData): string { + return 'xml/blank-system'; + } +} diff --git a/src/command/GenerateViewXmlFile.ts b/src/command/GenerateViewXmlFile.ts new file mode 100644 index 0000000..09bfa4e --- /dev/null +++ b/src/command/GenerateViewXmlFile.ts @@ -0,0 +1,27 @@ +import { SimpleTemplateGeneratorCommand } from './SimpleTemplateGeneratorCommand'; +import { TemplateWizardData } from 'wizard/SimpleTemplateWizard'; +import FileHeader from 'common/xml/FileHeader'; + +export default class GenerateViewXmlFile extends SimpleTemplateGeneratorCommand { + constructor() { + super('magento-toolbox.generateViewXmlFile'); + } + + getWizardTitle(): string { + return 'View XML File'; + } + + getFileHeader(data: TemplateWizardData): string | undefined { + return FileHeader.getHeader(data.module); + } + + getFilePath(data: TemplateWizardData): string { + const [vendor, module] = data.module.split('_'); + + return `app/code/${vendor}/${module}/etc/view.xml`; + } + + getTemplateName(data: TemplateWizardData): string { + return 'xml/blank-view'; + } +} diff --git a/src/command/GenerateWebapiXmlFileCommand.ts b/src/command/GenerateWebapiXmlFileCommand.ts index 5a96b12..115cd7c 100644 --- a/src/command/GenerateWebapiXmlFileCommand.ts +++ b/src/command/GenerateWebapiXmlFileCommand.ts @@ -15,7 +15,7 @@ export default class GenerateWebapiXmlFileCommand extends SimpleTemplateGenerato return FileHeader.getHeader(data.module); } - getTemplatePath(data: TemplateWizardData): string { + getFilePath(data: TemplateWizardData): string { const [vendor, module] = data.module.split('_'); return `app/code/${vendor}/${module}/etc/webapi.xml`; diff --git a/src/command/GenerateWidgetXmlFileCommand.ts b/src/command/GenerateWidgetXmlFileCommand.ts new file mode 100644 index 0000000..2bdd237 --- /dev/null +++ b/src/command/GenerateWidgetXmlFileCommand.ts @@ -0,0 +1,27 @@ +import { SimpleTemplateGeneratorCommand } from './SimpleTemplateGeneratorCommand'; +import { TemplateWizardData } from 'wizard/SimpleTemplateWizard'; +import FileHeader from 'common/xml/FileHeader'; + +export default class GenerateWidgetXmlFileCommand extends SimpleTemplateGeneratorCommand { + constructor() { + super('magento-toolbox.generateWidgetXmlFile'); + } + + getWizardTitle(): string { + return 'Widget XML File'; + } + + getFileHeader(data: TemplateWizardData): string | undefined { + return FileHeader.getHeader(data.module); + } + + getFilePath(data: TemplateWizardData): string { + const [vendor, module] = data.module.split('_'); + + return `app/code/${vendor}/${module}/etc/widget.xml`; + } + + getTemplateName(data: TemplateWizardData): string { + return 'xml/blank-widget'; + } +} diff --git a/src/command/SimpleTemplateGeneratorCommand.ts b/src/command/SimpleTemplateGeneratorCommand.ts index 69b5bf2..d0837ee 100644 --- a/src/command/SimpleTemplateGeneratorCommand.ts +++ b/src/command/SimpleTemplateGeneratorCommand.ts @@ -16,7 +16,7 @@ export abstract class SimpleTemplateGeneratorCommand extends Command { return []; } - abstract getTemplatePath(data: TemplateWizardData): string; + abstract getFilePath(data: TemplateWizardData): string; abstract getTemplateName(data: TemplateWizardData): string; @@ -60,7 +60,7 @@ export abstract class SimpleTemplateGeneratorCommand extends Command { ); const manager = new FileGeneratorManager([ - new TemplateGenerator(this.getTemplatePath(data), this.getTemplateName(data), { + new TemplateGenerator(this.getFilePath(data), this.getTemplateName(data), { ...this.getTemplateData(data), fileHeader: this.getFileHeader(data) ?? '', }), diff --git a/src/command/index.ts b/src/command/index.ts new file mode 100644 index 0000000..aa4c2f2 --- /dev/null +++ b/src/command/index.ts @@ -0,0 +1,27 @@ +export { default as IndexWorkspaceCommand } from './IndexWorkspaceCommand'; +export { default as GenerateModuleCommand } from './GenerateModuleCommand'; +export { default as GenerateContextPluginCommand } from './GenerateContextPluginCommand'; +export { default as CopyMagentoPathCommand } from './CopyMagentoPathCommand'; +export { default as GenerateXmlCatalogCommand } from './GenerateXmlCatalogCommand'; +export { default as GenerateObserverCommand } from './GenerateObserverCommand'; +export { default as GenerateBlockCommand } from './GenerateBlockCommand'; +export { default as GenerateEventsXmlCommand } from './GenerateEventsXmlCommand'; +export { default as GenerateGraphqlSchemaFileCommand } from './GenerateGraphqlSchemaFile'; +export { default as GenerateRoutesXmlFileCommand } from './GenerateRoutesXmlFileCommand'; +export { default as GenerateAclXmlFileCommand } from './GenerateAclXmlFileCommand'; +export { default as GenerateDiXmlFileCommand } from './GenerateDiXmlFileCommand'; +export { default as GeneratePreferenceCommand } from './GeneratePreferenceCommand'; +export { default as GenerateLayoutXmlCommand } from './GenerateLayoutXmlCommand'; +export { default as GenerateWebapiXmlFileCommand } from './GenerateWebapiXmlFileCommand'; +export { default as GeneratePageTypesXmlCommand } from './GeneratePageTypesXmlCommand'; +export { default as GenerateCrontabXmlCommand } from './GenerateCrontabXmlCommand'; +export { default as GenerateEmailTemplatesXmlCommand } from './GenerateEmailTemplatesXmlCommand'; +export { default as GenerateSectionsXmlCommand } from './GenerateSectionsXmlCommand'; +export { default as GenerateFieldsetXmlCommand } from './GenerateFieldsetXmlCommand'; +export { default as GenerateViewXmlFile } from './GenerateViewXmlFile'; +export { default as GenerateIndexerXmlFileCommand } from './GenerateIndexerXmlFileCommand'; +export { default as GenerateMviewXmlFileCommand } from './GenerateMviewXmlFileCommand'; +export { default as GenerateWidgetXmlFileCommand } from './GenerateWidgetXmlFileCommand'; +export { default as GenerateExtensionAttributesXmlFileCommand } from './GenerateExtensionAttributesXmlFileCommand'; +export { default as GenerateSystemXmlFileCommand } from './GenerateSystemXmlFileCommand'; +export { default as GenerateConfigXmlFileCommand } from './GenerateConfigXmlFileCommand'; diff --git a/src/extension.ts b/src/extension.ts index d656c2c..376445b 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -1,7 +1,3 @@ -// The module 'vscode' contains the VS Code extensibility API -// Import the module and reference it with the alias vscode in your code below -import GenerateModuleCommand from 'command/GenerateModuleCommand'; -import IndexWorkspaceCommand from 'command/IndexWorkspaceCommand'; import ExtensionState from 'common/ExtensionState'; import IndexRunner from 'indexer/IndexRunner'; import ActiveTextEditorChangeObserver from 'observer/ActiveTextEditorChangeObserver'; @@ -9,45 +5,20 @@ import * as vscode from 'vscode'; import DiagnosticCollectionProvider from 'diagnostics/DiagnosticCollectionProvider'; import ChangeTextEditorSelectionObserver from 'observer/ChangeTextEditorSelectionObserver'; import DocumentCache from 'cache/DocumentCache'; -import GenerateContextPluginCommand from 'command/GenerateContextPluginCommand'; import { XmlClasslikeDefinitionProvider } from 'definition/XmlClasslikeDefinitionProvider'; -import CopyMagentoPathCommand from 'command/CopyMagentoPathCommand'; -import GenerateXmlCatalogCommand from 'command/GenerateXmlCatalogCommand'; import XmlClasslikeHoverProvider from 'hover/XmlClasslikeHoverProvider'; import ObserverCodelensProvider from 'codelens/ObserverCodelensProvider'; -import GenerateObserverCommand from 'command/GenerateObserverCommand'; -import GenerateBlockCommand from 'command/GenerateBlockCommand'; -import GenerateEventsXmlCommand from 'command/GenerateEventsXmlCommand'; -import GenerateGraphqlSchemaFileCommand from 'command/GenerateGraphqlSchemaFile'; -import GenerateRoutesXmlFileCommand from 'command/GenerateRoutesXmlFileCommand'; -import GenerateAclXmlFileCommand from 'command/GenerateAclXmlFileCommand'; -import GenerateDiXmlFileCommand from 'command/GenerateDiXmlFileCommand'; -import GeneratePreferenceCommand from 'command/GeneratePreferenceCommand'; +import * as commands from 'command'; import Magento from 'util/Magento'; import { WorkspaceFolder } from 'vscode'; import Logger from 'util/Logger'; +import { Command } from 'command/Command'; // This method is called when your extension is activated // Your extension is activated the very first time the command is executed export async function activate(context: vscode.ExtensionContext) { console.log('[Magento Toolbox] Activating extension'); - const commands = [ - IndexWorkspaceCommand, - GenerateModuleCommand, - GenerateContextPluginCommand, - CopyMagentoPathCommand, - GenerateXmlCatalogCommand, - GenerateObserverCommand, - GenerateBlockCommand, - GenerateEventsXmlCommand, - GenerateGraphqlSchemaFileCommand, - GenerateRoutesXmlFileCommand, - GenerateAclXmlFileCommand, - GenerateDiXmlFileCommand, - GeneratePreferenceCommand, - ]; - const magentoWorkspaces: WorkspaceFolder[] = []; if (vscode.workspace.workspaceFolders) { @@ -60,8 +31,8 @@ export async function activate(context: vscode.ExtensionContext) { ExtensionState.init(context, magentoWorkspaces); - commands.forEach(command => { - const instance = new command(); + Object.values(commands).forEach(command => { + const instance = new command() as Command; Logger.log('Registering command', instance.getCommand()); diff --git a/templates/xml/blank-config.ejs b/templates/xml/blank-config.ejs new file mode 100644 index 0000000..e09d979 --- /dev/null +++ b/templates/xml/blank-config.ejs @@ -0,0 +1,7 @@ + +<% if (fileHeader) { -%> +<%- fileHeader %> +<% } -%> + + diff --git a/templates/xml/blank-crontab.ejs b/templates/xml/blank-crontab.ejs new file mode 100644 index 0000000..6ab66d2 --- /dev/null +++ b/templates/xml/blank-crontab.ejs @@ -0,0 +1,7 @@ + +<% if (fileHeader) { -%> +<%- fileHeader %> +<% } -%> + + diff --git a/templates/xml/blank-di.ejs b/templates/xml/blank-di.ejs index 0d78280..aacdd53 100644 --- a/templates/xml/blank-di.ejs +++ b/templates/xml/blank-di.ejs @@ -4,4 +4,4 @@ <% } -%> - \ No newline at end of file + diff --git a/templates/xml/blank-email-templates.ejs b/templates/xml/blank-email-templates.ejs new file mode 100644 index 0000000..48df29e --- /dev/null +++ b/templates/xml/blank-email-templates.ejs @@ -0,0 +1,7 @@ + +<% if (fileHeader) { -%> +<%- fileHeader %> +<% } -%> + + diff --git a/templates/xml/blank-events.ejs b/templates/xml/blank-events.ejs index 7e7cab1..888106d 100644 --- a/templates/xml/blank-events.ejs +++ b/templates/xml/blank-events.ejs @@ -4,4 +4,4 @@ <% } -%> - \ No newline at end of file + diff --git a/templates/xml/blank-extension-attributes.ejs b/templates/xml/blank-extension-attributes.ejs new file mode 100644 index 0000000..c2a1913 --- /dev/null +++ b/templates/xml/blank-extension-attributes.ejs @@ -0,0 +1,7 @@ + +<% if (fileHeader) { -%> +<%- fileHeader %> +<% } -%> + + diff --git a/templates/xml/blank-fieldset.ejs b/templates/xml/blank-fieldset.ejs new file mode 100644 index 0000000..ba00c6a --- /dev/null +++ b/templates/xml/blank-fieldset.ejs @@ -0,0 +1,7 @@ + +<% if (fileHeader) { -%> +<%- fileHeader %> +<% } -%> + + diff --git a/templates/xml/blank-indexer.ejs b/templates/xml/blank-indexer.ejs new file mode 100644 index 0000000..e2b1710 --- /dev/null +++ b/templates/xml/blank-indexer.ejs @@ -0,0 +1,7 @@ + +<% if (fileHeader) { -%> +<%- fileHeader %> +<% } -%> + + diff --git a/templates/xml/blank-layout.ejs b/templates/xml/blank-layout.ejs new file mode 100644 index 0000000..c49adf8 --- /dev/null +++ b/templates/xml/blank-layout.ejs @@ -0,0 +1,7 @@ + +<% if (fileHeader) { -%> +<%- fileHeader %> +<% } -%> +layout="admin-1column"<% } %> + xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd"> + diff --git a/templates/xml/blank-mview.ejs b/templates/xml/blank-mview.ejs new file mode 100644 index 0000000..6e2e3f8 --- /dev/null +++ b/templates/xml/blank-mview.ejs @@ -0,0 +1,7 @@ + +<% if (fileHeader) { -%> +<%- fileHeader %> +<% } -%> + + diff --git a/templates/xml/blank-page-types.ejs b/templates/xml/blank-page-types.ejs new file mode 100644 index 0000000..90481c0 --- /dev/null +++ b/templates/xml/blank-page-types.ejs @@ -0,0 +1,7 @@ + +<% if (fileHeader) { -%> +<%- fileHeader %> +<% } -%> + + \ No newline at end of file diff --git a/templates/xml/blank-sections.ejs b/templates/xml/blank-sections.ejs new file mode 100644 index 0000000..4b257fe --- /dev/null +++ b/templates/xml/blank-sections.ejs @@ -0,0 +1,7 @@ + +<% if (fileHeader) { -%> +<%- fileHeader %> +<% } -%> + + diff --git a/templates/xml/blank-system.ejs b/templates/xml/blank-system.ejs new file mode 100644 index 0000000..734b6d7 --- /dev/null +++ b/templates/xml/blank-system.ejs @@ -0,0 +1,9 @@ + +<% if (fileHeader) { -%> +<%- fileHeader %> +<% } -%> + + + + diff --git a/templates/xml/blank-view.ejs b/templates/xml/blank-view.ejs new file mode 100644 index 0000000..47db023 --- /dev/null +++ b/templates/xml/blank-view.ejs @@ -0,0 +1,7 @@ + +<% if (fileHeader) { -%> +<%- fileHeader %> +<% } -%> + + diff --git a/templates/xml/blank-webapi.ejs b/templates/xml/blank-webapi.ejs index 147511f..ee49872 100644 --- a/templates/xml/blank-webapi.ejs +++ b/templates/xml/blank-webapi.ejs @@ -4,4 +4,4 @@ <% } -%> - \ No newline at end of file + diff --git a/templates/xml/blank-widget.ejs b/templates/xml/blank-widget.ejs new file mode 100644 index 0000000..87d0840 --- /dev/null +++ b/templates/xml/blank-widget.ejs @@ -0,0 +1,7 @@ + +<% if (fileHeader) { -%> +<%- fileHeader %> +<% } -%> + + diff --git a/test-resources/reference/generator/module/module-with-comment.xml b/test-resources/reference/generator/module/module-with-comment.xml index 9104467..ebf3484 100644 --- a/test-resources/reference/generator/module/module-with-comment.xml +++ b/test-resources/reference/generator/module/module-with-comment.xml @@ -4,4 +4,4 @@ --> - \ No newline at end of file + diff --git a/test-resources/reference/generator/observer/events-adminhtml.xml b/test-resources/reference/generator/observer/events-adminhtml.xml index 96fe3a6..b147fca 100644 --- a/test-resources/reference/generator/observer/events-adminhtml.xml +++ b/test-resources/reference/generator/observer/events-adminhtml.xml @@ -5,4 +5,4 @@ - \ No newline at end of file + diff --git a/test-resources/reference/generator/observer/events-with-comment.xml b/test-resources/reference/generator/observer/events-with-comment.xml index 867ae2d..87943d8 100644 --- a/test-resources/reference/generator/observer/events-with-comment.xml +++ b/test-resources/reference/generator/observer/events-with-comment.xml @@ -8,4 +8,4 @@ Foo_Bar - \ No newline at end of file + diff --git a/test-resources/reference/generator/observer/events.xml b/test-resources/reference/generator/observer/events.xml index 96fe3a6..b147fca 100644 --- a/test-resources/reference/generator/observer/events.xml +++ b/test-resources/reference/generator/observer/events.xml @@ -5,4 +5,4 @@ - \ No newline at end of file + diff --git a/test-resources/reference/generator/plugin/di-adminhtml.xml b/test-resources/reference/generator/plugin/di-adminhtml.xml index 6357502..5a8a5ab 100644 --- a/test-resources/reference/generator/plugin/di-adminhtml.xml +++ b/test-resources/reference/generator/plugin/di-adminhtml.xml @@ -6,4 +6,4 @@ - \ No newline at end of file + diff --git a/test-resources/reference/generator/plugin/di.xml b/test-resources/reference/generator/plugin/di.xml index 6357502..5a8a5ab 100644 --- a/test-resources/reference/generator/plugin/di.xml +++ b/test-resources/reference/generator/plugin/di.xml @@ -6,4 +6,4 @@ - \ No newline at end of file + diff --git a/test-resources/reference/generator/preference/di.xml b/test-resources/reference/generator/preference/di.xml index a9f4d71..d25accd 100644 --- a/test-resources/reference/generator/preference/di.xml +++ b/test-resources/reference/generator/preference/di.xml @@ -3,4 +3,4 @@ xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd"> - \ No newline at end of file +