New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Require.js for packaging #38

Closed
chiquitinxx opened this Issue Jan 31, 2015 · 3 comments

Comments

Projects
None yet
1 participant
@chiquitinxx
Owner

chiquitinxx commented Jan 31, 2015

Hello!

As we have talked in issue #16, we are going to add require.js(http://requirejs.org/) as package manager. Now, the conversion is done file by file. But, with this improvement we want to give facilities to create bigger projects without a hell of files and dependencies managed manually. Seem it has good integration with Node.js, and it uses closure compiler for optimizations.

You can take a look at Serge idea project https://github.com/pioneer/grooscript-require

The hardest part is resolve dependencies. For example, if you want to convert a class, what classes are needed by that class? We have to do compiler job, see imports, classes used, inheritance, traits,... The target? When I convert a file, all dependencies are also converted and all that files are require.js modules.

Also we have to improve daemon converter, now has to listen changes in all the dependencies tree, also add more files when necessary. But this will be later.

At the moment I will create a new conversion option, when activated, conversion will be done as require.js modules. Without that conversion option, grooscript will work as it does now.

I'll create a branch called 'require' to work with. The plan: release the conversion process in 1.1 release. Later, the daemon.

If you have something to say, or if you want to contribute, please as soon as possible :). Thank you.

@chiquitinxx

This comment has been minimized.

Show comment
Hide comment
@chiquitinxx

chiquitinxx Apr 17, 2015

Owner

Hello!

In branch 'require' it starts to work. Just as reminder the idea, you will tell grooscript: ey! I want to convert this file to a require.js module. Grooscript will manage all dependencies, an also will convert all to require.js modules. You will have to include any classPath (or will take current folder) as any other conversion option, and all files has to be in that classpath.

GrooScript.setConversionProperty('classPath', 'src/main/groovy')
GrooScript.convertRequireJs(initialGroovyFile, destinationFolder)

If you want to use any of that modules, you have to add it to your require.js, and of course, you will have to load grooscript(.min).js and any dependency before.

I'll show examples soon, just say something if you miss something for the first version.

Owner

chiquitinxx commented Apr 17, 2015

Hello!

In branch 'require' it starts to work. Just as reminder the idea, you will tell grooscript: ey! I want to convert this file to a require.js module. Grooscript will manage all dependencies, an also will convert all to require.js modules. You will have to include any classPath (or will take current folder) as any other conversion option, and all files has to be in that classpath.

GrooScript.setConversionProperty('classPath', 'src/main/groovy')
GrooScript.convertRequireJs(initialGroovyFile, destinationFolder)

If you want to use any of that modules, you have to add it to your require.js, and of course, you will have to load grooscript(.min).js and any dependency before.

I'll show examples soon, just say something if you miss something for the first version.

@chiquitinxx

This comment has been minimized.

Show comment
Hide comment
@chiquitinxx

chiquitinxx May 13, 2015

Owner

I'm using it in books demo (require branch of https://github.com/chiquitinxx/books-demo). I had to change require.js file to set destination folder ('js/app') and initial groovy script ('bookDemo'):

requirejs.config({
    baseUrl: 'js/app',
    paths: {
        lib: '../lib',
        jquery: '../lib/jquery'
    }
});

requirejs(['jquery', 'lib/grooscript.min', 'lib/grooscript-tools'], function($) {
    requirejs(['Templates', 'lib/sockjs-0.3.4', 'lib/stomp', 'bookDemo']);
});

Defined require.js conversion task in build.grade

task myRequire(type: org.grooscript.gradle.RequireJsTask) {
    sourceFile = 'src/main/groovy/bookDemo.groovy'
    destinationFolder = 'src/main/resources/static/js/app'
}

When the task run, all files are converted and saved as require.js modules. bookDemo.groovy is the script where all is loaded, some groovy classes are used. For example BookPresenter.groovy:

package component

import demo.model.Book

class BookPresenter implements Chart {

    List<Book> books = []
    Counter booksCounter
    GQuery gQuery = new GQueryImpl()
    ...

The result js file is saved as 'src/main/resources/static/js/app/component/BookPresenter.js'. And the content is:

define(['component/Chart','demo/model/Book','component/Counter'], function (Chart,Book,Counter) {
function BookPresenter() {
  var gSobject = gs.inherit(gs.baseClass,'BookPresenter');
  gSobject.clazz = { name: 'component.BookPresenter', simpleName: 'BookPresenter'};
  gSobject.clazz.superclass = { name: 'java.lang.Object', simpleName: 'Object'};
  gSobject.clazz.interfaces = [{ name: 'component.Chart', simpleName: 'Chart'}];
  ...
return BookPresenter;
});

This is a preview, I wanted to show it, if you want say something. I have to finish gradle plugin to include a daemon conversion task for this require.js conversions. Very soon 1.1 release :)

And that's all folks!

Owner

chiquitinxx commented May 13, 2015

I'm using it in books demo (require branch of https://github.com/chiquitinxx/books-demo). I had to change require.js file to set destination folder ('js/app') and initial groovy script ('bookDemo'):

requirejs.config({
    baseUrl: 'js/app',
    paths: {
        lib: '../lib',
        jquery: '../lib/jquery'
    }
});

requirejs(['jquery', 'lib/grooscript.min', 'lib/grooscript-tools'], function($) {
    requirejs(['Templates', 'lib/sockjs-0.3.4', 'lib/stomp', 'bookDemo']);
});

Defined require.js conversion task in build.grade

task myRequire(type: org.grooscript.gradle.RequireJsTask) {
    sourceFile = 'src/main/groovy/bookDemo.groovy'
    destinationFolder = 'src/main/resources/static/js/app'
}

When the task run, all files are converted and saved as require.js modules. bookDemo.groovy is the script where all is loaded, some groovy classes are used. For example BookPresenter.groovy:

package component

import demo.model.Book

class BookPresenter implements Chart {

    List<Book> books = []
    Counter booksCounter
    GQuery gQuery = new GQueryImpl()
    ...

The result js file is saved as 'src/main/resources/static/js/app/component/BookPresenter.js'. And the content is:

define(['component/Chart','demo/model/Book','component/Counter'], function (Chart,Book,Counter) {
function BookPresenter() {
  var gSobject = gs.inherit(gs.baseClass,'BookPresenter');
  gSobject.clazz = { name: 'component.BookPresenter', simpleName: 'BookPresenter'};
  gSobject.clazz.superclass = { name: 'java.lang.Object', simpleName: 'Object'};
  gSobject.clazz.interfaces = [{ name: 'component.Chart', simpleName: 'Chart'}];
  ...
return BookPresenter;
});

This is a preview, I wanted to show it, if you want say something. I have to finish gradle plugin to include a daemon conversion task for this require.js conversions. Very soon 1.1 release :)

And that's all folks!

@chiquitinxx

This comment has been minimized.

Show comment
Hide comment
@chiquitinxx

chiquitinxx May 20, 2015

Owner

Merged in master

Owner

chiquitinxx commented May 20, 2015

Merged in master

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment