Skip to content

Commit 5e26e9c

Browse files
committed
Merge branch 'master' of github.com:/jquery/plugins.jquery.com
2 parents fa80730 + d6561e7 commit 5e26e9c

9 files changed

+307
-30
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
config.json
2+
plugins.db
23
node_modules

README.md

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ Simply add a [post-receive hook](http://help.github.com/post-receive-hooks/) to
1818
* jQuery's [web-base-template](https://github.com/jquery/web-base-template)
1919
* Web server (such as Apache)
2020
* PHP
21-
* MySql
21+
* MySQL
2222
* WordPress
2323
* node
2424
* git
@@ -27,13 +27,15 @@ Simply add a [post-receive hook](http://help.github.com/post-receive-hooks/) to
2727

2828
### web-base-template
2929

30-
Download or clone web-base-template
30+
1. Download or clone web-base-template
3131

32-
`git clone git://github.com/jquery/web-base-template.git`
32+
* `git clone git://github.com/jquery/web-base-template.git`
3333

3434
#### HOSTS
3535

36-
Add a `plugins.jquery.com.local` entry in /etc/hosts
36+
1. Add a `plugins.jquery.com.local` entry in /etc/hosts
37+
38+
* `127.0.0.1 plugins.jquery.com.local`
3739

3840
#### WordPress
3941

@@ -78,16 +80,12 @@ From http://plugins.jquery.com.local/wp-admin/
7880

7981
3. `npm install`
8082

81-
4. `mkdir -p tmp/plugin-repos`
82-
83-
5. `cp src/config-sample.json src/config.json`
83+
4. `cp src/config-sample.json src/config.json`
8484

85-
6. Edit src/config.json
86-
* Set `dbHost` to the hostname of your WordPress MySQL server
87-
* Set `dbPort` to your MySQL port (usually 3306)
88-
* Set `dbName` to the MySQL user name
89-
* Set `dbUser` to the MySQL password
85+
5. Edit src/config.json
86+
* Set `dbName` to your WordPress MySQL database name
87+
* Set `dbUser` to your WordPress MySQL database user
88+
* Set `dbPassword` to your WordPress MySQL database password
9089
* Leave `siteId` null (unless you happen to be using a Wordpress multi-site installation locally, in which case supply the site's ID in the multi-site install)
9190

92-
7. `node src/main.js`
93-
91+
6. `node src/main.js`

docs/package.md

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ file. It must be actual JSON, not just a JavaScript object literal.
2222
* <a href="#field-description">description</a>
2323
* <a href="#field-keywords">keywords</a>
2424
* <a href="#field-homepage">homepage</a>
25+
* <a href="#field-contributors">contributors</a>
2526
* <a href="#field-files">files</a>
2627

2728
## <a name="field-name">name</a>
@@ -125,7 +126,7 @@ discover your plugin as it's listed on the jQuery Plugins Site.
125126

126127
The url to the plugin homepage.
127128

128-
## <a name="field-conbtributors">people fields: author, contributors</a>
129+
## <a name="field-contributors">contributors</a>
129130

130131
An array of people.
131132

@@ -216,3 +217,47 @@ The following are equivalent:
216217

217218
You may not supply a comparator with a version containing an x. Any
218219
digits after the first "x" are ignored.
220+
221+
## <a href="sample">Sample package.json</a>
222+
223+
```json
224+
{
225+
"name": "color",
226+
"version": "2.0.0b1",
227+
"title": "jQuery.Color()",
228+
"author": {
229+
"name": "John Resig",
230+
"url": "https://github.com/jeresig"
231+
},
232+
"licenses": [
233+
{
234+
"type": "MIT",
235+
"url": "MIT-LICENSE.txt"
236+
},
237+
{
238+
"type": "GPL",
239+
"url": "GPL-LICENSE.txt"
240+
}
241+
],
242+
"dependencies": {
243+
"jquery": "1"
244+
},
245+
"description": "The main purpose of this plugin to animate color properties on elements using jQuery's .animate()",
246+
"keywords": [
247+
"color",
248+
"animate",
249+
"rgba",
250+
"hsla"
251+
],
252+
"homepage": "https://github.com/jquery/jquery-color",
253+
"contributors": [
254+
{
255+
"name": "Corey Frang",
256+
"url": "https://github.com/gnarf37"
257+
}
258+
],
259+
"files": [
260+
"jquery.color.js"
261+
]
262+
}
263+
```

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
"dependencies": {
1313
"mkdirp": "0.2.1",
1414
"mysql": "0.9.5",
15-
"semver": "1.0.12"
15+
"semver": "1.0.12",
16+
"sqlite3": "2.1.1"
1617
},
1718
"engines": {
1819
"node": "0.6.5"

src/config-sample.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"repoDir": "/tmp/plugin-repos",
3-
"pluginsDir": "/tmp/plugin-data",
3+
"pluginsDb": "plugins.db",
44
"dbHost": "localhost",
55
"dbPort": 3306,
66
"dbName": "mysql",

src/main.js

Lines changed: 65 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
var exec = require( "child_process" ).exec,
22
fs = require( "fs" ),
33
mkdirp = require( "mkdirp" ),
4-
template = require( "./template" ),
54
semver = require( "semver" ),
6-
wordpress = require( "./wordpress" )
5+
template = require( "./template" ),
6+
wordpress = require( "./wordpress" ),
7+
pluginsDb = require( "./pluginsdb" ),
78
config = require( "./config" );
89

910

@@ -234,8 +235,6 @@ function validatePackageJson( package, version ) {
234235
errors.push( "Missing required dependency: jquery." );
235236
}
236237

237-
// TODO: validate repo (must match actual GitHub repo)
238-
239238
return errors;
240239
}
241240

@@ -284,11 +283,11 @@ function processPlugin( repo, fn ) {
284283
}
285284

286285
if ( !versions.length ) {
287-
return fn( createError( "No semver tags.", "NO_SEMVER_TAGS" ) );
286+
return fn( null );
288287
}
289288

290-
// TODO: add plugin to database
291-
var allErrors = [],
289+
// TODO: track our actions so we can process metadata in done()
290+
var plugins = {},
292291
waiting = versions.length;
293292

294293
function progress() {
@@ -299,6 +298,7 @@ function processPlugin( repo, fn ) {
299298
}
300299

301300
function done() {
301+
// TODO: track invalid versions (user error, not system error)
302302
// TODO: update versionless post to have latest version
303303
// TODO: update metadata in WP
304304
// - don't list pre-release versions that are older than latest stable
@@ -315,25 +315,77 @@ function processPlugin( repo, fn ) {
315315
}
316316

317317
if ( data.errors.length ) {
318-
allErrors.concat( data.errors );
318+
// TODO: report errors to user
319319
return progress();
320320
}
321321

322-
// TODO: verify user is owner of plugin
323-
324-
data.package._downloadUrl = repoDetails.downloadUrl( version );
325-
_generatePage( data.package, function( error, data ) {
322+
wordpress.getVersions( data.package.name, function( error, versions ) {
326323
if ( error ) {
327324
// TODO: log failure for retry
328325
return progress();
329326
}
330327

328+
// this version has already been processed
329+
// TODO: when should we start passing around the clean version?
330+
if ( versions.indexOf( semver.clean( version ) ) !== -1 ) {
331+
return progress();
332+
}
333+
334+
_addPluginVersion( version, data.package, function( error ) {
335+
if ( error ) {
336+
return progress();
337+
}
338+
339+
var name = data.package.name;
340+
if ( !plugins[ name ] ) {
341+
plugins[ name ] = [];
342+
}
343+
plugins[ name ].push( semver.clean( version ) );
344+
progress();
345+
});
346+
});
347+
});
348+
});
349+
}
350+
351+
function _addPluginVersion( version, package, fn ) {
352+
// find out who owns this plugin
353+
// if there is no owner, then set the user as the owner
354+
pluginsDb.getOrSetOwner( package.name, repoDetails.userName, function( error, owner ) {
355+
if ( error ) {
356+
// TODO: log failure for retry
357+
return fn( error );
358+
}
359+
360+
// the plugin is owned by someone else
361+
if ( owner !== repoDetails.userName ) {
362+
// TODO: report error to user
363+
return fn( createError( "Plugin owned by someone else.", "NOT_OWNER", {
364+
owner: owner
365+
}));
366+
}
367+
368+
pluginsDb.addVersion( repoDetails, package, function( error ) {
369+
if ( error ) {
370+
// TODO: log failure for retry
371+
return fn( error );
372+
}
373+
374+
// add additional metadata and generate the plugin page
375+
package._downloadUrl = repoDetails.downloadUrl( version );
376+
_generatePage( package, function( error, data ) {
377+
if ( error ) {
378+
// TODO: log failure for retry
379+
return fn( error );
380+
}
381+
331382
wordpress.addVersionedPlugin( data, function( error ) {
332383
if ( error ) {
333384
// TODO: log failure for retry
385+
return fn( error );
334386
}
335387
console.log( "Added " + data.pluginName + " " + data.version );
336-
progress();
388+
fn();
337389
});
338390
});
339391
});

src/pluginsdb.js

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
var sqlite = require( "sqlite3" ),
2+
config = require( "./config" );
3+
4+
var db;
5+
6+
function connect( fn ) {
7+
db = new sqlite.Database( config.pluginsDb, fn );
8+
}
9+
10+
function auto( fn ) {
11+
return function() {
12+
var that = this,
13+
args = arguments;
14+
15+
if ( db ) {
16+
return fn.apply( that, args );
17+
}
18+
19+
connect(function( error ) {
20+
if ( error ) {
21+
return fn( error );
22+
}
23+
24+
fn.apply( that, args );
25+
});
26+
};
27+
}
28+
29+
var pluginsDb = module.exports = {
30+
getOwner: auto(function( plugin, fn ) {
31+
db.get( "SELECT owner FROM owners WHERE plugin = ?",
32+
[ plugin ], function( error, row ) {
33+
if ( error ) {
34+
return fn( error );
35+
}
36+
37+
if ( !row ) {
38+
return fn( null, null );
39+
}
40+
41+
return fn( null, row.owner );
42+
});
43+
}),
44+
45+
setOwner: auto(function( plugin, owner, fn ) {
46+
db.run( "INSERT INTO owners( plugin, owner ) VALUES( ?, ? )",
47+
[ plugin, owner ], function( error ) {
48+
if ( error ) {
49+
return fn( error );
50+
}
51+
52+
fn( null );
53+
});
54+
}),
55+
56+
getOrSetOwner: auto(function( plugin, owner, fn ) {
57+
pluginsDb.setOwner( plugin, owner, function( error ) {
58+
// successfully set owner (new plugin)
59+
if ( !error ) {
60+
return fn( null, owner );
61+
}
62+
63+
// there is already an owner
64+
if ( error.code === "SQLITE_CONSTRAINT" ) {
65+
return pluginsDb.getOwner( plugin, fn );
66+
}
67+
68+
fn( error );
69+
});
70+
}),
71+
72+
addVersion: auto(function( repoDetails, package, fn ) {
73+
// TODO: verify what data we need to store (build restore functionality to confirm)
74+
var data = JSON.stringify({
75+
git: repoDetails.git,
76+
package: package
77+
});
78+
// TODO: should we track timestamps so we can replay actions since a specific date?
79+
db.run( "INSERT INTO actions( action, data ) VALUES( ?, ? )",
80+
[ "addVersion", data ], function( error ) {
81+
if ( error ) {
82+
return fn( error );
83+
}
84+
85+
fn( null );
86+
});
87+
}),
88+
89+
getAllActions: auto(function( fn ) {
90+
db.all( "SELECT * FROM actions", fn );
91+
})
92+
};

0 commit comments

Comments
 (0)