Exemple #1
0
    function (err, files) {
        for (i in files)
        {
            var fullFilename = i;
            var filename = path.basename(i);

            if (filename.indexOf("_design.js") < 0) continue;

            if (path.extname(fullFilename) != ".js") continue;
            
            var docId = "_design/" + filename.replace("_design.js", "");

            var requireNameDir = path.relative(dir, path.dirname(fullFilename));
            var requireName = path.join(requireNameDir, path.basename(fullFilename));
            requireName = './' + requireName;

            var doc = require(requireName);
            doc._id = docId;
            
            doc.exportFilename = path.join(requireNameDir, path.basename(filename, ".js") + ".json");
            
            console.log('Design Doc: ' + doc._id + ", found here: " + fullFilename);
            couchapp.createApp(doc, '', function (app) { app.push(); } );
        }
    }
Exemple #2
0
  return through.obj(function (file, enc, cb) {
    var ddocObj = require(file.path)
    var url = /^https?:\/\//.test(dbName) ? dbName : buildURL(dbName, opts);

    if (file.isNull()) {
      return cb(null, file)
    }

    if (file.isStream()) {
      this.emit('error', new PluginError(PLUGIN_NAME, 'Streaming not supported.'))
      return cb(null, file)
    }

    if (path.extname(file.path) !== '.js') {
      this.emit('error', new PluginError(PLUGIN_NAME, 'File extension not supported.'))
      return cb(null, file)
    }

    if (has(opts, 'attachments')) {
      var attachmentsPath = path.join(process.cwd(), path.normalize(opts.attachments))
      couchapp.loadAttachments(ddocObj, attachmentsPath)
    }

    couchapp.createApp(ddocObj, url, function (app) {
      app.push(function () {
        gutil.log(PLUGIN_NAME, 'Couchapp pushed!')
        return cb(null, file)
      })
    })
  })
	return function(file,db){
	    couchapp
		.createApp(file,
			   'http://'+ user + '@' + ip + '/' + db,
			   function(design_doc){
			       design_doc.push()
			   })
	}
Exemple #4
0
module.exports = function(ddoc, dbPath, callbacks) {
  couchapp.createApp(ddoc, dbPath, function (webapp) {
    _createOnComplete = callbacks.createOnComplete || createOnComplete;

    callbacks.onComplete = _createOnComplete(dbPath, webapp, callbacks);

    // give the chance for calling app to enhance the ddoc
    callbacks.onLoaded(webapp.doc, callbacks.onComplete)
  });
}
 grunt.registerTask('designdoc_couchdb', 'Use couchapp to put couchdb/app.js in cercle db', function() {
   couchdb_url = 'http://*****:*****@127.0.0.1:5984/cercle';
   done = this.async();
   var path = require('path');
   var appobj = require(path.join(process.cwd(), './couchdb/app.coffee'));
   var couchapp = require('couchapp');
   return couchapp.createApp(appobj, couchdb_url, function(app) {
     return app.push(done);
   });
 });
Exemple #6
0
module.exports = function(schema_dir, dbPath, loaded_callback, pushed_callback) {

  if(!loaded_callback) {
    loaded_callback = function(){};
  }

  if (!pushed_callback) {
    pushed_callback = loaded_callback;
    loaded_callback = function(doc, cb){ cb(null, doc); };
  }

  var ddoc = require('./ddoc.js');

  ddoc.views.lib.types = {};
  var schemas = fs.readdirSync(schema_dir);
  var loaded = false;
  schemas.forEach(function(schema){

    if ( schema.indexOf('.js', schema.length - '.js'.length) === -1) return;

    loaded = true;

    var nice_name = schema.substring(0, schema.length -3); // take off .js
    var schema_path = path.join(schema_dir, schema);

    ddoc.views.lib.types[nice_name] = fs.readFileSync( schema_path ).toString()

    var to_add = rewrites(nice_name, require(schema_path));

    to_add.forEach(function(rewrite){
      ddoc.rewrites.unshift(rewrite);
    })

  });

  if (!loaded) return console.log('No schemas to push. Add some to the folder ' + schema_dir);

  couchapp.createApp(ddoc, dbPath, function (webapp) {

    // give the chance for calling app to enhance the ddoc
    loaded_callback(webapp.doc, function(err, final_doc){
      webapp.doc = final_doc;

      createDB(dbPath, function(err, resp){
        if (err) return pushed_callback(err);
        resp = JSON.parse(resp.body);
        if (resp.error && resp.error == 'unauthorized') {
              return pushed_callback("ERROR: " + resp.error + ", " + resp.reason + " (hint use -u user -p pass)");
        }
        if (resp.error && resp.error != 'file_exists')  return pushed_callback("ERROR: " + resp.error + ", " + resp.reason);
        webapp.push(pushed_callback);
      })
    })
  });
}
Exemple #7
0
 nano.db.create(dbName, function(err) {
   if (err) {
     console.log('Pleases ensure that couchdb is running.');
     return process.exit(1);
   }
   console.log('Database created.');
   baronDb = nano.use(dbName);
   var dbUrl = config.couchdb.url + '/' + config.couchdb.name;
   couchapp.createApp(ddoc, dbUrl, function(app) {
     app.push();
   });
 });
Exemple #8
0
module.exports = function (root, path, settings, doc, callback) {
    if (settings.app) {
        try {
            var mod = require(settings.app);
            var fake_url = 'http://localhost:5984/db';
            var app = couchapp.createApp(mod, fake_url, function (app) {
                app.prepare();
                addAttachments(app, function (err, app) {
                    if (err) {
                        return callback(err);
                    }
                    doc = packages.merge(doc, app.doc);
                    callback(null, doc);
                });
            });
        }
        catch (e) {
            return callback(e);
        }
    }
    else {
        callback(null, doc);
    }
};
Exemple #9
0
module.exports = function (done) {
  couchapp.createApp(app, dest, function (app) {
    app.push(done);
  });
};
function pushCouchapp(app, target) {
  var dfd = deferred();
  couchapp.createApp(require(absolutePath(app)), target, function (app) { app.push(function(resp) { dfd.resolve() }) })
  return dfd.promise();
}
var couchapp = require('couchapp'),
    path = require('path');

function abspath (pathname) {
  return path.join(process.env.PWD, path.normalize(pathname));
}

var COUCH_CONFIG = {};

//TODO: Make more robust
if (path.existsSync('/usr/local/etc/node3p-web/config.js')) {
  var config = require('/usr/local/etc/node3p-web/config');
  if ('couchConfig' in config) COUCH_CONFIG = config.couchConfig;
}

var couchurl = 'http://'+COUCH_CONFIG.host+':'+COUCH_CONFIG.port+'/node3p-web';

couchapp.createApp(require(abspath('./couchapp.js')), couchurl, function (app) {
    app.push();
});
Exemple #12
0
 docs.forEach(function(doc) {
   couchapp.createApp(doc, 'http://localhost:5984/bower-registry-testing', function(app) {
     app.push();
     return cb(null, true);
   });
 });
 return new Promise(function pushCouchApp(resolve, reject) {
   couchapp.createApp(npmjsApp, authedDatabaseUrl, function(app) {
     app.push(resolve);
   });
 }).finally(function() {
Exemple #14
0
function createViews (cb) {
  couchApp.createApp(require('./couch-data/views.js'), root, function (doc) {
    doc.push();
    cb && cb();
  });
}