diff --git a/.editorconfig b/.editorconfig index 86c8f59..98a761d 100644 --- a/.editorconfig +++ b/.editorconfig @@ -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 diff --git a/.jscsrc b/.jscsrc deleted file mode 100644 index 6e35a91..0000000 --- a/.jscsrc +++ /dev/null @@ -1,6 +0,0 @@ -{ - "preset": "grunt", - "disallowSpacesInAnonymousFunctionExpression": null, - "requireLineFeedAtFileEnd": true, - "validateIndentation": "\t" -} diff --git a/.jshintrc b/.jshintrc deleted file mode 100644 index 804f8af..0000000 --- a/.jshintrc +++ /dev/null @@ -1,13 +0,0 @@ -{ - "node": true, - "esnext": true, - "bitwise": true, - "camelcase": true, - "curly": true, - "immed": true, - "newcap": true, - "noarg": true, - "undef": true, - "unused": "vars", - "strict": true -} diff --git a/.travis.yml b/.travis.yml index 9b60c5e..2772f7c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,7 @@ language: node_js node_js: - - 'iojs' + - '5' + - '4' - '0.12' - '0.10' before_install: diff --git a/Gruntfile.js b/gruntfile.js similarity index 89% rename from Gruntfile.js rename to gruntfile.js index 46deb6c..f911695 100644 --- a/Gruntfile.js +++ b/gruntfile.js @@ -1,3 +1,4 @@ +/* eslint-disable quote-props */ 'use strict'; module.exports = function (grunt) { grunt.initConfig({ @@ -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'] @@ -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', @@ -156,8 +143,6 @@ module.exports = function (grunt) { ]); grunt.registerTask('default', [ - 'jshint:all', - 'jscs', 'php:test200', 'php:test301', 'php:test400', diff --git a/package.json b/package.json index 528c6ba..5a823e3 100644 --- a/package.json +++ b/package.json @@ -17,23 +17,7 @@ }, "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" @@ -41,5 +25,23 @@ "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" + } } diff --git a/readme.md b/readme.md index b6a2cdb..50fab70 100644 --- a/readme.md +++ b/readme.md @@ -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 ]); ``` @@ -137,14 +137,14 @@ grunt.registerTask('default', ['php']); ### port -Type: `number` +Type: `number`
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`
Default: `'127.0.0.1'` *(usually same as `localhost`)* The hostname the webserver will use. @@ -153,14 +153,14 @@ Use `0.0.0.0` if you want it to be accessible from the outside. ### base -Type: `string` +Type: `string`
Default: `'.'` From which folder the webserver will be served. Defaults to the directory of the Gruntfile. ### keepalive -Type: `boolean` +Type: `boolean`
Default: `false` Keep the server alive indefinitely. Any task specified after this will not run. @@ -181,7 +181,7 @@ Can be one of the following: ### router -Type: `string` +Type: `string`
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. @@ -200,35 +200,35 @@ if (preg_match('/\.(?:png|jpg|jpeg|gif)$/', $_SERVER["REQUEST_URI"])) { ### bin -Type: `string` +Type: `string`
Default: `'php'` Path to the PHP binary. Useful if you have multiple versions of PHP installed. ### ini -Type: `string` +Type: `string`
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`
Default: `false` Suppress output produced by the PHP-server. ### directives -Type: `object` +Type: `object`
Default: `{}` Add custom [ini directives](http://php.net/manual/en/ini.list.php). ### env -Type: `object` +Type: `object`
Default: `{}` Set environment variables for the PHP process. @@ -236,4 +236,4 @@ Set environment variables for the PHP process. ## License -MIT © [Sindre Sorhus](http://sindresorhus.com) +MIT © [Sindre Sorhus](https://sindresorhus.com) diff --git a/tasks/php.js b/tasks/php.js index 3eb035c..fab9c7f 100644 --- a/tasks/php.js +++ b/tasks/php.js @@ -1,3 +1,4 @@ +/* eslint-disable guard-for-in */ 'use strict'; var path = require('path'); var spawn = require('child_process').spawn; @@ -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...'); @@ -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; } @@ -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 () { @@ -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(); + }); }); }; diff --git a/test/test.js b/test/test.js index a74d0e6..094f05b 100644 --- a/test/test.js +++ b/test/test.js @@ -1,3 +1,4 @@ +/* eslint-env mocha */ 'use strict'; var assert = require('assert'); var got = require('got'); @@ -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(); }); }); @@ -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(); }); });