es4x icon indicating copy to clipboard operation
es4x copied to clipboard

Need migration guide documentation for moving vertx 3 js verticles to es4x

Open chefhoobajoob opened this issue 2 years ago • 9 comments

The vert.x 3 libraries made use of vertx-lang-js wrapper scripts in order to make vert.x libs accessible to js verticles. We also have some of our own "polyglot" class libraries that used that same scheme via codegen for using our own vertx utility libraries from js.

Assuming there is an analogous mechanism in es4x for using vert.x and/or custom libs that were using the vertx 3 vertx-lang-js wrappers, it would be extremely helpful if there was guidance documentation describing how to migrate such js code over to es4x.

chefhoobajoob avatar Sep 09 '21 15:09 chefhoobajoob

Not exactly the same topic, but related: it would be good to know how to package up an es4x project as a verticle "library" (not an app) to be loaded from java running on the jvm via the verticle factory, classpath requirements, etc. Like, for the vert.x 3 world, we had to ensure js directories were on the classpath and had to ensure NODE_PATH was defined so require statements could find dependencies. I'm sure there are differences there too. I've got bits and pieces on what to do from gitter convos, but there's not really much on this setup at reactiverse.io

chefhoobajoob avatar Sep 09 '21 16:09 chefhoobajoob

I've noticed that 've been missing some artifacts during the release. I'm working on the documentation of the process, but for now assume you can do anything like this (using maven, but can use gradle too):

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

  <parent>
    <groupId>io.reactiverse.es4x</groupId>
    <artifactId>es4x-generator</artifactId>
    <version>0.15.1-SNAPSHOT</version>
  </parent>

  <modelVersion>4.0.0</modelVersion>

  <artifactId>vertx-redis-client</artifactId>  <!-- <<<- here the java artifact you want to convert -->
  <version>1.0.0</version>

  <properties>
    <maven.groupId>io.vertx</maven.groupId>              <!-- <<<- here the java artifact group you want to convert -->
    <npm-name>@vertx/redis-client</npm-name>  <!-- <<<- here the npm desired package name -->
    <npm-version>4.1.3</npm-version>         <!-- <<<- here the java version you want to convert -->
    <npm-skip>false</npm-skip>

    <!-- language=json -->    <!-- <<<- any customization to package.json you want, but this is required -->
    <package-json>
      {
        "description": "${project.description}",
        "version": "${npm-version}",
        "license": "${npm-license}",
        "maven": {
          "groupId": "io.vertx",
          "artifactId": "vertx-redis-client",
          "version": "${npm-version}"
        }
      }
    </package-json>
  </properties>

  <dependencies>
    <!-- Sources to process -->
    <dependency>
      <groupId>${maven.groupId}</groupId>
      <artifactId>${project.artifactId}</artifactId>
      <version>${npm-version}</version>
    </dependency>
    <dependency>
      <groupId>${maven.groupId}</groupId>
      <artifactId>${project.artifactId}</artifactId>
      <version>${npm-version}</version>
      <scope>provided</scope>
      <classifier>sources</classifier>
    </dependency>
  </dependencies>

</project>

Running a mvn generate-sources should finish with a target/npm folder with your generated npm package you can later upload to npm or your local repository

pmlopes avatar Sep 10 '21 17:09 pmlopes

@chefhoobajoob I've started documenting the generation process here:

https://github.com/reactiverse/es4x/commit/4c9df8657ba8beb60f384ce99111689cce11484e#diff-2586b42924f021fe14c65861d3404f4b4015ee68c6592ce5633fee850940b470

pmlopes avatar Sep 10 '21 19:09 pmlopes

codegen does seem to be working from gradle with this setup:

image

image

I get an npm folder in <project-root>/src/main with package.json and the other expected files. Just need to figure out how to get dependencies and other properties configured

chefhoobajoob avatar Sep 10 '21 22:09 chefhoobajoob

If you look at the manual I've started, there's a lot of system properties in the maven snippet I've added. You will need to pass those environmental variables to the process running the annotation processor.

pmlopes avatar Sep 11 '21 08:09 pmlopes

Yes, was referring to those examples - thank you. I setup the gradle equivalent as a separate build script (es4x-codegen.gradle) where the es4x codegen system properties for the build can be managed, like so:

image

...and apply that script in the project build script during evaluation so the system properties are available to the codegen task: image

chefhoobajoob avatar Sep 11 '21 15:09 chefhoobajoob

@chefhoobajoob can you share a simple hello world with your gradle script? I think we can improve it to be an easy template to generate es4x packages.

pmlopes avatar Sep 13 '21 07:09 pmlopes

sure - i'll try to get one up and post the repo link here

chefhoobajoob avatar Sep 13 '21 15:09 chefhoobajoob

hello world example project here: https://github.com/chefhoobajoob/es4x-codegen-gradle

chefhoobajoob avatar Sep 13 '21 22:09 chefhoobajoob