mirror of
https://gitee.com/openharmony/napi_generator
synced 2025-02-07 09:47:29 +00:00
add generator
Signed-off-by: zhaoxudong <zhaoxudong@kaihongdigi.com>
This commit is contained in:
parent
cb17a32334
commit
fa05df19d9
@ -49,5 +49,5 @@
|
||||
|
||||
**表 2** 待开发特性
|
||||
|
||||
https://gitee.com/openharmony-sig/napi_generator/blob/master/release-notes/napi_generator-1.0.md
|
||||
https://gitee.com/openharmony-sig/napi_generator/blob/master/docs/%E7%89%88%E6%9C%AC%E8%A7%84%E5%88%92.md
|
||||
|
||||
|
13
src/generator/generator.iml
Normal file
13
src/generator/generator.iml
Normal file
@ -0,0 +1,13 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="PLUGIN_MODULE" version="4">
|
||||
<component name="DevKit.ModuleBuildProperties" url="file://$MODULE_DIR$/resources/META-INF/plugin.xml" />
|
||||
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||
<exclude-output />
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$/resources" type="java-resource" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
</module>
|
36
src/generator/resources/META-INF/plugin.xml
Normal file
36
src/generator/resources/META-INF/plugin.xml
Normal file
@ -0,0 +1,36 @@
|
||||
<idea-plugin>
|
||||
<id>com.sk.ng</id>
|
||||
<name>napi_generator</name>
|
||||
<version>1.0</version>
|
||||
<vendor email="support@yourcompany.com" url="http://www.yourcompany.com">YourCompany</vendor>
|
||||
|
||||
<description><![CDATA[
|
||||
Enter short description for your plugin here.<br>
|
||||
<em>most HTML tags may be used</em>
|
||||
]]></description>
|
||||
|
||||
<change-notes><![CDATA[
|
||||
Add change notes here.<br>
|
||||
<em>most HTML tags may be used</em>
|
||||
]]>
|
||||
</change-notes>
|
||||
|
||||
<!-- please see https://plugins.jetbrains.com/docs/intellij/build-number-ranges.html for description -->
|
||||
<idea-version since-build="173.0"/>
|
||||
|
||||
<!-- please see https://plugins.jetbrains.com/docs/intellij/plugin-compatibility.html
|
||||
on how to target different products -->
|
||||
<depends>com.intellij.modules.platform</depends>
|
||||
|
||||
<extensions defaultExtensionNs="com.intellij">
|
||||
<!-- Add your extensions here -->
|
||||
</extensions>
|
||||
|
||||
<actions>
|
||||
<!-- Add your actions here -->
|
||||
<action id="NapiGenerate.gen" class="com.sk.ng.GenDTS" text="generate .d.ts" description="generate napi files">
|
||||
<add-to-group group-id="ProjectViewPopupMenu" anchor="first"/>
|
||||
</action>
|
||||
</actions>
|
||||
|
||||
</idea-plugin>
|
72
src/generator/src/com/sk/ng/GenDTS.java
Normal file
72
src/generator/src/com/sk/ng/GenDTS.java
Normal file
@ -0,0 +1,72 @@
|
||||
package com.sk.ng;
|
||||
|
||||
import com.intellij.openapi.actionSystem.AnAction;
|
||||
import com.intellij.openapi.actionSystem.AnActionEvent;
|
||||
import com.intellij.openapi.actionSystem.PlatformDataKeys;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.ui.Messages;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class GenDTS extends AnAction {
|
||||
private static final Logger LOG = Logger.getInstance(GenDTS.class);
|
||||
|
||||
@Override
|
||||
public void actionPerformed(AnActionEvent e) {
|
||||
//获取需要处理的.d.ts文件绝对路径
|
||||
VirtualFile file = e.getData(PlatformDataKeys.VIRTUAL_FILE);
|
||||
if (file == null) return;
|
||||
//正则匹配所选文件名是否符合规范
|
||||
if (!Pattern.matches("@ohos.[a-zA-Z0-9]+.d.ts", file.getName())) {
|
||||
Messages.showErrorDialog("选择@ohos.xxx.d.ts文件生成", "错误");
|
||||
return;
|
||||
}
|
||||
String dest_path = file.getPath();
|
||||
|
||||
//执行命令行
|
||||
RunFun(dest_path);
|
||||
|
||||
Messages.showMessageDialog(e.getProject(), dest_path, "generating", Messages.getInformationIcon());
|
||||
}
|
||||
|
||||
public void RunFun(String dest_path) {
|
||||
String command = "";
|
||||
String sysName = System.getProperties().getProperty("os.name").toUpperCase();
|
||||
if (sysName.indexOf("WIN") >= 0) {
|
||||
URL res = getClass().getClassLoader().getResource("cmds/win/napi_generator-win.exe");
|
||||
String exePath = res.getPath().substring(1);
|
||||
command = exePath.replace("%20", " ") + " " + dest_path.replace("/", "\\");
|
||||
} else if (sysName.indexOf("LINUX") >= 0) {
|
||||
URL res = getClass().getClassLoader().getResource("cmds/linux/napi_generator-linux");
|
||||
command = res.getPath() + " " + dest_path;
|
||||
} else {
|
||||
//mac support
|
||||
}
|
||||
|
||||
try {
|
||||
Runtime.getRuntime().exec(command);
|
||||
} catch (IOException ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(AnActionEvent event) {
|
||||
//根据所选文件名,判断是否显示生成菜单项
|
||||
VirtualFile file = event.getData(PlatformDataKeys.VIRTUAL_FILE);
|
||||
if (file == null) {
|
||||
event.getPresentation().setEnabledAndVisible(false);
|
||||
return;
|
||||
} else {
|
||||
String extension = file.getExtension();
|
||||
if (extension != null && "ts".equals(extension)) {
|
||||
event.getPresentation().setEnabledAndVisible(true);
|
||||
} else {
|
||||
event.getPresentation().setEnabledAndVisible(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user