Skip to content

Commit

Permalink
Merge pull request #475 from opentable/housekeeping
Browse files Browse the repository at this point in the history
Housekeeping
  • Loading branch information
matteofigus committed Apr 26, 2017
2 parents fa6a84a + a5def5d commit 16c9f24
Show file tree
Hide file tree
Showing 10 changed files with 30 additions and 29 deletions.
4 changes: 2 additions & 2 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ module.exports = function(grunt){
grunt.registerTask('sauce', ['karma:sauce-linux', 'karma:sauce-osx', 'karma:sauce-windows']);
grunt.registerTask('test-local', ['eslint', 'mochaTest:unit', 'mochaTest:acceptance', 'karma:local']);
grunt.registerTask('test-local-silent', ['eslint', 'mochaTest:silent', 'karma:local']);
grunt.registerTask('test', ['eslint', 'mochaTest:unit', 'mochaTest:integration', 'mochaTest:acceptance']);
grunt.registerTask('test', ['eslint', 'mochaTest:all']);
grunt.registerTask('git-stage', [
'gitadd:versionFiles',
'gitcommit:version',
Expand All @@ -34,4 +34,4 @@ module.exports = function(grunt){
'gitadd:changelog',
'gitcommit:changelog'
]);
};
};
5 changes: 4 additions & 1 deletion src/registry/domain/components-cache/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ module.exports = (conf, cdn) => {

callback(null, cachedComponentsList);
},

load: (callback) => {

componentsList.getFromJson((jsonErr, jsonComponents) => {
componentsList.getFromDirectories((dirErr, dirComponents) => {
if(dirErr){
Expand All @@ -70,8 +72,9 @@ module.exports = (conf, cdn) => {
if(err){
return returnError('components_cache_refresh', err, callback);
}

cacheDataAndStartPolling(components, callback);
});
}
};
};
};
22 changes: 9 additions & 13 deletions src/registry/domain/repository.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,20 @@ const _ = require('lodash');

const ComponentsCache = require('./components-cache');
const packageInfo = require('../../../package.json');
const requireTemplate = require('../../utils/require-template');
const S3 = require('./s3');
const settings = require('../../resources/settings');
const strings = require('../../resources');
const validator = require('./validators');
const versionHandler = require('./version-handler');
const requireTemplate = require('../../utils/require-template');

module.exports = function(conf){

const cdn = !conf.local && new S3(conf),
repositorySource = conf.local ? 'local repository' : 's3 cdn',
componentsCache = ComponentsCache(conf, cdn);
const cdn = !conf.local && new S3(conf);
const repositorySource = conf.local ? 'local repository' : 's3 cdn';
const componentsCache = ComponentsCache(conf, cdn);

const getFilePath = (component, version, filePath) =>
`${conf.s3.componentsDir}/${component}/${version}/${filePath}`;
const getFilePath = (component, version, filePath) => `${conf.s3.componentsDir}/${component}/${version}/${filePath}`;

const coreTemplates = ['oc-template-jade', 'oc-template-handlebars'];
const templates = _
Expand Down Expand Up @@ -51,8 +50,8 @@ module.exports = function(conf){
getComponents: () => {

const validComponents = fs.readdirSync(conf.path).filter((file) => {
const isDir = fs.lstatSync(path.join(conf.path, file)).isDirectory(),
isValidComponent = isDir ? (fs.readdirSync(path.join(conf.path, file)).filter((file) => file === '_package').length === 1) : false;
const isDir = fs.lstatSync(path.join(conf.path, file)).isDirectory();
const isValidComponent = isDir ? (fs.readdirSync(path.join(conf.path, file)).filter((file) => file === '_package').length === 1) : false;

return isValidComponent;
});
Expand All @@ -69,7 +68,7 @@ module.exports = function(conf){
return callback(format(strings.errors.registry.COMPONENT_NOT_FOUND, componentName, repositorySource));
}

callback(null, [fs.readJsonSync(path.join(conf.path, componentName + '/package.json')).version]);
callback(null, [fs.readJsonSync(path.join(conf.path, `${componentName}/package.json`)).version]);
},
getDataProvider: (componentName) => {
if(componentName === 'oc-client'){
Expand Down Expand Up @@ -174,7 +173,7 @@ module.exports = function(conf){
`https:${conf.s3.path}${getFilePath('oc-client', packageInfo.version, 'src/oc-client.min.map')}`,

getStaticFilePath: (componentName, componentVersion, filePath) =>
repository.getComponentPath(componentName, componentVersion) + (conf.local ? settings.registry.localStaticRedirectorPath : '') + filePath,
`${repository.getComponentPath(componentName, componentVersion)}${(conf.local ? settings.registry.localStaticRedirectorPath : '')}${filePath}`,

getTemplates: () => templates,

Expand Down Expand Up @@ -233,9 +232,6 @@ module.exports = function(conf){
componentsCache.refresh(callback);
});
});
},
saveComponentsInfo: (componentsInfo, callback) => {
cdn.putFileContent(JSON.stringify(componentsInfo), `${conf.s3.componentsDir}/components.json`, true, callback);
}
};

Expand Down
8 changes: 4 additions & 4 deletions src/registry/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const ComponentRoute = require('./routes/component');
const ComponentsRoute = require('./routes/components');
const ComponentInfoRoute = require('./routes/component-info');
const ComponentPreviewRoute = require('./routes/component-preview');
const ListComponentsRoute = require('./routes/list-components');
const IndexRoute = require('./routes');
const PublishRoute = require('./routes/publish');
const settings = require('../resources/settings');
const StaticRedirectorRoute = require('./routes/static-redirector');
Expand All @@ -18,14 +18,14 @@ module.exports.create = function(app, conf, repository){
components: new ComponentsRoute(conf, repository),
componentInfo: new ComponentInfoRoute(conf, repository),
componentPreview: new ComponentPreviewRoute(conf, repository),
listComponents: new ListComponentsRoute(repository),
index: new IndexRoute(repository),
publish: new PublishRoute(repository),
staticRedirector: new StaticRedirectorRoute(repository)
};

if(conf.prefix !== '/'){
app.get('/', (req, res) => { res.redirect(conf.prefix); });
app.get(conf.prefix.substr(0, conf.prefix.length - 1), routes.listComponents);
app.get(conf.prefix.substr(0, conf.prefix.length - 1), routes.index);
}

app.get(conf.prefix + 'oc-client/client.js', routes.staticRedirector);
Expand All @@ -37,7 +37,7 @@ module.exports.create = function(app, conf, repository){
app.put(conf.prefix + ':componentName/:componentVersion', conf.beforePublish, routes.publish);
}

app.get(conf.prefix, routes.listComponents);
app.get(conf.prefix, routes.index);
app.post(conf.prefix, routes.components);

app.get(format('{0}:componentName/:componentVersion{1}', conf.prefix, settings.registry.componentInfoPath), routes.componentInfo);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ module.exports = function(repository){

if(isHtmlRequest && !!res.conf.discovery){

let componentsInfo = [],
componentsReleases = 0;
let componentsInfo = [], componentsReleases = 0;
const stateCounts = {};

async.each(components, (component, callback) => repository.getComponent(component, (err, result) => {
Expand All @@ -42,13 +41,13 @@ module.exports = function(repository){
}), (err) => {
if(err){ return next(err); }

componentsInfo = _.sortBy(componentsInfo, (componentInfo) => componentInfo.name);
componentsInfo = _.sortBy(componentsInfo, 'name');

return res.render('list-components', _.extend(baseResponse, {
return res.render('index', _.extend(baseResponse, {
availableDependencies: res.conf.dependencies,
availablePlugins: res.conf.plugins,
components: componentsInfo,
componentsReleases: componentsReleases,
componentsReleases,
componentsList: _.map(componentsInfo, (component) => {

const state = (!!component.oc && !!component.oc.state) ? component.oc.state : '';
Expand All @@ -60,11 +59,11 @@ module.exports = function(repository){

return {
name: component.name,
state: state
state
};
}),
q: req.query.q || '',
stateCounts: stateCounts
stateCounts
}));
});
} else {
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion src/utils/date-stringify.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

const padZero = require('./pad-zero');

module.exports = function(date){
module.exports = (date) => {
if(date instanceof Date) {
return date.getFullYear() + '/' + padZero(2, date.getMonth() + 1) + '/' + padZero(2, date.getDate()) +
' ' + padZero(2, date.getHours()) + ':' + padZero(2, date.getMinutes()) + ':' + padZero(2, date.getSeconds());
Expand Down
3 changes: 3 additions & 0 deletions tasks/mochaTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,8 @@ module.exports = {
options: {
reporter: 'progress'
}
},
all: {
src: ['test/unit/**/*.js', 'test/integration/**/*.js', 'test/acceptance/**/*.js']
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
const expect = require('chai').expect;
const sinon = require('sinon');

describe('registry : events-handler', () => {
describe('registry : domain : events-handler', () => {

const eventsHandler = require('../../src/registry/domain/events-handler');

Expand Down
File renamed without changes.

0 comments on commit 16c9f24

Please sign in to comment.