express-controllers
Advanced tools
Comparing version 0.2.0 to 1.0.0
49
index.js
/*! | ||
* Express - Controllers | ||
* Copyright(c) 2011 Nicholas Penree <drudge@conceited.net> | ||
* Express Controllers | ||
* Copyright(c) 2011-2014 Nicholas Penree <nick@penree.com> | ||
* MIT Licensed | ||
@@ -12,7 +12,8 @@ */ | ||
var express = require('express') | ||
, resource = require('express-resource') | ||
, readdir = require('fs').readdirSync | ||
, join = require('path').join | ||
, extname = require('path').extname | ||
var express = require('express'); | ||
var resource = require('express-resource'); // Monkey patch express | ||
var readdir = require('fs').readdirSync; | ||
var path = require('path'); | ||
var join = path.join; | ||
var extname = require('path').extname; | ||
@@ -22,4 +23,4 @@ /** | ||
* | ||
* This method will create an express resource for all files in your `controllers path` | ||
* setting, defaulting to `'/../../controllers/'`. | ||
* This method will create an express resource for all modules in the | ||
* `controllers path` setting, defaulting to `$CWD/controllers'`. | ||
* @param {Object} Express app | ||
@@ -29,22 +30,18 @@ * @return {Resource} | ||
*/ | ||
module.exports = | ||
express.HTTPServer.prototype.controllers = | ||
express.HTTPSServer.prototype.controllers = function(app){ | ||
var loaded = [] | ||
, self = app || this | ||
, controllerPath = self.set('controllers path') || __dirname + '/../../controllers'; | ||
readdir(controllerPath).forEach(function(file){ | ||
if (file.match(/^.*.js$/ig)){ | ||
var controller = file.replace(extname(file), ''); | ||
loaded.push(controller); | ||
if (typeof self.resource !== 'undefined'){ | ||
loaded[controller] = self.resource(controller, require(join(controllerPath, controller))); | ||
express.application.controllers = function(app) { | ||
var self = app || this; | ||
var defaultPath = path.resolve(join(process.cwd(), 'controllers')); | ||
var controllerPath = self.get('controllers path') || defaultPath; | ||
var onController = function(name) { | ||
if (name.match(/^.*.js$/ig)) { | ||
var controller = name.replace(extname(name), ''); | ||
if (typeof self.resource !== 'undefined') { | ||
self.resource(controller, require(join(controllerPath, controller))); | ||
} | ||
} | ||
}); | ||
return loaded; | ||
}; | ||
readdir(controllerPath).forEach(onController); | ||
return self; | ||
}; |
{ "name": "express-controllers" | ||
, "description": "MVC routing for express" | ||
, "version": "0.2.0" | ||
, "author": "Nicholas Penree <drudge@conceited.net>" | ||
, "description": "Dead simple MVC routing for express" | ||
, "version": "1.0.0" | ||
, "author": "Nicholas Penree <nick@penree.com>" | ||
, "repository" : { | ||
@@ -10,12 +10,11 @@ "type": "git" | ||
, "contributors": [] | ||
, "dependencies": { | ||
"express-resource": ">=0.2.1" | ||
, "dependencies": { | ||
"express-resource": "~1.0.0" | ||
} | ||
, "devDependencies": { | ||
"connect": "1.4.x" | ||
, "express": "2.3.x" | ||
"express": "4.x.x" | ||
} | ||
, "keywords": ["express", "rest", "resource", "mvc", "controller"] | ||
, "main": "index" | ||
, "engines": { "node": ">= 0.2.0" } | ||
, "engines": { "node": ">= 0.8.0" } | ||
} |
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
Non-existent author
Supply chain riskThe package was published by an npm account that no longer exists.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
10984
1
11
182
1
151
0
2
Updatedexpress-resource@~1.0.0