Comparing version 0.4.2 to 0.4.3
63
index.js
@@ -11,9 +11,43 @@ var path = require('path'); | ||
var larkMVC = function(options, lark){ | ||
var path = (!options || !options.path) ? 'models': options.path | ||
if (!options || !options.path) { | ||
var _path = 'models' | ||
}else{ | ||
var _path = options.path | ||
} | ||
if (process.mainModule) { | ||
_path = path.join(path.dirname(process.mainModule.filename), _path); | ||
} | ||
if (_path[_path.length - 1] !== '/') { | ||
_path += '/'; | ||
} | ||
rd.eachFileFilterSync(_path, /\.js$/, function (file) { | ||
if (0 !== file.indexOf(_path)) { | ||
throw new Error("File path " + file + " not expected, should be under " + _path); | ||
} | ||
var filename = path.basename(file) | ||
if (filename && filename[0] === '.') { | ||
return; | ||
} | ||
var relativePath = file.slice(_path.length); | ||
var _pathsplit = relativePath.split('/'); | ||
if (_pathsplit.length <= 1) { | ||
throw new Error('Invalid model path : ' + _path); | ||
} | ||
var filename = _pathsplit[_pathsplit.length - 1]; | ||
_pathsplit[_pathsplit.length - 1] = path.basename(filename, path.extname(filename)); | ||
rd.eachFileFilterSync(path, /\.js$/, function (file) { | ||
var func = require(file) | ||
if (func instanceof Function){ | ||
func(layerproxy, lark) | ||
var modelproxy = createModel(layerproxy, _pathsplit); | ||
var model = require(file); | ||
if (model instanceof Function) { | ||
return model(layerproxy, lark); | ||
} | ||
else if (model instanceof Object && !Array.isArray(model)) { | ||
for (var property in model) { | ||
if (!!modelproxy[property]) { | ||
throw new Error('Property ' + property + ' in mvc.xxx in use!'); | ||
} | ||
modelproxy[property] = model[property]; | ||
} | ||
} | ||
}); | ||
@@ -26,4 +60,23 @@ return function*(next) { | ||
function createModel (layerproxy, _pathsplit, type) { | ||
var type = type || _pathsplit.shift(); | ||
var name = _pathsplit.join('/'); | ||
switch (type) { | ||
case 'dao' : | ||
type = 'daoService'; | ||
break; | ||
case 'dataServices' : | ||
type = 'dataService'; | ||
break; | ||
case 'pageServices' : | ||
type = 'pageService'; | ||
break; | ||
default : | ||
throw new Error('Unknown model type ' + type); | ||
} | ||
return layerproxy[type].create(name); | ||
} | ||
var output = layerproxy; | ||
output.middleware = larkMVC | ||
module.exports = output |
{ | ||
"name": "lark-mvc", | ||
"version": "0.4.2", | ||
"version": "0.4.3", | ||
"description": "MVC for building web server with lark.js", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
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
16172
313
1