couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From chewbra...@apache.org
Subject [31/50] git commit: add custom grunt task for couch proxy server so no need to deploy to couch while developing COUCHDB-1708
Date Tue, 19 Mar 2013 23:24:40 GMT
add custom grunt task for couch proxy server so no need to deploy to couch while developing
COUCHDB-1708


Project: http://git-wip-us.apache.org/repos/asf/couchdb/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb/commit/d2040ab4
Tree: http://git-wip-us.apache.org/repos/asf/couchdb/tree/d2040ab4
Diff: http://git-wip-us.apache.org/repos/asf/couchdb/diff/d2040ab4

Branch: refs/heads/master
Commit: d2040ab43aa9a31d3442bce2cdd514003fad7e4a
Parents: 57164b9
Author: Garren Smith <garren.smith@gmail.com>
Authored: Sat Mar 16 13:42:00 2013 +0200
Committer: Garren Smith <garren.smith@gmail.com>
Committed: Sat Mar 16 13:55:24 2013 +0200

----------------------------------------------------------------------
 src/fauxton/app/initialize.js               |    4 +-
 src/fauxton/app/modules/databases/routes.js |    2 +-
 src/fauxton/grunt.js                        |  172 +++++++++++++++-------
 src/fauxton/package.json                    |    2 +-
 src/fauxton/readme.md                       |    5 +
 src/fauxton/tasks/couchserver.js            |   65 ++++++++
 6 files changed, 191 insertions(+), 59 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb/blob/d2040ab4/src/fauxton/app/initialize.js
----------------------------------------------------------------------
diff --git a/src/fauxton/app/initialize.js b/src/fauxton/app/initialize.js
index 6e4a652..eea19d1 100644
--- a/src/fauxton/app/initialize.js
+++ b/src/fauxton/app/initialize.js
@@ -27,8 +27,8 @@ function(app, _, Bootstrap) {
     // The root path to run the application through.
     // TODO: pick this up wither at build time or from the browser
     root: "/_utils/fauxton/",
-    // Is this sufficient?
-    host: window.location.protocol + "//" + window.location.host,
+    // Firefox does not support window.location.origin so have to check first
+    host: (window.location.origin) ? window.location.origin : window.location.protocol +
"//" + window.location.host,
 
     renderView: function(baseView, selector, view, options, callback) {
       baseView.setView(selector, new view(options)).render().then(callback);

http://git-wip-us.apache.org/repos/asf/couchdb/blob/d2040ab4/src/fauxton/app/modules/databases/routes.js
----------------------------------------------------------------------
diff --git a/src/fauxton/app/modules/databases/routes.js b/src/fauxton/app/modules/databases/routes.js
index 51ff5db..12edd0e 100644
--- a/src/fauxton/app/modules/databases/routes.js
+++ b/src/fauxton/app/modules/databases/routes.js
@@ -67,4 +67,4 @@ function(app, FauxtonAPI, Databases) {
   };
 
   return Databases;
-});
\ No newline at end of file
+});

http://git-wip-us.apache.org/repos/asf/couchdb/blob/d2040ab4/src/fauxton/grunt.js
----------------------------------------------------------------------
diff --git a/src/fauxton/grunt.js b/src/fauxton/grunt.js
index 890d5fb..fa612b9 100644
--- a/src/fauxton/grunt.js
+++ b/src/fauxton/grunt.js
@@ -140,7 +140,110 @@ module.exports = function(grunt) {
 
     // Create static html files from templates, for managing change of script
     // or css name.
+    template: {
+      couchdb:{
+        src: 'assets/index.underscore',
+        dest: '../../share/www/fauxton/index.html',
+        variables: {
+          assets_root: '/_utils/fauxton/',
+          requirejs: 'require.min.js',
+          base: '/_utils/fauxton/'
+        }
+      },
+      couchdebug:{
+        src: 'assets/index.underscore',
+        dest: '../../share/www/fauxton/index.html',
+        variables: {
+          assets_root: '/_utils/fauxton/',
+          requirejs: 'require.js',
+          base: '/_utils/fauxton/'
+        }
+      },
+      release: {
+        src: 'assets/index.underscore',
+        dest: 'dist/release/index.html',
+        variables: {
+          assets_root: '/',
+          requirejs: 'require.min.js',
+          base: '/'
+        }
+      },
+      debug: {
+        src: 'assets/index.underscore',
+        dest: 'dist/debug/index.html',
+        variables: {
+          assets_root: '/',
+          requirejs: 'require.js',
+          base: '/'
+        }
+      },
+      couchapp: {
+        src: 'assets/index.underscore',
+        dest: 'dist/debug/index.html',
+        variables: {
+          assets_root: '/fauxton/_design/fauxton/',
+          requirejs: 'require.js',
+          base: '/fauxton/_design/fauxton/index.html'
+        }
+      }
+    },
     template: templateSettings,
+    template: {
+      couchdb:{
+        src: 'assets/index.underscore',
+        dest: '../../share/www/fauxton/index.html',
+        variables: {
+          assets_root: '/_utils/fauxton/',
+          requirejs: 'require.min.js',
+          base: '/_utils/fauxton/'
+        }
+      },
+      couchdebug:{
+        src: 'assets/index.underscore',
+        dest: '../../share/www/fauxton/index.html',
+        variables: {
+          assets_root: '/_utils/fauxton/',
+          requirejs: 'require.js',
+          base: '/_utils/fauxton/'
+        }
+      },
+      release: {
+        src: 'assets/index.underscore',
+        dest: 'dist/release/index.html',
+        variables: {
+          assets_root: '/',
+          requirejs: 'require.min.js',
+          base: '/'
+        }
+      },
+      debug: {
+        src: 'assets/index.underscore',
+        dest: 'dist/debug/index.html',
+        variables: {
+          assets_root: '/',
+          requirejs: 'require.js',
+          base: '/'
+        }
+      },
+      server: {
+        src: 'assets/index.underscore',
+        dest: 'dist/debug/index.html',
+        variables: {
+          assets_root: '/assets/',
+          requirejs: 'require.js',
+          base: '/'
+        }
+      },
+      couchapp: {
+        src: 'assets/index.underscore',
+        dest: 'dist/debug/index.html',
+        variables: {
+          assets_root: '/fauxton/_design/fauxton/',
+          requirejs: 'require.js',
+          base: '/fauxton/_design/fauxton/index.html'
+        }
+      }
+    },
 
     // The concatenate task is used here to merge the almond require/define
     // shim and the templates into the application code.  It's named
@@ -177,63 +280,22 @@ module.exports = function(grunt) {
       ]
     },
 
-    // Running the server without specifying an action will run the defaults,
-    // port: 8000 and host: 127.0.0.1.  If you would like to change these
-    // defaults, simply add in the properties `port` and `host` respectively.
-    // Alternatively you can omit the port and host properties and the server
-    // task will instead default to process.env.PORT or process.env.HOST.
-    //
-    // Changing the defaults might look something like this:
-    //
-    // server: {
-    //   host: "127.0.0.1", port: 9001
-    //   debug: { ... can set host and port here too ...
-    //  }
-    //
-    //  To learn more about using the server task, please refer to the code
-    //  until documentation has been written.
-    server: {
-      // Ensure the favicon is mapped correctly.
-      files: { "favicon.ico": "favicon.ico" },
-
-      debug: {
-        // Ensure the favicon is mapped correctly.
-        "index": "./dist/debug/index.html",
-        files: { "favicon.ico": "favicon.ico" },
-
-        // Map `server:debug` to `debug` folders.
-        folders: {
-          "app": "dist/debug",
-          "assets/js/libs": "dist/debug",
-          "css": "dist/debug/css",
-          "js": "dist/debug/js"
-        }
-      },
-
-      proxies: {
-        '': {
-          host: 'localhost',
-          port: 5984,
-          https: false
-        }
-      },
-
-      release: {
-        // This makes it easier for deploying, by defaulting to any IP.
-        host: "0.0.0.0",
-
-        // Ensure the favicon is mapped correctly.
-        files: { "favicon.ico": "favicon.ico" },
-
-        // Map `server:release` to `release` folders.
-        folders: {
-          "app": "dist/release",
-          "assets/js/libs": "dist/release",
-          "assets/css": "dist/release"
-        }
+    // Runs a proxy server for easier development, no need to keep deploying to couchdb
+    couchserver: {
+      dist: './dist/debug/',
+      port: 8000,
+      proxy: {
+        host: 'localhost',
+        port: 5984,
+        https: false
       }
     },
 
+    watch: {
+      files: './app/**/*',
+      tasks: ['debug', 'template:server']
+    },
+
     // This task uses James Burke's excellent r.js AMD build tool.  In the
     // future other builders may be contributed as drop-in alternatives.
     requirejs: {
@@ -340,7 +402,7 @@ module.exports = function(grunt) {
   grunt.registerTask("minify", "min mincss");
   // deafult task - push to CouchDB
   grunt.registerTask("default", "test dependencies build release install");
-  grunt.registerTask("dev", "debug server:debug");
+  grunt.registerTask("dev", "debug template:server couchserver");
   // make a debug install
   grunt.registerTask("debug", "test dependencies build template copy:debug concat:debug");
   // make an install that is server by mochiweb under _utils

http://git-wip-us.apache.org/repos/asf/couchdb/blob/d2040ab4/src/fauxton/package.json
----------------------------------------------------------------------
diff --git a/src/fauxton/package.json b/src/fauxton/package.json
index 655cd80..891ea36 100644
--- a/src/fauxton/package.json
+++ b/src/fauxton/package.json
@@ -9,7 +9,7 @@
   "dependencies": {
     "async": "~0.1.22",
     "grunt": "~0.3.17",
-    "bbb": "0.1.10",
+    "bbb": "0.1.16",
     "couchapp": "0.9.1",
     "grunt-contrib": "~0.0.8",
     "grunt-contrib-copy": "~0.3.2",

http://git-wip-us.apache.org/repos/asf/couchdb/blob/d2040ab4/src/fauxton/readme.md
----------------------------------------------------------------------
diff --git a/src/fauxton/readme.md b/src/fauxton/readme.md
index c041735..409296f 100644
--- a/src/fauxton/readme.md
+++ b/src/fauxton/readme.md
@@ -41,6 +41,11 @@ A recent of [node.js](http://nodejs.org/) and npm is required.
     # Or fully compiled install
     # ./bin/bbb couchdb
 
+### Dev Server
+    Using the dev server is the easiest way to use fauxton, specially when developing for
it.
+
+    bbb dev
+
 ### To Deploy Fauxton
 
     ./bin/bbb couchapp_deploy - to deploy to your local [Couchdb instance] (http://localhost:5984/fauxton/_design/fauxton/index.html)

http://git-wip-us.apache.org/repos/asf/couchdb/blob/d2040ab4/src/fauxton/tasks/couchserver.js
----------------------------------------------------------------------
diff --git a/src/fauxton/tasks/couchserver.js b/src/fauxton/tasks/couchserver.js
new file mode 100644
index 0000000..9680c00
--- /dev/null
+++ b/src/fauxton/tasks/couchserver.js
@@ -0,0 +1,65 @@
+module.exports = function (grunt) {
+  var log = grunt.log;
+
+ grunt.registerTask("couchserver", 'Run a couch dev proxy server', function () {
+    var fs = require("fs"),
+    path = require("path"),
+    httpProxy = require('http-proxy'),
+    express = require("express"),
+    options = grunt.config('couchserver'), 
+    app = express();
+
+    // Options
+    var dist_dir = options.dist || './dist/debug/';
+    var port = options.port || 8000;
+
+    // Proxy options with default localhost
+    var proxy_target = options.proxy || {
+          host: 'localhost',
+          port: 5984,
+          https: false
+        };
+
+    // inform grunt that this task is async
+    var done = this.async();
+
+    // images don't have the full path, so have to have own route for them
+    app.get('/img/*', function (req, res) {
+      res.sendfile(path.join(dist_dir,req.url));
+    });
+
+    // serve any javascript or css files from here
+    app.get('/assets/*', function (req, res) {
+      res.sendfile(req.url.replace('/assets/',dist_dir));
+    });
+
+    // serve main index file from here
+    app.get('/', function (req, res) {
+      res.sendfile(path.join(dist_dir, 'index.html'));
+    });
+
+    // create proxy to couch for all couch requests
+    var proxy = new httpProxy.HttpProxy({ 
+      target: proxy_target
+    });
+
+    app.all('*', function (req, res) {
+      proxy.proxyRequest(req, res);
+    });
+
+    // Fail this task if any errors have been logged
+    if (grunt.errors) { 
+      return false;
+    }
+
+    var watch = grunt.util.spawn({cmd: 'bbb', grunt: true, args: ['watch']}, function (error,
result, code) {/* log.writeln(String(result));*/ });
+
+    watch.stdout.pipe(process.stdout);
+    watch.stderr.pipe(process.stderr);
+
+    log.writeln('Listening on ' + port);
+    app.listen(port);
+
+  });
+
+};


Mime
View raw message