-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support specific framework & plugin in scanner (#158)
- Loading branch information
Showing
29 changed files
with
383 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"name": "application-specific" | ||
} |
1 change: 1 addition & 0 deletions
1
test/fixtures/application_specific/src/config/config.default.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export const name = 'from application'; |
1 change: 1 addition & 0 deletions
1
test/fixtures/application_specific/src/config/config.private.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export const name = 'from application <private>'; |
16 changes: 16 additions & 0 deletions
16
test/fixtures/application_specific/src/config/plugin.default.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import path from 'path'; | ||
|
||
export default { | ||
mysql: { | ||
enable: true, | ||
path: path.resolve(__dirname, '../plugins/artus_plugin_mysql_rds'), | ||
}, | ||
redis: { | ||
enable: true, | ||
path: path.resolve(__dirname, '../plugins/artus_plugin_redis'), | ||
}, | ||
base: { | ||
enable: true, | ||
path: path.resolve(__dirname, '../plugins/artus_plugin_base'), | ||
}, | ||
}; |
17 changes: 17 additions & 0 deletions
17
test/fixtures/application_specific/src/controller/conifg.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { Context } from '@artus/pipeline'; | ||
import { HttpController, HttpMethod, HTTPMethodEnum } from '../../../frameworks/bar/src'; | ||
|
||
@HttpController() | ||
export default class Hello { | ||
@HttpMethod({ | ||
method: HTTPMethodEnum.GET, | ||
path: '/config', | ||
}) | ||
async index(ctx: Context) { | ||
const { params: { config } } = ctx.input; | ||
return { | ||
message: `get conifg succeed`, | ||
config, | ||
}; | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
test/fixtures/application_specific/src/controller/hello.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { Context } from '@artus/pipeline'; | ||
import { HttpController, HttpMethod, HTTPMethodEnum } from '../../../frameworks/bar/src'; | ||
|
||
@HttpController() | ||
export default class Hello { | ||
@HttpMethod({ | ||
method: HTTPMethodEnum.GET, | ||
path: '/home', | ||
}) | ||
async index(ctx: Context) { | ||
const { params: { config } } = ctx.input; | ||
return { title: `Hello Artus ${config.name}` }; | ||
} | ||
|
||
@HttpMethod({ | ||
method: HTTPMethodEnum.GET, | ||
path: '/get_name2', | ||
}) | ||
async name2(ctx: Context) { | ||
const { params: { config } } = ctx.input; | ||
return { title: `Hello Artus ${config.name2}` }; | ||
} | ||
|
||
@HttpMethod({ | ||
method: HTTPMethodEnum.GET, | ||
path: '/get_name3', | ||
}) | ||
async name3(ctx: Context) { | ||
const { params: { config } } = ctx.input; | ||
return { title: `Hello Artus ${config.name3}` }; | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
test/fixtures/application_specific/src/controller/plugin.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { HttpController, HttpMethod, HTTPMethodEnum } from '../../../frameworks/bar/src'; | ||
import { Inject } from '@artus/injection'; | ||
import { ArtusApplication } from '../../../../../src'; | ||
import { Context } from '@artus/pipeline'; | ||
|
||
@HttpController() | ||
export default class Hello { | ||
@Inject('ARTUS_MYSQL') | ||
private client: any; | ||
|
||
@HttpMethod({ | ||
method: HTTPMethodEnum.GET, | ||
path: '/plugin-mysql', | ||
}) | ||
async getMysqlClient() { | ||
return { | ||
client: await this.client.getClient(), | ||
}; | ||
} | ||
|
||
@HttpMethod({ | ||
method: HTTPMethodEnum.GET, | ||
path: '/plugin-redis', | ||
}) | ||
async getRedisClient(ctx: Context) { | ||
const app: ArtusApplication = ctx.input.params.app; | ||
let client; | ||
try { | ||
client = app.container.get('ARTUS_REDIS'); | ||
} catch { | ||
|
||
} | ||
|
||
const result = client ? { | ||
client: await client.getClient(), | ||
} : { message: 'plugin redis not enabled' }; | ||
return result; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import path from 'path'; | ||
import { Manifest, ArtusApplication, ArtusInjectEnum } from "../../../../src"; | ||
import { AbstractBar } from '../../frameworks/bar/src'; | ||
import { Inject, Injectable } from "@artus/injection"; | ||
|
||
@Injectable() | ||
export default class MyArtusApplication { | ||
@Inject('ABSTRACT_BAR') | ||
private bar: AbstractBar; | ||
@Inject(ArtusInjectEnum.Application) | ||
public artus: ArtusApplication; | ||
|
||
static async instance(manifest: Manifest): Promise<MyArtusApplication> { | ||
const app = new ArtusApplication(); | ||
await app.load(manifest, path.join(__dirname, '..')); | ||
const instance = app.container.get(MyArtusApplication); | ||
return instance; | ||
} | ||
|
||
isListening(): boolean { | ||
return this.bar.isListening(); | ||
} | ||
|
||
async run() { | ||
await this.artus.run(); | ||
} | ||
} | ||
|
||
export async function main(manifest: Manifest) { | ||
const app = await MyArtusApplication.instance(manifest); | ||
await app.run(); | ||
return app; | ||
} |
3 changes: 3 additions & 0 deletions
3
test/fixtures/application_specific/src/plugins/artus_plugin_base/meta.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"name": "base" | ||
} |
3 changes: 3 additions & 0 deletions
3
test/fixtures/application_specific/src/plugins/artus_plugin_base/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"name": "@artus/plugin-base" | ||
} |
5 changes: 5 additions & 0 deletions
5
test/fixtures/application_specific/src/plugins/artus_plugin_base/src/config.default.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export default { | ||
mysql: { | ||
clientName: 'mysql-ob-base', | ||
}, | ||
}; |
9 changes: 9 additions & 0 deletions
9
test/fixtures/application_specific/src/plugins/artus_plugin_mysql_ob/meta.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"name": "mysql", | ||
"configDir": "src/custom_config", | ||
"dependencies": [ | ||
{ | ||
"name": "base" | ||
} | ||
] | ||
} |
3 changes: 3 additions & 0 deletions
3
test/fixtures/application_specific/src/plugins/artus_plugin_mysql_ob/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"name": "@artus/plugin-mysql-ob" | ||
} |
19 changes: 19 additions & 0 deletions
19
test/fixtures/application_specific/src/plugins/artus_plugin_mysql_ob/src/app.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { Server } from 'http'; | ||
import { LifecycleHookUnit, LifecycleHook } from '../../../../../../../src/decorator'; | ||
import { ApplicationLifecycle } from '../../../../../../../src/types'; | ||
import { ArtusApplication, Inject, ArtusInjectEnum } from '../../../../../../../src'; | ||
import Client, { MysqlConfig } from './client'; | ||
|
||
export let server: Server; | ||
|
||
@LifecycleHookUnit() | ||
export default class MyLifecycle implements ApplicationLifecycle { | ||
@Inject(ArtusInjectEnum.Application) | ||
app: ArtusApplication; | ||
|
||
@LifecycleHook() | ||
async willReady() { | ||
const mysql = this.app.container.get('ARTUS_MYSQL') as Client; | ||
await mysql.init(this.app.config.mysql as MysqlConfig); | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
test/fixtures/application_specific/src/plugins/artus_plugin_mysql_ob/src/client.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { Injectable } from "@artus/injection"; | ||
|
||
export interface MysqlConfig { | ||
clientName: string | ||
} | ||
|
||
@Injectable({ | ||
id: 'ARTUS_MYSQL', | ||
}) | ||
export default class Client { | ||
private clientName = ''; | ||
|
||
async init(config: MysqlConfig) { | ||
this.clientName = config.clientName; | ||
} | ||
|
||
async getClient(): Promise<string> { | ||
return this.clientName; | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
...pplication_specific/src/plugins/artus_plugin_mysql_ob/src/custom_config/config.default.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export default { | ||
mysql: { | ||
clientName: 'mysql-ob', | ||
}, | ||
}; |
3 changes: 3 additions & 0 deletions
3
test/fixtures/application_specific/src/plugins/artus_plugin_mysql_rds/meta.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"name": "mysql" | ||
} |
3 changes: 3 additions & 0 deletions
3
test/fixtures/application_specific/src/plugins/artus_plugin_mysql_rds/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"name": "@artus/plugin-mysql-rds" | ||
} |
19 changes: 19 additions & 0 deletions
19
test/fixtures/application_specific/src/plugins/artus_plugin_mysql_rds/src/app.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { Server } from 'http'; | ||
import { LifecycleHookUnit, LifecycleHook } from '../../../../../../../src/decorator'; | ||
import { ApplicationLifecycle } from '../../../../../../../src/types'; | ||
import { ArtusApplication, Inject, ArtusInjectEnum } from '../../../../../../../src'; | ||
import Client, { MysqlConfig } from './client'; | ||
|
||
export let server: Server; | ||
|
||
@LifecycleHookUnit() | ||
export default class MyLifecycle implements ApplicationLifecycle { | ||
@Inject(ArtusInjectEnum.Application) | ||
app: ArtusApplication; | ||
|
||
@LifecycleHook() | ||
async willReady() { | ||
const mysql = this.app.container.get('ARTUS_MYSQL') as Client; | ||
await mysql.init(this.app.config.mysql as MysqlConfig); | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
test/fixtures/application_specific/src/plugins/artus_plugin_mysql_rds/src/client.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { Injectable } from "@artus/injection"; | ||
|
||
export interface MysqlConfig { | ||
clientName: string | ||
} | ||
|
||
@Injectable({ | ||
id: 'ARTUS_MYSQL', | ||
}) | ||
export default class Client { | ||
private clientName = ''; | ||
|
||
async init(config: MysqlConfig) { | ||
this.clientName = config.clientName; | ||
} | ||
|
||
async getClient(): Promise<string> { | ||
return this.clientName; | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
...ures/application_specific/src/plugins/artus_plugin_mysql_rds/src/config/config.default.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export default { | ||
mysql: { | ||
clientName: 'mysql-rds', | ||
}, | ||
}; |
3 changes: 3 additions & 0 deletions
3
test/fixtures/application_specific/src/plugins/artus_plugin_redis/meta.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"name": "redis" | ||
} |
3 changes: 3 additions & 0 deletions
3
test/fixtures/application_specific/src/plugins/artus_plugin_redis/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"name": "@artus/plugin-redis" | ||
} |
19 changes: 19 additions & 0 deletions
19
test/fixtures/application_specific/src/plugins/artus_plugin_redis/src/app.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { Server } from 'http'; | ||
import { LifecycleHookUnit, LifecycleHook } from '../../../../../../../src/decorator'; | ||
import { ApplicationLifecycle } from '../../../../../../../src/types'; | ||
import { ArtusApplication, Inject, ArtusInjectEnum } from '../../../../../../../src'; | ||
import Client, { RedisConfig } from './client'; | ||
|
||
export let server: Server; | ||
|
||
@LifecycleHookUnit() | ||
export default class MyLifecycle implements ApplicationLifecycle { | ||
@Inject(ArtusInjectEnum.Application) | ||
app: ArtusApplication; | ||
|
||
@LifecycleHook() | ||
async willReady() { | ||
const redis = this.app.container.get('ARTUS_REDIS') as Client; | ||
await redis.init(this.app.config.redis as RedisConfig); | ||
} | ||
} |
Oops, something went wrong.