Skip to content

Commit 7a55bd0

Browse files
committed
Code reorg.
1 parent 523c2d9 commit 7a55bd0

File tree

4 files changed

+344
-297
lines changed

4 files changed

+344
-297
lines changed

src/main.js

Lines changed: 3 additions & 122 deletions
Original file line numberDiff line numberDiff line change
@@ -11,54 +11,6 @@ var semver = require( "semver" ),
1111

1212

1313

14-
function validatePackageJson( package, version ) {
15-
var errors = [];
16-
17-
if ( !package.name ) {
18-
errors.push( "Missing required field: name." );
19-
} else if ( package.name.charAt( 0 ) === "_" || package.name.charAt( 0 ) === "." ) {
20-
errors.push( "Name cannot start with an underscore or dot." );
21-
}
22-
23-
if ( !package.version ) {
24-
errors.push( "Missing required field: version." );
25-
} else if ( package.version !== semver.clean( package.version ) ) {
26-
errors.push( "Package.json version (" + package.version + ") is invalid." );
27-
} else if ( package.version !== semver.clean( version ) ) {
28-
errors.push( "Package.json version (" + package.version + ") does not match tag (" + version + ")." );
29-
}
30-
31-
if ( !package.title ) {
32-
errors.push( "Missing required field: title." );
33-
}
34-
35-
if ( !package.author ) {
36-
errors.push( "Missing required field: author." );
37-
} else if ( !package.author.name ) {
38-
errors.push( "Missing required field: author.name." );
39-
}
40-
41-
if ( !package.licenses ) {
42-
errors.push( "Missing required field: licenses." );
43-
} else if ( !package.licenses.length ) {
44-
errors.push( "There must be at least one license." );
45-
} else if ( package.licenses.filter(function( license ) { return !license.url; }).length ) {
46-
errors.push( "Missing required field: license.url." );
47-
}
48-
49-
if ( !package.dependencies ) {
50-
errors.push( "Missing required field: dependencies." );
51-
} else if ( !package.dependencies.jquery ) {
52-
errors.push( "Missing required dependency: jquery." );
53-
}
54-
55-
return errors;
56-
}
57-
58-
59-
60-
61-
6214
function generatePage( package, fn ) {
6315
template.get( "page", function( error, template ) {
6416
if ( error ) {
@@ -100,11 +52,7 @@ function processPlugin( data, fn ) {
10052
},
10153

10254
function( error ) {
103-
if ( error ) {
104-
return fn( error );
105-
}
106-
107-
fn( null );
55+
fn( error );
10856
}
10957
);
11058
}
@@ -116,35 +64,12 @@ function processVersions( repo, fn ) {
11664
repo.getNewVersions( this );
11765
},
11866

119-
// validate each version
67+
// process the versions
12068
function( error, versions ) {
121-
if ( error ) {
122-
return fn( error );
123-
}
124-
12569
if ( !versions.length ) {
12670
return fn( null );
12771
}
12872

129-
var group = this.group();
130-
versions.forEach(function( version ) {
131-
validateVersion( version, group() );
132-
});
133-
},
134-
135-
// filter to only valid versions
136-
function( error, versions ) {
137-
return versions.filter(function( version ) {
138-
return !!(version && version.package);
139-
});
140-
},
141-
142-
// process the valid versions
143-
function( error, versions ) {
144-
if ( !versions.length ) {
145-
return fn();
146-
}
147-
14873
var group = this.group();
14974
versions.forEach(function( version ) {
15075
processVersion( version.version, version.package, group() );
@@ -189,59 +114,15 @@ function processVersions( repo, fn ) {
189114
wordpress.flush( this );
190115
},
191116

192-
// close connection to WordPress
193117
function( error ) {
194118
if ( error ) {
195119
return fn( error );
196120
}
197121

198-
wordpress.end();
199122
fn( null );
200123
}
201124
);
202125

203-
function validateVersion( version, fn ) {
204-
Step(
205-
// get the package.json
206-
function() {
207-
repo.getPackageJson( version, this );
208-
},
209-
210-
// check if we found a package.json
211-
function( error, package ) {
212-
if ( error ) {
213-
if ( error.userError ) {
214-
// TODO: report error to user
215-
} else {
216-
// TODO: log error for retry
217-
}
218-
return fn( error );
219-
}
220-
221-
if ( !package ) {
222-
return fn( null );
223-
}
224-
225-
return package;
226-
},
227-
228-
// validate package.json
229-
function( error, package ) {
230-
var errors = validatePackageJson( package, version );
231-
232-
if ( errors.length ) {
233-
// TODO: report errors to user
234-
return fn( null );
235-
}
236-
237-
fn( null, {
238-
version: version,
239-
package: package
240-
});
241-
}
242-
);
243-
}
244-
245126
function processVersion( version, package, fn ) {
246127
Step(
247128
// find out who owns this plugin
@@ -419,7 +300,6 @@ function processMeta( repo, fn ) {
419300
}
420301

421302
console.log( "Updated meta for " + plugin );
422-
wordpress.end();
423303
fn( null );
424304
}
425305
);
@@ -433,6 +313,7 @@ processPlugin({
433313
watchers: 25,
434314
forks: 3
435315
}, function( error, data ) {
316+
wordpress.end()
436317
// TODO: log error to file
437318
if ( error ) {
438319
console.log( error, error.stack );

0 commit comments

Comments
 (0)