module.exports = function()

in tasks/couchapp.js [24:96]


module.exports = function (grunt) {
  grunt.registerMultiTask("couchapp", "Install Couchapp", function () {
    // Loading 'couchapp' at runtime to avoid adding it to Fauxton's package.json
    // because 'npm audit' is reporting vulnerabilities against it, and the package is
    // no longer maintained.
    const couchapp = loadCouchapp();
    const done = this.async();
    const appobj = require(path.join(process.cwd(), path.normalize(this.data.app)));
    return couchapp.createApp(appobj, this.data.db, function (app) {
      return app.push(done);
    });
  });

  grunt.registerMultiTask("rmcouchdb", "Delete a Couch Database", function () {
    const _this = this;
    const done = this.async();
    const dbURL = new URL(this.data.db);
    const dbname = dbURL.pathname.replace(/^\//, "");
    try {
      const nano = require("nano")(dbURL.protocol + "//" + dbURL.host);
      nano.db.destroy(dbname, function (err) {
        if (err) {
          if (err.status_code && err.status_code === 404) {
            if (_this.data.options && _this.data.options.okay_if_missing) {
              grunt.log.writeln(
                "Database " + dbname + " not present... skipping."
              );
              return done(null, null);
            }
            grunt.warn("Database " + dbname + " does not exist.");

          } else {
            grunt.warn(err);
          }
        }
        return done(err, null);
      });
    } catch (e) {
      grunt.warn(e);
      done(e, null);
    }
  });

  grunt.registerMultiTask(
    "mkcouchdb",
    "Create a new Couch Database",
    function () {
      const _this = this;
      const done = this.async();
      const dbURL = new URL(this.data.db);
      const dbname = dbURL.pathname.replace(/^\//, "");
      try {
        const nano = require("nano")(dbURL.protocol + "//" + dbURL.host);
        nano.db.create(dbname, function (err) {
          if (_this.data.options && _this.data.options.okay_if_exists) {
            if (err) {
              grunt.log.writeln("Database " + dbname + " exists, skipping");
            }
            return done(null, null);
          }
          if (err) {
            grunt.warn(err);
          }
          return done(err, null);

        });
      } catch (e) {
        grunt.warn(e);
        done(e, null);
      }
    }
  );
};