Javascript and Node.js plugin

Before doing any kind of work, I would like to have feedback on a possible extension for javascript mainly for node.js. I know a plugin already exist but I feel it doesn’t follow the Gradle way of configuring your project. Here is a first draft of the targeted build.gradle:

apply plugin: 'nodejs'
  sources {
    main {
        javaScript {
            srcDir "src/main/javascript"
        }
    }
}
  model {
    nodeModules {
        main {
            source sources.main.javascript
            source sources.main
                  // Fetch dependencies from Npm repository
            dependencies {
                runtime library: 'colors', version: '*'
                runtime library: 'flatiron', version: '0.1.x'
                runtime library: 'optimist', version: '0.2.x'
                runtime library: 'union', version: '0.1.x'
                runtime library: 'ecstatic', version: '0.1.x'
                runtime library: 'plates', url: 'https://github.com/flatiron/plates/tarball/master'
                development library: 'vows', version: '0.5.x'
                development library: 'request', version: '2.1.x'
                bundled library: 'union'
                bundled library: 'ecstatic'
            }
        }
    }
      testSuites {
        mainTest(QUnit) {
            // Same underlying object as the one from nodeModules meaning you also get depenencies and source
        }
    }
}
  apply plugin: 'npm-publish'
  publishing {
    publications {
        create('http-server', NpmPublication) {
            from nodeModules.main
              description = "a simple zero-configuration command-line http server"
            revision "0.3.0"
              // The following parameter could be all replace by the withJson hook as
            // Gradle would most likely have no value to understand those values.
            analyze false
            preferGlobal true
            license 'MIT'
            keywords ['cli', 'http', 'server']
            contributors {
                contributor name:"Marak Squires", email: "marak@nodejitsu.com"
                //or contributor "Marak Squires <marak@nodejitsu.com>"
            }
            homepage 'http://bob.org/'
            bugs url: 'http://github.com/owner/project/issues', email: 'project@hostname.com'
            author name: 'Barney Rubble', email: 'b@rubble.com', url: 'http://barnyrubble.tumblr.com/'
            //or author "Barney Rubble <b@rubble.com> (http://barnyrubble.tumblr.com/)"
            main "./lib/bob"
            engines node: '>=0.6'
                descriptor.withJson {
                // A lot like withXml and use the Groovy Json parser
            }
        }
    }
}

This script use the same configuration convention used in the new native development in Gradle. Note, that this build script example is an extensive example. Normally, lots of the default configuration would be done for you.

Comment, pitch improvement, critics, etc. are welcome!

1 Like

Hi Daniel - sorry for the delayed reply.

This looks pretty interesting. It’s cool the way you’ve adopted the new configuration conventions from the native support, as well as the new publishing support. This is the sort of directly we eventually want to take with all of our language support, and it would be cool to have another example domain to drive the model forward.

If you’re motivated to move forward with this, the first step would be to get a design discussion going on the Gradle developers list: dev@gradle.codehaus.org. We’d then look to break this work out into implementable, testable stories in a design doc. If you’re willing to work on the implementation, we’d be happy to help out with the design.

Thanks for taking the time to submit this proposal. We look forward to working with you on this soon!

is the Node.js plugin supported by gradle???

No, it’s not supported by the Gradle development team.

OK, i wish it will be supported by gradle in the near future.