Skip to content

Commit

Permalink
Merge pull request #1 from mmdapl/feat/code
Browse files Browse the repository at this point in the history
feat: 初始化模块,增加文档和配置
  • Loading branch information
mmdapl authored Jun 18, 2024
2 parents 668c6be + 071f332 commit e49ccea
Show file tree
Hide file tree
Showing 54 changed files with 14,811 additions and 6,337 deletions.
9 changes: 4 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
logs/
node_modules/
package-lock.json
coverage/
.idea/
run/
.DS_Store
typings/
.vscode
/**/.DS_Store
/.vscode/
/.vscode
dist/
*/jsconfig.json
*/.turbo/
.husky
/**/jsconfig.json
/**/**/.nuxt/
/**/.nuxt/
/.turbo/
**/.turbo/
**/**/.output/
**/.output/
**/node_modules

2 changes: 2 additions & 0 deletions packages/egg-axios/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# @142vip/egg-axios

7 changes: 6 additions & 1 deletion packages/egg-axios/package.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
{
"name": "@142vip/egg-axios"
"name": "@142vip/egg-axios",
"private": false,
"description": "公众号搜:储凡",
"keywords": ["公众号搜:储凡"],
"author": "mmdapl <[email protected]>",
"license": "MIT"
}
2 changes: 2 additions & 0 deletions packages/egg-grpc-client/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# @142vip/egg-grpc-client

7 changes: 6 additions & 1 deletion packages/egg-grpc-client/package.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
{
"name": "@142vip/egg-grpc-client"
"name": "@142vip/egg-grpc-client",
"private": false,
"description": "公众号搜:储凡",
"keywords": ["公众号搜:储凡"],
"author": "mmdapl <[email protected]>",
"license": "MIT"
}
2 changes: 2 additions & 0 deletions packages/egg-grpc-server/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# @142vip/egg-grpc-server

7 changes: 6 additions & 1 deletion packages/egg-grpc-server/package.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
{
"name": "@142vip/egg-grpc-server"
"name": "@142vip/egg-grpc-server",
"private": false,
"description": "公众号搜:储凡",
"keywords": ["公众号搜:储凡"],
"author": "mmdapl <[email protected]>",
"license": "MIT"
}
2 changes: 2 additions & 0 deletions packages/egg-redis/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# @142vip/egg

8 changes: 8 additions & 0 deletions packages/egg-redis/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"name": "@142vip/egg",
"private": false,
"description": "公众号搜:储凡",
"keywords": ["公众号搜:储凡"],
"author": "mmdapl <[email protected]>",
"license": "MIT"
}
2 changes: 2 additions & 0 deletions packages/egg-sequelize/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# @142vip/egg-sequelize

7 changes: 6 additions & 1 deletion packages/egg-sequelize/package.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
{
"name": "@142vip/egg-sequelize"
"name": "@142vip/egg-sequelize",
"private": false,
"description": "公众号搜:储凡",
"keywords": ["公众号搜:储凡"],
"author": "mmdapl <[email protected]>",
"license": "MIT"
}
2 changes: 2 additions & 0 deletions packages/egg-swagger/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# @142vip/egg-swagger

7 changes: 6 additions & 1 deletion packages/egg-swagger/package.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
{
"name": "@142vip/egg-swagger"
"name": "@142vip/egg-swagger",
"private": false,
"description": "公众号搜:储凡",
"keywords": ["公众号搜:储凡"],
"author": "mmdapl <[email protected]>",
"license": "MIT"
}
2 changes: 2 additions & 0 deletions packages/egg/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# @142vip/egg

7 changes: 6 additions & 1 deletion packages/egg/package.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
{
"name": "@142vip/egg"
"name": "@142vip/egg",
"private": false,
"description": "公众号搜:储凡",
"keywords": ["公众号搜:储凡"],
"author": "mmdapl <[email protected]>",
"license": "MIT"
}
2 changes: 2 additions & 0 deletions packages/fairy-cli/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# @142vip/fairy-cli

1 change: 1 addition & 0 deletions packages/fairy-cli/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './src'
14 changes: 13 additions & 1 deletion packages/fairy-cli/package.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
{
"name": "@142vip/fairy-cli"
"name": "@142vip/fairy-cli",
"private": false,
"main": "index.d.ts",
"description": "公众号搜:储凡、fairy-cli",
"keywords": ["公众号搜:储凡"],
"scripts": {
"build": "tsc"
},
"devDependencies": {
"shelljs": "^0.8.5"
},
"author": "mmdapl <[email protected]>",
"license": "MIT"
}
54 changes: 54 additions & 0 deletions packages/fairy-cli/src/exec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/**
* 脚本执行器,执行shell命令
*/
import {join} from "path";
import {exec,exit} from 'shelljs'


const cwd = join(__dirname, '..')
process.env.PATH = `${join(cwd, 'node_modules', '.bin')}:${process.env.PATH}`

/**
* 监听进程
* - 退出进程
*/
process.on('exit', () => {
exit()
})


/**
* 执行shell指令
*/
export async function execShell(commands: string | string[]):Promise<void>{
let runCommands:string[] = []
if (typeof commands === 'string') {
runCommands.push(commands)
}

// 批量执行
if (Array.isArray(commands)) {
runCommands = commands
}

for (let index = 0; index < runCommands.length; index++) {
const command = runCommands[index]
const count = index + 1
console.log(`step${count}:\n${command} \nstep${count}(start): === `)
// await syncExec(command)
const execResult = await exec(command)
// 打印输出结果
console.log(execResult.stdout);
console.log(`step${count}(ending): === \n`)
// 指令异常,不执行后续指令,非0退出
if (execResult.code !== 0) {
exit(1)
break;
}
}
}


exports.execShell = async commands => {

}
1 change: 1 addition & 0 deletions packages/fairy-cli/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './exec'
13 changes: 13 additions & 0 deletions packages/fairy-cli/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"rootDir": "src",
"outDir": "dist",
"target": "es2018"
},
"exclude": [
"dist",
"node_modules",
"test"
]
}
2 changes: 2 additions & 0 deletions packages/nest-redis/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# @142vip/nest-redis

1 change: 1 addition & 0 deletions packages/nest-redis/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './src'
8 changes: 8 additions & 0 deletions packages/nest-redis/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"name": "@142vip/nest-redis",
"private": false,
"description": "公众号搜:储凡",
"keywords": ["公众号搜:储凡"],
"author": "mmdapl <[email protected]>",
"license": "MIT"
}
Empty file.
13 changes: 13 additions & 0 deletions packages/nest-redis/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"rootDir": "src",
"outDir": "dist",
"target": "es2018"
},
"exclude": [
"dist",
"node_modules",
"test"
]
}
2 changes: 2 additions & 0 deletions packages/nest-typeorm/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# @142vip/nest-redis

1 change: 1 addition & 0 deletions packages/nest-typeorm/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './src'
17 changes: 17 additions & 0 deletions packages/nest-typeorm/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"name": "@142vip/nest-redis",
"private": false,
"description": "公众号搜:储凡",
"keywords": [
"公众号搜:储凡"
],

"author": "mmdapl <[email protected]>",
"license": "MIT",
"dependencies": {
"@142vip/nest": "workspace:*",
"@nestjs/typeorm": "^10.0.2",
"mysql2": "^3.10.1",
"typeorm": "^0.3.20"
}
}
7 changes: 7 additions & 0 deletions packages/nest-typeorm/src/core/base.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import {EntityManager} from "typeorm";
import {InjectEntityManager} from "@nestjs/typeorm";

export class BaseDBService{
@InjectEntityManager()
public readonly entityManager: EntityManager
}
11 changes: 11 additions & 0 deletions packages/nest-typeorm/src/core/custom-repository.decorator.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { SetMetadata } from '@nestjs/common'
import {TYPEORM_CUSTOM_REPOSITORY} from "./typeorm.constant";


/**
* 自定义Repo装饰器
* @param entity
*/
export function CustomRepository(entity: new (...args: any) => any): ClassDecorator {
return SetMetadata(TYPEORM_CUSTOM_REPOSITORY, entity)
}
1 change: 1 addition & 0 deletions packages/nest-typeorm/src/core/typeorm.constant.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const TYPEORM_CUSTOM_REPOSITORY = 'TYPEORM_CUSTOM_REPOSITORY'
73 changes: 73 additions & 0 deletions packages/nest-typeorm/src/core/typeorm.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import type { DynamicModule, Provider } from '@nestjs/common'
import {
TypeOrmModule,
TypeOrmModuleOptions,
getDataSourceToken,
getRepositoryToken,
} from '@nestjs/typeorm'
import type {
TypeOrmModuleAsyncOptions,
} from '@nestjs/typeorm/dist/interfaces/typeorm-options.interface'
import type { DataSource } from 'typeorm'
import {TYPEORM_CUSTOM_REPOSITORY} from "./typeorm.constant";

type EntitiesOrRepositories = (new (...args: any) => any)[]

// types.setTypeParser(types.builtins.INT8, val => Number.parseInt(val, 10))
// types.setTypeParser(types.builtins.NUMERIC, val => Number.parseFloat(val))

export class TypeormModule {
public static forFeature(entitiesOrRepositories: EntitiesOrRepositories, token?: string): DynamicModule {
const providers: Provider[] = []

const entities = entitiesOrRepositories.map((Repository) => {
const entity = Reflect.getMetadata(TYPEORM_CUSTOM_REPOSITORY, Repository)
if (entity) {
providers.push({
provide: getRepositoryToken(Repository, token),
useFactory: (dataSource: DataSource) => {
const baseRepo = dataSource.getRepository(entity)
return new Repository(
baseRepo.target,
baseRepo.manager,
baseRepo.queryRunner,
)
},
inject: [getDataSourceToken(token)],
})
return entity
}
return Repository
})

const forFeature = TypeOrmModule.forFeature(entities, token)

return {
module: TypeormModule,
providers,
imports: [forFeature],
exports: [...providers, forFeature],
global: true,
}
}

public static forRoot(options: TypeOrmModuleOptions): DynamicModule {
return {
module: TypeormModule,
providers: [],
exports: [],
imports: [TypeOrmModule.forRoot(options)],
global: true,
}
}

public static forRootAsync(options: TypeOrmModuleAsyncOptions): DynamicModule {
return {
module: TypeormModule,
providers: [],
exports: [],
imports: [TypeOrmModule.forRootAsync(options)],
global: true,
}
}
}
3 changes: 3 additions & 0 deletions packages/nest-typeorm/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export * from './core/base.service'
export * from './core/typeorm.module'
export * from './core/custom-repository.decorator'
13 changes: 13 additions & 0 deletions packages/nest-typeorm/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"rootDir": "src",
"outDir": "dist",
"target": "es2018"
},
"exclude": [
"dist",
"node_modules",
"test"
]
}
9 changes: 9 additions & 0 deletions packages/nest/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# @142vip/nest



## 参考资料

- 官方文档:<https://docs.nestjs.com/>
- 中文文档:<>

1 change: 1 addition & 0 deletions packages/nest/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './src'
Loading

0 comments on commit e49ccea

Please sign in to comment.