Skip to content

Commit

Permalink
meta tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
sindresorhus committed Apr 17, 2016
1 parent 5b18aee commit 0061615
Show file tree
Hide file tree
Showing 9 changed files with 55 additions and 86 deletions.
5 changes: 1 addition & 4 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@ charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[package.json]
[{package.json,*.yml}]
indent_style = space
indent_size = 2

[*.md]
trim_trailing_whitespace = false
6 changes: 0 additions & 6 deletions .jscsrc

This file was deleted.

13 changes: 0 additions & 13 deletions .jshintrc

This file was deleted.

3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
language: node_js
node_js:
- 'iojs'
- '5'
- '4'
- '0.12'
- '0.10'
before_install:
Expand Down
17 changes: 1 addition & 16 deletions Gruntfile.js → gruntfile.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable quote-props */
'use strict';
module.exports = function (grunt) {
grunt.initConfig({
Expand All @@ -6,18 +7,6 @@ module.exports = function (grunt) {
src: 'test/test.js'
}
},
jshint: {
all: ['tasks/**/*.js', 'Gruntfile.js'],
options: {
jshintrc: true
}
},
jscs: {
src: ['tasks/**/*.js', 'Gruntfile.js'],
options: {
config: '.jscsrc'
}
},
watch: {
test: {
files: ['noop']
Expand Down Expand Up @@ -141,8 +130,6 @@ module.exports = function (grunt) {
grunt.loadNpmTasks('grunt-simple-mocha');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-browser-sync');
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-jscs');

grunt.registerTask('phpwatch', [
'php:test200',
Expand All @@ -156,8 +143,6 @@ module.exports = function (grunt) {
]);

grunt.registerTask('default', [
'jshint:all',
'jscs',
'php:test200',
'php:test301',
'php:test400',
Expand Down
38 changes: 20 additions & 18 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,29 +17,31 @@
},
"repository": "sindresorhus/grunt-php",
"scripts": {
"test": "grunt"
},
"dependencies": {
"bin-version-check": "^2.0.0",
"get-port": "^1.0.0",
"object-assign": "^2.0.0",
"opn": "^1.0.0"
},
"devDependencies": {
"got": "^2.9.2",
"grunt": "^0.4.5",
"grunt-browser-sync": "^2.0.0",
"grunt-cli": "^0.1.13",
"grunt-contrib-jshint": "^0.11.1",
"grunt-contrib-watch": "^0.6.1",
"grunt-jscs": "^1.6.0",
"grunt-simple-mocha": "^0.4.0"
"test": "xo && grunt"
},
"engines": {
"node": ">=0.10.0"
},
"license": "MIT",
"files": [
"tasks"
]
],
"dependencies": {
"bin-version-check": "^2.0.0",
"get-port": "^2.0.0",
"object-assign": "^4.0.1",
"opn": "^4.0.1"
},
"devDependencies": {
"got": "^5.6.0",
"grunt": "^1.0.1",
"grunt-browser-sync": "^2.0.0",
"grunt-cli": "^1.2.0",
"grunt-contrib-watch": "^1.0.0",
"grunt-simple-mocha": "^0.4.0",
"xo": "*"
},
"peerDependencies": {
"grunt": ">=0.4.0"
}
}
24 changes: 12 additions & 12 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ grunt.initConfig({

grunt.registerTask('serve', [
'php:dist', // Start PHP Server
'browserSync:dist', // Using the php instance as a proxy
'browserSync:dist', // Using the PHP instance as a proxy
'watch' // Any other watch tasks you want to run
]);
```
Expand Down Expand Up @@ -137,14 +137,14 @@ grunt.registerTask('default', ['php']);

### port

Type: `number`
Type: `number`<br>
Default: `8000`

The port on which you want to access the webserver. Task will fail if the port is already in use. Use the special value `?` to use a system-assigned port.

### hostname

Type: `string`
Type: `string`<br>
Default: `'127.0.0.1'` *(usually same as `localhost`)*

The hostname the webserver will use.
Expand All @@ -153,14 +153,14 @@ Use `0.0.0.0` if you want it to be accessible from the outside.

### base

Type: `string`
Type: `string`<br>
Default: `'.'`

From which folder the webserver will be served. Defaults to the directory of the Gruntfile.

### keepalive

Type: `boolean`
Type: `boolean`<br>
Default: `false`

Keep the server alive indefinitely. Any task specified after this will not run.
Expand All @@ -181,7 +181,7 @@ Can be one of the following:

### router

Type: `string`
Type: `string`<br>

Optionally specify the path to a [router script](http://php.net/manual/en/features.commandline.webserver.php#example-380) that is run at the start of each HTTP request. If this script returns `false`, then the requested resource is returned as-is. Otherwise the script's output is returned to the browser.

Expand All @@ -200,40 +200,40 @@ if (preg_match('/\.(?:png|jpg|jpeg|gif)$/', $_SERVER["REQUEST_URI"])) {

### bin

Type: `string`
Type: `string`<br>
Default: `'php'`

Path to the PHP binary. Useful if you have multiple versions of PHP installed.

### ini

Type: `string`
Type: `string`<br>
Default: Built-in `php.ini`

Path to a custom [`php.ini`](http://php.net/manual/en/ini.php) config file.

### silent

Type: `boolean`
Type: `boolean`<br>
Default: `false`

Suppress output produced by the PHP-server.

### directives

Type: `object`
Type: `object`<br>
Default: `{}`

Add custom [ini directives](http://php.net/manual/en/ini.list.php).

### env

Type: `object`
Type: `object`<br>
Default: `{}`

Set environment variables for the PHP process.


## License

MIT © [Sindre Sorhus](http://sindresorhus.com)
MIT © [Sindre Sorhus](https://sindresorhus.com)
30 changes: 16 additions & 14 deletions tasks/php.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable guard-for-in */
'use strict';
var path = require('path');
var spawn = require('child_process').spawn;
Expand All @@ -20,20 +21,24 @@ module.exports = function (grunt) {
}, function (res) {
var statusCodeType = Number(res.statusCode.toString()[0]);
if ([2, 3, 4].indexOf(statusCodeType) !== -1) {
return cb();
cb();
return;
} else if (statusCodeType === 5) {
grunt.fail.warn(
'Server docroot returned 500-level response. Please check ' +
'your configuration for possible errors.'
);
return cb();

cb();
return;
}

checkServer(hostname, port, path, cb);
}).on('error', function (err) {
}).on('error', function () {
// back off after 1s
if (++checkServerTries > 20) {
return cb();
cb();
return;
}

grunt.verbose.writeln('PHP server not started. Retrying...');
Expand All @@ -56,13 +61,7 @@ module.exports = function (grunt) {
directives: {}
});

getPort(function (err, port) {
if (err) {
grunt.warn(err);
cb();
return;
}

getPort().then(function (port) {
if (options.port === '?') {
options.port = port;
}
Expand Down Expand Up @@ -107,8 +106,9 @@ module.exports = function (grunt) {

var path = '/';
if (typeof options.open === 'string') {
path = (options.open.indexOf('/') !== 0 ? '/' : '') + options.open;
path = (options.open.indexOf('/') === 0 ? '' : '/') + options.open;
}

// check when the server is ready. tried doing it by listening
// to the child process `data` event, but it's not triggered...
checkServer(options.hostname, options.port, path, function () {
Expand All @@ -119,9 +119,11 @@ module.exports = function (grunt) {
if (options.open) {
open('http://' + host + path);
}

}.bind(this));
}.bind(this));
}.bind(this));
}.bind(this)).catch(function (err) {
grunt.warn(err);
cb();
});
});
};
5 changes: 3 additions & 2 deletions test/test.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-env mocha */
'use strict';
var assert = require('assert');
var got = require('got');
Expand Down Expand Up @@ -36,7 +37,7 @@ it('should start a PHP-server when the status code is 400', function (cb) {
this.timeout(20000);

got('http://0.0.0.0:8010', function (err) {
assert.equal(err.code, 400);
assert.equal(err.statusCode, 400);
cb();
});
});
Expand All @@ -45,7 +46,7 @@ it('should start a PHP-server when the status code is 404', function (cb) {
this.timeout(20000);

got('http://0.0.0.0:8011', function (err) {
assert.equal(err.code, 404);
assert.equal(err.statusCode, 404);
cb();
});
});
Expand Down

0 comments on commit 0061615

Please sign in to comment.