Git Product home page Git Product logo

grunt-hoodie's Introduction

grunt-hoodie

Build Status NPM version Dependency Status devDependency Status

Start hoodie and delay grunting till it is ready. Triggers a callback with hosts and ports of couchDB, www and pocket.

Getting Started

This plugin requires Grunt ~0.4.1

If you haven't used Grunt before, be sure to check out the Getting Started guide, as it explains how to create a Gruntfile as well as install and use Grunt plugins. Once you're familiar with that process, you may install this plugin with this command:

npm install grunt-hoodie --save-dev

Once the plugin has been installed, it may be enabled inside your Gruntfile with this line of JavaScript:

grunt.loadNpmTasks('grunt-hoodie');

The "hoodie" task

Overview

In your project's Gruntfile, add a section named hoodie to the data object passed into grunt.initConfig().

grunt.initConfig({
  hoodie: {
    start: {
      options: {
        callback: function (config) {
          // For example, set the port of grunt-connect-proxy:
          // grunt.config.set('connect.proxies.0.port', config.stack.www.port);
        }
      }
    },
    stop: {}
  },
});

// Imagine you have a task `e2e` that runs end to end tests and needs hoodie
// server to be running.
grunt.registerTask('run_e2e', [ 'hoodie:start', 'e2e', 'hoodie:stop' ]);

So you can:

$ grunt run_e2e

Options

options.callback

Type: Function Default value: function(config) {}

A callback that is called when hoodie is up and running. Has one param called config which contains the host and port information.

options.childProcessOptions

Type: Object Default value: {silent: true}

Allows to pass options to the childProcess.fork where hoodie runs.

hoodie: {
  start: {
    options: {
      childProcessOptions: {
        cwd: process.cwd() + '/myapp',
        env: env
      }
    }
  },
  stop: {}
}

Usage Example

In this example, the port of grunt-connect-proxy for the /_api of hoodie is set after hoodie started.

grunt.initConfig({
  hoodie: {
    start: {
      options: {
        callback: function(config) {
          grunt.config.set('connect.proxies.0.port', config.stack.www.port);
        }
      }
    }
  },
  connect: {
    options: {
      port: 9000,
      hostname: 'localhost'
    },
    proxies: [
      {
        context: '/_api',
        host: 'localhost',
        port: false,
        https: false,
        changeOrigin: false
      }
    ],},
})

In this other example we start the hoodie server, send an HTTP request to get the combined javascript and put it in a file. This can be useful as part of a build process.

grunt.initConfig({
  hoodie: {
    start: {
      options: {
        callback: function (config) {
          grunt.config.set('hoodiejs.options.port', config.stack.www.port);
        }
      }
    },
    stop: {}
  },
});

grunt.registerTask('hoodiejs', function () {
  // Dependens on successful execution of hoodie:start. Note that
  // grunt.task.requires won't actually RUN the other task(s). It'll just check
  // to see that it has run and not failed.
  grunt.task.requires('hoodie:start');

  var done = this.async();
  var options = this.options();
  var url = 'http://localhost:' + options.port + '/_api/_files/hoodie.js';
  http.get(url, function (res) {
    var fname = path.join(__dirname, 'some/path/hoodie.js');
    res.pipe(fs.createWriteStream(fname)).on('finish', function () {
      done();
    });
  }).on('error', function (err) {
    grunt.log.error(err);
    done(false);
  });
});

So you should now be able to run:

$ grunt hoodie:start hoodiejs

Contributing

Take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using Grunt.

grunt-hoodie's People

Contributors

boennemann avatar gr2m avatar janl avatar lupomontero avatar ro-ka avatar shinnn avatar svnlto avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

grunt-hoodie's Issues

cannot get the /_api proxy working

Hey Robert,

I try to get the proxy working as you use it for grunt-hoodie, but it doesn't work.

the connect config in my Gruntfile.js looks like this:

    // grunt server settings
    connect: {
      options: {
        port: 9000,

        // '0.0.0.0' allows for access from outside
        // 'localhost' prevents access from outside
        hostname: '0.0.0.0'
      },
      proxies: [
        {
          context: '/_api',
          host: 'localhost',
          port: 6040,
          https: false,
          changeOrigin: false
        }
      ],
      livereload: {
        options: {
          middleware: function (connect) {
            return [
              livereloadSnippet,
              mountFolder(connect, '.tmp'),
              mountFolder(connect, 'app')
            ];
          }
        }
      },
      test: {
        options: {
          middleware: function (connect) {
            return [
              mountFolder(connect, '.tmp'),
              mountFolder(connect, 'test')
            ];
          }
        }
      },

I've simply hardcoded the port number 6040 which is correct, hoodie is running on this port and localhost:6040/_api' works. I startgrunt serverbut then get a 404 atlocalhost:9000/_api`.

Did I misunderstood something?

How to enable debugging in worker.js?

The ultimate goal, is I want to debug server side worker.js, in the hoodie-plugin-template (a new plugin under development starting from this template)

So I think the standard way to do it is to call

grunt --debug test:browser

So my first guess is that grunt-hoodie, needs to detect grunt's debug property and set debug in childProcessOptions perhaps?

hide the Waiting for CouchDB spinner

When I start Hoodie with grunt hoodie, it shows the typical spinner, but instead of getting rewritten in-place, it ends up looking something like this

Initializing...
CouchDB started: http://127.0.0.1:6042
Waiting for CouchDB [-*----] 20s Waiting for CouchDB [--*---] 20s Waiting for CouchDB [---*--] 20s Waiting for CouchDB [----*-] SUCCESS 

There is a config.boring setting that shows a simple Waiting for CouchDB... instead, but I couldn't figure out how to set that configuration, see https://github.com/hoodiehq/hoodie-server/blob/master/lib/couch.js#L119

Sorry I can't help better, I really couldn't figure out how to fix this myself

revise README.md

hoodie: {
      start: {
        options: {
          callback: function (stack) {
            // For example, set the port of grunt-connect-proxy:
            grunt.config.set('connect.proxies.0.port', stack.stack.www.port);
          }
        }
      }
    },

stack.www is undefined now, should use stack.stack.www.port instead.

The whole structure of callback is:

{ app: { started: true },
  pid: 35963,
  stack:
   { couch: { port: 6003, host: '127.0.0.1' },
     www: { port: 6001, host: '127.0.0.1' },
     admin: { port: 6002, host: '127.0.0.1' } } }

Show hoodie output in console

Except for errors there is no output visible in the console. Print out the startup information of hoodie.

Bonus: Allow password input on first startup.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.