|
1 | 1 | package com.axellience.vuegwtplugin; |
2 | 2 |
|
| 3 | +import com.intellij.openapi.compiler.CompilerPaths; |
| 4 | +import com.intellij.openapi.compiler.ex.CompilerPathsEx; |
| 5 | +import com.intellij.openapi.vfs.VfsUtil; |
| 6 | +import com.intellij.openapi.vfs.VirtualFileManager; |
3 | 7 | import org.jetbrains.annotations.NotNull; |
4 | 8 | import org.jetbrains.annotations.Nullable; |
5 | 9 | import org.jetbrains.concurrency.Promise; |
|
19 | 23 | import com.intellij.psi.PsiDocumentManager; |
20 | 24 | import com.intellij.psi.PsiFile; |
21 | 25 |
|
| 26 | +import java.io.IOException; |
| 27 | +import java.nio.file.Files; |
| 28 | +import java.nio.file.Path; |
| 29 | +import java.nio.file.StandardCopyOption; |
| 30 | + |
22 | 31 | public class VueGWTFileWatcher implements FileDocumentManagerListener { |
23 | 32 |
|
24 | 33 | private static final Logger LOGGER = Logger.getInstance(VueGWTFileWatcher.class); |
@@ -67,11 +76,27 @@ private void compileComponent(VirtualFile javaComponent, VirtualFile htmlTemplat |
67 | 76 | if (module == null) { |
68 | 77 | return; |
69 | 78 | } |
| 79 | + var sourceRoot = projectFileIndex.getSourceRootForFile(javaComponent); |
| 80 | + if(sourceRoot == null) |
| 81 | + return; |
| 82 | + |
| 83 | + var htmlPath = htmlTemplate.getPath(); |
| 84 | + var relativeHtmlPath = htmlPath.substring(sourceRoot.getPath().length()); |
| 85 | + var outputs = CompilerPaths.getOutputPaths(new Module[] { module }); |
| 86 | + if(outputs.length == 0) |
| 87 | + return; |
| 88 | + |
| 89 | + var targetPath = Path.of(outputs[0], relativeHtmlPath); |
| 90 | + try { |
| 91 | + Files.copy(Path.of(htmlPath), targetPath, StandardCopyOption.REPLACE_EXISTING); |
| 92 | + } catch (IOException e) { |
| 93 | + return; |
| 94 | + } |
70 | 95 |
|
71 | 96 | CompilerManager compilerManager = CompilerManager.getInstance(project); |
72 | 97 | if (!compilerManager.isCompilationActive() |
73 | 98 | && !compilerManager.isExcludedFromCompilation(javaComponent)) { |
74 | | - compilerManager.compile(new VirtualFile[] {javaComponent, htmlTemplate}, null); |
| 99 | + compilerManager.compile(new VirtualFile[] {javaComponent}, null); |
75 | 100 | } |
76 | 101 | }); |
77 | 102 | } |
|
0 commit comments