npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

yapi-ts-generator

v1.0.3

Published

CLI plugin to export YApi interfaces to TypeScript files.

Downloads

180

Readme

yapi-ts-generator

English | 简体中文

CLI 插件,结合 yapi-cliyapi-ts-gen 的生成逻辑,把 YApi 中的接口导出为 TypeScript 文件。支持按 host 读取全局配置、可选 httpsAgent、以及基于路径的自定义输出。

安装要求

  • Node.js >= 14
  • 全局安装:npm i yapi-ts-generator -g(生成命令 ytg

快速开始

  1. 初始化全局配置(存放 host/user/httpsAgent)

    ytg init -g
    # 生成: ~/.yapi-ts-genterator/config.yml (模板来自 template/global.yml)

    打开文件根据自己的 YApi host 调整。支持:

    • host: 仅匹配域名(类似 ssh config)
    • user: { name, password, token }token 不存在时会尝试使用 name/password 登录获取。
    • httpsAgent: { pfx, passphrase };当项目配置里 httpsAgent: true 时启用。
  2. 在业务仓库初始化项目配置

    ytg init -d
    # 生成: ./.yapi-ts-generator.config.yml (模板来自 template/config.yml)

    常用字段:

    • yapiUrl: YApi 导出地址(在 https://your-yapi-domain/project/xxxx/setting 的「生成 ts services」模块获取,带 token 或依赖全局配置自动填充)
    • httpsAgent: true 时会在请求中套用对应 host 的 httpsAgent
    • outputDir / outputFileNames: 生成文件位置与接口/方法文件名
    • isGenerateHandlerFile: 是否生成请求方法文件
    • stripPathPrefixes: 去除接口路径前缀
    • customOutputs: 按路径前缀分文件输出
  3. 预检连接

    ytg test
    # 仅尝试拉取 JSON,不写文件
  4. 生成 TS

    ytg create       # 按配置生成
    ytg create -c    # 先清空 outputDir 再生成
    ytg create -e path/to/custom.config.yml  # 指定项目配置文件
  5. 查看配置(YAML -> JSON)

    ytg config -g    # 展示全局配置路径及内容
    ytg config -d    # 展示项目配置路径及内容
  6. 帮助与版本

    ytg --help
    ytg --version
  7. 快速生成(不依赖项目配置文件)

    ytg quick-create -u "<yapi_export_url>" -o ./generated -f api.ts
    # 可选:--request-import "@/utils/request" --strip-path api,v1 --https-agent

模板可扩展

  • 包根目录 template/ 下自带两个模板文件,供 ytg init 使用:
    • template/global.yml
    • template/config.yml
  • 需要新增字段时,直接修改模板文件即可,后续 ytg init 会按最新模板生成。

工作原理概要

  • 从项目配置读取 yapiUrl,匹配 host 后可自动填充 token / httpsAgent。
  • 拉取 YApi JSON,按 customOutputs/默认规则生成 TS,格式化输出。
  • ytg test 只验证拉取链路;ytg create 负责实际生成文件。