npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

grunt-port-pick

v1.5.3

Published

Scan and pick an available port, for other grunt tasks

Downloads

1,755

Readme

#grunt-port-pick Build Status Dependency Status devDependency Status Coverage Status

##Installation

Install npm package:

npm install grunt-port-pick --save-dev

Add the following to your project's Gruntfile in order to load the task:

grunt.loadNpmTasks('grunt-port-pick');

##Usage Examples

Tired of manually configuring ports only to have them conflict? This task will scan for an unused port, given a range, and swap in the unused port into other tasks' configurations.

####A basic example showing how to inject an available port into a config:

// Project configuration.
grunt.initConfig({
  portPick: {
    karma: {
      targets: [
        'karma.options.port'
      ]
    }
  },

  karma: {
    options: {
      port: 0
    }
  }
});

grunt.registerTask('test', [ 'portPick', 'karma' ]);

####A streamlined example of the simplified portPickIndie task:

// Project configuration.
grunt.initConfig({
  portPickIndie: {
    options: {
      port: 7000,
      extra: 4
    }
  }
});

grunt.registerTask('showOff', 'Dump picked ports', function() {
  grunt.log.writeln(grunt.config.get('port-pick-1'));
  grunt.log.writeln(grunt.config.get('port-pick-2'));
  grunt.log.writeln(grunt.config.get('port-pick-3'));
  grunt.log.writeln(grunt.config.get('port-pick-4'));
});

grunt.registerTask('default', ['portPickIndie', 'showOff']);

####A complex example showing the various ways you can pick and reference ports:

// Project configuration.
grunt.initConfig({
  // Specify what ports need to be injected where and what additional ports
  // need to be allotted.
  portPick: {
    options: {
      port: 8760,
      extra: 1
    },
    selenium: {
      targets: [
        'selenium.options.port',
        'protractor.test1.options.args.seleniumPort',
        'protractor.test1.options.args.baseUrl',
        'protractor.test2.options.args.seleniumPort'
      ]
    },
    parallelFuncTest1: {
      options: {
        name: 'port-pick-connect1'
      },
      targets: [
        'connect.test1.port',
      ]
    },
    parallelFuncTest2: {
      options: {
        name: 'port-pick-connect2'
      },
      targets: [
        'connect.test2.port',
      ]
    }
  },

  // Sample selenium runner.  8768 is used if available, otherwise the next
  // available port starting at 8760 will be used.
  selenium: {
    options: {
      port: 8768
    },
  },

  // Sample grunt-connect target to emulate two concurrently running web
  // servers where the ports are dynamically set.
  connect: {
    test1: {
      port: 0
    },
    test2: {
      port: 0
    }
  },

  // Sample grunt-protractor-runner target to emulate two e2e runners hitting
  // the two connect web servers started above.  Shows the port injected into
  // a url object as well as via a templated named config.
  protractor: {
    test1: {
      options: {
        args: {
          seleniumPort: 0,
          baseUrl: 'http://localhost:0'
        }
      }
    },
    test2: {
      options: {
        args: {
          seleniumPort: 0,
          baseUrl: 'http://localhost:<%= grunt.config.get("port-pick-connect2") %>'
        }
      }
    }
  },

  // Sample grunt-karma target to emulate the karma port selection for running
  // unit tests alongside with our e2e tests above, using the "extraPorts"
  // option to have the port available via grunt templates.
  karma: {
    parallel: {
      options: {
        port: '<%= grunt.config.get("port-pick-1") %>'
      }
    }
  },

  parallel: {
    options: {
      stream: true
    },
    tests: {
      tasks: [{
        grunt: true,
        args: [
          'portPick',
          'unit',
          'func1',
          'func2',
          '--portPickUsePorts=<%= grunt.config.get("port-pick-used") %>']
      }]
    }
  }
});

grunt.registerTask('func1', [ 'portPick:parallelFuncTest1', 'connect:test1', 'protractor:test1' ]);
grunt.registerTask('func2', [ 'portPick:parallelFuncTest2', 'connect:test2', 'protractor:test2' ]);
grunt.registerTask('unit', [ 'karma:parallel' ]);

grunt.registerTask('test', [ 'portPick', 'selenium', 'parallel:tests' ]);

##Options

  1. port -- The port to start scanning from, inclusive, for the first available port to use. Defaults to 8765.
  2. limit -- Do not scan for more than this number of ports, fail if one is not found between port and port + limit. Defaults to false, port-pick will scan all the way up to 65535.
  3. extra -- Set the number of extra port-pick-# configurations to supply. Defaults to 0. If set to greater than 0, it will populate <%= port-pick-1 %>, <%= port-pick-2 %>, etc.
  4. hostname -- The IP/hostname to bind to when checking for available ports. Defaults to 0.0.0.0, so binds to all interfaces.
  5. name -- Set the property name for port-pick to use when picking a port for a target. Defaults to undefined where it will not populate a separate configuration with the target's selected port.

##Command line options

  1. --portPickUsePorts=#,#,... -- A comma delimited list of ports to select from, instead of scanning for new unused ports. This is useful if you need to provide the ports that were selected to spawned grunt tasks, such as when using grunt-parallel or grunt-concurrent. Defaults to undefined.