Repository: hoodiehq/hoodie (js)

Issue:
merge `options.client` of hapi plugin into bundled `new Hoodie(options)`
see https://github.com/hoodiehq/hoodie/blob/79dde6b8c4151d803aea0a1e58463d3ad6c06663/server/plugins/client/bundle.js#L85-L92

what we want is stringify `options.client` and then set `option.url` from the hapi plugin’s `options.url`

Pull request:
pass `options.client` to `Hoodie` client constructor
closes #762

Patch:
diff --git a/cli/hoodie-defaults.js b/cli/hoodie-defaults.js
index 4a5e5304..72b158e1 100644
--- a/cli/hoodie-defaults.js
+++ b/cli/hoodie-defaults.js
@@ -6,6 +6,7 @@ function getHoodieDefaults () {
     port: 8080,
     data: '.hoodie',
     public: 'public',
+    client: {},
     dbUrl: undefined,
     dbUrlPassword: undefined,
     dbUrlUsername: undefined,
diff --git a/cli/options.js b/cli/options.js
index 75877398..a86b4d7f 100644
--- a/cli/options.js
+++ b/cli/options.js
@@ -120,6 +120,7 @@ function getCliOptions (projectPath) {
   }
 
   options.public = webrootLocator(options.public)
+  options.client = defaults.client
 
   // rc & yargs are setting keys we are not interested in, like in-memory or _
   // so we only pick the relevant ones based on they keys of the default options.
diff --git a/cli/parse-options.js b/cli/parse-options.js
index d983793f..a4f81829 100644
--- a/cli/parse-options.js
+++ b/cli/parse-options.js
@@ -35,7 +35,8 @@ function parseOptions (options) {
       data: options.data,
       public: options.public
     },
-    inMemory: Boolean(options.inMemory)
+    inMemory: Boolean(options.inMemory),
+    client: options.client
   }
 
   log.level = config.loglevel
diff --git a/server/plugins/client/bundle.js b/server/plugins/client/bundle.js
index db03a3aa..8a31c1a3 100644
--- a/server/plugins/client/bundle.js
+++ b/server/plugins/client/bundle.js
@@ -83,12 +83,21 @@ function buildBundle (config, plugins, callback) {
 
   hoodieBundleSource += 'var Hoodie = require("@hoodie/client")\n'
   hoodieBundleSource += 'var options = {\n'
+
+  if (config.client) {
+    Object.keys(config.client).forEach(function (key) {
+      hoodieBundleSource += '  "' + key + '": ' + JSON.stringify(config.client[key]) + ',\n'
+    })
+  }
+
   if (config.url) {
     hoodieBundleSource += '  url: "' + config.url + '",\n'
   } else {
     hoodieBundleSource += '  url: location.origin,\n'
   }
+
   hoodieBundleSource += '  PouchDB: require("pouchdb-browser")\n'
+
   hoodieBundleSource += '}\n'
   hoodieBundleSource += 'module.exports = new Hoodie(options)\n'
   plugins.forEach(function (pluginPath) {


Test patch:
diff --git a/test/unit/cli/hoodie-default-test.js b/test/unit/cli/hoodie-default-test.js
index 27de6773..00fe6afb 100644
--- a/test/unit/cli/hoodie-default-test.js
+++ b/test/unit/cli/hoodie-default-test.js
@@ -8,6 +8,7 @@ test('hoodie defaults test', function (group) {
     t.deepEqual(defaults, {
       address: '127.0.0.1',
       adminPassword: undefined,
+      client: {},
       data: '.hoodie',
       dbAdapter: 'pouchdb-adapter-fs',
       dbUrl: undefined,
diff --git a/test/unit/plugins-client-bundle-test.js b/test/unit/plugins-client-bundle-test.js
index b1e79d9d..2672829f 100644
--- a/test/unit/plugins-client-bundle-test.js
+++ b/test/unit/plugins-client-bundle-test.js
@@ -99,12 +99,16 @@ test('bundle client', function (group) {
     })
 
     bundleClient('client.js', 'bundle.js', {
-      url: 'https://myapp.com'
+      url: 'https://myapp.com',
+      client: {
+        foo: 'bar'
+      }
     }, function (error, buffer) {
       t.error(error)
 
       var expected = 'var Hoodie = require("@hoodie/client")\n' +
                      'var options = {\n' +
+                     '  "foo": "bar",\n' +
                      '  url: "https://myapp.com",\n' +
                      '  PouchDB: require("pouchdb-browser")\n' +
                      '}\n' +