Skip to content

Commit

Permalink
feat: [BREAKING_CHANGE] use egg-core (eggjs#44)
Browse files Browse the repository at this point in the history
* feat: [BREAKING_CHANGE] use egg-core

* fix: miss app and config to publish

* deps: upgrade egg-rest

* deps: update using autod

* test: use supertest@2

* Release 0.1.0-beta.3

* feat: enable logrotater by default

* chore: add circleci

* refactor: rename logrotater => logrotator

* feat: remove log-reload event

* test: let examples pass test

* fix: remove more close event

* refactor: extract Symbol as a constant

* deps: upgrade egg-core

* Release 0.1.0-beta.4

* fix: use egg when customEgg is not specified
  • Loading branch information
popomore authored and atian25 committed Aug 18, 2016
1 parent 91ed665 commit 350d0f5
Show file tree
Hide file tree
Showing 83 changed files with 303 additions and 710 deletions.
1 change: 1 addition & 0 deletions .autod.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ module.exports = {
devprefix: '^',
exclude: [
'test/fixtures',
'examples',
],
devdep: [
'autod',
Expand Down
2 changes: 1 addition & 1 deletion lib/core/app/extend/agent.js → app/extend/agent.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

const Singleton = require('../../singleton');
const Singleton = require('../../lib/core/singleton');

// 空的 instrument 返回,用于生产环境,避免每次创建对象
const emptyInstrument = {
Expand Down
12 changes: 6 additions & 6 deletions lib/core/app/extend/application.js → app/extend/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
const http = require('http');
const assert = require('assert');
const accepts = require('accepts');
const Keygrip = require('../../keygrip');
const Service = require('../../base_service');
const view = require('../../view');
const AppWorkerClient = require('../../app_worker_client');
const util = require('../../util');
const Singleton = require('../../singleton');
const Keygrip = require('../../lib/core/keygrip');
const Service = require('../../lib/core/base_service');
const view = require('../../lib/core/view');
const AppWorkerClient = require('../../lib/core/app_worker_client');
const util = require('../../lib/core/util');
const Singleton = require('../../lib/core/singleton');

const KEYS = Symbol('Application#keys');
const APP_CLIENTS = Symbol('Application#appClients');
Expand Down
2 changes: 1 addition & 1 deletion lib/core/app/extend/context.js → app/extend/context.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const delegate = require('delegates');
const jsonpBody = require('jsonp-body');
const ContextLogger = require('egg-logger').EggContextLogger;
const Cookies = require('egg-cookies');
const util = require('../../util');
const util = require('../../lib/core/util');

const LOGGER = Symbol('LOGGER');
const CORE_LOGGER = Symbol('CORE_LOGGER');
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
13 changes: 13 additions & 0 deletions circle.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
machine:
node:
version: 4

dependencies:
override:
- npm i npminstall && node_modules/.bin/npminstall

test:
post:
- node --version
- npm --version
- npm run ci
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
6 changes: 3 additions & 3 deletions lib/core/config/plugin.js → config/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,13 +114,13 @@ module.exports = {

/**
* logger file rotater
* @member {Object} Plugin#logrotater
* @member {Object} Plugin#logrotator
* @property {Boolean} enable - `true` by default
* @since 1.0.0
*/
logrotater: {
logrotator: {
enable: true,
package: 'egg-logrotater',
package: 'egg-logrotator',
},

/**
Expand Down
4 changes: 4 additions & 0 deletions examples/cookie/config/config.default.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
'use strict';

exports.keys = 'my cooo00ooooool keys';
exports.security = {
csrf: false,
ctoken: false,
};
2 changes: 1 addition & 1 deletion examples/cookie/test/index.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

const path = require('path');
const request = require('supertest-as-promised');
const request = require('supertest');
const mm = require('egg-mock');

describe('example cookie test', () => {
Expand Down
4 changes: 4 additions & 0 deletions examples/cookie_session/config/config.default.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
'use strict';

exports.keys = 'my cooo00ooooool keys';
exports.security = {
csrf: false,
ctoken: false,
};
2 changes: 1 addition & 1 deletion examples/cookie_session/test/index.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

const path = require('path');
const request = require('supertest-as-promised');
const request = require('supertest');
const mm = require('egg-mock');

describe('example cookie_session test', () => {
Expand Down
2 changes: 1 addition & 1 deletion examples/helloworld/test/index.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

const path = require('path');
const request = require('supertest-as-promised');
const request = require('supertest');
const mm = require('egg-mock');

describe('example helloworld test', () => {
Expand Down
2 changes: 1 addition & 1 deletion examples/multipart/test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

const assert = require('assert');
const path = require('path');
const request = require('supertest-as-promised');
const request = require('supertest');
const mm = require('egg-mock');
const formstream = require('formstream');
const urllib = require('urllib');
Expand Down
2 changes: 1 addition & 1 deletion examples/static/test/index.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

const path = require('path');
const request = require('supertest-as-promised');
const request = require('supertest');
const mm = require('egg-mock');

describe('example static test', () => {
Expand Down
25 changes: 3 additions & 22 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* Start egg application with cluster mode
* @since 1.0.0
*/
exports.startCluster = require('./lib/cluster/index').startCluster;
exports.startCluster = require('./lib/cluster');

/**
* @member {Application} Egg#Application
Expand All @@ -34,33 +34,14 @@ exports.AgentWorkerClient = require('./lib/core/agent_worker_client');
*/
exports.AppWorkerClient = require('./lib/core/app_worker_client');

/**
* @member {MasterLoader} Egg#MasterLoader
* @since 1.0.0
*/
exports.MasterLoader = require('./lib/core/loader').MasterLoader;

/**
* @member {AppWorkerLoader} Egg#AppWorkerLoader
* @since 1.0.0
*/
exports.AppWorkerLoader = require('./lib/core/loader').AppWorkerLoader;
exports.AppWorkerLoader = require('./lib/loader').AppWorkerLoader;

/**
* @member {AgentWorkerLoader} Egg#AgentWorkerLoader
* @since 1.0.0
*/
exports.AgentWorkerLoader = require('./lib/core/loader').AgentWorkerLoader;

/**
* @member {Service} Egg#Service
* @since 1.0.0
*/
exports.Service = require('./lib/core/base_service');

/**
* @member {Logger} Egg#console
* @see Application#console
* @since 1.0.0
*/
exports.console = require('./lib/core/console');
exports.AgentWorkerLoader = require('./lib/loader').AgentWorkerLoader;
16 changes: 10 additions & 6 deletions lib/agent.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
'use strict';

const path = require('path');
const EggApplication = require('./egg');
const AgentWorkerLoader = require('./core/loader').AgentWorkerLoader;
const AgentWorkerLoader = require('./loader').AgentWorkerLoader;
const AgentWorkerClient = require('./core/agent_worker_client');

const AGENT_CLIENTS = Symbol('Agent#agentClients');
const EGG_LOADER = Symbol.for('egg#loader');
const EGG_PATH = Symbol.for('egg#eggPath');

/**
* Agent 对象,由 AgentWorker 实例化,和 {@link Application} 共用继承 {@link EggApplication} 的 API
Expand All @@ -21,10 +24,7 @@ class Agent extends EggApplication {
options.type = 'agent';
super(options);

// 扩展 Agent API
this.loader.loadAgent();
// 加载自定义 agent.js
this.loader.loadCustomAgent();
this.loader.load();

// 不让 agent 退出
setInterval(() => {}, 24 * 60 * 60 * 1000);
Expand Down Expand Up @@ -85,10 +85,14 @@ class Agent extends EggApplication {
this.coreLogger.error(err);
}

get [Symbol.for('egg#loader')]() {
get [EGG_LOADER]() {
return AgentWorkerLoader;
}

get [EGG_PATH]() {
return path.join(__dirname, '..');
}

close() {
process.removeListener('uncaughtException', this._uncaughtExceptionHandler);
super.close();
Expand Down
13 changes: 10 additions & 3 deletions lib/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,13 @@

'use strict';

const path = require('path');
const graceful = require('graceful');
const EggApplication = require('./egg');
const AppWorkerLoader = require('./core/loader').AppWorkerLoader;
const AppWorkerLoader = require('./loader').AppWorkerLoader;

const EGG_LOADER = Symbol.for('egg#loader');
const EGG_PATH = Symbol.for('egg#eggPath');

/**
* Application 对象,由 AppWorker 实例化,和 {@link Agent} 共用继承 {@link EggApplication} 的 API
Expand All @@ -24,15 +28,18 @@ class Application extends EggApplication {
options = options || {};
options.type = 'application';
super(options);
this.loader.loadApplication();
this.loader.load();
this.on('server', server => this.onServer(server));
}

get [Symbol.for('egg#loader')]() {
get [EGG_LOADER]() {
return AppWorkerLoader;
}

get [EGG_PATH]() {
return path.join(__dirname, '..');
}

onServer(server) {
graceful({
server: [ server ],
Expand Down
18 changes: 3 additions & 15 deletions lib/cluster/index.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,11 @@
/**
* cluster start, start flow:
*
* [startCluster] -> master -> agent_worker -> new [Agent] -> agentWorkerLoader
* `-> app_worker -> new [Application] -> appWorkerLoader
*/

'use strict';

const path = require('path');
const startCluster = require('egg-cluster').startCluster;

/**
* cluster start egg app
* @method Egg#startCluster
* @param {Object} options - see {@link https://github.com/egg/egg-cluster}
* @param {Function} callback - start success callback
*/
exports.startCluster = function(options, callback) {
module.exports = (options, callback) => {
options = options || {};
options.eggPath = path.join(__dirname, '../..');
options.customEgg = options.customEgg || path.join(__dirname, '../..');
console.log(options);
startCluster(options, callback);
};
5 changes: 0 additions & 5 deletions lib/core/console.js

This file was deleted.

67 changes: 0 additions & 67 deletions lib/core/loader/app_worker_loader.js

This file was deleted.

17 changes: 0 additions & 17 deletions lib/core/loader/master_loader.js

This file was deleted.

6 changes: 0 additions & 6 deletions lib/core/logger.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,6 @@ module.exports = function createLoggers(app) {
// 启动成功了,所有日志不输出到终端,
// 除本地环境,本地环境还是可以根据 consoleLevel 控制日志
app.ready(() => app.config.env !== 'local' && loggers.disableConsole());

// 日志切割: 从 logrotater 插件发来的消息
app.messenger.on('log-reload', () => {
loggers.reload('got log-reload message');
loggers.coreLogger.info('[egg:logger] logger reload: got log-reload message from self');
});
loggers.coreLogger.info('[egg:logger] init all loggers with options: %j', loggerConfig);

return loggers;
Expand Down
Loading

0 comments on commit 350d0f5

Please sign in to comment.