Skip to content

Commit

Permalink
类型调整优化
Browse files Browse the repository at this point in the history
  • Loading branch information
yafoo committed Feb 22, 2024
1 parent cac5614 commit abcdf54
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 8 deletions.
6 changes: 3 additions & 3 deletions jj.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
/**
* jj.js核心库<br/>
* {App, Controller, Db, Model, Pagination, View, Logger, Cookie, Response, Upload, Url, Middleware, Cache, Context, View, utils}
* {App, Cache, Context, Controller, Cookie, Ctx, Db, Logger, Middleware, Model, Pagination, Response, Upload, Url, View, utils}
* @module core
* @type {import('./lib/types').Core}
* @type {import('./types').Core}
*/
module.exports = new Proxy({}, {
get: (target, prop) => {
if(prop in target || typeof prop == 'symbol' || prop == 'inspect'){
if(prop in target || typeof prop == 'symbol' || ['inspect', 'router', 'run', 'types'].includes(prop)) {
return target[prop];
}
prop = prop.toLowerCase();
Expand Down
8 changes: 8 additions & 0 deletions lib/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class App extends Koa
{
/**
* @override
* @param {...any} args - listen(port, ip, callback(err){})
*/
listen(...args) {
// exception
Expand Down Expand Up @@ -45,6 +46,13 @@ class App extends Koa
// router
this.use(router.routes()).use(router.allowedMethods());

// types
if(cfg_app.app_debug) {
if(require('./utils/fs').isFileSync(path.join(cfg_app.base_dir, 'jsconfig.json'))) {
require('./types')();
}
}

// server
return super.listen(...args);
}
Expand Down
6 changes: 3 additions & 3 deletions lib/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ const app = {
common_app: 'common', // 公共应用,存放公共模型及逻辑
controller_folder: 'controller', //控制器目录名

static_dir: '', // 静态文件目录,相对于应用根目录,为空或false时,关闭静态访问
static_dir: '', // 静态文件目录,相对于应用根目录,为空时,关闭静态访问

koa_body: null // koa-body配置参数,为''、null、false时,关闭koa-body
koa_body: null // koa-body配置参数,为null或空时,关闭koa-body
}

const view = {
Expand All @@ -40,7 +40,7 @@ const db = {
}

const log = {
log_level: ['app', 'error'], // [app, error, warning, info, debug, http, sql]
log_level: ['system', 'error'], // [system, error, warning, info, debug, http, sql]
log_handle: function(level, ...args) {console.log(`[${format('YY-mm-dd HH:ii:ss')}] [${level}]`, ...args.map(msg => typeof msg == 'string' ? msg : JSON.stringify(msg)));}
}

Expand Down
4 changes: 2 additions & 2 deletions types.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@
* @property {string} [default_action=index] - 默认方法
* @property {string} [common_app=common] - 公共应用,存放公共模型及逻辑
* @property {string} [controller_folder=controller] - 控制器目录名
* @property {(string|boolean)} [static_dir=''] - 静态文件目录,相对于应用根目录,为空或false时,关闭静态访问
* @property {(string|boolean|null|object)} [koa_body=null] - koa-body配置参数,为''、null、false时,关闭koa-body
* @property {string} [static_dir=''] - 静态文件目录,相对于应用根目录,为空时,关闭静态访问
* @property {?object} [koa_body=null] - koa-body配置参数,为null或空时,关闭koa-body
* @property {string} [base_dir] - 应用根目录(会自动计算)
*/

Expand Down

0 comments on commit abcdf54

Please sign in to comment.