--- /dev/null
+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
+
{parse} = require 'url'
{existsSync:exists} = path
{exec, spawn} = require 'child_process'
+{mkdirp, mkdirpAsync} = require './mkdirp'
_ = require 'underscore'
_.str = require 'underscore.string'
# 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'
{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) ->
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()
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()