JavaScript library development using ANT and YUICompressor

Since I need to port a huge ActionScript project to JavaScript I see myself confronted with different practices of code organization, workspace structures and a lot more JavaScript specific stuff. I’m used to big, strongly typed ActionScript library development with hundreds of classes and interfaces but I’m not quite sure how to transfer my programming skills from ActionScript to JavaScript.

After reading loads of informations I think I created an reusable and understandable build process for my JavaScript project. I bet you’ve already read a lot about YUICompressor and ANT so here you’ll find just some brief informations.

This is my example workspace with file type src subfolders and even another subfolder within the js directory named like the JavaScript library it contains. All ANT files can be found in src/ant:
 

Now let’s have a look at system.properties. This file bundles the system specific settings and usually won’t need changes at all after your initial setup. Only YUI_COMPRESSOR_JAR and YUI_COMPRESSOR_CHARSET will affect the build.xml. I still don’t know what’s the correct charset, but my encoding problems might be caused by the editor. I’ll figure that out later…

#
# SYSTEM PROPERTIES
#

# Version number separated for easy changes
YUI_COMPRESSOR_VERSION=2.4.6

# Absolut path to YUICompressor home directory
YUI_COMPRESSOR_HOME=/Users/you/.../YUICompressor/${YUI_COMPRESSOR_VERSION}

# Absolute path to JAR file (used in build.xml!)
YUI_COMPRESSOR_JAR=${YUI_COMPRESSOR_HOME}/build/yuicompressor-${YUI_COMPRESSOR_VERSION}.jar

# Charset used with YUICompressor - MAKE SURE THIS IS CORRECT FOR YOUR SYSTEM!!!
YUI_COMPRESSOR_CHARSET=MacRoman
#YUI_COMPRESSOR_CHARSET=UTF-8
#YUI_COMPRESSOR_CHARSET=ANSI
#YUI_COMPRESSOR_CHARSET=ISO-8859-1

The project.properties currently only contains the basic workspace structure.

#
# PROJECT PROPERTIES
#

# Workspace root relative to build.xml
WORKSPACE_ROOT=../..

# Main binary directory
BIN_DIR=${WORKSPACE_ROOT}/bin

# JavaScript bin directory
BIN_JS_DIR=${BIN_DIR}/js

# Main source directory
SRC_DIR=${WORKSPACE_ROOT}/src

# JavaScript source directory
SRC_JS_DIR=${SRC_DIR}/js

Finally there is the main build.xml. I was trying hard to write an understandable documentation. Just follow these steps (also found more detailed within the file):

  1. Replace the default library name and prefix with your’s.
  2. Add your source files.
  3. Choose your browser and html file (works at least with Mac OS X).
  4. Run the ANT task called YOUR_LIBRARY_PREFIX_run().


	
	
	
	
	
	
	
	
    
    	
    	
        
        
    

	
    
        
    	
    		
    		
    	
    

	
    
        
    	
        
            
            
        
    

	
    
    	
    	
        
            
                
            
            
            	
            
            
            
            
            
        
    
	
	
	
	
	
	
	
	
	
	
	
	
	
	
    
    	
    	
    	
    
    
    	
    	
    
	
	
	
		
	
	
		
			
			
			
		
	
	
		
			
			
			
		
	
	
		
			
			
		
	
	
		
		
	
	

Notice that it’s possible to have multiple libraries within a single build.xml. Simply use different prefixes!

In the end I found most of the core informations at http://www.samaxes.com and http://www.darronschall.com/weblog. Thank you guys! And of course the ANT and YUICompressor manuals accessible through Google ;).

And now I have two question:

  • Will you tell me your preferred editor?
  • Will you give me a hint according to code organization?

Please.

9 thoughts on “JavaScript library development using ANT and YUICompressor”

  1. hi raab, i think it’s funny to use our dev skills for javascript. in a current project we use backbone.js, it’s a nice little mvc framework with a cool event system.
    half year ago we used the puremvc for mootools, feels also nearly like ActionScript.
    we use NetBeans for editing but there is really bad code completion. at FFK11 somebody said http://www.jetbrains.com/webstorm/ is a nice js editor, maybe you give it a try.

    sooo, fireabend!!!!

    lg mad

  2. Hi Mr. flanderz. Did we met at FFK11??? I can’t remember.

    PureMVC is a good advice since the ActionScript project is also based on PureMVC. But PureMVC seems not to use a specific namespace but lots of globals (e.g. “Controller”, “Model”). In the case of my project I need to make sure it’s “sandboxed” as much als possible. Thanks anyway!

  3. @derRaab> I’m the creator of the PureMVC to JavaScript port. I also prefer to use namespaces to access all my classes in JavaScript project and would I preferred to do so for PureMVC port. But by the past a lot of JS dev (not coming from ActionScript) found this cumbersome and usefulness so we decided not to use them.

    There’s an hidden feature in the PureMVC JS port. Just declare a var HidePureMVC = true; on the top of your webpage before loading the JS file whic contains PureMVC and you can access the class with their namespace.

    This is not the full “org.puremvc.js.objs.core.Controller” but “puremvc.Controller” as using all those namespace on imports adds unwanted weight to the project but this is sufficient not to collide with others project.

    You can have more documentation on how to access or declare your own class + namespace on the library documentation page on Github I used to create the PureMVC JavaScript port : https://github.com/tekool/objs/wiki

    Hope this helps.

  4. @derRaab > What licensing model do you need? I’m the creator of the project and can write you any mail you need to derogate to this license problem. Licensing on PureMVC is more problematic but I’m pretty sure that Cliff Hall will never bug you with a licensing problem . As Objs also uses YUICompressor + Ant it would have been great for you.

  5. Yeah, I really like the basic syntax of Objs! It would be absolute perfect for me to use PureMVC based on Objs since I’m porting a big PureMVC based project.

    PureMVC comes with Creative Commons v3 so it would be nice if Objs would come with the same licence. Maybe I’m wrong, but I think it’s not possible to use a GPL v3 with the project I’m working on because it won’t be open sourced?

  6. In reality it’s not possible to directly use a Creative Commons license with a software. But you can embed GNUGPL software in a CC license. But as said before I can write you a line by e-mail to authorize you to use Objs in a non GPL software if you really need it.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>