Skip to content

Conversation

@CodeCasterX
Copy link
Member

🔗 相关问题 / Related Issue

  • 这是一个功能增强,改进现有启动脚本的跨平台兼容性 / This is a feature enhancement to improve cross-platform compatibility of startup scripts

📋 变更类型 / Type of Change

  • 🚀 功能增强 / Feature enhancement (improve existing functionality without breaking changes)
  • 🔧 重构 / Refactoring (no functional changes)
  • 📚 文档更新 / Documentation update

📝 变更目的 / Purpose of the Change

中文说明:

原有的 Bash 启动脚本存在跨平台兼容性问题:

  1. 仅支持 Unix/Linux 系统,无法在 Windows 上运行
  2. 在 macOS 上存在兼容性问题(readlink -f 命令不可用)
  3. 错误处理和信号处理不够完善
  4. 代码可维护性较差

本次改进使用 Node.js 重写启动脚本,实现真正的跨平台支持,同时保持命令行接口完全兼容,无需修改现有文档和使用方式。

English Description:

The original Bash startup script has cross-platform compatibility issues:

  1. Only supports Unix/Linux systems, cannot run on Windows
  2. Has compatibility issues on macOS (readlink -f command not available)
  3. Insufficient error handling and signal processing
  4. Poor code maintainability

This improvement rewrites the startup script using Node.js to achieve true cross-platform support, while maintaining full command-line interface compatibility without modifying existing documentation and usage.

📋 主要变更 / Brief Changelog

启动脚本重构 / Startup Script Refactoring:

  • 使用 Node.js 重写核心启动逻辑(fit.js,164 行)
  • Unix/Linux/macOS 使用 fit 脚本(Node.js 包装器)
  • Windows 使用 fit.cmd 批处理文件
  • 移除旧的 fit.bat 文件

跨平台兼容性 / Cross-Platform Compatibility:

  • 解决 Bash 脚本在不同系统上的兼容性问题
  • 避免 macOS 上 readlink -f 不可用的问题
  • 统一 Windows/Linux/macOS 的使用体验
  • 使用 __dirname 实现跨平台路径处理

功能增强 / Feature Enhancements:

  • 改进错误处理和错误信息输出
  • 正确处理进程信号(SIGINT/SIGTERM)
  • 更清晰的参数解析逻辑
  • 更好的代码可维护性(JavaScript vs Bash)

文档更新 / Documentation Updates:

  • 重构 fit-launcher/README.md,从模块级别进行说明
  • 添加架构设计、启动流程等技术文档
  • 完善使用说明和故障排除指南
  • 文档从脚本说明扩展为完整的模块文档

🧪 验证变更 / Verifying this Change

测试步骤 / Test Steps

  1. 版本信息测试:

    ./fit version
    # 预期输出:Version: 3.5.5-SNAPSHOT
  2. 帮助信息测试:

    ./fit help
    # 预期输出:显示完整的帮助信息
  3. 启动测试(需要编译后的 JAR 文件):

    mvn clean install
    ./fit start
    # 预期:能够正常启动应用
  4. 参数传递测试:

    ./fit start -Xmx1g -Xms512m testarg
    # 预期:Java 参数和程序参数都能正确传递
  5. Windows 兼容性测试:

    fit.cmd version
    fit.cmd help
    # 预期:Windows 上能够正常运行

测试覆盖 / Test Coverage

  • 所有现有测试都通过 / All existing tests pass
  • 我已经进行了手动测试 / I have performed manual testing
    • ✅ Unix/macOS 上测试通过(fit version, fit help
    • ✅ 脚本文件权限正确设置
    • ✅ 参数解析逻辑正确
  • 我已经添加了单元测试 / I have added unit tests
    • 注:启动脚本为 Node.js 实现,属于基础设施代码,通过手动测试验证

📸 截图 / Screenshots

测试结果:

$ ./fit version
Version: 3.5.5-SNAPSHOT

$ ./fit help
Usage: fit <command> [arguments]
Commands:
  start    Start the application
  debug    Start the application in debug mode
  version  Display the version number
  help     Display this help message

文件结构:

fit-launcher/src/main/resources/bin/
├── fit         # Unix/Linux/macOS 启动脚本 (79B)
├── fit.js      # Node.js 核心脚本 (3.9K)
└── fit.cmd     # Windows 启动脚本 (32B)

✅ 贡献者检查清单 / Contributor Checklist

基本要求 / Basic Requirements:

  • 这是一个功能增强,不需要单独的 Issue / This is a feature enhancement that doesn't require a separate issue
  • 你的 Pull Request 只解决一个问题,没有包含其他不相关的变更 / Your PR addresses just this issue, without pulling in other changes
  • PR 中的每个 commit 都有有意义的主题行和描述 / Each commit in the PR has a meaningful subject line and body

代码质量 / Code Quality:

  • 我的代码遵循项目的代码规范 / My code follows the project's coding standards
  • 我已经进行了自我代码审查 / I have performed a self-review of my code
  • 我已经为复杂的代码添加了必要的注释 / I have commented my code, particularly in hard-to-understand areas
    • Node.js 脚本包含详细的中文注释
    • 每个函数都有清晰的功能说明

测试要求 / Testing Requirements:

  • 基础检查通过:mvn -B clean package -Dmaven.test.skip=true / Basic checks pass
  • 单元测试通过:mvn clean install / Unit tests pass
  • 手动测试验证所有命令正常工作 / Manual testing verifies all commands work correctly

文档和兼容性 / Documentation and Compatibility:

  • 我已经更新了相应的文档 / I have made corresponding changes to the documentation
    • 完全重写了 fit-launcher/README.md
    • 从脚本说明扩展为完整的模块级文档
  • 如果有破坏性变更,我已经在 PR 描述中详细说明 / If there are breaking changes, I have documented them in detail
    • 无破坏性变更 / No breaking changes
    • 命令行接口保持 100% 兼容
    • 所有现有文档和脚本无需修改
  • 我已经考虑了向后兼容性 / I have considered backward compatibility
    • ✅ 命令用法完全一致:./fit start, ./fit debug, ./fit version, ./fit help
    • ✅ 参数传递机制保持不变
    • ✅ 环境变量设置保持不变
    • ✅ 所有现有功能都得到保留

📋 附加信息 / Additional Notes

技术栈要求 / Technical Stack Requirements:

  • Node.js 12.0+ (推荐 16.0+)
  • Java 17+

兼容性保证 / Compatibility Guarantees:

  • ✅ 命令行接口 100% 向后兼容
  • ✅ 所有现有文档无需修改
  • ✅ 所有现有自动化脚本无需修改
  • ✅ 用户无需改变使用习惯

迁移说明 / Migration Notes:

  • 对于大多数用户:无需任何操作,使用方式完全一致
  • 如果系统未安装 Node.js:从 https://nodejs.org/ 下载安装
  • 对于自动化脚本:无需修改,所有命令保持原样

后续计划 / Future Plans:

  • 考虑添加配置文件支持
  • 添加更多诊断和调试选项
  • 优化启动性能

审查者注意事项 / Reviewer Notes:

重点审查项 / Key Review Points:

  1. 跨平台兼容性验证:

    • 请在 Windows、Linux、macOS 上测试脚本是否正常工作
    • 验证 Node.js 路径处理在不同系统上的正确性
  2. 向后兼容性检查:

    • 确认所有现有命令用法保持不变
    • 验证参数传递机制的一致性
    • 检查环境变量设置是否与原版本一致
  3. 文档完整性:

    • 检查新的 README.md 是否准确描述了模块功能
    • 验证使用说明和故障排除指南的准确性
  4. 代码质量:

    • 检查 Node.js 代码的健壮性
    • 验证错误处理和信号处理的正确性
    • 确认代码注释的清晰性

测试建议 / Testing Suggestions:

# 1. 编译项目
mvn clean install

# 2. 测试版本命令
./fit version

# 3. 测试帮助命令
./fit help

# 4. 测试启动命令(如果有可用的应用)
./fit start

# 5. 测试参数传递
./fit start -Xmx512m testarg

# 6. 在 Windows 上测试
fit.cmd version

潜在风险 / Potential Risks:

  • 需要 Node.js 运行环境(新增依赖)
  • 但风险可控:Node.js 已广泛部署,且大多数 CI/CD 环境都已预装

收益 / Benefits:

  • ✅ 真正的跨平台支持
  • ✅ 更好的错误处理
  • ✅ 更易维护的代码
  • ✅ 与现代开发工具生态保持一致

主要改进:
1. 启动脚本重构
   - 使用 Node.js 重写核心启动逻辑 (fit.js)
   - Unix/Linux/macOS 使用 fit 脚本(Node.js 实现)
   - Windows 使用 fit.cmd 批处理文件
   - 移除旧的 fit.bat 文件

2. 跨平台兼容性
   - 解决 Bash 脚本在不同系统上的兼容性问题
   - 避免 macOS 上 readlink -f 不可用的问题
   - 统一 Windows/Linux/macOS 的使用体验

3. 功能增强
   - 改进错误处理和错误信息输出
   - 正确处理进程信号 (SIGINT/SIGTERM)
   - 更清晰的参数解析逻辑
   - 更好的代码可维护性

4. 文档更新
   - 重构模块 README,从模块级别进行说明
   - 添加架构设计、启动流程等技术文档
   - 完善使用说明和故障排除指南

技术栈:Node.js 12+
命令接口保持完全兼容,无需修改现有文档和脚本
@CodeCasterX CodeCasterX added this to the 3.5.x milestone Nov 8, 2025
@CodeCasterX CodeCasterX requested a review from a team November 8, 2025 12:19
@CodeCasterX CodeCasterX self-assigned this Nov 8, 2025
@CodeCasterX CodeCasterX requested review from XinLi-cyber and removed request for a team November 8, 2025 12:19
@CodeCasterX CodeCasterX added type: enhancement A general enhancement in: fit Issues in FIT modules labels Nov 8, 2025
@CodeCasterX CodeCasterX modified the milestones: 3.5.x, 3.5.6 Nov 8, 2025
CodeCasterX and others added 3 commits November 8, 2025 23:20
添加项目级别的开发规范和自动化规则:

1. 文件权限管理规则
   - 动态获取文件所有者信息,避免硬编码用户名
   - 从 pom.xml 等参考文件自动获取权限设置
   - 支持跨协作者使用,提高团队协作便利性

2. Pull Request 提交规范
   - 自动读取 .github/PULL_REQUEST_TEMPLATE.md
   - 确保 PR 描述符合项目规范
   - 简化 PR 创建流程

配置文件位置:.claude/project-rules.md
适用范围:所有使用 Claude Code 的项目协作者
新增功能:
1. 脚手架命令 (fit init)
   - 支持快速创建 FIT 项目结构
   - 交互式输入项目信息
   - 命令行参数模式支持
   - 自动生成标准项目结构

2. 项目模板生成
   - pom.xml(包含 FIT 依赖配置)
   - Application.java(启动类)
   - HelloController.java(示例控制器)
   - Message.java(示例领域模型)
   - README.md(项目文档)
   - .gitignore(版本控制忽略文件)

3. 命令参数
   - --group-id: 指定 Maven Group ID
   - --artifact-id: 指定 Maven Artifact ID
   - --package: 指定 Java 包名
   - 支持交互式和非交互式两种模式

4. 文档更新
   - README 中添加 init 命令使用说明
   - 包含详细的使用示例和参数说明

使用示例:
  ./fit init my-app
  ./fit init my-app --group-id=com.mycompany --artifact-id=my-app

脚手架功能降低了 FIT 项目的上手难度,提高开发效率
- 支持创建独立的 Service (SPI) 和 Plugin 项目,符合 FIT 框架的插件架构规范
- 将模板代码从 fit.js 中分离到独立的 .tpl 文件,提高可维护性
- 新增交互式引导模式,所有参数均有合理默认值,用户可直接回车使用
- 保持向后兼容,支持命令行参数方式用于自动化场景
- Service 项目使用 build-service goal,Plugin 项目使用 build-plugin 和 package-plugin goals
- Plugin 项目自动依赖对应的 Service 项目

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
@CodeCasterX
Copy link
Member Author

🎉 新增功能:FIT 脚手架工具

本 PR 在 Node.js 启动脚本的基础上,新增了强大的脚手架功能,用于快速初始化 FIT 项目。

主要特性

1️⃣ 支持 Service/Plugin 分离架构

符合 FIT 框架的插件架构规范,支持创建两种类型的项目:

  • Service (SPI) - 服务接口定义,使用 @Genericable 注解
  • Plugin - 插件实现,使用 @Component@Fitable 注解

参考实现:examples/fit-example/03-dynamic-plugin

2️⃣ 交互式引导模式

用户体验优化,支持三种使用方式:

完全交互式(最简单)

fit init

指定项目名的交互式

fit init my-project

非交互式(适合 CI/CD)

fit init weather-service --type=service --service=Weather
fit init default-weather --type=plugin --service=Weather \
    --service-group-id=com.example --service-artifact-id=weather-service

3️⃣ 模板系统重构

  • 将所有模板代码从 fit.js 中分离到独立的 .tpl 文件
  • 提高代码可维护性和可读性
  • 模板目录:bin/templates/{service,plugin}/

4️⃣ 智能默认值

所有参数都有合理的默认值,用户可直接回车使用:

  • Group ID: com.example
  • Artifact ID: 项目名称
  • Package: groupId.artifactId(自动转换)
  • Service Name: Demo
  • Service Version: 1.0-SNAPSHOT

技术细节

Service 项目生成内容:

  • pom.xml - 使用 build-service goal
  • {ServiceName}.java - 服务接口(带 @Genericable
  • README.md - 项目文档
  • .gitignore - 版本控制配置

Plugin 项目生成内容:

  • pom.xml - 使用 build-pluginpackage-plugin goals,自动依赖对应的 Service
  • Default{ServiceName}.java - 实现类(带 @Component@Fitable
  • application.yml - FIT 配置文件
  • README.md - 项目文档
  • .gitignore - 版本控制配置

使用文档

详细使用说明请查看:

fit help

代码变更

  • 重构 fit.js:+684行 / -340行
  • 新增 8 个模板文件
  • 符合 FIT 框架规范,架构清晰

测试状态: ✅ 已通过功能测试
向后兼容: ✅ 保持完全兼容
文档更新: ✅ Help 信息已更新

🤖 Generated with Claude Code

@CodeCasterX CodeCasterX merged commit 6addb25 into 3.5.x Nov 9, 2025
6 checks passed
@CodeCasterX CodeCasterX deleted the fit-enhancement-startup branch November 9, 2025 02:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

in: fit Issues in FIT modules type: enhancement A general enhancement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants