From 36c031bd9e1be300e37efe37ea6c60d33af37fa9 Mon Sep 17 00:00:00 2001 From: popomore Date: Mon, 15 Aug 2016 20:45:05 +0800 Subject: [PATCH 1/2] refactor(logger): improve debug message --- lib/loader/egg_loader.js | 1 + lib/loader/mixin/config.js | 4 ++-- lib/loader/mixin/plugin.js | 4 ++-- test/loader/mixin/load_config.test.js | 11 +++++++---- 4 files changed, 12 insertions(+), 8 deletions(-) diff --git a/lib/loader/egg_loader.js b/lib/loader/egg_loader.js index 9fda0b71..92a195f9 100644 --- a/lib/loader/egg_loader.js +++ b/lib/loader/egg_loader.js @@ -27,6 +27,7 @@ class EggLoader { assert(fs.existsSync(this.options.baseDir), `${this.options.baseDir} not exists`); assert(this.options.app, 'options.app is required'); assert(this.options.logger, 'options.logger is required'); + debug('EggLoader options %j', options); this.app = this.options.app; diff --git a/lib/loader/mixin/config.js b/lib/loader/mixin/config.js index 09cfa790..621dc35b 100644 --- a/lib/loader/mixin/config.js +++ b/lib/loader/mixin/config.js @@ -86,8 +86,8 @@ module.exports = { assert(!config.coreMiddleware, 'Can not define coreMiddleware in app or plugin'); } if (!isApp) { - assert(!config.middleware, 'Can not define middleware in framework or plugin'); - assert(!config.proxy, 'Can not define proxy in framework or plugin'); + assert(!config.middleware, 'Can not define middleware in ' + filepath); + assert(!config.proxy, 'Can not define proxy in ' + filepath); } return config; diff --git a/lib/loader/mixin/plugin.js b/lib/loader/mixin/plugin.js index 35f1a148..249eb088 100644 --- a/lib/loader/mixin/plugin.js +++ b/lib/loader/mixin/plugin.js @@ -105,14 +105,14 @@ module.exports = { // disable the plugin that not match the serverEnv if (env && plugin.env.length && plugin.env.indexOf(env) === -1) { - debug('Disabled %j as env is %j, but got %j', name, plugin.env, env); + debug('Disable %j, as env is %j but got %j', name, plugin.env, env); plugin.enable = false; continue; } // Can't enable the plugin implicitly when it's disabled by application if (appPlugins[name] && !appPlugins[name].enable) { - debug('Disabled %j as disabled by app', name); + debug('Disable %j, as disabled by app', name); continue; } diff --git a/test/loader/mixin/load_config.test.js b/test/loader/mixin/load_config.test.js index 3373a0b3..33c605d2 100644 --- a/test/loader/mixin/load_config.test.js +++ b/test/loader/mixin/load_config.test.js @@ -1,6 +1,7 @@ 'use strict'; const should = require('should'); +const path = require('path'); const utils = require('../../utils'); describe('test/loader/mixin/load_config.test.js', function() { @@ -62,11 +63,12 @@ describe('test/loader/mixin/load_config.test.js', function() { }); it('should throw when plugin define middleware', function() { + const pluginDir = utils.getFilepath('plugin/plugin-middleware'); app = utils.createApp('plugin', { plugins: { middleware: { enable: true, - path: utils.getFilepath('plugin/plugin-middleware'), + path: pluginDir, }, }, }); @@ -74,15 +76,16 @@ describe('test/loader/mixin/load_config.test.js', function() { (function() { loader.loadPlugin(); loader.loadConfig(); - }).should.throw('Can not define middleware in framework or plugin'); + }).should.throw(`Can not define middleware in ${path.join(pluginDir, 'config/config.default.js')}`); }); it('should throw when plugin define proxy', function() { + const pluginDir = utils.getFilepath('plugin/plugin-proxy'); app = utils.createApp('plugin', { plugins: { proxy: { enable: true, - path: utils.getFilepath('plugin/plugin-proxy'), + path: pluginDir, }, }, }); @@ -90,7 +93,7 @@ describe('test/loader/mixin/load_config.test.js', function() { (function() { loader.loadPlugin(); loader.loadConfig(); - }).should.throw('Can not define proxy in framework or plugin'); + }).should.throw(`Can not define proxy in ${path.join(pluginDir, 'config/config.default.js')}`); }); it('should throw when app define coreMiddleware', function() { From 07186a8f1ccdce302c8e03c57ee16d8052828412 Mon Sep 17 00:00:00 2001 From: popomore Date: Mon, 15 Aug 2016 21:59:53 +0800 Subject: [PATCH 2/2] feat: rename egg-loader to egg-core --- README.md | 26 +++++++++++++------------- README.zh-CN.md | 28 ++++++++++++++-------------- lib/loader/egg_loader.js | 2 +- lib/loader/file_loader.js | 2 +- lib/loader/mixin/config.js | 2 +- lib/loader/mixin/extend.js | 4 ++-- lib/loader/mixin/middleware.js | 2 +- lib/loader/mixin/plugin.js | 2 +- package.json | 12 ++++++------ 9 files changed, 40 insertions(+), 40 deletions(-) diff --git a/README.md b/README.md index 246d5588..c6911864 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# egg-loader +# egg-core [![NPM version][npm-image]][npm-url] [![build status][travis-image]][travis-url] @@ -7,18 +7,18 @@ [![Known Vulnerabilities][snyk-image]][snyk-url] [![npm download][download-image]][download-url] -[npm-image]: https://img.shields.io/npm/v/egg-loader.svg?style=flat-square -[npm-url]: https://npmjs.org/package/egg-loader -[travis-image]: https://img.shields.io/travis/eggjs/egg-loader.svg?style=flat-square -[travis-url]: https://travis-ci.org/eggjs/egg-loader -[codecov-image]: https://codecov.io/github/eggjs/egg-loader/coverage.svg?branch=master -[codecov-url]: https://codecov.io/github/eggjs/egg-loader?branch=master -[david-image]: https://img.shields.io/david/eggjs/egg-loader.svg?style=flat-square -[david-url]: https://david-dm.org/eggjs/egg-loader -[snyk-image]: https://snyk.io/test/npm/egg-loader/badge.svg?style=flat-square -[snyk-url]: https://snyk.io/test/npm/egg-loader -[download-image]: https://img.shields.io/npm/dm/egg-loader.svg?style=flat-square -[download-url]: https://npmjs.org/package/egg-loader +[npm-image]: https://img.shields.io/npm/v/egg-core.svg?style=flat-square +[npm-url]: https://npmjs.org/package/egg-core +[travis-image]: https://img.shields.io/travis/eggjs/egg-core.svg?style=flat-square +[travis-url]: https://travis-ci.org/eggjs/egg-core +[codecov-image]: https://codecov.io/github/eggjs/egg-core/coverage.svg?branch=master +[codecov-url]: https://codecov.io/github/eggjs/egg-core?branch=master +[david-image]: https://img.shields.io/david/eggjs/egg-core.svg?style=flat-square +[david-url]: https://david-dm.org/eggjs/egg-core +[snyk-image]: https://snyk.io/test/npm/egg-core/badge.svg?style=flat-square +[snyk-url]: https://snyk.io/test/npm/egg-core +[download-image]: https://img.shields.io/npm/dm/egg-core.svg?style=flat-square +[download-url]: https://npmjs.org/package/egg-core A core Plugable framework based on [koa](https://github.com/koajs/koa) diff --git a/README.zh-CN.md b/README.zh-CN.md index 271da401..2e05120f 100644 --- a/README.zh-CN.md +++ b/README.zh-CN.md @@ -1,4 +1,4 @@ -# egg-loader +# egg-core [![NPM version][npm-image]][npm-url] [![build status][travis-image]][travis-url] @@ -7,18 +7,18 @@ [![Known Vulnerabilities][snyk-image]][snyk-url] [![npm download][download-image]][download-url] -[npm-image]: https://img.shields.io/npm/v/egg-loader.svg?style=flat-square -[npm-url]: https://npmjs.org/package/egg-loader -[travis-image]: https://img.shields.io/travis/eggjs/egg-loader.svg?style=flat-square -[travis-url]: https://travis-ci.org/eggjs/egg-loader -[codecov-image]: https://codecov.io/github/eggjs/egg-loader/coverage.svg?branch=master -[codecov-url]: https://codecov.io/github/eggjs/egg-loader?branch=master -[david-image]: https://img.shields.io/david/eggjs/egg-loader.svg?style=flat-square -[david-url]: https://david-dm.org/eggjs/egg-loader -[snyk-image]: https://snyk.io/test/npm/egg-loader/badge.svg?style=flat-square -[snyk-url]: https://snyk.io/test/npm/egg-loader -[download-image]: https://img.shields.io/npm/dm/egg-loader.svg?style=flat-square -[download-url]: https://npmjs.org/package/egg-loader +[npm-image]: https://img.shields.io/npm/v/egg-core.svg?style=flat-square +[npm-url]: https://npmjs.org/package/egg-core +[travis-image]: https://img.shields.io/travis/eggjs/egg-core.svg?style=flat-square +[travis-url]: https://travis-ci.org/eggjs/egg-core +[codecov-image]: https://codecov.io/github/eggjs/egg-core/coverage.svg?branch=master +[codecov-url]: https://codecov.io/github/eggjs/egg-core?branch=master +[david-image]: https://img.shields.io/david/eggjs/egg-core.svg?style=flat-square +[david-url]: https://david-dm.org/eggjs/egg-core +[snyk-image]: https://snyk.io/test/npm/egg-core/badge.svg?style=flat-square +[snyk-url]: https://snyk.io/test/npm/egg-core +[download-image]: https://img.shields.io/npm/dm/egg-core.svg?style=flat-square +[download-url]: https://npmjs.org/package/egg-core egg 文件加载器 @@ -26,7 +26,7 @@ egg 文件加载器 ```js const app = koa(); -const Loader = require('egg-loader'); +const Loader = require('egg-core'); const loader = new Loader({ baseDir: '/path/to/app', eggPath: '/path/to/framework', diff --git a/lib/loader/egg_loader.js b/lib/loader/egg_loader.js index 92a195f9..c6e70c26 100644 --- a/lib/loader/egg_loader.js +++ b/lib/loader/egg_loader.js @@ -4,7 +4,7 @@ const fs = require('fs'); const path = require('path'); const assert = require('assert'); const isFunction = require('is-type-of').function; -const debug = require('debug')('egg-loader'); +const debug = require('debug')('egg-core'); const FileLoader = require('./file_loader'); const ContextLoader = require('./context_loader'); const loadFile = require('../utils').loadFile; diff --git a/lib/loader/file_loader.js b/lib/loader/file_loader.js index c749a41d..3f97a493 100644 --- a/lib/loader/file_loader.js +++ b/lib/loader/file_loader.js @@ -2,7 +2,7 @@ const assert = require('assert'); const fs = require('fs'); -const debug = require('debug')('egg-loader:loader'); +const debug = require('debug')('egg-core:loader'); const path = require('path'); const globby = require('globby'); const is = require('is-type-of'); diff --git a/lib/loader/mixin/config.js b/lib/loader/mixin/config.js index 621dc35b..d00bf21f 100644 --- a/lib/loader/mixin/config.js +++ b/lib/loader/mixin/config.js @@ -1,6 +1,6 @@ 'use strict'; -const debug = require('debug')('egg-loader:config'); +const debug = require('debug')('egg-core:config'); const fs = require('fs'); const path = require('path'); const extend = require('extend'); diff --git a/lib/loader/mixin/extend.js b/lib/loader/mixin/extend.js index 1c526713..42457d5a 100644 --- a/lib/loader/mixin/extend.js +++ b/lib/loader/mixin/extend.js @@ -3,7 +3,7 @@ const fs = require('fs'); const path = require('path'); const interopRequire = require('interop-require'); -const debug = require('debug')('egg-loader:extend'); +const debug = require('debug')('egg-core:extend'); const utils = require('../../utils'); module.exports = { @@ -91,7 +91,7 @@ module.exports = { try { ext = interopRequire(filepath); } catch (err) { - err.message = `[egg-loader] load file ${require.resolve(filepath)} error: ${err.message}`; + err.message = `[egg-core] load file ${require.resolve(filepath)} error: ${err.message}`; throw err; } diff --git a/lib/loader/mixin/middleware.js b/lib/loader/mixin/middleware.js index bb56c285..a1ee2a5e 100644 --- a/lib/loader/mixin/middleware.js +++ b/lib/loader/mixin/middleware.js @@ -2,7 +2,7 @@ const join = require('path').join; const is = require('is-type-of'); -const debug = require('debug')('egg-loader:middleware'); +const debug = require('debug')('egg-core:middleware'); const inspect = require('util').inspect; module.exports = { diff --git a/lib/loader/mixin/plugin.js b/lib/loader/mixin/plugin.js index 249eb088..c12a0ebb 100644 --- a/lib/loader/mixin/plugin.js +++ b/lib/loader/mixin/plugin.js @@ -2,7 +2,7 @@ const fs = require('fs'); const path = require('path'); -const debug = require('debug')('egg-loader:plugin'); +const debug = require('debug')('egg-core:plugin'); const sequencify = require('../../utils/sequencify'); const loadFile = require('../../utils').loadFile; diff --git a/package.json b/package.json index 8888e13d..51a1e09b 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { - "name": "egg-loader", - "version": "0.0.3", - "description": "egg loader", + "name": "egg-core", + "version": "0.1.0", + "description": "A core Plugable framework based on koa", "main": "index.js", "scripts": { "lint": "eslint lib test *.js", @@ -11,7 +11,7 @@ }, "repository": { "type": "git", - "url": "git+https://github.com/eggjs/egg-loader.git" + "url": "git+https://github.com/eggjs/egg-core.git" }, "keywords": [ "egg", @@ -20,9 +20,9 @@ "author": "gxcsoccer ", "license": "MIT", "bugs": { - "url": "https://github.com/eggjs/egg-loader/issues" + "url": "https://github.com/eggjs/egg-core/issues" }, - "homepage": "https://github.com/eggjs/egg-loader#readme", + "homepage": "https://github.com/eggjs/egg-core#readme", "engines": { "node": ">= 4.0.0" },