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

@aplus-frontend/api-generator

v1.0.1

Published

APlus API code generator from OpenAPI documentation

Readme

@aplus-frontend/api-generator

从 OpenAPI 文档生成 TypeScript 接口代码的工具,支持 CLI 和 API两种使用方式。

安装

pnpm add @aplus-frontend/api-generator

CLI 使用

初始化配置

在项目根目录下创建 api-generate.jsonapi-doc.json 配置文件:

npx aplus-gen init

生成代码

# 使用内置模板
npx aplus-gen generate

# 指定项目目录
npx aplus-gen generate --dir /path/to/project

# 使用自定义模板
npx aplus-gen generate --template /path/to/templates

API 使用

import { generate, initConfig, getBuiltinTemplateDir } from '@aplus-frontend/api-generator';

// 初始化配置
await initConfig({
  workspaceRoot: '/path/to/project',
});

// 生成代码
const result = await generate({
  workspaceRoot: '/path/to/project',
  templateDir: getBuiltinTemplateDir(),
});

if (result.success) {
  console.log('生成成功:', result.indexPath, result.interfacePath);
} else {
  console.error('生成失败:', result.error);
}

配置说明

api-generate.json

{
  "apiPath": "src/api",
  "serviceName": "/api/v1",
  "defPath": "@/utils/http",
  "hooks": true
}

| 字段 | 类型 | 说明 | |------|------|------| | apiPath | string | API 文件存放路径 | | serviceName | string | 服务路径前缀 | | defPath | string | HTTP 工具导入路径 | | hooks | boolean | 是否生成 vue-request hooks |

api-doc.json

OpenAPI/Swagger JSON 文档内容。

生成的文件结构

src/api/
├── index.ts       # 接口函数
└── interface.ts   # TypeScript 类型定义

自定义模板

模板使用 Nunjucks 语法,包含以下模板文件:

  • interface.njk - 类型定义模板
  • service.njk - 接口函数模板

自定义模板时,保持相同的变量结构即可。

高级用法

自定义文件系统

import type { FileSystem } from '@aplus-frontend/api-generator';

class CustomFileSystem implements FileSystem {
  async readFile(filePath: string): Promise<string> { /* ... */ }
  async writeFile(filePath: string, content: string): Promise<void> { /* ... */ }
  async stat(filePath: string) { /* ... */ }
  async mkdir(dirPath: string, options?: { recursive: boolean }): Promise<void> { /* ... */ }
  async exists(filePath: string): Promise<boolean> { /* ... */ }
}

const result = await generate({
  workspaceRoot: '/path/to/project',
  templateDir: getBuiltinTemplateDir(),
  fs: new CustomFileSystem(),
});

自定义消息处理

import type { MessageHandler } from '@aplus-frontend/api-generator';

const result = await generate({
  workspaceRoot: '/path/to/project',
  templateDir: getBuiltinTemplateDir(),
  messageHandler: {
    info: (msg) => console.log('[INFO]', msg),
    error: (msg) => console.error('[ERROR]', msg),
    warn: (msg) => console.warn('[WARN]', msg),
  },
});

License

MIT