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: complete 2.x beta #630

Merged
merged 50 commits into from
Sep 13, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
3af2cd1
feat: new 2.x
czy88840616 Aug 31, 2020
4645dd0
fix: fix compatibility
czy88840616 Aug 31, 2020
eed4e41
test: pass all case and remove midway-web
czy88840616 Sep 1, 2020
eb6e973
chore: update test
czy88840616 Sep 1, 2020
6d52116
chore: add test node_modules
czy88840616 Sep 2, 2020
2ddfc79
chore: add test node_modules
czy88840616 Sep 2, 2020
53f4be0
test: fix core test
czy88840616 Sep 2, 2020
8da2d01
test: add public dir
czy88840616 Sep 2, 2020
4094e5c
chore: add decorator interface
czy88840616 Sep 3, 2020
0a3a73e
chore: remove eslint
czy88840616 Sep 3, 2020
3f466d8
feat: add koa/express
czy88840616 Sep 3, 2020
21c70f0
refactor: change test framework to jest
czy88840616 Sep 5, 2020
97b6538
refactor: remove definition and add web for koa
czy88840616 Sep 5, 2020
afe304a
test: reactor new faas framework and test passed
czy88840616 Sep 5, 2020
623eba2
refactor: export Framework
czy88840616 Sep 5, 2020
185a0ab
chore: update jest file
czy88840616 Sep 5, 2020
a9cae29
fix: add ignore files
czy88840616 Sep 5, 2020
855c24d
refactor: add express framework
czy88840616 Sep 6, 2020
25a8b73
fix: fix middleware typings
czy88840616 Sep 7, 2020
5bfa5b5
test: add case for @midwayjs/express
czy88840616 Sep 7, 2020
171ae3f
refactor: remove register config
czy88840616 Sep 7, 2020
7d44743
feat: support egg-scripts
czy88840616 Sep 7, 2020
abbaafc
type: update typing with generateController
czy88840616 Sep 8, 2020
c16cc59
chore: fix conflicts
czy88840616 Sep 8, 2020
81e32f5
fix: support cluster
czy88840616 Sep 8, 2020
696d419
feat: support egg-cluster start
czy88840616 Sep 8, 2020
b35305e
chore: update
czy88840616 Sep 9, 2020
8547e57
feat: update midway-bin
czy88840616 Sep 9, 2020
5196196
refactor: remove egg-bin
czy88840616 Sep 9, 2020
472db8f
revert midway-bin
czy88840616 Sep 11, 2020
efeac17
revert midway-bin
czy88840616 Sep 11, 2020
b9a8f4d
feat: add socket.io
czy88840616 Sep 12, 2020
05eb246
test: add case for socket
czy88840616 Sep 12, 2020
f0c8f3f
test: add case for socket.io
czy88840616 Sep 12, 2020
ec0ec6e
feat: add createHttpRequest method
czy88840616 Sep 13, 2020
b240982
chore: remove empty
czy88840616 Sep 13, 2020
4e7c353
fix: fix dep
czy88840616 Sep 13, 2020
5b5354c
chore: ignore err test
czy88840616 Sep 13, 2020
e4c8b60
chore: ignore err test
czy88840616 Sep 13, 2020
f233844
fix: remove setup file
czy88840616 Sep 13, 2020
0c79b2e
fix: remove old test
czy88840616 Sep 13, 2020
76f6ad1
test: add timeout for egg
czy88840616 Sep 13, 2020
6529c1c
test: add timeout for egg
czy88840616 Sep 13, 2020
d97347a
fix: fix arg
czy88840616 Sep 13, 2020
b0bf150
chore: skip
czy88840616 Sep 13, 2020
c459b45
chore: upgrade test
czy88840616 Sep 13, 2020
47526c9
chore: set global timeout
czy88840616 Sep 13, 2020
c42c26c
chore: set global timeout
czy88840616 Sep 13, 2020
ea87e84
chore: set global timeout
czy88840616 Sep 13, 2020
0c3c16f
doc: home (#636)
czy88840616 Sep 13, 2020
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
test: pass all case and remove midway-web
  • Loading branch information
czy88840616 committed Sep 1, 2020
commit eed4e41708a06bed289fc79879adbc59fb11d804
24 changes: 19 additions & 5 deletions packages/bootstrap/src/bootstrap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,19 @@ function isTypeScriptEnvironment() {
return TS_MODE_PROCESS_FLAG === 'true' || !!require.extensions['.ts'];
}

class BootstrapStarter {
export class BootstrapStarter {
private appDir;
private bootstrapItems: IMidwayFramework[] = [];
private globalOptions: Partial<IMidwayBootstrapOptions>;

public configure(options: Partial<IMidwayBootstrapOptions>) {
this.globalOptions = options;
return this;
}

public pushFrameworkUnit(unit: IMidwayFramework) {
public load(unit: IMidwayFramework) {
this.bootstrapItems.push(unit);
return this;
}

public async init() {
Expand All @@ -34,6 +36,18 @@ class BootstrapStarter {
);
}

public async run() {
await Promise.all(
this.getActions('run', {})
);
}

public async stop() {
await Promise.all(
this.getActions('stop', {})
);
}

public getActions(action: string, args?): any[] {
return this.bootstrapItems.map(item => {
return item[action](args);
Expand Down Expand Up @@ -66,7 +80,7 @@ export class Bootstrap {
* @param unit
*/
static load(unit: IMidwayFramework) {
this.getStarter().pushFrameworkUnit(unit);
this.getStarter().load(unit);
return this;
}

Expand All @@ -79,13 +93,13 @@ export class Bootstrap {

static async run() {
await this.getStarter().init();
return Promise.all(this.getStarter().getActions('run')).catch(
return this.getStarter().run().catch(
console.error
);
}

static async stop() {
return Promise.all(this.getStarter().getActions('stop')).catch(
return this.getStarter().stop().catch(
console.error
);
}
Expand Down
2 changes: 1 addition & 1 deletion packages/bootstrap/src/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export { Bootstrap } from './bootstrap';
export { Bootstrap, BootstrapStarter } from './bootstrap';
37 changes: 32 additions & 5 deletions packages/core/src/baseFramework.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { ContainerLoader } from './';

export abstract class BaseFramework<T extends IConfigurationOptions>
implements IMidwayFramework {
protected isTsMode = true;
protected baseDir: string;
protected appDir: string;
protected configurationOptions: T;
Expand All @@ -25,22 +26,35 @@ export abstract class BaseFramework<T extends IConfigurationOptions>
this.baseDir = options.baseDir;
this.appDir = options.appDir;

await this.beforeInitialize(options);

this.containerLoader = new ContainerLoader({
baseDir: this.baseDir,
isTsMode: true,
isTsMode: this.isTsMode,
preloadModules: options.preloadModules || [],
});

/**
* initialize containerLoader and initialize ioc container instance
*/
await this.beforeInitialize(options);
this.containerLoader.initialize();

/**
* load directory and bind files to ioc container
*/
await this.beforeDirectoryLoad(options);
const applicationContext = this.containerLoader.getApplicationContext();
applicationContext.registerObject('baseDir', this.baseDir);
applicationContext.registerObject('appDir', this.appDir);
// 如果没有关闭autoLoad 则进行load
this.containerLoader.loadDirectory(options);
await this.afterDirectoryLoad(options);

/**
* start to load configuration and lifeCycle
*/
await this.containerLoader.refresh();
await this.afterInitialize(options);

}

public getApplicationContext(): IMidwayContainer {
Expand All @@ -63,11 +77,24 @@ export abstract class BaseFramework<T extends IConfigurationOptions>

public abstract run(): Promise<void>;

public abstract stop(): Promise<void>;
public async stop(): Promise<void> {
await this.beforeStop();
await this.containerLoader.stop();
}

protected async beforeStop(): Promise<void> {}

protected async beforeInitialize(
options: Partial<IMidwayBootstrapOptions>
): Promise<void> {}
): Promise<void> {};

protected async beforeDirectoryLoad(
options: Partial<IMidwayBootstrapOptions>
): Promise<void> {};

protected async afterDirectoryLoad(
options: Partial<IMidwayBootstrapOptions>
): Promise<void> {};

protected abstract async afterInitialize(
options: Partial<IMidwayBootstrapOptions>
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,7 @@ export interface IMidwayBootstrapOptions {
disableAutoLoad: boolean;
pattern: string[];
ignore: string[];
isTsMode: boolean;
}

export interface IConfigurationOptions {}
Expand Down
7 changes: 6 additions & 1 deletion packages/core/src/loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export class ContainerLoader {
if (!loadOpts.disableAutoLoad) {
// use baseDir in parameter first
const baseDir = loadOpts.baseDir || this.baseDir;
const defaultLoadDir = this.isTsMode ? [baseDir] : ['app', 'lib'];
const defaultLoadDir = this.isTsMode ? [baseDir] : [];
this.applicationContext.load({
loadDir: (loadOpts.loadDir || defaultLoadDir).map(dir => {
return buildLoadDir(baseDir, dir);
Expand All @@ -91,4 +91,9 @@ export class ContainerLoader {
await this.pluginContext.ready();
await this.applicationContext.ready();
}

async stop() {
await this.pluginContext.stop();
await this.applicationContext.stop();
}
}
3 changes: 2 additions & 1 deletion packages/decorator/src/web/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ export interface ControllerOption {
prefix: string;
routerOptions: {
sensitive?: boolean;
middleware?: KoaMiddlewareParamArray
middleware?: KoaMiddlewareParamArray;
alias?: string[];
};
}

Expand Down
20 changes: 0 additions & 20 deletions packages/midway-web/.autod.conf.js

This file was deleted.

Loading