Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

74 changes: 74 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,18 @@
"type": "string",
"default": "bin/magento",
"description": "Path to Magento CLI tool. Relative to workspace root or absolute path."
},
"magento-toolbox.phpFileHeaderComment": {
"type": "string",
"editPresentation": "multilineText",
"default": "",
"markdownDescription": "`%module%` will be replaced with the module name. \n\n **Do not add comment symbols like `/*` or `*/`, they will be added automatically.** \n\n Separate lines with the newline character `\\n`"
},
"magento-toolbox.xmlFileHeaderComment": {
"type": "string",
"editPresentation": "multilineText",
"default": "",
"markdownDescription": "`%module%` will be replaced with the module name. \n\n **Do not add comment symbols like `<!--` or `-->`, they will be added automatically.**"
}
}
},
Expand All @@ -42,6 +54,10 @@
"command": "magento-toolbox.generateModule",
"title": "Magento Toolbox: Generate Module"
},
{
"command": "magento-toolbox.generateBlock",
"title": "Magento Toolbox: Generate Block"
},
{
"command": "magento-toolbox.indexWorkspace",
"title": "Magento Toolbox: Index Workspace"
Expand All @@ -61,6 +77,30 @@
{
"command": "magento-toolbox.generateObserver",
"title": "Magento Toolbox: Generate Observer"
},
{
"command": "magento-toolbox.generateEventsXml",
"title": "Magento Toolbox: Generate Events XML"
},
{
"command": "magento-toolbox.generateGraphqlSchemaFile",
"title": "Magento Toolbox: Generate GraphQL Schema File"
},
{
"command": "magento-toolbox.generateRoutesXmlFile",
"title": "Magento Toolbox: Generate Routes XML"
},
{
"command": "magento-toolbox.generateAclXmlFile",
"title": "Magento Toolbox: Generate ACL XML"
},
{
"command": "magento-toolbox.generateDiXmlFile",
"title": "Magento Toolbox: Generate DI XML"
},
{
"command": "magento-toolbox.generateWebapiXmlFile",
"title": "Magento Toolbox: Generate Webapi XML"
}
],
"menus": {
Expand Down Expand Up @@ -97,6 +137,39 @@
"command": "magento-toolbox.copyMagentoPath",
"title": "Magento Toolbox: Copy Magento Path",
"when": "resourceExtname in magento-toolbox.supportedMagentoPathExtensions && resourcePath =~ /view/"
},
{
"command": "magento-toolbox.generateObserver",
"when": "resourcePath =~ /app\\/code\\/.+\\/.+/i",
"arguments": []
},
{
"command": "magento-toolbox.generateBlock",
"when": "resourcePath =~ /app\\/code\\/.+\\/.+/i"
},
{
"command": "magento-toolbox.generateEventsXml",
"when": "resourcePath =~ /app\\/code\\/.+\\/.+/i"
},
{
"command": "magento-toolbox.generateGraphqlSchemaFile",
"when": "resourcePath =~ /app\\/code\\/.+\\/.+/i"
},
{
"command": "magento-toolbox.generateRoutesXmlFile",
"when": "resourcePath =~ /app\\/code\\/.+\\/.+/i"
},
{
"command": "magento-toolbox.generateAclXmlFile",
"when": "resourcePath =~ /app\\/code\\/.+\\/.+/i"
},
{
"command": "magento-toolbox.generateDiXmlFile",
"when": "resourcePath =~ /app\\/code\\/.+\\/.+/i"
},
{
"command": "magento-toolbox.generateWebapiXmlFile",
"when": "resourcePath =~ /app\\/code\\/.+\\/.+/i"
}
]
}
Expand Down Expand Up @@ -157,6 +230,7 @@
"php-parser": "^3.2.2",
"react": "^19.0.0",
"react-dom": "^19.0.0",
"slugify": "^1.6.6",
"typescript-json-serializer": "^6.0.1",
"typescript-memoize": "^1.1.1",
"validatorjs": "^3.22.1"
Expand Down
2 changes: 1 addition & 1 deletion src/codelens/ObserverCodelensProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export default class ObserverCodelensProvider implements CodeLensProvider {
const codelens = new CodeLens(range, {
title: 'Create an Observer',
command: 'magento-toolbox.generateObserver',
arguments: [event.name],
arguments: [undefined, event.name],
});

codelenses.push(codelens);
Expand Down
22 changes: 22 additions & 0 deletions src/command/GenerateAclXmlFileCommand.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { SimpleTemplateGeneratorCommand } from './SimpleTemplateGeneratorCommand';
import { TemplateWizardData } from 'wizard/SimpleTemplateWizard';

export default class GenerateAclXmlFileCommand extends SimpleTemplateGeneratorCommand {
constructor() {
super('magento-toolbox.generateAclXmlFile');
}

getWizardTitle(): string {
return 'ACL XML File';
}

getTemplatePath(data: TemplateWizardData): string {
const [vendor, module] = data.module.split('_');

return `app/code/${vendor}/${module}/etc/acl.xml`;
}

getTemplateName(data: TemplateWizardData): string {
return 'xml/blank-acl';
}
}
58 changes: 58 additions & 0 deletions src/command/GenerateBlockCommand.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import { Command } from 'command/Command';
import BlockClassGenerator from 'generator/block/BlockClassGenerator';
import BlockWizard, { BlockWizardData } from 'wizard/BlockWizard';
import FileGeneratorManager from 'generator/FileGeneratorManager';
import { Uri, window } from 'vscode';
import Common from 'util/Common';
import WizzardClosedError from 'webview/error/WizzardClosedError';
import IndexManager from 'indexer/IndexManager';
import ModuleIndexer from 'indexer/module/ModuleIndexer';

export default class GenerateBlockCommand extends Command {
constructor() {
super('magento-toolbox.generateBlock');
}

public async execute(uri?: Uri): Promise<void> {
const moduleIndex = IndexManager.getIndexData(ModuleIndexer.KEY);
let contextModule: string | undefined;

const contextUri = uri || window.activeTextEditor?.document.uri;

if (moduleIndex && contextUri) {
const module = moduleIndex.getModuleByUri(contextUri);

if (module) {
contextModule = module.name;
}
}

const blockWizard = new BlockWizard();

let data: BlockWizardData;

try {
data = await blockWizard.show(contextModule);
} catch (error) {
if (error instanceof WizzardClosedError) {
return;
}

throw error;
}

const manager = new FileGeneratorManager([new BlockClassGenerator(data)]);

const workspaceFolder = Common.getActiveWorkspaceFolder();

if (!workspaceFolder) {
window.showErrorMessage('No active workspace folder');
return;
}

await manager.generate(workspaceFolder.uri);
await manager.writeFiles();
await manager.refreshIndex(workspaceFolder);
manager.openFirstFile();
}
}
39 changes: 39 additions & 0 deletions src/command/GenerateDiXmlFileCommand.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { MagentoScope } from 'types';
import { SimpleTemplateGeneratorCommand } from './SimpleTemplateGeneratorCommand';
import { TemplateWizardData } from 'wizard/SimpleTemplateWizard';

export default class GenerateDiXmlFileCommand extends SimpleTemplateGeneratorCommand {
constructor() {
super('magento-toolbox.generateDiXmlFile');
}

getAreas(): MagentoScope[] {
return [
MagentoScope.Global,
MagentoScope.Adminhtml,
MagentoScope.Frontend,
MagentoScope.Cron,
MagentoScope.WebapiRest,
MagentoScope.WebapiSoap,
MagentoScope.Graphql,
];
}

getWizardTitle(): string {
return 'DI XML File';
}

getTemplatePath(data: TemplateWizardData): string {
const [vendor, module] = data.module.split('_');

if (data.area && data.area !== MagentoScope.Global) {
return `app/code/${vendor}/${module}/etc/${data.area}/di.xml`;
}

return `app/code/${vendor}/${module}/etc/di.xml`;
}

getTemplateName(data: TemplateWizardData): string {
return 'xml/blank-di';
}
}
44 changes: 44 additions & 0 deletions src/command/GenerateEventsXmlCommand.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { SimpleTemplateGeneratorCommand } from './SimpleTemplateGeneratorCommand';
import { TemplateWizardData } from 'wizard/SimpleTemplateWizard';
import { MagentoScope } from 'types';
import FileHeader from 'common/xml/FileHeader';

export default class GenerateEventsXmlCommand extends SimpleTemplateGeneratorCommand {
constructor() {
super('magento-toolbox.generateEventsXml');
}

getWizardTitle(): string {
return 'Events XML File';
}

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);
}

getTemplatePath(data: TemplateWizardData): string {
const [vendor, module] = data.module.split('_');

if (data.area && data.area !== MagentoScope.Global) {
return `app/code/${vendor}/${module}/etc/${data.area}/events.xml`;
}

return `app/code/${vendor}/${module}/etc/events.xml`;
}

getTemplateName(data: TemplateWizardData): string {
return 'xml/blank-events';
}
}
22 changes: 22 additions & 0 deletions src/command/GenerateGraphqlSchemaFile.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { SimpleTemplateGeneratorCommand } from './SimpleTemplateGeneratorCommand';
import { TemplateWizardData } from 'wizard/SimpleTemplateWizard';

export default class GenerateGraphqlSchemaFileCommand extends SimpleTemplateGeneratorCommand {
constructor() {
super('magento-toolbox.generateGraphqlSchemaFile');
}

getWizardTitle(): string {
return 'GraphQL Schema File';
}

getTemplatePath(data: TemplateWizardData): string {
const [vendor, module] = data.module.split('_');

return `app/code/${vendor}/${module}/etc/schema.graphqls`;
}

getTemplateName(data: TemplateWizardData): string {
return 'graphql/blank-schema';
}
}
23 changes: 20 additions & 3 deletions src/command/GenerateObserverCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,39 @@ import ObserverWizard, { ObserverWizardData } from 'wizard/ObserverWizard';
import WizzardClosedError from 'webview/error/WizzardClosedError';
import FileGeneratorManager from 'generator/FileGeneratorManager';
import Common from 'util/Common';
import { window } from 'vscode';
import { Uri, window } from 'vscode';
import ObserverClassGenerator from 'generator/observer/ObserverClassGenerator';
import ObserverEventsGenerator from 'generator/observer/ObserverEventsGenerator';
import IndexManager from 'indexer/IndexManager';
import ModuleIndexer from 'indexer/module/ModuleIndexer';

export default class GenerateObserverCommand extends Command {
constructor() {
super('magento-toolbox.generateObserver');
}

public async execute(eventName?: string): Promise<void> {
public async execute(uri?: Uri, eventName?: string): Promise<void> {
eventName = typeof eventName === 'string' ? eventName : undefined;

const moduleIndex = IndexManager.getIndexData(ModuleIndexer.KEY);
let contextModule: string | undefined;

const contextUri = uri || window.activeTextEditor?.document.uri;

if (moduleIndex && contextUri) {
const module = moduleIndex.getModuleByUri(contextUri);

if (module) {
contextModule = module.name;
}
}

const observerWizard = new ObserverWizard();

let data: ObserverWizardData;

try {
data = await observerWizard.show(eventName);
data = await observerWizard.show(eventName, contextModule);
} catch (error) {
if (error instanceof WizzardClosedError) {
return;
Expand Down
Loading