Skip to content

Commit aec07d4

Browse files
committed
Implement base file generation logic
1 parent 752496c commit aec07d4

File tree

15 files changed

+743
-6
lines changed

15 files changed

+743
-6
lines changed

resources/META-INF/plugin.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
<action id="MagentoCreateACronjob" class="com.magento.idea.magento2plugin.actions.generation.NewCronjobAction" />
6161
<action id="MagentoCreateAViewModel" class="com.magento.idea.magento2plugin.actions.generation.NewViewModelAction" />
6262
<action id="MagentoCreateAGraphQlResolver" class="com.magento.idea.magento2plugin.actions.generation.NewGraphQlResolverAction" />
63+
<action id="MagentoCreateCLICommand" class="com.magento.idea.magento2plugin.actions.generation.NewCLICommandAction" />
6364
<add-to-group group-id="NewGroup" anchor="last"/>
6465
</group>
6566

@@ -161,6 +162,7 @@
161162
<internalFileTemplate name="Magento GraphQL Resolver Class"/>
162163
<internalFileTemplate name="Magento Cronjob Class"/>
163164
<internalFileTemplate name="Magento Crontab Xml"/>
165+
<internalFileTemplate name="Magento CLI Command"/>
164166
</extensions>
165167

166168
<extensions defaultExtensionNs="com.jetbrains.php">
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
#parse("PHP File Header.php")
3+
4+
#if (${NAMESPACE})
5+
6+
namespace ${NAMESPACE};
7+
8+
#end
9+
10+
use Symfony\Component\Console\Command\Command;
11+
use Symfony\Component\Console\Input\InputInterface;
12+
use Symfony\Component\Console\Output\OutputInterface;
13+
14+
class ${NAME} extends Command
15+
{
16+
/**
17+
* @inheritDoc
18+
*/
19+
protected function configure()
20+
{
21+
$this->setName('${CLI_COMMAND_NAME}');
22+
$this->setDescription('${CLI_COMMAND_DESCRIPTION}');
23+
parent::configure();
24+
}
25+
26+
/**
27+
* CLI command description
28+
*
29+
* @param InputInterface $input
30+
* @param OutputInterface $output
31+
*
32+
* @return void
33+
*/
34+
protected function execute(InputInterface $input, OutputInterface $output): void
35+
{
36+
// todo: implement CLI command logic here
37+
}
38+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<!--
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
-->
7+
<html lang="en">
8+
<body>
9+
<table width="100%" border="0" cellpadding="5" cellspacing="0" style="border-collapse: collapse">
10+
<tr>
11+
<td>
12+
<font face="verdana" size="-1">
13+
Magento enables your component to add commands to our Symfony-like command-line interface (CLI).
14+
<a href="https://devdocs.magento.com/guides/v2.3/extension-dev-guide/cli-cmds/cli-howto.html">
15+
Read more</a> about Magneto CLI commands.
16+
</font>
17+
</td>
18+
</tr>
19+
</table>
20+
21+
<table width="100%" border="0" cellpadding="5" cellspacing="0" style="border-collapse: collapse">
22+
<tr>
23+
<td colspan="3"><font face="verdana" size="-1">Template's variables:</font></td>
24+
</tr>
25+
<tr>
26+
<td valign="top"><nobr><font face="verdana" size="-2"><b>${NAMESPACE}</b></font></nobr></td>
27+
<td width="10">&nbsp;</td>
28+
<td width="100%" valign="top"><font face="verdana" size="-1">Created PHP CLI command class namespace.</font></td>
29+
</tr>
30+
<tr>
31+
<td valign="top"><nobr><font face="verdana" size="-2"><b>${NAME}</b></font></nobr></td>
32+
<td width="10">&nbsp;</td>
33+
<td width="100%" valign="top"><font face="verdana" size="-1">PHP class for the CLI command name.</font></td>
34+
</tr>
35+
<tr>
36+
<td valign="top"><nobr><font face="verdana" size="-2"><b>${NAME}</b></font></nobr></td>
37+
<td width="10">&nbsp;</td>
38+
<td width="100%" valign="top"><font face="verdana" size="-1">PHP class for the CLI command name.</font></td>
39+
</tr>
40+
<tr>
41+
<td valign="top"><nobr><font face="verdana" size="-2"><b>${CLI_COMMAND_NAME}</b></font></nobr></td>
42+
<td width="10">&nbsp;</td>
43+
<td width="100%" valign="top"><font face="verdana" size="-1">Name of the CLI used under the bin/magento.</font></td>
44+
</tr>
45+
<tr>
46+
<td valign="top"><nobr><font face="verdana" size="-2"><b>${CLI_COMMAND_DESCRIPTION}</b></font></nobr></td>
47+
<td width="10">&nbsp;</td>
48+
<td width="100%" valign="top"><font face="verdana" size="-1">Description of the CLI command used under the bin/magento.</font></td>
49+
</tr>
50+
</table>
51+
</body>
52+
</html>

resources/magento2/common.properties

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,10 @@ common.cancel=Cancel
99
common.error=Error
1010
common.module.target=Target Module
1111
common.area.target=Target Area
12+
common.cli.class.name=Class Name
13+
common.cli.cli.description=CLI Description
14+
common.cli.cli.name=CLI Name
15+
common.cli.parent.directory=Parent Directory
16+
common.cli.create.new.cli.command.title=Create a new Magento 2 CLI Command
17+
common.cli.generate.error=New CLI Command Generation Error
18+
common.cli.class.title=CLI Command Class
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*
2+
* Copyright © Magento, Inc. All rights reserved.
3+
* See COPYING.txt for license details.
4+
*/
5+
package com.magento.idea.magento2plugin.actions.generation;
6+
7+
import com.intellij.ide.IdeView;
8+
import com.intellij.openapi.actionSystem.*;
9+
import com.intellij.openapi.project.Project;
10+
import com.intellij.psi.PsiDirectory;
11+
import com.magento.idea.magento2plugin.MagentoIcons;
12+
import com.magento.idea.magento2plugin.actions.generation.dialog.NewCLICommandDialog;
13+
import org.jetbrains.annotations.NotNull;
14+
15+
public class NewCLICommandAction extends AnAction {
16+
public static String ACTION_NAME = "Magento 2 CLI Command";
17+
public static String ACTION_DESCRIPTION = "Create a new Magento 2 CLI Command";
18+
19+
NewCLICommandAction() {
20+
super(ACTION_NAME, ACTION_DESCRIPTION, MagentoIcons.MODULE);
21+
}
22+
23+
@Override
24+
public void actionPerformed(@NotNull AnActionEvent e) {
25+
DataContext dataContext = e.getDataContext();
26+
IdeView view = LangDataKeys.IDE_VIEW.getData(dataContext);
27+
28+
if (view == null) {
29+
return;
30+
}
31+
32+
Project project = CommonDataKeys.PROJECT.getData(dataContext);
33+
if (project == null) {
34+
return;
35+
}
36+
37+
PsiDirectory directory = view.getOrChooseDirectory();
38+
if (directory == null) {
39+
return;
40+
}
41+
42+
NewCLICommandDialog.open(project, directory);
43+
}
44+
45+
@Override
46+
public boolean isDumbAware() {
47+
return false;
48+
}
49+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/*
2+
* Copyright © Magento, Inc. All rights reserved.
3+
* See COPYING.txt for license details.
4+
*/
5+
package com.magento.idea.magento2plugin.actions.generation.data;
6+
7+
public class CLICommandClassData {
8+
private final String className;
9+
private final String parentDirectory;
10+
private final String commandName;
11+
private final String commandDescription;
12+
private final String namespace;
13+
private final String moduleName;
14+
15+
public CLICommandClassData(
16+
String cliClassName,
17+
String cliParentDirectory,
18+
String cliCommandName,
19+
String cliCommandDescription,
20+
String namespace,
21+
String moduleName
22+
) {
23+
this.className = cliClassName;
24+
this.parentDirectory = cliParentDirectory;
25+
this.commandName = cliCommandName;
26+
this.commandDescription = cliCommandDescription;
27+
this.namespace = namespace;
28+
this.moduleName = moduleName;
29+
}
30+
31+
public String getClassName() {
32+
return className;
33+
}
34+
35+
public String getParentDirectory() {
36+
return parentDirectory;
37+
}
38+
39+
public String getCommandName() {
40+
return commandName;
41+
}
42+
43+
public String getCommandDescription() {
44+
return commandDescription;
45+
}
46+
47+
public String getNamespace() {
48+
return namespace;
49+
}
50+
51+
public String getModuleName() {
52+
return moduleName;
53+
}
54+
}

src/com/magento/idea/magento2plugin/actions/generation/dialog/AbstractDialog.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,22 @@
44
*/
55
package com.magento.idea.magento2plugin.actions.generation.dialog;
66

7+
import com.magento.idea.magento2plugin.bundles.CommonBundle;
8+
79
import javax.swing.*;
810
import java.awt.*;
911

1012
/**
1113
* All code generate dialog should extend this class
1214
*/
1315
public abstract class AbstractDialog extends JDialog {
16+
17+
protected CommonBundle bundle;
18+
19+
public AbstractDialog() {
20+
this.bundle = new CommonBundle();
21+
}
22+
1423
protected void centerDialog(AbstractDialog dialog) {
1524
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
1625
int x = screenSize.width / 2 - dialog.getSize().width / 2;
Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="com.magento.idea.magento2plugin.actions.generation.dialog.NewCLICommandDialog">
3+
<grid id="27dc6" binding="contentPane" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
4+
<margin top="10" left="10" bottom="10" right="10"/>
5+
<constraints>
6+
<xy x="20" y="20" width="678" height="289"/>
7+
</constraints>
8+
<properties/>
9+
<border type="none"/>
10+
<children>
11+
<grid id="bce24" layout-manager="GridLayoutManager" row-count="6" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
12+
<margin top="0" left="0" bottom="0" right="0"/>
13+
<constraints>
14+
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
15+
</constraints>
16+
<properties/>
17+
<border type="none"/>
18+
<children>
19+
<component id="61353" class="javax.swing.JTextField" binding="cliCommandClassNameField">
20+
<constraints>
21+
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
22+
<preferred-size width="150" height="-1"/>
23+
</grid>
24+
</constraints>
25+
<properties>
26+
<text value=""/>
27+
</properties>
28+
</component>
29+
<vspacer id="911bd">
30+
<constraints>
31+
<grid row="4" column="1" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
32+
</constraints>
33+
</vspacer>
34+
<component id="82342" class="javax.swing.JTextField" binding="cliCommandParentDirectoryField">
35+
<constraints>
36+
<grid row="1" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
37+
<preferred-size width="150" height="-1"/>
38+
</grid>
39+
</constraints>
40+
<properties/>
41+
</component>
42+
<component id="a06d9" class="javax.swing.JTextField" binding="cliCommandNameField">
43+
<constraints>
44+
<grid row="2" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
45+
<preferred-size width="150" height="-1"/>
46+
</grid>
47+
</constraints>
48+
<properties>
49+
<text value=""/>
50+
</properties>
51+
</component>
52+
<component id="9e289" class="javax.swing.JTextField" binding="cliCommandDescriptionField">
53+
<constraints>
54+
<grid row="3" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
55+
<preferred-size width="150" height="-1"/>
56+
</grid>
57+
</constraints>
58+
<properties/>
59+
</component>
60+
<component id="86880" class="javax.swing.JLabel">
61+
<constraints>
62+
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
63+
</constraints>
64+
<properties>
65+
<labelFor value="61353"/>
66+
<text resource-bundle="magento2/common" key="common.cli.class.name"/>
67+
</properties>
68+
</component>
69+
<component id="f6c65" class="javax.swing.JLabel">
70+
<constraints>
71+
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
72+
</constraints>
73+
<properties>
74+
<labelFor value="82342"/>
75+
<text resource-bundle="magento2/common" key="common.cli.parent.directory"/>
76+
</properties>
77+
</component>
78+
<component id="8696b" class="javax.swing.JLabel">
79+
<constraints>
80+
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
81+
</constraints>
82+
<properties>
83+
<labelFor value="a06d9"/>
84+
<text resource-bundle="magento2/common" key="common.cli.cli.name"/>
85+
</properties>
86+
</component>
87+
<component id="abeb0" class="javax.swing.JLabel">
88+
<constraints>
89+
<grid row="3" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
90+
</constraints>
91+
<properties>
92+
<labelFor value="9e289"/>
93+
<text resource-bundle="magento2/common" key="common.cli.cli.description"/>
94+
</properties>
95+
</component>
96+
<grid id="5f3c" layout-manager="GridLayoutManager" row-count="2" column-count="3" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
97+
<margin top="0" left="0" bottom="0" right="0"/>
98+
<constraints>
99+
<grid row="5" column="1" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
100+
</constraints>
101+
<properties/>
102+
<border type="none"/>
103+
<children>
104+
<hspacer id="a90e6">
105+
<constraints>
106+
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
107+
</constraints>
108+
</hspacer>
109+
<vspacer id="d4f72">
110+
<constraints>
111+
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
112+
</constraints>
113+
</vspacer>
114+
<component id="2f87d" class="javax.swing.JButton" binding="buttonOK">
115+
<constraints>
116+
<grid row="1" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
117+
</constraints>
118+
<properties>
119+
<text resource-bundle="magento2/common" key="common.ok"/>
120+
</properties>
121+
</component>
122+
<component id="1c5a0" class="javax.swing.JButton" binding="buttonCancel">
123+
<constraints>
124+
<grid row="1" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
125+
</constraints>
126+
<properties>
127+
<text resource-bundle="magento2/common" key="common.cancel"/>
128+
</properties>
129+
</component>
130+
</children>
131+
</grid>
132+
</children>
133+
</grid>
134+
</children>
135+
</grid>
136+
</form>

0 commit comments

Comments
 (0)