Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 41ef164c2e |
11
README.md
11
README.md
@@ -1 +1,12 @@
|
|||||||
# FlutterJson2DartModel
|
# FlutterJson2DartModel
|
||||||
|
|
||||||
|
自动生成`json_serializable`需要的代码,并自动运行flutter pub run build_runner build —delete-conflicting-outputs命令
|
||||||
|
|
||||||
|
## 安装
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
## 使用
|
||||||
|
|
||||||
|
选择需要创建Dart实体类的文件夹右键菜单选择`Dart Model Class From Json`
|
||||||
|
|
||||||
|
|||||||
@@ -1,10 +1,12 @@
|
|||||||
|
fun properties(key: String) = project.findProperty(key).toString()
|
||||||
|
|
||||||
plugins {
|
plugins {
|
||||||
id("org.jetbrains.intellij") version "1.1"
|
id("org.jetbrains.intellij") version "1.1"
|
||||||
java
|
java
|
||||||
}
|
}
|
||||||
|
|
||||||
group = "club.ximeng.plugin.flutter"
|
group = properties("pluginGroup")
|
||||||
version = "0.0.1"
|
version = properties("pluginVersion")
|
||||||
|
|
||||||
repositories {
|
repositories {
|
||||||
mavenCentral()
|
mavenCentral()
|
||||||
@@ -27,20 +29,24 @@ dependencies {
|
|||||||
|
|
||||||
// See https://github.com/JetBrains/gradle-intellij-plugin/
|
// See https://github.com/JetBrains/gradle-intellij-plugin/
|
||||||
intellij {
|
intellij {
|
||||||
version.set("2019.3.5")
|
pluginName.set(properties("pluginName"))
|
||||||
|
version.set(properties("platformVersion"))
|
||||||
|
|
||||||
plugins.set("Dart:193.7547,io.flutter:41.0.5".split(',').map(String::trim).filter(String::isNotEmpty))
|
// Plugin Dependencies. Uses `platformPlugins` property from the gradle.properties file.
|
||||||
|
plugins.set(properties("platformPlugins").split(',').map(String::trim).filter(String::isNotEmpty))
|
||||||
|
|
||||||
updateSinceUntilBuild.set(false)
|
updateSinceUntilBuild.set(false)
|
||||||
}
|
}
|
||||||
tasks {
|
tasks {
|
||||||
patchPluginXml {
|
patchPluginXml {
|
||||||
changeNotes.set("""
|
changeNotes.set(
|
||||||
|
"""
|
||||||
v1.0.<br>
|
v1.0.<br>
|
||||||
<em>第一次发布</em> """.trimIndent())
|
<em>第一次发布</em> """.trimIndent()
|
||||||
|
)
|
||||||
}
|
}
|
||||||
runPluginVerifier {
|
runPluginVerifier {
|
||||||
ideVersions.set("2020.3.4, 2021.1.3, 2021.2.1,2022.1.2".split(',').map(String::trim).filter(String::isNotEmpty))
|
ideVersions.set(properties("pluginVerifierIdeVersions").split(',').map(String::trim).filter(String::isNotEmpty))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
tasks.getByName<Test>("test") {
|
tasks.getByName<Test>("test") {
|
||||||
|
|||||||
23
gradle.properties
Normal file
23
gradle.properties
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
# IntelliJ Platform Artifacts Repositories
|
||||||
|
# -> https://plugins.jetbrains.com/docs/intellij/intellij-artifacts.html
|
||||||
|
pluginGroup=club.ximeng.plugin.flutter
|
||||||
|
pluginName=FlutterJson2DartModel
|
||||||
|
pluginVersion=1.0.1
|
||||||
|
|
||||||
|
# Plugin Verifier integration -> https://github.com/JetBrains/gradle-intellij-plugin#plugin-verifier-dsl
|
||||||
|
# See https://jb.gg/intellij-platform-builds-list for available build versions.
|
||||||
|
pluginVerifierIdeVersions=2020.3.4, 2021.1.3, 2021.2.1,2022.1.2
|
||||||
|
|
||||||
|
# https://www.jetbrains.com/intellij-repository/releases
|
||||||
|
#platformVersion=2019.3.5
|
||||||
|
#platformVersion=IU-212.5712.43
|
||||||
|
platformVersion=2021.2.4
|
||||||
|
|
||||||
|
|
||||||
|
# Plugin Dependencies -> https://plugins.jetbrains.com/docs/intellij/plugin-dependencies.html
|
||||||
|
# https://plugins.jetbrains.com/plugin/13122-shell-script/versions
|
||||||
|
# https://plugins.jetbrains.com/plugin/13123-terminal/versions
|
||||||
|
# https://plugins.jetbrains.com/plugin/6351-dart/versions
|
||||||
|
# https://plugins.jetbrains.com/plugin/9212-flutter/versions
|
||||||
|
#platformPlugins=com.intellij.java,java,Dart:193.7547,io.flutter:41.0.5,com.jetbrains.sh:193.6494.42,org.jetbrains.plugins.terminal:193.5233.63
|
||||||
|
platformPlugins=com.intellij.java,java,Dart:212.5741,io.flutter:68.1.2,com.jetbrains.sh:212.5457.16,org.jetbrains.plugins.terminal:212.5284.17
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
package club.ximeng.plugin.flutter.model.action;
|
||||||
|
|
||||||
|
import club.ximeng.plugin.flutter.model.util.CommandUtil;
|
||||||
|
import com.intellij.openapi.actionSystem.AnAction;
|
||||||
|
import com.intellij.openapi.actionSystem.AnActionEvent;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author liu xm
|
||||||
|
* @date 2022-06-29 15:07
|
||||||
|
*/
|
||||||
|
public class RunCommandBuild extends AnAction {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(AnActionEvent e) {
|
||||||
|
String command = "flutter pub run build_runner build";
|
||||||
|
CommandUtil.runFlutterPubRun(e.getProject(), command);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
package club.ximeng.plugin.flutter.model.action;
|
||||||
|
|
||||||
|
import club.ximeng.plugin.flutter.model.util.CommandUtil;
|
||||||
|
import com.intellij.openapi.actionSystem.AnAction;
|
||||||
|
import com.intellij.openapi.actionSystem.AnActionEvent;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author liu xm
|
||||||
|
* @date 2022-06-29 15:46
|
||||||
|
*/
|
||||||
|
public class RunCommandWatch extends AnAction {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(AnActionEvent e) {
|
||||||
|
String command = "flutter pub run build_runner watch";
|
||||||
|
CommandUtil.runFlutterPubRun(e.getProject(), command);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -10,7 +10,6 @@ import com.intellij.ui.TitledSeparator;
|
|||||||
import com.intellij.ui.components.JBCheckBox;
|
import com.intellij.ui.components.JBCheckBox;
|
||||||
import com.intellij.util.ui.JBUI;
|
import com.intellij.util.ui.JBUI;
|
||||||
import com.intellij.util.ui.components.BorderLayoutPanel;
|
import com.intellij.util.ui.components.BorderLayoutPanel;
|
||||||
import org.jetbrains.annotations.Nls;
|
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
@@ -32,7 +31,6 @@ public class JsonModelConfigurable implements Configurable {
|
|||||||
*
|
*
|
||||||
* @return the visible name of the configurable component
|
* @return the visible name of the configurable component
|
||||||
*/
|
*/
|
||||||
@Nls(capitalization = Nls.Capitalization.Title)
|
|
||||||
@Override
|
@Override
|
||||||
public String getDisplayName() {
|
public String getDisplayName() {
|
||||||
return PluginBundle.message("settingsPageName");
|
return PluginBundle.message("settingsPageName");
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import club.ximeng.plugin.flutter.model.PluginBundle;
|
|||||||
import club.ximeng.plugin.flutter.model.handle.ModelGeneratorHandle;
|
import club.ximeng.plugin.flutter.model.handle.ModelGeneratorHandle;
|
||||||
import club.ximeng.plugin.flutter.model.model.ModelInfo;
|
import club.ximeng.plugin.flutter.model.model.ModelInfo;
|
||||||
import club.ximeng.plugin.flutter.model.util.ClipboardUtil;
|
import club.ximeng.plugin.flutter.model.util.ClipboardUtil;
|
||||||
|
import club.ximeng.plugin.flutter.model.util.CommandUtil;
|
||||||
import club.ximeng.plugin.flutter.model.util.JacksonUtil;
|
import club.ximeng.plugin.flutter.model.util.JacksonUtil;
|
||||||
import cn.hutool.core.io.FileUtil;
|
import cn.hutool.core.io.FileUtil;
|
||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
@@ -99,7 +100,11 @@ public class JsonInputDialog extends JDialog {
|
|||||||
Messages.showErrorDialog("Class 名称不能为空", "提示");
|
Messages.showErrorDialog("Class 名称不能为空", "提示");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (StrUtil.isBlank(jsonText)) {
|
if (!className.matches("^[a-zA-Z]*")) {
|
||||||
|
Messages.showErrorDialog("请输入正确的 Class 名称", "提示");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (StrUtil.isBlank(jsonText) || !JacksonUtil.isValidJson(jsonText)) {
|
||||||
Messages.showErrorDialog("请输入正确的JSON", "提示");
|
Messages.showErrorDialog("请输入正确的JSON", "提示");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -113,6 +118,8 @@ public class JsonInputDialog extends JDialog {
|
|||||||
String modelClass = modelGeneratorHandle.generateDartModelClass();
|
String modelClass = modelGeneratorHandle.generateDartModelClass();
|
||||||
createDartFile(modelClass, modelInfo.getFileName());
|
createDartFile(modelClass, modelInfo.getFileName());
|
||||||
sendNotification("Dart model class 文件生成成功");
|
sendNotification("Dart model class 文件生成成功");
|
||||||
|
// 执行命令
|
||||||
|
CommandUtil.runFlutterPubRun(project);
|
||||||
// 在此处添加您的代码
|
// 在此处添加您的代码
|
||||||
dispose();
|
dispose();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,57 @@
|
|||||||
|
package club.ximeng.plugin.flutter.model.util;
|
||||||
|
|
||||||
|
import com.intellij.openapi.project.Project;
|
||||||
|
import com.intellij.openapi.ui.Messages;
|
||||||
|
import com.intellij.openapi.wm.ToolWindow;
|
||||||
|
import com.intellij.openapi.wm.ToolWindowManager;
|
||||||
|
import com.intellij.ui.content.Content;
|
||||||
|
import org.jetbrains.plugins.terminal.ShellTerminalWidget;
|
||||||
|
import org.jetbrains.plugins.terminal.TerminalToolWindowFactory;
|
||||||
|
import org.jetbrains.plugins.terminal.TerminalView;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author liu xm
|
||||||
|
* @date 2022-06-29 14:03
|
||||||
|
*/
|
||||||
|
public class CommandUtil {
|
||||||
|
static String command = "flutter pub run build_runner build --delete-conflicting-outputs";
|
||||||
|
|
||||||
|
public static void runFlutterPubRun(Project project) {
|
||||||
|
runFlutterPubRun(project, command);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void runFlutterPubRun(Project project, String command) {
|
||||||
|
String terminalName = "DartModelClassFromJson";
|
||||||
|
String workingDirectory = project.getBasePath();
|
||||||
|
TerminalView terminalView = TerminalView.getInstance(project);
|
||||||
|
ToolWindow window = ToolWindowManager.getInstance(project)
|
||||||
|
.getToolWindow(TerminalToolWindowFactory.TOOL_WINDOW_ID);
|
||||||
|
if (window == null) {
|
||||||
|
Messages.showErrorDialog("请检查是否已安装以下两个插件: Terminal 和 Shell Script", "提示");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
Content content = window.getContentManager().findContent(terminalName);
|
||||||
|
if (content != null) {
|
||||||
|
// 2019.3
|
||||||
|
// terminalView.detachWidgetAndRemoveContent(content);
|
||||||
|
// 2020.3
|
||||||
|
terminalView.closeTab(content);
|
||||||
|
}
|
||||||
|
} catch (Exception ignored) {
|
||||||
|
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
// 2019.3
|
||||||
|
// ShellTerminalWidget terminalWidget = terminalView.createLocalShellWidget(workingDirectory);
|
||||||
|
// 2020.3
|
||||||
|
ShellTerminalWidget terminalWidget = terminalView.createLocalShellWidget(workingDirectory, terminalName);
|
||||||
|
|
||||||
|
terminalWidget.executeCommand(command);
|
||||||
|
} catch (IOException exception) {
|
||||||
|
Messages.showErrorDialog("Cannot run command:" + command + " " + exception.getMessage(), "提示");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,10 +1,8 @@
|
|||||||
package club.ximeng.plugin.flutter.model.util;
|
package club.ximeng.plugin.flutter.model.util;
|
||||||
|
|
||||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
|
||||||
import com.fasterxml.jackson.core.type.TypeReference;
|
import com.fasterxml.jackson.core.type.TypeReference;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -17,7 +15,7 @@ public class JacksonUtil {
|
|||||||
public static <T> T json2Object(String jsonStr, TypeReference<T> valueTypeRef) {
|
public static <T> T json2Object(String jsonStr, TypeReference<T> valueTypeRef) {
|
||||||
try {
|
try {
|
||||||
return MAPPER.readValue(jsonStr, valueTypeRef);
|
return MAPPER.readValue(jsonStr, valueTypeRef);
|
||||||
} catch (IOException e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -26,7 +24,7 @@ public class JacksonUtil {
|
|||||||
public static <T> T json2Object(String jsonStr, Class<T> objClass) {
|
public static <T> T json2Object(String jsonStr, Class<T> objClass) {
|
||||||
try {
|
try {
|
||||||
return MAPPER.readValue(jsonStr, objClass);
|
return MAPPER.readValue(jsonStr, objClass);
|
||||||
} catch (IOException e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -36,7 +34,7 @@ public class JacksonUtil {
|
|||||||
Object object = json2Object(jsonStr, Object.class);
|
Object object = json2Object(jsonStr, Object.class);
|
||||||
try {
|
try {
|
||||||
return MAPPER.writerWithDefaultPrettyPrinter().writeValueAsString(object);
|
return MAPPER.writerWithDefaultPrettyPrinter().writeValueAsString(object);
|
||||||
} catch (JsonProcessingException e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
@@ -55,7 +53,7 @@ public class JacksonUtil {
|
|||||||
try {
|
try {
|
||||||
MAPPER.readTree(json);
|
MAPPER.readTree(json);
|
||||||
return true;
|
return true;
|
||||||
} catch (IOException exception) {
|
} catch (Exception exception) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
<idea-plugin>
|
<idea-plugin>
|
||||||
<idea-version since-build="193"/>
|
<idea-version since-build="212"/>
|
||||||
<id>club.ximeng.plugin.model.flutter-json-to-model</id>
|
<id>club.ximeng.plugin.model.flutter-json-to-model</id>
|
||||||
<name>FlutterJson2DartModel</name>
|
<name>FlutterJson2DartModel</name>
|
||||||
<vendor email="960132232@qq.com" url="https://github.com/lxm-flutter/xxx">liu</vendor>
|
<vendor email="960132232@qq.com" url="https://github.com/lxm-flutter/xxx">liu</vendor>
|
||||||
@@ -20,6 +20,9 @@
|
|||||||
|
|
||||||
<change-notes>
|
<change-notes>
|
||||||
<![CDATA[
|
<![CDATA[
|
||||||
|
<h2>1.0.1</h2>
|
||||||
|
- 新增代码生成后自动运行flutter pub run build_runner build —delete-conflicting-outputs命令
|
||||||
|
- 右键菜单添加 build_runner 的 build watch快捷菜单
|
||||||
<br/>
|
<br/>
|
||||||
<h2>1.0.0</h2>
|
<h2>1.0.0</h2>
|
||||||
- Initial release
|
- Initial release
|
||||||
@@ -31,6 +34,9 @@
|
|||||||
<!-- please see https://plugins.jetbrains.com/docs/intellij/plugin-compatibility.html
|
<!-- please see https://plugins.jetbrains.com/docs/intellij/plugin-compatibility.html
|
||||||
on how to target different products -->
|
on how to target different products -->
|
||||||
<depends>com.intellij.modules.platform</depends>
|
<depends>com.intellij.modules.platform</depends>
|
||||||
|
<depends>com.intellij.java</depends>
|
||||||
|
<depends>com.jetbrains.sh</depends>
|
||||||
|
<depends>org.jetbrains.plugins.terminal</depends>
|
||||||
|
|
||||||
<extensions defaultExtensionNs="com.intellij">
|
<extensions defaultExtensionNs="com.intellij">
|
||||||
<!-- Add your extensions here -->
|
<!-- Add your extensions here -->
|
||||||
@@ -43,12 +49,6 @@
|
|||||||
|
|
||||||
<actions>
|
<actions>
|
||||||
<!-- Add your actions here -->
|
<!-- Add your actions here -->
|
||||||
<!-- <action id="FlutterBeanFactory.ID" class="club.ximeng.idea.plugin.flutter.action.dart_to_helper.FlutterBeanFactoryAction"-->
|
|
||||||
<!-- text="FlutterBeanFactory"-->
|
|
||||||
<!-- description="Dart files ending in entity generate dart bean factory for use">-->
|
|
||||||
<!-- <add-to-group group-id="BuildMenu" anchor="first"/>-->
|
|
||||||
<!-- <keyboard-shortcut keymap="$default" first-keystroke="alt j"/>-->
|
|
||||||
<!-- </action>-->
|
|
||||||
<action id="FlutterJsonToDartBeanModel.JsonToDartBeanAction"
|
<action id="FlutterJsonToDartBeanModel.JsonToDartBeanAction"
|
||||||
class="club.ximeng.plugin.flutter.model.action.JsonToDartBeanAction"
|
class="club.ximeng.plugin.flutter.model.action.JsonToDartBeanAction"
|
||||||
text="Dart Model Class From Json"
|
text="Dart Model Class From Json"
|
||||||
@@ -56,5 +56,19 @@
|
|||||||
description="Generate dart bean class File from JSON">
|
description="Generate dart bean class File from JSON">
|
||||||
<add-to-group group-id="NewGroup" anchor="after" relative-to-action="NewFile"/>
|
<add-to-group group-id="NewGroup" anchor="after" relative-to-action="NewFile"/>
|
||||||
</action>
|
</action>
|
||||||
|
<action id="FlutterJsonToDartBeanModel.RunCommandBuild"
|
||||||
|
class="club.ximeng.plugin.flutter.model.action.RunCommandBuild"
|
||||||
|
text="Flutter Build Runner Build"
|
||||||
|
icon="Icons.ICON"
|
||||||
|
description="run 'flutter pub run build_runner build'.">
|
||||||
|
<add-to-group group-id="EditorPopupMenu" anchor="first"/>
|
||||||
|
</action>
|
||||||
|
<action id="FlutterJsonToDartBeanModel.RunCommandWatch"
|
||||||
|
class="club.ximeng.plugin.flutter.model.action.RunCommandWatch"
|
||||||
|
text="Flutter Build Runner Watch"
|
||||||
|
icon="Icons.ICON"
|
||||||
|
description="run 'flutter pub run build_runner watch'.">>
|
||||||
|
<add-to-group group-id="EditorPopupMenu" anchor="first"/>
|
||||||
|
</action>
|
||||||
</actions>
|
</actions>
|
||||||
</idea-plugin>
|
</idea-plugin>
|
||||||
Reference in New Issue
Block a user