Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: rename egg-loader to egg-core #8

Merged
merged 2 commits into from
Aug 15, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# egg-loader
# egg-core

[![NPM version][npm-image]][npm-url]
[![build status][travis-image]][travis-url]
Expand All @@ -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)

Expand Down
28 changes: 14 additions & 14 deletions README.zh-CN.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# egg-loader
# egg-core

[![NPM version][npm-image]][npm-url]
[![build status][travis-image]][travis-url]
Expand All @@ -7,26 +7,26 @@
[![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 文件加载器

## 使用说明

```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',
Expand Down
3 changes: 2 additions & 1 deletion lib/loader/egg_loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion lib/loader/file_loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
6 changes: 3 additions & 3 deletions lib/loader/mixin/config.js
Original file line number Diff line number Diff line change
@@ -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');
Expand Down Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions lib/loader/mixin/extend.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion lib/loader/mixin/middleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
6 changes: 3 additions & 3 deletions lib/loader/mixin/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;
}

Expand Down
12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand All @@ -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",
Expand All @@ -20,9 +20,9 @@
"author": "gxcsoccer <[email protected]>",
"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"
},
Expand Down
11 changes: 7 additions & 4 deletions test/loader/mixin/load_config.test.js
Original file line number Diff line number Diff line change
@@ -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() {
Expand Down Expand Up @@ -62,35 +63,37 @@ 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,
},
},
});
const loader = app.loader;
(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,
},
},
});
const loader = app.loader;
(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() {
Expand Down