Skip to content

Commit

Permalink
Use synth-api module
Browse files Browse the repository at this point in the history
Add test coverage reporting to Code Climate
  • Loading branch information
JonAbrams committed Jun 4, 2014
1 parent ac08187 commit 9becc32
Show file tree
Hide file tree
Showing 10 changed files with 27 additions and 337 deletions.
1 change: 1 addition & 0 deletions .gitignore
@@ -1 +1,2 @@
node_modules
coverage
3 changes: 3 additions & 0 deletions .npmignore
@@ -0,0 +1,3 @@
node_modules
test
coverage
2 changes: 2 additions & 0 deletions .travis.yml
Expand Up @@ -3,3 +3,5 @@ node_js:
- "0.10"
notifications:
email: false
env:
- secure: "SqS2nLVAGu9Tdy3ZkYVu0BHBS29Eu6uzdhkv/72HIx8ioVIbO2uSYNWAgedCgCgRYk6FnmEt2U9rKWl3+I20IC6BLfol2+xciwmuyBDCWggdXqYV1gW5j6Fu5ycC/uWqbDYRS5bJzf6auyTJws0z7zt1IWlmdDw9sfWywSdO3Dw="
5 changes: 3 additions & 2 deletions Makefile
@@ -1,4 +1,5 @@
test:
./node_modules/.bin/mocha --reporter list
./node_modules/.bin/istanbul cover ./node_modules/.bin/_mocha -- -u exports -R spec
./node_modules/.bin/codeclimate < coverage/lcov.info

.PHONY: test
.PHONY: test
1 change: 0 additions & 1 deletion lib/frontendRenderer.js
Expand Up @@ -2,7 +2,6 @@ var path = require('path'),
Promise = require('bluebird'),
fs = Promise.promisifyAll( require('fs') ),
jade = require('jade'),
handlers = require('./handlersParser.js').apiHandlers,
assets = require('./assets.js');

exports.index = function (req, res) {
Expand Down
140 changes: 0 additions & 140 deletions lib/handlersParser.js

This file was deleted.

32 changes: 0 additions & 32 deletions lib/utils.js

This file was deleted.

7 changes: 5 additions & 2 deletions package.json
Expand Up @@ -24,15 +24,18 @@
"bluebird": "^1.0.3",
"nopt": "^2.2.0",
"connect": "^2.14.4",
"st": "^0.4.1"
"st": "^0.4.1",
"synth-api": "0.1.0"
},
"devDependencies": {
"mocha": "~1.14.0",
"should": "~2.1.0",
"supertest": "~0.9.0",
"temp": "~0.6.0",
"touch": "0.0.2",
"promised-mongo": "^0.11"
"promised-mongo": "^0.11",
"codeclimate-test-reporter": "0.0.3",
"istanbul": "^0.2.10"
},
"repository": "git://github.com/JonAbrams/synth",
"scripts": {
Expand Down
39 changes: 13 additions & 26 deletions synth.js
@@ -1,4 +1,5 @@
var express = require('express'),
var synthApi = require('synth-api'),
express = require('express'),
_ = require('lodash'),
path = require('path'),
os = require('os'),
Expand All @@ -13,17 +14,19 @@ var md5sum = function (str) {
return crypto.createHash('md5').update(str).digest('hex');
};

var handlersParser = require('./lib/handlersParser.js');
var frontend = require('./lib/frontendRenderer.js');
var assets = require('./lib/assets.js');

var app = express();
var handlers;

var defaultCatchAll = function (req, res) {
res.send(404, { error: 'Resource not found'});
};

/* the main synth init function */
exports = module.exports = function (options) {
options = options || {};
var resourceDir = options.resourceDir || path.join(process.cwd(), 'back/resources');
var defaultResourceDir = path.join(process.cwd(), 'back/resources');
var viewDir = options.viewDir || path.join(process.cwd(), 'front');
var viewEngine = options.viewEngine || 'jade';
if (!!options.production) process.env.NODE_ENV = 'production';
Expand All @@ -34,25 +37,12 @@ exports = module.exports = function (options) {
});

/* On startup, parse all the resource handling modules */
handlersParser.setApiTimeout(options.apiTimeout);
handlers = handlersParser.parse(resourceDir);

/* Tell the express app to listen for each API request handler */
var registerHandler = function (handler) {
app[handler.method]( handler.path, handler.func() );
};
/* Register the custom actions first */
handlers.filter(function (handler) {
return handler.isCustom;
}).forEach(registerHandler);
handlers.filter(function (handler) {
return !handler.isCustom;
}).forEach(registerHandler);

/* Handle API requests */
app.all('/api/*', function (req, res) {
res.send(404, { error: 'Resource not found'});
});
var handlers = synthApi.generateHandlers({
resourceDir: options.resourceDir || defaultResourceDir,
app: options.app || app,
timeout: options.apiTimeout || 5000,
catchAll: options.catchAll || defaultCatchAll
}).handlers;

/* Handle front-end requests for assets */
assets.init();
Expand Down Expand Up @@ -151,9 +141,6 @@ exports.app = app;
// Expose the command-line commands programmatically
exports.commands = require('./lib/commands.js');

// Return the raw express-style handlers
exports.apiHandlers = handlersParser.apiHandlers;

exports.jsFiles = assets.jsFiles;

exports.cssFiles = assets.cssFiles;

0 comments on commit 9becc32

Please sign in to comment.