Skip to content
This repository was archived by the owner on Aug 2, 2022. It is now read-only.
This repository was archived by the owner on Aug 2, 2022. It is now read-only.

Add support for CommonJs, es6 or UMD modules #63

@luisvt

Description

@luisvt

Please add support for converting the groovy files into js using commonJs modules. For example having next code:

// Person.groovy
package com.example.grooscript_sample.models

class Person {
    String firstName
    String lastName
}

and:

// PersonPresenter.groovy
package com.example.grooscript_sample.presenters

import com.example.grooscript_sample.models.Person

class PersonPresenter {
    Person person
    def buttonClick() {
        if (person.firstName) {
            $('#salutes').append("<p>Hello ${person.firstName}!</p>")
        }
    }
}

should be transpiled to:

// Person.js

module.exports.Person = function Person() {
  var gSobject = gs.init('Person');
  gSobject.clazz = { name: 'com.example.grooscript_sample.models.Person', simpleName: 'Person'};
  gSobject.clazz.superclass = { name: 'java.lang.Object', simpleName: 'Object'};
  gSobject.firstName = null;
  gSobject.lastName = null;
  if (arguments.length == 1) {gs.passMapToObject(arguments[0],gSobject);};
  
  return gSobject;
 };

and:

// PersonPresenter.js

var Person = require('./Person');

module.export.PersonPresenter = function PersonPresenter() {
  var gSobject = gs.init('PersonPresenter');
  gSobject.clazz = { name: 'com.example.grooscript_sample.presenters.PersonPresenter', simpleName: 'PersonPresenter'};
  gSobject.clazz.superclass = { name: 'java.lang.Object', simpleName: 'Object'};
  gSobject.person = null;
  gSobject['buttonClick'] = function(it) {
    if (gs.bool(gs.gp(gSobject.person,"firstName"))) {
      return gs.mc(gs.mc(this,"$",["#salutes"], gSobject),"append",["<p>Hello " + (gs.gp(gSobject.person,"firstName")) + "!</p>"]);
     };
   }
  if (arguments.length == 1) {gs.passMapToObject(arguments[0],gSobject);};
  
  return gSobject;
 };

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions