Skip to content

Commit

Permalink
feat: rename koa plugin and support nestjs
Browse files Browse the repository at this point in the history
  • Loading branch information
thonatos committed Jan 18, 2024
1 parent c565e25 commit 02dd493
Show file tree
Hide file tree
Showing 63 changed files with 1,091 additions and 33 deletions.
432 changes: 422 additions & 10 deletions common/config/rush/pnpm-lock.yaml

Large diffs are not rendered by default.

File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "artusx-legacy",
"name": "artusx-express",
"version": "1.0.0",
"description": "legacy for artusx",
"description": "express for artusx",
"main": "index.js",
"scripts": {
"build": "",
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
{
"name": "artusx-web",
"name": "artusx-koa",
"version": "1.0.0",
"description": "web for artusx",
"description": "koa for artusx",
"main": "index.js",
"scripts": {
"dev": "npx nodemon src/bootstrap.ts",
"build": ""
"build": "",
"dev": "npx nodemon src/bootstrap.ts"
},
"dependencies": {
"nodemon": "~3.0.2",
"@artus/core": "^2.x",
"@artusx/core": "workspace:*",
"@artusx/utils": "workspace:*",
"nodemon": "~3.0.2",
"reflect-metadata": "^0.1.13"
},
"devDependencies": {
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
27 changes: 27 additions & 0 deletions packages/apps/artusx-nest/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# ArtusX-API

> undefined project with web-server powered by ArtusX.
## Usage

### Development

```bash
pnpm i
pnpm run dev
```

### Production

```bash
pnpm run start

# nohup
nohup pnpm run start &
```

### Requirement

- Docker
- Node.js 18.x
- Typescript 4.x+
29 changes: 29 additions & 0 deletions packages/apps/artusx-nest/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"name": "artusx-nest",
"version": "1.0.0",
"description": "nest for artusx",
"main": "index.js",
"scripts": {
"build": "",
"dev": "npx nodemon src/bootstrap.ts"
},
"dependencies": {
"@artus/core": "^2.x",
"@artusx/plugin-nest": "workspace:*",
"@artusx/utils": "workspace:*",
"@nestjs/common": "~10.3.0",
"@nestjs/core": "~10.3.0",
"@nestjs/platform-express": "~10.3.0",
"nodemon": "~3.0.2",
"reflect-metadata": "^0.1.13",
"rxjs": "~7.8.1"
},
"devDependencies": {
"@artus/tsconfig": "~1.0.1",
"@types/node": "~20.10.6",
"nodemon": "~3.0.2",
"ts-node": "~10.9.2",
"tslib": "~2.6.2",
"typescript": "~5.3.3"
}
}
9 changes: 9 additions & 0 deletions packages/apps/artusx-nest/src/bootstrap.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import path from 'path';
import { Application } from '@artusx/utils';

(async () => {
await Application.start({
root: path.resolve(__dirname),
configDir: 'config'
});
})();
7 changes: 7 additions & 0 deletions packages/apps/artusx-nest/src/config/config.default.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { AppModule } from '../root/app.module';

export default {
nest: {
rootModule: AppModule
}
};
6 changes: 6 additions & 0 deletions packages/apps/artusx-nest/src/config/plugin.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export default {
nest: {
enable: true,
package: '@artusx/plugin-nest'
}
};
13 changes: 13 additions & 0 deletions packages/apps/artusx-nest/src/root/app.controller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { Controller, Get } from '@nestjs/common';
import { AppService } from './app.service';

@Controller()
export class AppController {
constructor(private appService: AppService) {}

@Get()
async getHome(): Promise<string> {
const message = await this.appService.getHome();
return message;
}
}
16 changes: 16 additions & 0 deletions packages/apps/artusx-nest/src/root/app.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { Module, DynamicModule } from '@nestjs/common';
import { AppController } from './app.controller';
import { AppService } from './app.service';
import { BaseModule } from './base/base.module';

@Module({})
export class AppModule {
static registerAsync(options: any): DynamicModule {
return {
module: AppModule,
imports: [BaseModule.register(options)],
controllers: [AppController],
providers: [AppService]
};
}
}
13 changes: 13 additions & 0 deletions packages/apps/artusx-nest/src/root/app.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { Inject, Injectable } from '@nestjs/common';
import { BaseService } from './base/base.service';

@Injectable()
export class AppService {
@Inject(BaseService)
baseService: BaseService;

async getHome(): Promise<string> {
const message = await this.baseService.getWelcomeMessage();
return message;
}
}
25 changes: 25 additions & 0 deletions packages/apps/artusx-nest/src/root/base/base.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { DynamicModule, Module } from '@nestjs/common';
import { BaseService } from './base.service';

export const BASE_MODULE_OPTIONS = 'BASE_MODULE_OPTIONS';

export interface BaseModuleOptions {
container?: any;
}

@Module({})
export class BaseModule {
static register(options: BaseModuleOptions): DynamicModule {
return {
module: BaseModule,
providers: [
{
provide: BASE_MODULE_OPTIONS,
useValue: options
},
BaseService
],
exports: [BaseService]
};
}
}
19 changes: 19 additions & 0 deletions packages/apps/artusx-nest/src/root/base/base.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { Container } from '@artus/core';
import { Inject, Injectable } from '@nestjs/common';
import { BASE_MODULE_OPTIONS, BaseModuleOptions } from './base.module';
import InfoService from '../../service/info';

@Injectable()
export class BaseService {
container: Container;

constructor(@Inject(BASE_MODULE_OPTIONS) options: BaseModuleOptions) {
this.container = options.container;
}

async getWelcomeMessage(): Promise<string> {
const infoService = this.container.get(InfoService) as InfoService;
const info = await infoService.getName();
return info;
}
}
12 changes: 12 additions & 0 deletions packages/apps/artusx-nest/src/service/info.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { Inject, Injectable, ArtusInjectEnum, ArtusApplication } from '@artus/core';

@Injectable()
export default class InfoService {
@Inject(ArtusInjectEnum.Application)
app: ArtusApplication;

async getName(): Promise<string> {
console.log('app.config', this.app.config);
return 'InfoService';
}
}
2 changes: 2 additions & 0 deletions packages/apps/artusx-nest/src/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from '@artusx/plugin-nest';
export { default as INestClient } from '@artusx/plugin-nest/client';
12 changes: 12 additions & 0 deletions packages/apps/artusx-nest/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"extends": "@artus/tsconfig",
"compilerOptions": {
"baseUrl": ".",
"strictNullChecks": true,
"resolveJsonModule": true,
"module": "NodeNext",
"moduleResolution": "NodeNext",
"outDir": "dist"
},
"include": ["src/**/*.ts", "src/**/*.json"]
}
2 changes: 1 addition & 1 deletion packages/libs/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"dependencies": {
"@artus/core": "^2.x",
"@artus/pipeline": "^0.2",
"@artusx/plugin-application-http": "workspace:*",
"@artusx/plugin-koa": "workspace:*",
"@koa/bodyparser": "~5.0.0",
"@koa/cors": "~5.0.0"
},
Expand Down
4 changes: 2 additions & 2 deletions packages/libs/core/src/config/plugin.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export default {
'application-http': {
koa: {
enable: true,
package: '@artusx/plugin-application-http'
package: '@artusx/plugin-koa'
}
};
2 changes: 1 addition & 1 deletion packages/libs/core/src/lifecycle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {

import cors from '@koa/cors';
import { bodyParser } from '@koa/bodyparser';
import { KoaApplication } from '@artusx/plugin-application-http';
import { KoaApplication } from '@artusx/plugin-koa';

@LifecycleHookUnit()
export default class ArtusXCoreLifecycle implements ApplicationLifecycle {
Expand Down
2 changes: 1 addition & 1 deletion packages/libs/core/src/types.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export * from '@artusx/plugin-application-http';
export * from '@artusx/plugin-koa';
3 changes: 0 additions & 3 deletions packages/plugins/application-http/meta.json

This file was deleted.

File renamed without changes.
File renamed without changes.
3 changes: 3 additions & 0 deletions packages/plugins/koa/meta.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"name": "koa"
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@artusx/plugin-application-http",
"name": "@artusx/plugin-koa",
"version": "1.0.1-dev.16",
"description": "application-http plugin for artusx",
"description": "koa plugin for artusx",
"keywords": [
"artus.js"
],
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.
File renamed without changes.
File renamed without changes.
File renamed without changes.
1 change: 1 addition & 0 deletions packages/plugins/nest/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
lib
3 changes: 3 additions & 0 deletions packages/plugins/nest/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# ArtusX plugin redis

> https://github.com/thonatos/artusx
3 changes: 3 additions & 0 deletions packages/plugins/nest/meta.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"name": "nest"
}
56 changes: 56 additions & 0 deletions packages/plugins/nest/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
{
"name": "@artusx/plugin-nest",
"version": "1.0.1-dev.16",
"description": "nest plugin for artusx",
"keywords": [
"artus.js"
],
"license": "MIT",
"author": "Suyi <[email protected]>",
"exports": {
".": {
"types": "./lib/index.d.ts",
"default": "./lib/index.js"
},
"./constants": {
"types": "./lib/constants.d.ts",
"default": "./lib/constants.js"
},
"./client": {
"types": "./lib/client.d.ts",
"default": "./lib/client.js"
},
"./lifecycle": {
"types": "./lib/lifecycle.d.ts",
"default": "./lib/lifecycle.js"
}
},
"main": "lib/index.js",
"types": "lib/index.d.js",
"files": [
"lib"
],
"scripts": {
"build": "npm run tsc && npm run build:metadata",
"build:metadata": "cp meta.json ./lib/meta.json",
"tsc": "rm -rf lib && tsc"
},
"dependencies": {
"@artus/core": "^2.x",
"@artus/pipeline": "^0.2",
"@nestjs/common": "~10.3.0",
"@nestjs/core": "~10.3.0"
},
"devDependencies": {
"@artus/tsconfig": "^1.0.1",
"@types/node": "^18.11.17",
"tslib": "^2.5.0",
"typescript": "^4.9.4"
},
"peerDependencies": {
"reflect-metadata": "^0.1.13"
},
"publishConfig": {
"access": "public"
}
}
Loading

0 comments on commit 02dd493

Please sign in to comment.