added a basic working JS compiler maven plugin (though it doesn't currently let you specify any library files to compile)
This commit is contained in:
@@ -1,7 +1,9 @@
|
||||
package sample
|
||||
|
||||
class Hello {
|
||||
var x = 0
|
||||
|
||||
fun doSomething(): Unit {
|
||||
println("Hello world!")
|
||||
x++
|
||||
}
|
||||
}
|
||||
@@ -122,6 +122,22 @@
|
||||
<generatePom>true</generatePom>
|
||||
</configuration>
|
||||
</execution>
|
||||
<execution>
|
||||
<id>org.jetbrains.kotlin:dartc</id>
|
||||
<phase>verify</phase>
|
||||
<goals>
|
||||
<goal>install-file</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<groupId>org.jetbrains.kotlin</groupId>
|
||||
<artifactId>dartc</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<packaging>jar</packaging>
|
||||
<file>${kotlin-sdk}/lib/js/dartc.jar</file>
|
||||
<createChecksum>true</createChecksum>
|
||||
<generatePom>true</generatePom>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
|
||||
@@ -107,6 +107,14 @@
|
||||
<version>2.9</version>
|
||||
</dependency>
|
||||
-->
|
||||
|
||||
|
||||
<!-- for JS generation -->
|
||||
<dependency>
|
||||
<groupId>org.jetbrains.kotlin</groupId>
|
||||
<artifactId>dartc</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<build>
|
||||
<sourceDirectory>src/main/java</sourceDirectory>
|
||||
|
||||
+6
@@ -10,6 +10,12 @@ import org.jetbrains.jet.cli.CompilerArguments;
|
||||
*/
|
||||
public class K2JSCompilerMojo extends KotlinBaseMojo {
|
||||
|
||||
/**
|
||||
* The output JS file name
|
||||
*
|
||||
* @required
|
||||
* @parameter default-value="${project.build.directory}/js/${project.artifactId}.js"
|
||||
*/
|
||||
private String outFile;
|
||||
|
||||
@Override
|
||||
|
||||
+2
-6
@@ -13,6 +13,7 @@ import org.jetbrains.k2js.facade.K2JSTranslator;
|
||||
import java.io.File;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static kotlin.io.namespace.use;
|
||||
@@ -22,10 +23,6 @@ import static kotlin.io.namespace.use;
|
||||
*/
|
||||
public class K2JSCompilerPlugin implements CompilerPlugin {
|
||||
|
||||
/**
|
||||
* @required
|
||||
* @parameter default-value="${project.build.directory}/target/js/${project.artifactId}.js"
|
||||
*/
|
||||
private String outFile = "target/js/program.js";
|
||||
|
||||
public void processFiles(CompilerPluginContext context) {
|
||||
@@ -38,8 +35,7 @@ public class K2JSCompilerPlugin implements CompilerPlugin {
|
||||
@NotNull
|
||||
@Override
|
||||
public List<JetFile> getLibFiles() {
|
||||
// TODO
|
||||
return null;
|
||||
return new ArrayList<JetFile>();
|
||||
}
|
||||
};
|
||||
K2JSTranslator translator = new K2JSTranslator(config);
|
||||
|
||||
+11
@@ -21,6 +21,14 @@ public abstract class KotlinBaseMojo extends AbstractMojo {
|
||||
*/
|
||||
private String src;
|
||||
|
||||
/**
|
||||
* The output directory for bytecode classes
|
||||
*
|
||||
* @required
|
||||
* @parameter default-value="${project.build.directory}/classes"
|
||||
*/
|
||||
private String outputDir;
|
||||
|
||||
@Override
|
||||
public void execute() throws MojoExecutionException, MojoFailureException {
|
||||
arguments = createCompilerArguments();
|
||||
@@ -28,6 +36,9 @@ public abstract class KotlinBaseMojo extends AbstractMojo {
|
||||
if (src != null) {
|
||||
arguments.setSrc(src);
|
||||
}
|
||||
if (outputDir != null) {
|
||||
arguments.setOutputDir(outputDir);
|
||||
}
|
||||
configureCompilerArguments(arguments);
|
||||
|
||||
compiler.exec(System.err, arguments);
|
||||
|
||||
Reference in New Issue
Block a user