Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
A command line tool for running JavaScript scripts that use the Asychronous Module Defintion API (AMD) for declaring and using JavaScript modules and regular JavaScript script files.
JavaScript Java
branch: master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
amd4j-closure
amd4j-core
amd4j-maven-plugin
amd4j-tool
.gitignore
.travis.yml
LICENSE
README.md
checkstyle.xml
pom.xml

README.md

amd4j Build Status

A command line tool for running JavaScript scripts that use the Asychronous Module Defintion API (AMD) for declaring and using JavaScript modules and regular JavaScript script files.

This projects aims to be an alternative to the Rhino version of r.js created by @jrburke.

why?

Beside all the good work and efforts that @jrburke did in r.js for Java. I found r.js extremely slow because the use of Rhino.

So, amd4j need to be extremely fast.

why not?

I love AMD!! So, I created this tool (inspired by r.js) for processing AMD scripts in Java where node.js isn't an option

API Usage

Optimizing an AMD script:

  new Amd4j()
    .optimize(new Config("module.js", new File("module.out.js")));

Analyzing an AMD script:

  Module result = new Amd4j().analyze(new Config("module.js")));

  // print graph
  System.out.println(result.toStringTree());

  // get dependencies
  Iterable<Module> dependencies = result.getDependencies(false);

  // get transitive dependencies
  Iterable<Module> dependencies = result.getDependencies(true);

Command Line Usage

Optimizing an AMD script:

java -jar amd4j-tool.jar -o baseUrl=. name=module.js out=module.opt.js

Analyzing an AMD script:

java -jar amd4j-tool.jar -a baseUrl=. name=module.js

Maven Usage

Optimizing an AMD script:

  <build>
    <plugins>
      <plugin>
        <groupId>com.github.jknack</groupId>
        <artifactId>amd4j-maven-plugin</artifactId>
        <version>${amd4j-version}</version>
        <configuration>
          <baseUrl>src/webapp/js</baseUrl>
          <!-- ${script.name} will be replaced by home and page -->
          <out>${project.build.directory}/${project.build.finalName}/${script.name}.opt.js</out>
          <inlineText>true</inlineText>
          <useStrict>false</useStrict>
          <buildFile></buildFile>
          <!-- One of: none, white (strip comments, spaces and lines), closure (simple optimizations),  closure.advanced, closure.white -->
          <optimize>none</optimize>

          <!--file to be processed-->
          <names>
            <name>home</name>
            <name>page</name>
          </names>

          <!--path configuration-->
          <paths>
            <path>jquery:empty:</path>
            <path>topbar:widgets/topbar/topbar</path>
            <path>sidebar:widgets/sidebar/sidebar</path>
          </paths>
        </configuration>
        <executions>
          <execution>
            <id>optimize</id>
            <goals>
              <goal>optimize</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>

The plugin will generate two files: target/${project.build.finalName}/home.opt.js and target/${project.build.finalName}/page.opt.js

Analyzing an AMD script:

Just change the goal to: analyze

what is supported so far?

  • Processing of single AMD script as input
  • Naming modules (the optimizer is able to insert module's names)
  • Dependency resolution support
  • build profile support
  • paths support
  • text! plugin support
  • shim support

maven

Stable version: 0.1.1

  <dependency>
    <groupId>com.github.jknack</groupId>
    <artifactId>amd4j</artifactId>
    <version>${amd4j-version}</version>
  </dependency>

Development version: 0.1.2-SNAPSHOT

SNAPSHOT versions are NOT synchronized to Central. If you want to use a snapshot version you need to add the https://oss.sonatype.org/content/repositories/snapshots/ repository to your pom.xml.

dependencies

+- org.apache.commons:commons-lang3:jar:3.1:compile
+- org.slf4j:slf4j-api:jar:1.6.4:compile
+- commons-io:commons-io:jar:2.4:compile

help and support

Bugs, Issues and Features

related projects

r.js

credits

@jrburke

author

@edgarespina

license

Apache License 2

Something went wrong with that request. Please try again.