Skip to content

Commit

Permalink
Merge pull request #9 from xudafeng/project-config
Browse files Browse the repository at this point in the history
update project config
  • Loading branch information
xudafeng committed Oct 30, 2016
2 parents 0656603 + 6bb468e commit f228573
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 16 deletions.
16 changes: 10 additions & 6 deletions README.md
@@ -1,11 +1,15 @@
# detect-port
[![logo][logo-image]][logo-url]

---

[![NPM version][npm-image]][npm-url]
[![node version][node-image]][node-url]
[![build status][travis-image]][travis-url]
[![Coveralls][coveralls-image]][coveralls-url]
[![node version][node-image]][node-url]
[![npm download][download-image]][download-url]

[logo-image]: ./logo.png
[logo-url]: https://npmjs.org/package/detect-port
[npm-image]: https://img.shields.io/npm/v/detect-port.svg?style=flat-square
[npm-url]: https://npmjs.org/package/detect-port
[travis-image]: https://img.shields.io/travis/xudafeng/detect-port.svg?style=flat-square
Expand Down Expand Up @@ -48,17 +52,17 @@ detect(port, (err, _port) => {
* for a yield syntax instead of callback function implement
*/

var co = require('co');
const co = require('co');

co(function *() {
var _port = yield detect(port);
const _port = yield detect(port);

if (port === _port) {
console.log(`port: ${port} was not occupied`);
} else {
console.log(`port: ${port} was occupied, try port: ${_port}`);
}
})();
});

/**
* use as a promise
Expand All @@ -78,7 +82,7 @@ detect(port)

```

## Cli Tool
## Command Line Tool

```shell
$ npm i detect-port -g
Expand Down
8 changes: 6 additions & 2 deletions bin/detect-port
Expand Up @@ -55,10 +55,14 @@ if (!arg_0) {
console.log(` ${pkg.homepage}`);
console.log();
} else {
main(port, (err, port) => {
main(port, (err, _port) => {
if (err) {
console.log(`get available port failed with ${err}`);
}
console.log(`get available port ${port}`);

if (port !== _port) {
console.log(`port ${port} was occupied`);
}
console.log(`get available port ${_port}`);
});
}
2 changes: 1 addition & 1 deletion index.js
Expand Up @@ -13,4 +13,4 @@

'use strict';

module.exports = require('./lib');
module.exports = require('./lib/detect-port');
File renamed without changes.
Binary file added logo.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "detect-port",
"version": "1.0.2",
"version": "1.0.4",
"description": "detect available port",
"keywords": [
"detect",
Expand Down
4 changes: 2 additions & 2 deletions test/cli.test.js
Expand Up @@ -48,8 +48,8 @@ describe('command-line tool test', () => {
});

it('should output available port from the given port', function *() {
const givenPort = 8080;
var res = yield cliTest.execFile(binFile, [givenPort], {});
const givenPort = 9000;
const res = yield cliTest.execFile(binFile, [givenPort], {});
const port = parseInt(res.stdout.split(' ')[3], 10);
port.should.within(givenPort, 65535);
});
Expand Down
8 changes: 4 additions & 4 deletions test/detect-port.test.js
Expand Up @@ -18,7 +18,7 @@ const detectPort = require('..');
describe('detect port test', () => {

it('callback with occupied port', done => {
var _port = 80;
const _port = 80;
detectPort(_port, (err, port) => {
if (err) {
console.log(err);
Expand All @@ -38,17 +38,17 @@ describe('detect port test', () => {
});

it('generator usage', function *() {
var _port = 8080;
const _port = 8080;
try {
var port = yield detectPort(_port);
const port = yield detectPort(_port);
port.should.within(_port, 65535);
} catch (err) {
console.log(err);
}
});

it('promise usage', done => {
var _port = 8080;
const _port = 8080;
detectPort(_port)
.then(port => {
port.should.within(_port, 65535);
Expand Down

0 comments on commit f228573

Please sign in to comment.