mirror of https://github.com/msgbyte/tailchat
chore: 增加service action扫描脚本用于自动生成swagger jsdoc文档
parent
fbf4205dfb
commit
ca48e46215
@ -0,0 +1,29 @@
|
|||||||
|
{
|
||||||
|
"name": "tailchat-service-swagger-generator",
|
||||||
|
"private": true,
|
||||||
|
"version": "1.0.0",
|
||||||
|
"description": "",
|
||||||
|
"main": "index.js",
|
||||||
|
"bin": "./dist/index.js",
|
||||||
|
"scripts": {
|
||||||
|
"dev": "tsc --watch",
|
||||||
|
"prepare": "tsc",
|
||||||
|
"test": "echo \"Error: no test specified\" && exit 1"
|
||||||
|
},
|
||||||
|
"keywords": [
|
||||||
|
"msgbyte",
|
||||||
|
"moonrailgun",
|
||||||
|
"tailchat"
|
||||||
|
],
|
||||||
|
"author": "moonrailgun <moonrailgun@gmail.com>",
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"globby": "11.1.0",
|
||||||
|
"ts-morph": "^16.0.0",
|
||||||
|
"ts-node": "^10.9.1"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"@types/node": "^18.11.18",
|
||||||
|
"typescript": "^4.9.4"
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,31 @@
|
|||||||
|
import { Project } from 'ts-morph';
|
||||||
|
import path from 'path';
|
||||||
|
import globby from 'globby';
|
||||||
|
import { processService } from './processService';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* https://ts-morph.com/setup/
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 扫描服务
|
||||||
|
*/
|
||||||
|
async function scanServices() {
|
||||||
|
const serviceFiles = await globby('./services/**/*.service.ts');
|
||||||
|
|
||||||
|
console.time('parse project usage');
|
||||||
|
const project = new Project({
|
||||||
|
tsConfigFilePath: path.resolve(process.cwd(), './tsconfig.json'),
|
||||||
|
});
|
||||||
|
console.timeEnd('parse project usage');
|
||||||
|
|
||||||
|
console.time('parse source usage');
|
||||||
|
|
||||||
|
// 单个测试
|
||||||
|
const sourceFile = project.getSourceFileOrThrow(serviceFiles[0]);
|
||||||
|
processService(sourceFile);
|
||||||
|
|
||||||
|
console.timeEnd('parse source usage');
|
||||||
|
}
|
||||||
|
|
||||||
|
scanServices();
|
@ -0,0 +1,10 @@
|
|||||||
|
import { MethodDeclaration, ParameterDeclaration, SyntaxKind } from 'ts-morph';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取函数参数列表
|
||||||
|
*/
|
||||||
|
export function getMethodParameters(
|
||||||
|
methodDeclaration: MethodDeclaration
|
||||||
|
): ParameterDeclaration[] {
|
||||||
|
return methodDeclaration.getChildrenOfKind(SyntaxKind.Parameter);
|
||||||
|
}
|
@ -0,0 +1,11 @@
|
|||||||
|
{
|
||||||
|
"extends": "../../tsconfig.json",
|
||||||
|
"compilerOptions": {
|
||||||
|
"declaration": true,
|
||||||
|
"rootDir": "./src",
|
||||||
|
"outDir": "./dist",
|
||||||
|
"typeRoots": ["./node_modules/@types"],
|
||||||
|
},
|
||||||
|
"include": ["./src/**/*"],
|
||||||
|
"exclude": ["./node_modules/**/*", "./dist/**/*"]
|
||||||
|
}
|
Loading…
Reference in New Issue