* allow services to export >1 classes
This change to loadServiceClasses() allows us to define
services which either export a single service class e.g:
module.exports = class Cdnjs extends BaseService {
//...
}
or more than one. e.g:
module.exports = {
GemVersion,
GemDownloads,
GemOwner,
GemRank,
}
* refactor ruby gem badges
- move badge code to service classes
- throw exceptions for errors
- use let and const
- change tests to expect 'downloads' label for error badges
- general tidying
* fix typo in tests
* Don't always use class name in example label
This allows (for example) GemVersion and GemDownloads
both to use the example label 'Gem'
38 lines
856 B
JavaScript
38 lines
856 B
JavaScript
'use strict';
|
|
|
|
const glob = require('glob');
|
|
|
|
// Match modules with the same name as their containing directory.
|
|
// e.g. services/appveyor/appveyor.js
|
|
const serviceRegex = /\/services\/(.*)\/\1\.js$/;
|
|
|
|
function loadServiceClasses() {
|
|
// New-style services
|
|
const services = glob.sync(`${__dirname}/**/*.js`)
|
|
.filter(path => serviceRegex.test(path))
|
|
.map(path => require(path));
|
|
|
|
const serviceClasses = [];
|
|
services.forEach(service => {
|
|
if (typeof service === 'function') {
|
|
serviceClasses.push(service);
|
|
} else {
|
|
for (const serviceClass in service) {
|
|
serviceClasses.push(service[serviceClass]);
|
|
}
|
|
}
|
|
});
|
|
|
|
return serviceClasses;
|
|
}
|
|
|
|
function loadTesters() {
|
|
return glob.sync(`${__dirname}/**/*.tester.js`)
|
|
.map(path => require(path));
|
|
}
|
|
|
|
module.exports = {
|
|
loadServiceClasses,
|
|
loadTesters,
|
|
};
|