# 开发指南

统一的版本管理工具,支持UniApp、微信小程序等多种项目类型的版本号更新。

# 功能特性

  • 🚀 支持多种项目类型:UniApp、UniBest、微信小程序
  • 🔍 自动检测并更新所有相关文件,不存在的文件会自动跳过
  • 📦 支持语义化版本和日期版本两种versionCode生成模式
  • 🛠️ 统一的CLI接口,易于使用
  • 📝 完整的TypeScript类型支持
  • 🔧 支持自定义版本号

# 安装

# 全局安装
npm install -g @itriton/version

# 或者使用pnpm
pnpm add -g @itriton/version

# 或者使用yarn
yarn global add @itriton/version

# 使用方法

# 方式1:全局安装使用

# 全局安装
npm install -g @itriton/version

# 基本用法
itriton-version patch                    # 补丁版本更新
itriton-version minor                   # 次版本更新  
itriton-version major                   # 主版本更新
itriton-version custom 2.0.0           # 自定义版本号

# 指定versionCode模式
itriton-version patch date             # 使用日期versionCode
itriton-version minor semantic         # 使用语义化versionCode (默认)

# 方式2:使用npx(推荐)

# 无需安装,直接使用npx
npx @itriton/version patch
npx @itriton/version minor date
npx @itriton/version major
npx @itriton/version custom 2.0.0

# 方式3:在package.json中配置脚本

{
  "scripts": {
    "update:version": "npx @itriton/version patch",
    "update:version-patch": "npx @itriton/version patch date",
    "update:version-minor": "npx @itriton/version minor date",
    "update:version-major": "npx @itriton/version major date",
    "update:version-custom": "npx @itriton/version custom date"
  }
}

然后运行:

npm run update:version
npm run update:version-patch
npm run update:version-minor
npm run update:version-major
npm run update:version-custom

# 完整示例

# 次版本更新,日期versionCode
npx @itriton/version minor date

# 自定义版本号,语义化versionCode
npx @itriton/version custom semantic 2.0.0

# 自定义版本号,日期versionCode
npx @itriton/version custom date 2.0.0

# 查看帮助信息
npx @itriton/version --help

# 参数说明

# 更新类型

  • major - 主版本号更新 (1.0.0 -> 2.0.0)
  • minor - 次版本号更新 (1.0.0 -> 1.1.0)
  • patch - 补丁版本号更新 (1.0.0 -> 1.0.1)
  • custom - 自定义版本号

# versionCode模式

  • semantic - 语义化版本 (基于版本号,默认)
  • date - 日期版本 (年月日时)

# versionCode说明

  • 语义化模式: 1.2.3 -> 123
  • 日期模式: 2024年12月25日14时 -> 2024122514
  • 最大值限制: 2147483647
  • 超过限制时会自动使用最大值

# 支持的项目文件

工具会自动检测并更新以下文件(如果存在):

# UniApp项目

  • package.json - 更新version字段
  • manifest.config.tssrc/manifest.json - 更新versionName和versionCode
  • src/config/index.js - 更新VERSION常量
  • .minicirc - 更新version字段

# UniBest项目

  • package.json - 更新version字段
  • manifest.config.ts - 更新versionName和versionCode
  • .minicirc - 更新version字段

# 微信小程序项目

  • package.json - 更新version字段
  • project.miniapp.json - 更新version和versionCode字段
  • miniprogram/config/index.js - 更新VERSION常量

# 工作原理

  1. 自动检测: 工具会自动扫描项目目录,查找所有可能的配置文件
  2. 智能更新: 只更新存在的文件,不存在的文件会被静默跳过
  3. 版本同步: 确保所有相关文件中的版本号保持一致
  4. 错误处理: 提供友好的错误提示和帮助信息

# 开发

# 克隆项目
git clone <repository-url>
cd itriton-version

# 安装依赖
pnpm install

# 开发模式 (监听文件变化)
pnpm dev

# 构建项目
pnpm build

# 发布
pnpm build:publish

# 许可证

ISC

上次更新: 9/10/2025, 2:08:19 PM