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

Make avet build to of egg #30

Merged
merged 36 commits into from
Dec 28, 2017
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
f
  • Loading branch information
okoala committed Dec 28, 2017
commit 83e1535c446bd75847473c230592d786b8754d4d
2 changes: 1 addition & 1 deletion packages/avet-bin/lib/cmd/build.js
Original file line number Diff line number Diff line change
@@ -52,7 +52,7 @@ class BuildCommand extends Command {
const devArgs = this.formatArgs(context);
const options = {
execArgv: context.execArgv,
env: { NODE_ENV: 'production' },
env: { NODE_ENV: 'production', AVET_RUN_ENV: 'build' },
};

yield this.helper.forkNode(this.buildBin, devArgs, options);
6 changes: 3 additions & 3 deletions packages/avet-server/lib/server.js
Original file line number Diff line number Diff line change
@@ -28,9 +28,9 @@ class Server {
this.dev = options.dev;

if (this.dev) {
// require('source-map-support').install({
// hookRequire: true,
// });
require('source-map-support').install({
hookRequire: true,
});
}

this.dir = options.dir;
1 change: 1 addition & 0 deletions packages/avet/index.js
Original file line number Diff line number Diff line change
@@ -9,6 +9,7 @@ exports.buildApp = require('./lib/build');
/**
* Start avet application with cluster mode
*/
exports.startCluster = require('./lib/start-cluster');
exports.Application = require('./lib/application');
exports.Agent = require('./lib/agent');
exports.AppWorkerLoader = require('./lib/core/loader/app_worker_loader');
30 changes: 16 additions & 14 deletions packages/avet/lib/application.js
Original file line number Diff line number Diff line change
@@ -7,7 +7,6 @@ const AvetServer = require('avet-server/lib/server');

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

class Application extends EggApplication {
constructor(...opts) {
@@ -18,19 +17,22 @@ class Application extends EggApplication {
this.addAliases = moduleAlias.addAliases;
this.addPath = moduleAlias.addPath;

this[EGG_READY_TIMEOUT_ENV] = Number.parseInt(
process.env.EGG_READY_TIMEOUT_ENV || 20000,
10
);

const config = getAverConfiguration(this);
this.avetServer = new AvetServer(config);
this.beforeStart(async () => {
// check env is local and need prepare ready
if (this.config.env === 'local') {
await this.avetServer.prepare();
}
});
// this[EGG_READY_TIMEOUT_ENV] = Number.parseInt(
// process.env.EGG_READY_TIMEOUT_ENV || 20000,
// 10
// );

// don't run in build env
if (process.env.AVET_RUN_ENV !== 'build') {
const config = getAverConfiguration(this);
this.avetServer = new AvetServer(config);
this.beforeStart(async () => {
// check env is local and need prepare ready
if (this.config.env === 'local') {
await this.avetServer.prepare();
}
});
}
}

get layouts() {
14 changes: 3 additions & 11 deletions packages/avet/lib/build.js
Original file line number Diff line number Diff line change
@@ -4,16 +4,8 @@ const { getAverConfiguration } = require('./utils');

module.exports = options => {
const app = new Application(options);
const { dir } = app.config.app;
const config = getAverConfiguration(app);

app.ready(err => {
if (err) {
console.error(err);
process.exit(1);
}

const { dir } = app.config.app;
const config = getAverConfiguration(app);

createBuild(dir, config);
});
createBuild(dir, config);
};
11 changes: 11 additions & 0 deletions packages/avet/lib/start-cluster.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
const egg = require('./core/egg');
const path = require('path');

const { startCluster } = egg;
const EGG_PATH = path.dirname(__dirname);

module.exports = function(options, callback) {
options = options || {};
options.framework = EGG_PATH;
startCluster(options, callback);
};