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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
Next Next commit
feat: new 2.x
  • Loading branch information
czy88840616 committed Aug 31, 2020
commit 3af2cd155f56a518698432e889e47f706b0612b3
9 changes: 0 additions & 9 deletions .githooks/pre-commit/filter.sh

This file was deleted.

6 changes: 0 additions & 6 deletions .prettierrc

This file was deleted.

3 changes: 3 additions & 0 deletions .prettierrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
...require('mwts/.prettierrc.json')
}
45 changes: 5 additions & 40 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,17 @@
"description": "a web framework for complex Node.js application",
"version": "1.0.0",
"devDependencies": {
"@types/chai": "^4.2.11",
"@types/lodash": "^4.14.150",
"@types/mocha": "^5.2.7",
"@types/jest": "^26.0.10",
"@types/node": "^10.17.21",
"autocannon": "^2.4.1",
"chalk": "^3.0.0",
"debug": "^4.1.1",
"eslint": "^6.1.0",
"gh-pages": "^2.2.0",
"git-hooks": "^1.1.10",
"jest": "^26.4.0",
"lerna": "^3.20.2",
"lerna-relinker": "^1.4.0",
"node-ab": "0.0.6",
"mwts": "^1.0.5",
"opencollective": "^1.0.3",
"opencollective-postinstall": "^2.0.2",
"rimraf": "^3.0.2",
"tree-kill": "^1.2.2",
"tslint": "^5.20.1",
"tslint-no-unused-expression-chai": "^0.1.4",
"ts-jest": "^26.2.0",
"typescript": "^3.8.3",
"vuepress": "^0.14.11"
},
Expand Down Expand Up @@ -60,38 +52,11 @@
"url": "http://github.com/midwayjs/midway.git"
},
"engines": {
"node": ">= 8.2.1"
"node": ">= 8.0.0"
},
"license": "MIT",
"collective": {
"type": "opencollective",
"url": "https://opencollective.com/midway"
},
"nyc": {
"include": [
"packages/**/src/*.ts",
"packages/**/src/**/*.ts",
"packages/midway-bin/lib/*.js",
"packages/midway-init/lib/*.js"
],
"exclude": [
"**/typings",
"**/*.d.ts",
"**/dist",
"**/test",
"**/src/domain.ts",
"**/src/interface.ts",
"packages/midway-web/src/baseController.ts",
"packages/midway-web/src/decorators/babel.ts"
],
"extension": [
".ts",
".js"
],
"reporter": [
"json",
"html"
],
"all": true
}
}
4 changes: 4 additions & 0 deletions packages/bootstrap/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports = {
preset: 'ts-jest',
testEnvironment: 'midway-bin/jest/env.js',
};
35 changes: 35 additions & 0 deletions packages/bootstrap/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"name": "@midwayjs/bootstrap",
"version": "1.0.0",
"description": "midwayjs bootstrap",
"main": "dist/index",
"typings": "dist/index.d.ts",
"scripts": {
"build": "midway-bin build -c",
"lint": "../../node_modules/.bin/tslint --format prose -c ../../tslint.json --fix 'src/**/*.ts' 'test/**/*.ts'",
"test": "../../node_modules/.bin/jest",
"cov": "midway-bin clean && midway-bin cov --ts",
"autod": "midway-bin autod"
},
"keywords": [
"midway",
"IoC",
"bootstrap"
],
"files": [
"src",
"dist"
],
"license": "MIT",
"devDependencies": {
"midway-bin": "^2.0.15"
},
"dependencies": {
"@midwayjs/core": "^2.1.4"
},
"author": "Harry Chen <czy88840616@gmail.com>",
"repository": {
"type": "git",
"url": "http://github.com/midwayjs/midway.git"
}
}
92 changes: 92 additions & 0 deletions packages/bootstrap/src/bootstrap.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
import { IMidwayFramework, IMidwayBootstrapOptions } from '@midwayjs/core';
import { join } from 'path';

function isTypeScriptEnvironment() {
const TS_MODE_PROCESS_FLAG: string = process.env.MIDWAY_TS_MODE;
if ('false' === TS_MODE_PROCESS_FLAG) {
return false;
}
// eslint-disable-next-line node/no-deprecated-api
return TS_MODE_PROCESS_FLAG === 'true' || !!require.extensions['.ts'];
}

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

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

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

public async init() {
this.appDir = this.globalOptions.baseDir;
await Promise.all(
this.getActions('initialize', {
...this.globalOptions,
baseDir: this.getBaseDir(),
appDir: this.appDir,
})
);
}

public getActions(action: string, args?): any[] {
return this.bootstrapItems.map(item => {
return item[action](args);
});
}

private getBaseDir() {
if (isTypeScriptEnvironment()) {
return join(this.appDir, 'src');
} else {
return join(this.appDir, 'dist');
}
}
}

export class Bootstrap {
static starter: BootstrapStarter;

/**
* set global configuration for midway
* @param configuration
*/
static configure(configuration: Partial<IMidwayBootstrapOptions>) {
this.getStarter().configure(configuration);
return this;
}

/**
* load midway framework unit
* @param unit
*/
static load(unit: IMidwayFramework) {
this.getStarter().pushFrameworkUnit(unit);
return this;
}

private static getStarter() {
if (!this.starter) {
this.starter = new BootstrapStarter();
}
return this.starter;
}

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

static async stop() {
return Promise.all(this.getStarter().getActions('stop')).catch(
console.error
);
}
}
1 change: 1 addition & 0 deletions packages/bootstrap/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { Bootstrap } from './bootstrap';
56 changes: 56 additions & 0 deletions packages/bootstrap/test/index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import { Bootstrap } from '../src';
import {
IMidwayFramework,
IMidwayApplication,
IMidwayBootstrapOptions,
IMidwayContainer,
} from '@midwayjs/core';

class TestFrameworkUnit implements IMidwayFramework {
options;
app;
configure(options: any): TestFrameworkUnit {
this.options = options;
return this;
}
async run(): Promise<any> {
return 'bbb';
}

async stop(): Promise<void> {
}

async initialize(options: IMidwayBootstrapOptions): Promise<void> {
this.app = { bbb: 22 };
}
getApplicationContext(): IMidwayContainer {
return { a: 1 } as any;
}
getApplication(): IMidwayApplication {
return this.app;
}
}

describe('/test/index.test.ts', () => {
it('create case', async () => {
const bootstrap = Bootstrap.configure({
baseDir: __dirname,
});

expect(bootstrap);

const framework = new TestFrameworkUnit().configure({
port: 7001,
});
await bootstrap.load(framework).run();
expect(framework);
expect(framework.getApplicationContext()).toStrictEqual({ a: 1 });
expect(framework.app).toStrictEqual({ bbb: 22 });
expect(framework.getApplication()).toStrictEqual({ bbb: 22 });


// Bootstrap.configure({})
// .load(new TestFrameworkUnit().configure({port: 7001}))
// .run();
});
});
11 changes: 11 additions & 0 deletions packages/bootstrap/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"extends": "../../tsconfig.json",
"compileOnSave": true,
"compilerOptions": {
"rootDir": "src",
"outDir": "dist"
},
"include": [
"./src/**/*.ts"
]
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"main": "dist/index",
"typings": "dist/index.d.ts",
"scripts": {
"build": "npm run lint && midway-bin build -c",
"build": "midway-bin build -c",
"lint": "../../node_modules/.bin/tslint --format prose -c ../../tslint.json --fix 'src/**/*.ts' 'test/**/*.ts'",
"test": "npm run lint && midway-bin clean && NODE_ENV=test midway-bin test --ts",
"cov": "midway-bin clean && midway-bin cov --ts",
Expand All @@ -31,9 +31,9 @@
},
"dependencies": {
"@midwayjs/decorator": "^2.1.4",
"@midwayjs/glob": "^1.0.2",
"debug": "^4.1.1",
"extend2": "^1.0.0",
"globby": "^10.0.1",
"is-type-of": "^1.2.1",
"lodash.assign": "^4.2.0",
"lodash.clonedeep": "^4.5.0",
Expand Down
69 changes: 69 additions & 0 deletions packages/core/src/baseFramework.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import {
IConfigurationOptions,
IMidwayApplication,
IMidwayBootstrapOptions,
IMidwayContainer,
IMidwayFramework,
} from './interface';
import { ContainerLoader } from './';

export abstract class BaseFramework<T extends IConfigurationOptions>
implements IMidwayFramework {
protected baseDir: string;
protected appDir: string;
protected configurationOptions: T;
protected containerLoader: ContainerLoader;

public configure(options: T): IMidwayFramework {
this.configurationOptions = options;
return this;
}

public async initialize(
options: Partial<IMidwayBootstrapOptions>
): Promise<void> {
this.baseDir = options.baseDir;
this.appDir = options.appDir;

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

const applicationContext = this.containerLoader.getApplicationContext();
applicationContext.registerObject('baseDir', this.baseDir);
applicationContext.registerObject('appDir', this.appDir);
// 如果没有关闭autoLoad 则进行load
this.containerLoader.loadDirectory(options);
await this.containerLoader.refresh();
await this.afterInitialize(options);
}

public getApplicationContext(): IMidwayContainer {
return this.containerLoader.getApplicationContext();
}

public getConfiguration(key?: string): any {
return this.getApplicationContext()
.getConfigService()
.getConfiguration(key);
}

public getCurrentEnvironment() {
return this.getApplicationContext()
.getEnvironmentService()
.getCurrentEnvironment();
}

public abstract getApplication(): IMidwayApplication;

public abstract run(): Promise<void>;

public abstract stop(): Promise<void>;

protected abstract async afterInitialize(
options: Partial<IMidwayBootstrapOptions>
): Promise<void>;
}
Loading