Comparing version 0.3.14 to 0.3.15
@@ -220,3 +220,2 @@ var fs = require("fs"); | ||
*/ | ||
var _cache = {}; | ||
global.F = function(name, value, rootPath){ | ||
@@ -226,26 +225,13 @@ if (rootPath === undefined) { | ||
}; | ||
var filename = rootPath + "/" + name + ".json"; | ||
var filePath = rootPath + "/" + name + ".json"; | ||
if (value !== undefined) { | ||
if (value === null) { | ||
if (isFile(filename)) { | ||
fs.unlink(filename, function(){}); | ||
}; | ||
return; | ||
}; | ||
var dir = path.dirname(filename); | ||
mkdir(dir); | ||
_cache[name] = value; | ||
fs.writeFile(filename, JSON.stringify(value), function(){ | ||
chmod(filename); | ||
mkdir(path.dirname(filePath)); | ||
fs.writeFile(filePath, JSON.stringify(value), function(){ | ||
chmod(filePath); | ||
}); | ||
return; | ||
}; | ||
if (_cache[name] !== undefined) { | ||
return _cache[name]; | ||
if (isFile(filePath)) { | ||
return JSON.parse(getFileContent(filePath)); | ||
}; | ||
if (isFile(filename)) { | ||
var data = JSON.parse(getFileContent(filename)); | ||
_cache[name] = data; | ||
return data; | ||
}; | ||
return false; | ||
@@ -252,0 +238,0 @@ } |
@@ -133,2 +133,3 @@ /** | ||
}); | ||
/** | ||
@@ -139,27 +140,38 @@ * run | ||
App.run = function(){ | ||
//命令行调用 | ||
if (APP_MODE) { | ||
if (APP_MODE && App.mode[APP_MODE]) { | ||
return App.mode[APP_MODE](); | ||
}; | ||
return App.mode._default(); | ||
} | ||
/** | ||
* 不同模式下的run | ||
* @type {Object} | ||
*/ | ||
App.mode = { | ||
cli: function(){ | ||
var http = thinkRequire("Http")[APP_MODE](APP_MODE_DATA); | ||
return App.listener(http); | ||
}; | ||
var clusterNums = C('use_cluster'); | ||
//不使用cluster | ||
if (clusterNums === false) { | ||
return App.createServer(); | ||
} | ||
if (clusterNums === 0 || clusterNums === true) { | ||
clusterNums = require('os').cpus().length; | ||
}; | ||
if (cluster.isMaster) { | ||
for (var i = 0; i < clusterNums; i++) { | ||
cluster.fork(); | ||
}, | ||
_default: function(){ | ||
var clusterNums = C('use_cluster'); | ||
//不使用cluster | ||
if (clusterNums === false) { | ||
return App.createServer(); | ||
} | ||
cluster.on('exit', function(worker, code, signal) { | ||
console.log('worker ' + worker.process.pid + ' died'); | ||
process.nextTick(function(){ | ||
if (clusterNums === 0 || clusterNums === true) { | ||
clusterNums = require('os').cpus().length; | ||
}; | ||
if (cluster.isMaster) { | ||
for (var i = 0; i < clusterNums; i++) { | ||
cluster.fork(); | ||
} | ||
cluster.on('exit', function(worker, code, signal) { | ||
console.log('worker ' + worker.process.pid + ' died'); | ||
process.nextTick(function(){ | ||
cluster.fork(); | ||
}); | ||
}); | ||
}); | ||
}else { | ||
App.createServer(); | ||
}else { | ||
App.createServer(); | ||
} | ||
} | ||
@@ -211,3 +223,3 @@ } | ||
}) | ||
}else if (http.res) {};{ | ||
}else if (http.res) { | ||
//显示默认的错误页 | ||
@@ -214,0 +226,0 @@ promise = promise.catch(function(err){ |
@@ -363,3 +363,3 @@ var util = require('util'); | ||
}; | ||
options.modal = this.name; | ||
options.model = this.name; | ||
return promise.then(function(fields){ | ||
@@ -685,9 +685,11 @@ // 字段类型验证 | ||
var self = this; | ||
var parsedOptions = {}; | ||
return this.parseOptions(options, { | ||
limit: 1 | ||
}).then(function(options){ | ||
return self.db.select(options).then(function(data){ | ||
var result = data[0] ? data[0] : {}; | ||
return self._afterFind(result, options); | ||
}) | ||
parsedOptions = options; | ||
return self.db.select(options); | ||
}).then(function(data){ | ||
var result = data[0] ? data[0] : {}; | ||
return self._afterFind(result, parsedOptions); | ||
}) | ||
@@ -710,6 +712,8 @@ }, | ||
var self = this; | ||
var parsedOptions = {}; | ||
return this.parseOptions(options).then(function(options){ | ||
parsedOptions = options; | ||
return self.db.select(options); | ||
}).then(function(result){ | ||
return self._afterSelect(result, options); | ||
return self._afterSelect(result, parsedOptions); | ||
}); | ||
@@ -812,3 +816,3 @@ }, | ||
* 解析SQL语句 | ||
* @return {[type]} [description] | ||
* @return promise [description] | ||
*/ | ||
@@ -858,2 +862,5 @@ parseSql: function(sql, parse){ | ||
options: function(options){ | ||
if (options === true) { | ||
return this._options; | ||
}; | ||
this._options = options; | ||
@@ -860,0 +867,0 @@ return this; |
@@ -129,2 +129,13 @@ //自动加载进行识别的路径 | ||
C(require(THINK_PATH + "/Conf/debug.js")); | ||
//debug下自定义状态的配置 | ||
var status = C('app_status'); | ||
if (status) { | ||
if (isFile(CONF_PATH + "/" + status + '.js')) { | ||
C(require(CONF_PATH + "/" + status + ".js")); | ||
}; | ||
}else{ | ||
if (isFile(CONF_PATH + '/debug.js')) { | ||
C(require(CONF_PATH + '/debug.js')); | ||
}; | ||
} | ||
if (APP_MODE) { | ||
@@ -138,3 +149,3 @@ var modeFiles = [ | ||
var conf = require(file); | ||
var key = APP_MODE + "_key"; | ||
var key = APP_MODE + "_debug"; | ||
if (conf[key]) { | ||
@@ -146,13 +157,2 @@ C(conf[key]); | ||
}; | ||
//debug下自定义状态的配置 | ||
var status = C('app_status'); | ||
if (status) { | ||
if (isFile(CONF_PATH + "/" + status + '.js')) { | ||
C(require(CONF_PATH + "/" + status + ".js")); | ||
}; | ||
}else{ | ||
if (isFile(CONF_PATH + '/debug.js')) { | ||
C(require(CONF_PATH + '/debug.js')); | ||
}; | ||
} | ||
}, | ||
@@ -159,0 +159,0 @@ /** |
{ | ||
"name": "thinkjs", | ||
"description": "thinkphp web framework for nodejs", | ||
"version": "0.3.14", | ||
"version": "0.3.15", | ||
"author": { | ||
@@ -6,0 +6,0 @@ "name": "welefen", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
191579
5727