Moves preset save directory out of WWW and into VAR.
authordsc <dsc@wikimedia.org>
Wed, 14 Mar 2012 08:43:23 +0000 (01:43 -0700)
committerdsc <dsc@wikimedia.org>
Wed, 14 Mar 2012 08:43:23 +0000 (01:43 -0700)
Update to `connect-compiler-extras` means we can load minified `.mod.js` files.
Switches `CommonJSCompiler` for `CommonJSDefineCompiler`, and removes `vendor/require.js`.

lib/main.co
lib/server/mkdirp.co [new file with mode: 0644]
lib/server/server.co
lib/util/backbone.co
www/modules.yaml

index 0d45e25..e621416 100644 (file)
@@ -1,4 +1,6 @@
-Seq = require 'seq'
+Seq      = require 'seq'
+Backbone = require 'backbone'
+
 { _, op,
 } = require 'kraken/util'
 { ChartLibrary, DygraphsLibrary,
@@ -13,6 +15,7 @@ Seq = require 'seq'
 { VisView, VisModel,
 } = require 'kraken/vis'
 
+
 root = this
 CHART_OPTIONS_SPEC    = []
 CHART_DEFAULT_OPTIONS = {}
diff --git a/lib/server/mkdirp.co b/lib/server/mkdirp.co
new file mode 100644 (file)
index 0000000..fb6db6c
--- /dev/null
@@ -0,0 +1,46 @@
+fs = require 'fs'
+path = require 'path'
+
+
+
+expand = exports.expand = (...parts) ->
+    p = path.normalize path.join ...parts
+    if p.indexOf('~') is 0
+        home = process.env.HOME or process.env.HOMEPATH
+        p = path.join home, p.slice(1)
+    path.resolve p
+
+
+# Recursively make missing directories, eating EEXIST errors.
+mkdirpAsync = exports.mkdirpAsync = function mkdirpAsync (p, mode=8r0755, cb)
+    [cb, mode] = [mode, 8r0755] if typeof mode is 'function'
+    cb or= (->)
+    p = expand(p)
+    
+    exists <- path.exists p
+    return cb null if exists
+    
+    ps = p.split '/'
+    _p = ps.slice(0, -1).join '/'
+    
+    err <- mkdirpAsync _p, mode
+    return cb null if err?.code is 'EEXIST'
+    return cb err  if err
+    
+    err <- fs.mkdir _p
+    return cb null if err?.code is 'EEXIST'
+    return cb err  if err
+
+
+# Recursively make missing directories, eating EEXIST errors.
+mkdirp = exports.mkdirp = \
+mkdirpSync = exports.mkdirpSync = (p, mode=8r0755) ->
+    made_any = false
+    _p = ''
+    for part of expand(p).slice(1).split('/')
+        _p += '/' + part
+        continue if path.existsSync _p
+        made_any = true
+        fs.mkdirSync _p, mode
+    made_any
+
index 294ff43..b09bfd5 100755 (executable)
@@ -5,6 +5,7 @@ path     = require 'path'
 {parse}  = require 'url'
 {existsSync:exists} = path
 {exec, spawn} = require 'child_process'
+{mkdirp, mkdirpAsync} = require './mkdirp'
 
 _        = require 'underscore'
 _.str    = require 'underscore.string'
@@ -88,16 +89,20 @@ app.configure ->
     
     # wrap modules in commonjs closure for browser
     app.use compiler do
-        enabled : 'commonjs'
+        enabled : 'commonjs_define'
         src     : [ STATIC ]
         dest    : VAR
-        options : commonjs : { drop_path_parts:1, drop_full_ext:false }
+        options :
+            commonjs        : { drop_path_parts:1, drop_full_ext:false }
+            commonjs_define : { drop_path_parts:1, drop_full_ext:false }
         log_level : LOG_LEVEL
     app.use compiler do
-        enabled : 'commonjs'
+        enabled : 'commonjs_define'
         src     : [ VAR, WWW ]
         dest    : VAR
-        options : commonjs : { drop_path_parts:1, drop_full_ext:true }
+        options :
+            commonjs        : { drop_path_parts:1, drop_full_ext:true }
+            commonjs_define : { drop_path_parts:1, drop_full_ext:true }
         log_level : LOG_LEVEL
     app.use require('browserify') do
         mount   : '/vendor/browserify.js'
@@ -134,12 +139,13 @@ app.post '/graph/save', (req, res, next) ->
     {slug} = data
     if not slug
         return res.send {result:"error", message:"slug required!"}, 501
+    mkdirp "#VAR/presets" if not exists "#VAR/presets"
     
-    err <- fs.writeFile "#WWW/presets/#slug.json", JSON.stringify(data), "utf8"
+    err <- fs.writeFile "#VAR/presets/#slug.json", JSON.stringify(data), "utf8"
     if err
         res.send { result:"error", message:err.message or String(err) }, 501
     else
-        res.send {result:"ok"}
+        res.send { result:"ok" }
 
 
 app.get '/graph/:slug\.json', (req, res, next) ->
@@ -148,7 +154,7 @@ app.get '/graph/:slug\.json', (req, res, next) ->
 
 app.get '/preset/:slug', (req, res, next) ->
     {slug} = req.params
-    if exists("#WWW/presets/#slug.yaml") or exists("#WWW/presets/#slug.json")
+    if exists("#VAR/presets/#slug.yaml") or exists("#VAR/presets/#slug.json")
         req.url .= replace /^\/preset\/[^\/?]/i, "/presets/#slug.json"
         # req.url += '.json'
     next()
@@ -170,7 +176,7 @@ app.get '/graph/:slug/:action/?', (req, res) ->
 
 app.get '/:type/:action/?', (req, res, next) ->
     {type, action} = req.params
-    if path.existsSync "#WWW/#type/#action.jade"
+    if exists "#WWW/#type/#action.jade"
         res.render "#type/#action"
     else
         next()
index 8246d1d..ee7276c 100644 (file)
@@ -1,5 +1,8 @@
 _ = require 'underscore'
-# Backbone = require 'backbone'
+window?._ = _
+Backbone = require 'backbone'
+window?.Backbone = Backbone
+Backbone.setDomLibrary that if window? and (window.jQuery or window.Zepto or window.ender)
 
 
 _backbone = do
index 5510f5c..3ade6ac 100644 (file)
@@ -17,16 +17,17 @@ dev:
         - jquery.history.min
         - jquery.hotkeys.min
         - jquery.isotope.min
-        # - jquery.tipsy.min
+        # - jquery.tipsy.min # handled by bootstrap now?
         - spin.min
         - jquery.spin.min
         - bootstrap.min
         - browserify
-        - require
-        - underscore.mod
-        - underscore.string.mod
-        - backbone
-        - showdown.mod
+        # - require
+        - underscore.mod.min
+        - underscore.string.mod.min
+        - backbone.mod.min
+        - backbone.nested.mod.min
+        - showdown.mod.min
         - jade.runtime.min
         - dygraph.min
 
@@ -43,6 +44,7 @@ dev:
                 - op
                 - backbone
                 - parser
+                - cascade
                 - index
             - base
             - chart: