Commits

"Pau...@exalead.com>"  committed 6ca6eb9

added release|debug|concat mode

  • Participants
  • Parent commits 457ae10

Comments (0)

Files changed (4)

File tumbler/src/tumbler-build.coffee

 
 ARGUMENTS = [
     [ ["-t", "--target"], "target", true, "Target to build" ]
+    [ ["-m", "--mode"], "mode", true, "(debug|release)" ]
 ]
 
+
 ARGUMENTS_PARSER = new utils.ArgumentParser
     args: ARGUMENTS
+    defaultConfig:
+        mode: "debug"
     configFile: ".tumbler"
 
+
 help = ->
     ARGUMENTS_PARSER.help()
 

File tumbler/src/tumbler-deploy.coffee

     [ ["-t", "--targets"], "targets", true, "Path to a JSON file containing the list of file to be deployed. Path should be relative to cwd." ],
     [ ["-d", "--destination"], "destination", true, "Destination directory" ],
     [ ["-h", "--help" ], "help", false, "Print this help" ]
+    [ ["-m", "--mode"], "mode", true, "(debug|release)" ]
 ]
 
 ARGUMENTS_PARSER = new utils.ArgumentParser
     args: ARGUMENTS
     defaultConfig:
         source: process.cwd()
+        mode: "release"
         targets: "targets"
     configFile: ".tumbler"
 
 help = ->
     ARGUMENTS_PARSER.help()
 
-
 visit_directory = (dir_path,action,cond)->
     # visits children before parents
     if cond? and cond dir_path

File tumbler/src/tumbler-server.coffee

 
 ARGUMENTS = [
     [ ["-p", "--port"], "port", true, "Server port" ]
+    [ ["-m", "--mode"], "mode", true, "(debug|release)" ]
 ]
 
 ARGUMENTS_PARSER = new utils.ArgumentParser
     args: ARGUMENTS
     defaultConfig:
         port: 10000
+        mode: "debug"
     configFile: ".tumbler"
 
 help = ->

File tumbler/src/tumbler.coffee

         cmd = @make_command src
         dest_file = fs.createWriteStream dest,W_FILE
         child = spawn.apply @,cmd
-        child.stdout.pipe dest_file 
+        child.stdout.pipe dest_file
         error_msg = ""
         child.stderr.on "data",(data)->
             error_msg += data.toString()
         # returns the list of 
         # sources that are required to build
         # the destination
-        @get_target_list dest
+        [ @get_bundle_detail_file(dest) ].concat @get_target_list(dest)
     
     get_target_list: (dest)->
         root = path.dirname dest
         # Try to build the destination.
         # At this point we assume all sources
         # have already been built.
-        sources = @get_source_list dest
+        targets = @get_target_list dest
         dest_file = fs.createWriteStream dest,W_FILE
-        concatenate sources,dest_file,success,failure
+        concatenate targets,dest_file,success,failure
 
-scriptTag = (script)->
-    "<script src='#{script}' text='javascript'>"
-
-writeScriptTags = (sources,dest_file,success,failure) ->
+writeScriptTags = (sources,dest_file,urlPrefix,success,failure) ->
+    scriptTags = ""
     for source in sources
-        scriptTag = "<script src='/#{source}' text='javascript'></script>"
-        fs.writeSync dest_file, 'document.write("' + scriptTag + '");\n'
+        scriptTags += "\\t<script src='#{urlPrefix + source}' text='javascript'></script>\\n"
+    fs.writeSync dest_file, 'document.write("' + scriptTags + '");\n'
     fs.closeSync dest_file
     success()
 
+
+class ReleaseBundleCompiler extends BundleCompiler
+    
+    constructor: ->
+        @uglify = require 'uglify-js'
+    
+    build: (dest, success, failure)->
+        targets = @get_target_list dest
+        dest_file = fs.openSync dest,'w', W_FILE
+
+        dest_file = fs.createWriteStream dest,W_FILE
+        child = spawn 'uglifyjs' , [ "--reserved-names", "arguments" ]
+        concatenate targets,child.stdin,((m)->console.log "concat success"),((m)->console.log "error")
+        child.stdout.pipe dest_file
+        error_msg = ""
+        child.stderr.on "data",(data)->
+            console.log "ERR:",data.toString()
+            error_msg += data.toString()
+        child.on "exit",(code)->
+            if (code==0)
+                success()
+            else
+                console.log "compilation failed"
+                fs.unlink dest
+                failure error_msg
+
+
+
 class DebugBundleCompiler extends BundleCompiler
     
-    get_bundle_detail_file: (dest)->
-        dest+".bundle"
-            
+    constructor: (config)->
+        @urlPrefix = config.urlPrefix
+                
     get_source_list: (dest)->
         # returns the list of 
         # sources that are required to build
         # the destination
-        []
+        [ @get_bundle_detail_file(dest) ]
     
     build: (dest, success, failure)->
         # Try to build the destination.
         # have already been built.
         targets = @get_target_list dest
         dest_file = fs.openSync dest,'w', W_FILE
-        writeScriptTags targets,dest_file,success,failure
+        writeScriptTags targets,dest_file,@urlPrefix,success,failure
 
 class TrivialCompiler extends Compiler
     # Simply serve already existing 
             msg: "couldn't find any compiler"
 
 
-makeBuilder = (config)->
+makeBuilderConcat = (config)->
     builder = new Builder()
-    builder.register_compiler new DebugBundleCompiler()
+    builder.register_compiler new BundleCompiler
+        urlPrefix: "http://localhost:" + config.port + "/"
     builder.register_compiler new SimpleCompiler 'coffee', 'js', 'coffee', ['-p']
     try
         sprite = require 'tumbler-sprite'
     builder.register_compiler new TrivialCompiler()
     builder
 
+makeBuilderRelease = (config)->
+    builder = new Builder()
+    builder.register_compiler new ReleaseBundleCompiler
+    builder.register_compiler new SimpleCompiler 'coffee', 'js', 'coffee', ['-p']
+    try
+        sprite = require 'tumbler-sprite'
+        builder.register_compiler new sprite.SpriteCompiler()
+    catch exception
+        console.log "Couldn't load sprite"
+    builder.register_compiler new SimpleCompiler 'less', 'css', 'lessc',[]
+    builder.register_compiler new TrivialCompiler()
+    builder
+
+
+makeBuilderDebug = (config)->
+    builder = new Builder()
+    builder.register_compiler new DebugBundleCompiler
+        urlPrefix: "http://localhost:" + config.port + "/"
+    builder.register_compiler new SimpleCompiler 'coffee', 'js', 'coffee', ['-p']
+    try
+        sprite = require 'tumbler-sprite'
+        builder.register_compiler new sprite.SpriteCompiler()
+    catch exception
+        console.log "Couldn't load sprite"
+    builder.register_compiler new SimpleCompiler 'less', 'css', 'lessc',[]
+    builder.register_compiler new TrivialCompiler()
+    builder
+
+MODES =
+    "release": makeBuilderRelease
+    "concat": makeBuilderConcat
+    "debug": makeBuilderDebug
+
+makeBuilder = (config)->
+    MODES[config.mode](config)
+    
 exports.makeBuilder = makeBuilder
 exports.Compiler = Compiler
 exports.BundleCompiler = BundleCompiler