{"id":18262916,"url":"https://github.com/midwayjs/ts-analysis","last_synced_at":"2025-04-09T01:24:55.825Z","repository":{"id":45242232,"uuid":"276528697","full_name":"midwayjs/ts-analysis","owner":"midwayjs","description":"TypeScript Code Analysis","archived":false,"fork":false,"pushed_at":"2021-12-28T16:18:25.000Z","size":29,"stargazers_count":0,"open_issues_count":1,"forks_count":1,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-04-06T07:16:31.543Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/midwayjs.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-07-02T02:25:59.000Z","updated_at":"2020-07-09T09:29:28.000Z","dependencies_parsed_at":"2022-09-09T23:02:12.732Z","dependency_job_id":null,"html_url":"https://github.com/midwayjs/ts-analysis","commit_stats":null,"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/midwayjs%2Fts-analysis","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/midwayjs%2Fts-analysis/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/midwayjs%2Fts-analysis/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/midwayjs%2Fts-analysis/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/midwayjs","download_url":"https://codeload.github.com/midwayjs/ts-analysis/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247954538,"owners_count":21024237,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-05T11:09:16.473Z","updated_at":"2025-04-09T01:24:55.786Z","avatar_url":"https://github.com/midwayjs.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ts-analysis\nAnalysis TypeScript Code to Json\n\n\u003cp align=\"center\"\u003e\n  \u003ca href=\"https://www.npmjs.com/package/@midwayjs/ts-analysis\" alt=\"npm version\"\u003e\n    \u003cimg src=\"https://img.shields.io/npm/v/@midwayjs/ts-analysis.svg?style=flat\" /\u003e\n  \u003c/a\u003e\n  \u003ca href=\"./LICENSE\" alt=\"GitHub license\"\u003e\n    \u003cimg src=\"https://img.shields.io/badge/license-MIT-blue.svg\" /\u003e\n  \u003c/a\u003e\n  \u003ca href=\"https://github.com/midwayjs/midway-serverless/actions?query=workflow%3A%22Node.js+CI%22\" alt=\"Node.js CI\"\u003e\n    \u003cimg src=\"https://img.shields.io/badge/Node.js%20CI-passing-brightgreen\" /\u003e\n  \u003c/a\u003e\n  \u003ca href=\"https://github.com/midwayjs/ts-analysis\" alt=\"Activity\"\u003e\n    \u003cimg src=\"https://img.shields.io/github/commit-activity/m/midwayjs/ts-analysis\" /\u003e\n  \u003c/a\u003e\n  \u003ca href=\"https://github.com/midwayjs/ts-analysis/graphs/contributors\" alt=\"Contributors\"\u003e\n    \u003cimg src=\"https://img.shields.io/github/contributors/midwayjs/ts-analysis\" /\u003e\n  \u003c/a\u003e\n\u003c/p\u003e\n\n## Usage\n```ts\n// Use Class\nimport { TsAnalysis } from '@midwayjs/ts-analysis';\n\nasync (codePath) =\u003e {\n  const analysisInstance = new TsAnalysis(codePath);    // 初始化实例\n  await analysisInstance.start();                       // 分析器启动\n  const result = await analysisInstance.getResult();    // 获取分析结果\n  return result;\n}\n\n// Use Instance\nimport { tsAnalysis } from '@midwayjs/ts-analysis';\n\nasync (codePath) =\u003e {\n  const result = await tsAnalysis(codePath)             // 获取分析结果\n  return result;\n}\n```\n\n## Result Demo\n### Decorator\n\n```ts\n// decorator.ts\n@Provider()\nclass Test {\n\n  constructor(name: string, age: number) {}\n\n  @Inject('context')\n  ctx;\n\n  @Func('index.handler', { method: 'GET', path: '/api/test' })\n  async handler() { }\n}\n\n// result\n{\n  decorators: {\n    Provider: [\n      {\n        sourceFile: '/Users/xxx/decorator.ts',  // 代码所在位置\n        position: {                             // 装饰器所在位置\n          start: {                              // 装饰器开始位置\n            ln: 0,\n            col: 0\n          },\n          end: {                                // 装饰器结束位置\n            ln: 0,\n            col: 12\n          }\n        },\n        params: [\n          // 参数\n        ],\n        target: {                               // 装饰的目标\n          type: 'class',                        // 目标类型\n          name: 'Test',                         // 目标名称\n          position: {                           // 目标代码位置\n            ... // 格式参照上述位置结构\n          },\n          params: [                             // 目标参数列表，class即为constructor参数列表\n            { \n              name: 'name',\n              type: 'string'\n            },\n            { \n              name: 'age',\n              type: 'number'\n            }\n          ]\n        },\n        childDecorators: {\n          Inject: [\n            ... // 结构类似\n          ],\n          Func: [\n            ... // 结构类似\n          ]\n        }\n      }\n    ],\n    Inject: [\n      ... // 结构类似\n    ],\n    Func: [\n      ... // 结构类似\n    ]\n  }\n\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmidwayjs%2Fts-analysis","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmidwayjs%2Fts-analysis","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmidwayjs%2Fts-analysis/lists"}