diff --git a/.jshintignore b/.jshintignore new file mode 100644 index 0000000..ae42ebb --- /dev/null +++ b/.jshintignore @@ -0,0 +1 @@ +php-webkit/jquery.min.js \ No newline at end of file diff --git a/.jshintrc b/.jshintrc new file mode 100644 index 0000000..372dd8d --- /dev/null +++ b/.jshintrc @@ -0,0 +1,29 @@ +{ + "node": true, + "esnext": true, + "camelcase": false, + "curly": true, +"-W041": false, + "immed": true, + "indent": 2, + "latedef": false, + "newcap": true, + "noarg": true, + "regexp": true, + "undef": false, + "unused": false, + "trailing": true, + "smarttabs": true, + "white": true, + "globals": { + /* Mocha */ + "describe": false, + "it": false, + "before": false, + "beforeEach": false, + "after": false, + "afterEach": false, + /* Lodash / Underscore */ + "_": false + } +} diff --git a/gulpfile.js b/gulpfile.js new file mode 100644 index 0000000..f2a9669 --- /dev/null +++ b/gulpfile.js @@ -0,0 +1,21 @@ +'use strict'; + +var gulp = require('gulp'); +var mocha = require('gulp-mocha'); +var jshint = require('gulp-jshint'); +var stylish = require('jshint-stylish'); + +gulp.task('lint', function () { + return gulp.src([ + './php-webkit/**/*.js', + './lib/**/*.js' + ]) + .pipe(jshint()) + .pipe(jshint.reporter(stylish)) + .pipe(jshint.reporter('fail')); +}); + +gulp.task('test', ['lint'], function () { + return gulp.src('./tests/index.js') + .pipe(mocha({bail: true})); +}); diff --git a/php-webkit/bridge.js b/lib/bridge.js similarity index 95% rename from php-webkit/bridge.js rename to lib/bridge.js index 1001f63..d6349d1 100644 --- a/php-webkit/bridge.js +++ b/lib/bridge.js @@ -19,8 +19,12 @@ function runPHP(req, response, next, phpinfo){ var pathinfo = ""; var i = req.url.indexOf(".php"); - if(i > 0) pathinfo = parts.pathname.substring(i+4); - else pathinfo = parts.pathname; + + if(i > 0) { + pathinfo = parts.pathname.substring(i+4); + } else { + pathinfo = parts.pathname; + } var env = { SERVER_SIGNATURE: "php-webkit", @@ -65,7 +69,7 @@ function runPHP(req, response, next, phpinfo){ REDIRECT_STATUS: 1 }; - Object.keys(req.headers).map(function(x){return env["HTTP_"+x.toUpperCase().replace("-", "_")] = req.headers[x];}); + Object.keys(req.headers).map(function(x){env["HTTP_"+x.toUpperCase().replace("-", "_")] = req.headers[x];}); if(/.*?\.php$/.test(file)){ var res = "", err = ""; @@ -104,7 +108,7 @@ function runPHP(req, response, next, phpinfo){ if(lines.length){ do { var m = lines[line].split(": "); - if(m[0] === "") break; + if(m[0] === "") { break; } //console.log("HEADER: "+m[0]+": "+m[1]); if(m[0] == "Status"){ @@ -141,8 +145,11 @@ exports.cgi = function(phpinfo){ req.on('data', function(chunk) { //data.write(chunk.toString('binary'), data.length, chunk.length, 'binary'); //console.log(chunk); - if(!data) data = chunk; - else data = data+chunk; + if(!data) { + data = chunk; + } else { + data = data+chunk; + } //data = data.concat(chunk); }); req.on('end', function() { @@ -151,5 +158,5 @@ exports.cgi = function(phpinfo){ //console.log("ENCODING: "+req.get("Content-type")+", len: "+req.rawBody.length); runPHP(req, res, next, phpinfo); }); - } -} \ No newline at end of file + }; +}; \ No newline at end of file diff --git a/package.json b/package.json index 31d7114..1ffe0df 100644 --- a/package.json +++ b/package.json @@ -1,17 +1,28 @@ { "name": "php-webkit", "description": "Allows you to run PHP within node-webkit.", - "version": "0.1", -"dependencies":{ - "express":"4.*.*" + "version": "0.0.1", + "dependencies":{ + "express":"*" + }, + "scripts": { + "test": "./node_modules/gulp/bin/gulp.js test" + }, + "devDependencies": { + "mocha": "1.*", + "must": ">= 0.11 < 1", + "gulp": "3.*", + "gulp-jshint": "1.*", + "gulp-mocha": "0.*", + "jshint-stylish": "0.*" }, "main": "./php-webkit/index.html", "node-remote": "", "phpwebkit": { - "bin": "", //The location of your php-cgi binary - "path": "./application", //The path to your PHP application - "host": "127.0.0.1", //The host the PHP app runs on - "port": 9090 //The port the PHP app runs on + "bin": "", + "path": "./application", + "host": "127.0.0.1", + "port": 9090 }, "license":"MIT", "window": { diff --git a/php-webkit/main.js b/php-webkit/main.js index 850243d..eefe193 100644 --- a/php-webkit/main.js +++ b/php-webkit/main.js @@ -1,7 +1,7 @@ var gui = require('nw.gui'); var win = gui.Window.get(); var http = require('http'); -var php = require('./bridge'); +var php = require('../lib/bridge'); var express = require('express'); var app = express(); var os = require('os'); diff --git a/tests/index.js b/tests/index.js new file mode 100644 index 0000000..07480f4 --- /dev/null +++ b/tests/index.js @@ -0,0 +1,9 @@ +var phpBridge = require('../lib/bridge'); +var demand = require('must'); + +describe('php-nw Bridge.js', function () { + it('should exist', function () { + demand(phpBridge).to.exist(); + }); +}); +