Code Monkey home page Code Monkey logo

grunt-open's Introduction

grunt-open

Open urls and files from a grunt task

Installation

Install using npm in the root of your project directory (where your package.json and Gruntfile.js are located)

npm install --save-dev grunt-open

Usage

This is used as part of your grunt tasks, between the server and watch tasks

grunt.registerTask('default', ['server', 'open', 'watch']);

You can specify different configurations so that you can set up task chains (see the configuration below for this example's config)

grunt.registerTask('dev', ['server', 'open:dev', 'watch']);
grunt.registerTask('build', ['build', 'server', 'open:build', 'watch:build');

Gruntfile Configuration

This is a very simple task and takes two configuration parameters, path (required) and app (optional). If app is not specified, the default system browser will be launched

grunt.initConfig({
  open : {
    dev : {
      path: 'http://127.0.0.1:8888/src',
      app: 'Google Chrome'
    },
    build : {
      path : 'http://google.com/',
      app: 'Firefox'
    },
    file : {
      path : '/etc/hosts'
    },
    custom: {
      path : function () {
        return grunt.option('path');
      } 
    }
  }
})

grunt.loadNpmTasks('grunt-open');

Options

openOn

Type: String

While it may not be common, you may want to delay the opening of your path at a later time of the grunt process. The option openOn allows you to define an event (coming through from grunt.event) that would signal the expected triggering of open. Example:

grunt.initConfig({
  open: {
    delayed: {
      path: 'http://localhost:3000',
      app: 'Google Chrome',
      options: {
        openOn: 'serverListening'
      }
    }
  }
});

grunt.registerTask('server', function () {
  var server = require('myServer');
  server.listen(3000, function (err) {
    if (!err) {
      grunt.log.writeln('Server started');
      grunt.event.emit('serverListening'); // triggers open:delayed
    }
  });
})

delay

Type : Number

Set a delay for the open. Note: This task moves on immediately. If this is the last task in your chain you run the risk of node exiting before your open is called.

Contributing

In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using grunt.

Release History

  • 0.2.3 merged support for functions in config, added delay, merged openOn
  • 0.2.2 added app parameter.
  • 0.2.0 grunt 0.4.0 support, added and preferring path parameter.
  • 0.1.0 initial release

License

MIT License, see LICENSE for details.

grunt-open's People

Contributors

blai avatar davidgruebl avatar eddiemonge avatar gableroux avatar jsoverson avatar raspo avatar yunfengzhao915 avatar

Stargazers

 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  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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

grunt-open's Issues

License issue

Your package.json file shows MIT:

  "licenses": [
    {
      "type": "MIT",
      "url": "https://github.com/onehealth/grunt-open/blob/master/LICENSE"
    }
  ],

But your LICENSE files shows it as Apache:

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

Can you sync these up so that they are reported properly?

command injection vulnerability - noted from npm audit

npm audit barks an alert to a critical vulnerability with this package.
It returns:

┌───────────────┬──────────────────────────────────────────────────────────────┐
│ Critical      │ Command Injection                                            │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Package       │ open                                                         │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Patched in    │ No patch available                                           │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Dependency of │ grunt-open [dev]                                             │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Path          │ grunt-open > open                                            │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ More info     │ https://nodesecurity.io/advisories/663                       │
└───────────────┴──────────────────────────────────────────────────────────────┘

Support for choose launchers

Is it possible to add support for which browser (or browsers) should be executed ?

In testacular it is avaiable. There are configs for each supported browser (e.g. Chrome, Firefox ).

I think that in config could be option launchers where will be added default launchers for file. ( no browsers, cause in future users could add others configurations for programs which would be launched on open, e.q. editor )

Add grunt multitask support for the app option

Currently, this task does not use this.options() to look up the app option, but explicitly uses this.data.app or this.data.application. This breaks multitask shared options configuration.

Open html file using Grunt open

I made grunt open task on the next way:
module.exports = function(grunt) {

grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
open : {

        AngularSeedApp : {
            path: 'http://127.0.0.1:8888/app/index.html',
            //app: 'Google Chrome'
        },

});
grunt.loadNpmTasks('grunt-open');

After this I run in command line:
grunt open
and chrome runs and I got this
Oops! Google Chrome could not connect to 127.0.0.1:8888

Try reloading: 127.­0.­0.­1:­8888/­app/­index.­html

How I can solve this issue that I get my preview of index.html in browser (chrome is my default).

Ubuntu 13.04

Hi,

I am using grunt-open without any problem with Windows 7 but unfortunately it does not open my browser using Ubuntu 13.04. Any advice would be much appreciated. :)

Set delay

I'm currently running a concurrent task that watches my files, starts my server and opens the browser. Due to the nature of my server it blocks all other scripts from being executed afterwards. So whenever my browser gets opened, I get a blank screen. Immediately after pressing f5 the page is loaded fine. A slight delay would fix this.

Many thanks,

Yoshua

option to reuse tab each time open is called (might require browser plugin)

Unless you are diligent about closing new tabs, starting and killing grunt many times while debugging eventually the browser will have a sea of identical tabs.

It would be nice if there was an option to request the browser to "reuse" the same tab each time grunt-open was used.

I haven't looked to see if browsers have this option on the command line. I'm guessing it's not possible to request the browser uses the same tab the way target="name" works on <a href.., so this might require a browser extension.

Other ideas how to prevent the sea of tabs from happening?

'app' option is broken in 0.2.4 release

The 'app' option is ignored in the 0.2.4 release. Whatever the app is set to, the url is always opened in the default browser. Rolled back to 0.2.3 and verified that the option works there.

Needed to add files to my config?

Just mucking around here trying to get a configuration together that starts my server, sets up watches, and opens a browser. I couldn't get grunt-open to work for the longest time, and was getting errors "cannot read property 'orig' of undefined" on the multiTask defined in the module. When I changed the multiTask to a plain task (registerTask), I started getting "cannot read property 'url' of undefined." Reading around, I found some hints that the module might be expecting a "files:" config, even though it's not documented. In the end, I came up with this (using this specific syntax), and everything finally worked:

open: {
     all: {
           files: { src: ['./index.html'] },
           path: 'http://localhost:<%= connect.server.options.port %>',
           app: 'chrome'
      }
},

Any ideas why I was having this issue? I don't see that anyone else has encountered it. Thanks, and thanks for the package.

Specify the ability to open more than one page

If i need to open more than one page the grunt open task doesn't allow for the ability to using the following syntax:

open: {
   url1: {
      server: {
        url: 'http://localhost:<%= express.options.port %>/index.html'
      }
  },

   url2: {
      server: {
        url: 'http://localhost:<%= express.options.port %>/index2.html'
      }
    }
}

Or am i missing something? What is the way to do so?

Allow openOn to pass in data

grunt-livestyle passes the port in the 'serverListening' event. It would be nice if I could write a function that would use that in the url to be opened.

grunt-open doesn't operate properly with grunt-contrib-watch on Windows 8

This is a minimal example to point out the problem.

Assuming a basic grunt installation exists, copy these three files in an empty folder and run npm install. Next run grunt. Now a browser should open and load "www.google.com". Then modify and save the test.coffee file. The browser should open www.google.de every time you modify the file test.coffee.

On my system Windows8 x64, node v0.10.13, and grunt v0.4.1 just the first open before "watching" is executed properly.

Gruntfile.coffee

module.exports = (grunt) ->
    require('matchdep').filterDev('grunt-*').forEach grunt.loadNpmTasks
    grunt.initConfig
        watch:
            test:
                files: ['test.coffee']
                tasks: ['open']
        open:
            server:
                path: 'http://www.google.com'
    grunt.registerTask 'live', [
        'open'
        'watch'
    ]
    grunt.registerTask 'default', ['live']

package.json

{
  "name": "openwatch",
  "version": "0.0.1",
  "dependencies": {},
  "devDependencies": {
    "grunt": "~0.4.1",
    "matchdep": "~0.1.2",
    "grunt-contrib-watch": "~0.4.4",
    "grunt-open": "~0.2.0"
  },
  "engines": {
    "node": ">=0.8.0"
  }
}

test.coffee

test = true

open file only if exists

i generate a html report (tests fail case), and then want to open it, only if its generated. I want to ignore the open task (skip with success), in case there is no report-file. (tests success case)
Is there a simple way without pull-request or another npm package?

Grunt 0.4 Release

I'm posting this issue to let you know that we will be publishing Grunt 0.4 on Monday, February 18th.

If your plugin is not already Grunt 0.4 compatible, would you please consider updating it? For an overview of what's changed, please see our migration guide.

If you'd like to develop against the final version of Grunt before Monday, please specify "grunt": "0.4.0rc8" as a devDependency in your project. After Monday's release, you'll be able to use "grunt": "~0.4.0" to actually publish your plugin. If you depend on any plugins from the grunt-contrib series, please see our list of release candidates for compatible versions. All of these will be updated to final status when Grunt 0.4 is published.

Also, in an effort to reduce duplication of effort and fragmentation in the developer community, could you review the grunt-contrib series of plugins to see if any of your functionality overlaps significantly with them? Grunt-contrib is community maintained with 40+ contributors—we'd love to discuss any additions you'd like to make.

Finally, we're working on a new task format that doesn't depend on Grunt: it's called node-task. Once this is complete, there will be one more conversion, and then we'll never ask you to upgrade your plugins to support our changes again. Until that happens, thanks for bearing with us!

If you have any questions about how to proceed, please respond here, or join us in #grunt on irc.freenode.net.

Thanks, we really appreciate your work!

openOn should only open once when the event first occurs

I have a grunt serve task that does a build, starts a web server, then uses grunt-open to launch the web page once the server has fully started. I use the openOn option because it is the most reliable way to ensure that the asynchronous server startup is complete and thereby avoid launching the page before the server is ready.

Unfortunately, the open task continues to run every time the event is fired (in my case, on every server restart). This results in every change to a server-dependent file not just restarting the server but also popping up a new tab in the browser despite the open task running only once at initial startup.

The simplest fix is to replace grunt.event.on( with grunt.event.once(. The implementation is a matter of opinion, it might be preferable for backwards compatibility to introduce an openOnceOn option to explicitly open only once. Either way it would be good to update the documentation for openOn to specify whether it opens just once or every time the event is triggered.

Warning: Spawn ENOENT

I keep getting "Warning: Spawn ENOENT" problem when I am running grunt-open.

My setup

I have all my project files on Google Drive. I am doing my development on the files directly on them (using Google Drive desktop).

I just want to open the index.html file when I run grunt. Just that simple.

Part of my Gruntfile.js

open: {
all: {
path : 'index.html'
}
},

But I couldn't get it working? What am I missing?
I have tried the exact Gruntfile code on another machine and it works perfectly fine.

Requires "delay" to work with grunt-watch

It seems that the recent modifications three days ago have caused the plugin not to work with grunt-watch unless you set a delay or perhaps openOn. I set a delay of 100 and now the watch works fine.

(In my setup, grunt-open is preceded by ericclemmons/grunt-express-server and followed by grunt-watch)

Specify a callback as an option

What do you think about accepting a callback function as an option which can be called after grunt open is finished? Would you be open to adding it to this module?

How to use this plugin on a docker machine?

This plugin works perfectly on my local machine, however, it doesn't work on my Docker machine. On my local machine the open task set as following:

  server: {
    url: 'http://localhost:<%= express.options.port %>'
  }

On my Docker machine as following:

  server: {
    url: 'http://192.168.99.100:<%= express.options.port %>'
  }

NOTE: 192.168.99.100 is my VM's ip address on my Mac.

I got the following error:

app_1   | Running "open:server" (open) task
app_1   | Warning: Command failed: /bin/sh -c /www/app/node_modules/open/vendor/xdg-open "http://192.168.99.100:3000"
app_1   | /www/app/node_modules/open/vendor/xdg-open: 1: /www/app/node_modules/open/vendor/xdg-open: xdg-mime: not found
app_1   | xdg-open: no method available for opening 'http://192.168.99.100:3000'

I have been googling for a while but still no luck. Any help would be appreciated.

`url` and `file`

Having both url and file when they don't differ doesn't make sense.

Use path or uri for both instead.

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.