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

biz-template-generate

v1.1.3

Published

Clean Architecture Android template code generator

Downloads

3

Readme

Clean Architecture Android Code Generator

🚀 一个用于生成 Android Clean Architecture 代码的自动化工具,支持生成完整的业务模块代码结构。

✨ 特性

  • 🏗️ 自动生成 Clean Architecture 完整代码结构
  • 📝 支持自定义业务模块配置
  • 🔧 生成 Domain 层:Model、Repository、UseCase
  • 📊 生成 Data 层:API、DataSource、DTO、Mapper、Repository
  • 🎯 遵循 Android 开发最佳实践
  • ⚡ 快速生成,提高开发效率

📦 安装

全局安装(推荐)

npm install -g biz-template-generate

本地安装

npm install biz-template-generate

🚀 使用方法

1. 创建配置文件

创建一个 JSON 配置文件,例如 user-template.json

{
  "name": "User",
  "description": "用户管理业务模块",
  "packageName": "com.maidocha.growth",
  "author": "yule",
  "methods": [
    {
      "name": "login",
      "description": "用户登录",
      "httpMethod": "POST",
      "endpoint": "/v1/user/login",
      "returnType": "UserLogin",
      "requestParameters": {
        "username": "String",
        "password": "String"
      },
      "responseBody": {
        "token": "String",
        "userId": "Int",
        "userInfo": "UserInfo"
      }
    },
    {
      "name": "getProfile",
      "description": "获取用户资料",
      "httpMethod": "GET",
      "endpoint": "/v1/user/profile",
      "returnType": "UserProfile",
      "requestParameters": {
        "userId": "Int"
      },
      "responseBody": {
        "userId": "Int",
        "username": "String",
        "email": "String",
        "avatar": "String",
        "createTime": "Long"
      }
    }
  ]
}

2. 生成代码

# 使用全局安装的工具
biz-template-generate user-template.json

# 或指定输出目录
biz-template-generate user-template.json ./my-output

# 使用本地安装的工具
npx biz-template-generate user-template.json

3. 查看生成结果

生成的代码结构如下:

generated/
└── user/
    ├── data/
    │   ├── api/
    │   │   └── UserApi.kt
    │   ├── datasource/
    │   │   └── UserDataSource.kt
    │   ├── dto/
    │   │   ├── req/
    │   │   │   ├── LoginReq.kt
    │   │   │   └── GetProfileReq.kt
    │   │   └── rsp/
    │   │       ├── LoginDTO.kt
    │   │       └── GetProfileDTO.kt
    │   ├── mapper/
    │   │   ├── LoginMapper.kt
    │   │   └── GetProfileMapper.kt
    │   └── repository/
    │       └── UserRepository.kt
    └── domain/
        ├── model/
        │   ├── Login.kt
        │   └── GetProfile.kt
        ├── repository/
        │   └── IUserRepository.kt
        └── usecase/
            ├── LoginUseCase.kt
            └── GetProfileUseCase.kt

📋 配置文件说明

主要字段

  • name: 业务模块名称(如 "User"、"Order")
  • packageName: 包名(如 "com.maidocha.growth")
  • author: 作者名称
  • methods: 方法列表

方法配置

每个方法包含以下字段:

  • name: 方法名称
  • description: 方法描述
  • httpMethod: HTTP 方法(可选,默认为 "POST")
  • endpoint: API 端点(可选,会自动生成)
  • returnType: 返回类型
  • requestParameters: 请求参数字典(键值对格式)
  • responseBody: 响应体字段字典(键值对格式)

参数配置

新的简化格式使用键值对方式定义参数:

{
  "requestParameters": {
    "username": "String",
    "password": "String"
  },
  "responseBody": {
    "token": "String",
    "userId": "Int"
  }
}
  • : 参数名称
  • : 参数类型(如 "String"、"Int"、"Long"、"Boolean"、"List" 等)

🎯 生成的代码特点

命名规范

  • 带业务前缀的类:API、DataSource、Repository、IRepository
  • 不带业务前缀的类:DTO、Model、UseCase、Mapper

代码结构

  • 遵循 Clean Architecture 分层原则
  • 使用 Kotlin 协程和 suspend 函数
  • 集成 Either 和 Failure 错误处理
  • 自动生成完整的注释和文档
  • 智能处理空参数和空响应体

依赖关系

生成的代码依赖以下库:

import com.maidocha.common.functional.Either
import com.maidocha.common.result.Failure

📝 更新日志

v1.1.3 (2025-07-09)

  • 重大改进:简化配置文件格式
    • requestParametersresponseBody 从复杂对象格式改为简洁的键值对格式
    • 新格式:{"paramName": "paramType"} 替代 [{"name": "paramName", "type": "paramType", ...}]
    • 大幅简化配置文件编写,提高可读性和维护性
    • 更新所有模板文件以支持新的简化格式
    • 更新 README.md 文档和示例配置
  • 🔧 技术改进
    • 优化 TypeScript 类型定义,使用 Record<string, string> 替代复杂数组
    • 修复所有模板文件中的参数处理逻辑
    • 改进交互式配置生成器,支持新的参数格式
  • 📚 文档更新
    • 更新 README.md 中的配置示例
    • 添加新的配置格式说明
    • 更新参数配置文档

v1.1.2 (2025-07-05)

  • 🐞 修复 npm 包未包含 dist 目录导致无法运行的问题

v1.1.1 (2025-07-05)

  • 🚀 1.1.1 版本发布,常规优化和问题修复

v1.1.0 (2025-07-04)

  • 🔧 修复 API 层配置
    • 修复 BaseContentResponse 包名为 com.maidocha.network.dto.BaseContentResponse
    • 修改 API 参数格式为 @Body body: TestReq 而不是 @Field 参数
    • 正确导入 req 和 rsp DTO 包
  • 🔧 修复 Model 层属性规则
    • 基本类型属性(String、Int、Long等)为非空
    • 对象类型属性为可空,默认值为 null
  • 🔧 修复 DataSource 层
    • 参照 CpDataSource 写法,使用 safeApiCall 而不是 try-catch
    • 添加对应的 mapper.transform 导入
    • 使用 isFailure()AppLog 进行错误处理

v1.0.6 (2025-07-04)

  • 优化 UseCase 层结构
    • 修复 UseCase 层参数,去掉末尾的 ?,所有参数都是非空的
    • 简化 UseCase 结构,直接在 run 方法中调用 repository 方法
    • 优化类型声明,直接使用 Params 类型,不需要加类名前缀

v1.0.5 (2025-07-04)

  • 🔧 修复 Repository 层参数问题
    • 修复 Repository 层参数,去掉末尾的 ?,所有参数都是非空的
    • 确保 Domain Repository 接口和 Data Repository 实现类参数一致

v1.0.4 (2025-07-04)

  • 🔧 修复 Mapper 和 DataSource 生成问题
    • 修复 DataSource 中正确导入 Mapper 的 transform 方法
    • 修复 Mapper 中所有 ?. 操作符后添加类型安全的默认值
    • 去掉必需字段逻辑,所有配置中的字段都是必需字段
    • 更新 README.md 示例,为所有参数添加 description 描述

v1.0.3 (2025-07-04)

  • 优化 DTO 生成
    • 为每个参数添加 @Expose 注解
    • 将参数注释放在单独的一行,提高可读性
    • 支持自定义 serializedName 字段映射

v1.0.2 (2025-07-04)

  • 🔧 修复 UseCase 生成问题
    • 移除了不必要的接口实现 IxxxUseCase
    • requestParameters 为空时,不生成 Params 类,使用 Unit 作为参数类型
    • 简化了 UseCase 结构,只继承 SuspendCallbackUseCase

v1.0.1 (2025-07-04)

  • 新增功能:支持空请求参数和空响应体的智能处理
    • requestParameters 为空时,API 接口不传参数
    • responseBody 为空时,API 接口返回 BaseContentResponse<Unit>
    • 智能跳过不必要的文件生成(DTO、Model、Mapper)
    • 优化了 Repository、DataSource、UseCase 的返回类型处理

v1.0.0 (2025-07-03)

  • 🚀 初始版本发布
  • 支持完整的 Clean Architecture 代码生成
  • 支持自定义业务模块配置

📝 示例配置文件

项目包含多个示例配置文件:

  • simple-config.json: 简单示例
  • example-config.json: 完整示例
  • templates/: 各种业务模块模板

🔧 开发

本地开发

# 克隆项目
git clone <repository-url>
cd biz-template-generate

# 安装依赖
npm install

# 本地链接工具
npm run install-tool

# 测试生成
biz-template-generate example-config.json

构建和发布

# 构建项目
npm run build

# 发布到 npm
npm run publish-tool

🤝 贡献

欢迎提交 Issue 和 Pull Request!

📄 许可证

MIT License

🆘 支持

如果遇到问题,请:

  1. 检查配置文件格式是否正确
  2. 确保所有必需字段都已填写
  3. 查看生成的错误信息
  4. 提交 Issue 描述问题

Happy Coding! 🎉