Advertisement
codemonkey

Cakefile

Jul 19th, 2012
276
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. BUILD_JS_PATH = 'public/broadmap.js'
  2. BUILD_CSS_PATH = 'public/broadmap.css'
  3.  
  4. tasks =
  5.     watch: ->
  6.         nodewatch = require 'nodewatch'
  7.         _ = require 'underscore'
  8.         _.str = require 'underscore.string'
  9.  
  10.         # Add folders to be watched
  11.         nodewatch.add('./css').add('./src', true).add('./vendor')
  12.  
  13.         # Listener
  14.         nodewatch.onChange (file, prev, curr, action)->
  15.             console.log (file + ' changed')
  16.  
  17.             # Check whether to rebuild css or js
  18.             if _.str.include file, '/bito.broadmap/css/'
  19.                 tasks.buildcss()
  20.             else if _.str.include file, '/bito.broadmap/src/' or
  21.                     _.str.include file, '/bito.broadmap/vendor/'
  22.                 tasks.buildsrc()
  23.        
  24.         tasks.buildcss()
  25.         tasks.buildsrc()
  26.        
  27.         console.log 'Watching project'
  28.  
  29.     buildsrc: ->
  30.         stitch = require 'stitch'
  31.         fs = require 'fs'
  32.  
  33.         # Create stitch package
  34.         pkg = stitch.createPackage
  35.             paths: [__dirname + '/src']
  36.             dependencies: [
  37.                 __dirname + '/vendor/jquery-1.7.1.min.js'
  38.                 __dirname + '/vendor/jquery-ui-1.8.18.min.js'
  39.                 __dirname + '/vendor/jquery.cookie.js'
  40.                 __dirname + '/vendor/jquery.iframe-transport.js'
  41.                 __dirname + '/vendor/jquery.fileupload.js'
  42.             ]
  43.        
  44.         # Compile the package
  45.         pkg.compile (err, src)->
  46.             if err
  47.                 console.warn 'Coffee compile failed:'
  48.                 console.warn err.toString()
  49.             else
  50.                 # Save the source code
  51.                 fs.writeFile BUILD_JS_PATH, src, (err)->
  52.                     if err then throw err
  53.                     console.log 'Compiled src to ' + BUILD_JS_PATH
  54.    
  55.     buildcss: ->
  56.         stylus = require 'stylus'
  57.         fs = require 'fs'
  58.  
  59.         # Load the index stylus file
  60.         indexstyl = fs.readFileSync __dirname + '/css/index.styl', 'utf8'
  61.  
  62.         # Render the stylus
  63.         stylus.render indexstyl, {paths: ['css']}, (err, css)->
  64.             if err
  65.                 console.warn 'Stylus compile failed:'
  66.                 console.warn err.toString()
  67.             else
  68.                 # Save the css to a file
  69.                 fs.writeFile BUILD_CSS_PATH, css, 'utf8', (err)->
  70.                     if err then throw err
  71.  
  72.                     console.log 'Compiled css to ' + BUILD_CSS_PATH
  73.  
  74.     build: ->
  75.         tasks.buildsrc()
  76.         tasks.buildcss()
  77.  
  78. task 'watch',
  79.      'Watch and rebuild the project using Node Watcher',
  80.      tasks.watch
  81.  
  82. task 'buildsrc',
  83.      'Build the project coffee-script into the public folder',
  84.      tasks.buildsrc
  85.  
  86. task 'buildcss',
  87.      'Build the project stylus into the public folder',
  88.      tasks.buildcss
  89.  
  90. task 'build', 'Builds the Broadmap application to public/', tasks.build
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement