Skip to content

Commit a8a3ebb

Browse files
committed
Converted update script to an HTTP server. Moved long running scripts to scripts/; ranamed src/ to lib/. Fixes jquery-archive#35 - Convert post-receive hook to HTTP server.
1 parent b3ae49c commit a8a3ebb

15 files changed

+47
-35
lines changed

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ From http://dev.plugins.jquery.com/wordpress/wp-admin/
5959
1. Update Site Address
6060

6161
* Select Settings -> General
62-
* Set Site Address to http://plugins.jquery.com.local
62+
* Set Site Address to http://dev.plugins.jquery.com
6363

6464
2. Activate the plugins-jquery-com theme
6565

@@ -93,8 +93,8 @@ From http://dev.plugins.jquery.com/wordpress/wp-admin/
9393
6. `grunt setup`
9494
* This is a one time setup.
9595

96-
7. `node src/update.js`
97-
* This expects a post-receive hook as stdin. You can use `{"repository":{"url":"http://github.com/scottgonzalez/temp-jquery-foo","watchers":3,"forks":25}}` for testing.
96+
7. `node scripts/update-server.js`
97+
* This starts an HTTP server on port 8001, which expects post-receive hooks as requests.
9898

99-
8. `node src/wp-update.js`
100-
* This is intended to run as a long running processes, monitored by a system such as monit.
99+
8. `node scripts/wordpress-update.js`
100+
* This is a long running process which keeps WordPress in sync with the plugins DB.

grunt.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
var config = require( "./src/config" );
1+
var config = require( "./lib/config" );
22

33
module.exports = function( grunt ) {
44

@@ -7,7 +7,7 @@ grunt.loadNpmTasks( "grunt-wordpress" );
77
grunt.initConfig({
88
lint: {
99
grunt: "grunt.js"
10-
// src: "src/**"
10+
// src: [ "lib/**", "scripts/**" ]
1111
},
1212

1313
wordpress: config.wordpress
@@ -70,7 +70,7 @@ grunt.registerTask( "setup-wordpress", function() {
7070

7171
grunt.registerTask( "setup-pluginsdb", function() {
7272
var done = this.async();
73-
require( "./src/pluginsdb" )._setup(function( error ) {
73+
require( "./lib/pluginsdb" )._setup(function( error ) {
7474
if ( error ) {
7575
return done( false );
7676
}
@@ -81,7 +81,7 @@ grunt.registerTask( "setup-pluginsdb", function() {
8181

8282
grunt.registerTask( "setup-retrydb", function() {
8383
var done = this.async();
84-
require( "./src/retrydb" )._setup(function( error ) {
84+
require( "./lib/retrydb" )._setup(function( error ) {
8585
if ( error ) {
8686
return done( false );
8787
}
@@ -91,8 +91,8 @@ grunt.registerTask( "setup-retrydb", function() {
9191
});
9292

9393
grunt.registerTask( "restore-repos", function() {
94-
var service = require( "./src/service" ),
95-
pluginsDb = require( "./src/pluginsdb" ),
94+
var service = require( "./lib/service" ),
95+
pluginsDb = require( "./lib/pluginsdb" ),
9696
done = this.async();
9797

9898
pluginsDb.getAllRepos(function( error, repos ) {
File renamed without changes.

src/hook.js renamed to lib/hook.js

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

scripts/update-server.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
var http = require( "http" ),
2+
hook = require( "../lib/hook" ),
3+
logger = require( "../lib/logger" );
4+
5+
process.on( "uncaughtException", function( error ) {
6+
logger.error( "Uncaught exception: " + error.stack );
7+
});
8+
9+
http.createServer(function( request, response ) {
10+
var json = "";
11+
request.setEncoding( "utf8" );
12+
request.on( "data", function( chunk ) {
13+
json += chunk;
14+
});
15+
request.on( "end", function() {
16+
response.writeHead( 200 );
17+
response.end();
18+
19+
try {
20+
json = JSON.parse( json );
21+
} catch( e ) {
22+
logger.error( "Invalid request: " + json );
23+
return;
24+
}
25+
26+
hook.processHook( json, function( error ) {
27+
if ( error ) {
28+
logger.error( "Error processing hook: " + error.stack );
29+
}
30+
});
31+
});
32+
}).listen( 8001 );

src/wp-update.js renamed to scripts/wordpress-update.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
var fs = require( "fs" ),
22
semver = require( "semver" ),
33
Step = require( "step" ),
4-
wordpress = require( "./wordpress" ),
5-
pluginsDb = require( "./pluginsdb" ),
6-
service = require( "./service" ),
7-
logger = require( "./logger" );
4+
wordpress = require( "../lib/wordpress" ),
5+
pluginsDb = require( "../lib/pluginsdb" ),
6+
service = require( "../lib/service" ),
7+
logger = require( "../lib/logger" );
88

99
process.on( "uncaughtException", function( error ) {
1010
logger.error( "Uncaught exception: " + error.stack );

src/update.js

Lines changed: 0 additions & 20 deletions
This file was deleted.

0 commit comments

Comments
 (0)