easyci 0.1.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e16811fbe303dcd906e4dfbbb6d77d95467d9d7c91d67c6299c399677074565b
4
- data.tar.gz: 25eba83f49c25ce27f04e040e37e210b1f4e70b5c2a94df60391cbf4d0cf07d8
3
+ metadata.gz: 52ad4bed8dabbcf19bc106286047500b3c77d76839a94d961ee7fde58ce2696a
4
+ data.tar.gz: f7464d713c16eba856835d656e429a3ead16d40b222a65afeb6a61817496fef2
5
5
  SHA512:
6
- metadata.gz: 3f70f76959081795b47f8f12a75f52201c8613851f8588f08ce9c704f57c443143f8f25a24b8226fb37efdcf76faaeb8d602b17551c93c421888fcfc1bdf70f8
7
- data.tar.gz: 0ff6bde5e2a75ae58bddd2f87772e4ff4853f3378d0b555b68272b7eb5499d0dd38259e7ed3f62c73e22d8e6f2c0e59822306f11d209ba321d18a44bfbea239b
6
+ metadata.gz: 232b65b1e8b19525263ef3eb631bc83d28f37df6eefb27cd324e2931863bc13a687c57870504bec20639a16ae4ac33952ab064ab913f3718c9e5c9d9d8667eeb
7
+ data.tar.gz: 634cf16b0860979ea83e74bc286c8eaf7472699876f91ef05f82d840313f17c2a23a998e1d3fbeaea57da8efd2150fe4623b25783b4b72bac42174409bb6b662
data/LICENSE CHANGED
File without changes
data/README.md CHANGED
@@ -10,14 +10,37 @@ gem install easyci
10
10
 
11
11
  ## 使用方法
12
12
 
13
- ### Unity依赖关系图
13
+ ### Unity依赖关系图与截图
14
14
 
15
- 分析Unity项目并生成依赖关系图:
15
+ #### 本地项目分析
16
+
17
+ 分析本地Unity项目并生成依赖关系图和截图:
16
18
 
17
19
  ```bash
18
- easyci unitydraw --project-path=/path/to/unity/project --output=dependencies.png
20
+ easyci unitydraw --project-path=/path/to/unity/project --output=dependencies.png --execute-method=YourMethod.Execute
19
21
  ```
20
22
 
23
+ #### Gitee仓库分析
24
+
25
+ 从Gitee仓库拉取项目并生成依赖关系图和截图:
26
+
27
+ ```bash
28
+ easyci unitydraw --repo=username/repo --branch=master --compress
29
+ ```
30
+
31
+ #### 完整选项
32
+
33
+ unitydraw命令支持以下选项:
34
+
35
+ - `--project-path=PATH`: 指定本地Unity项目路径
36
+ - `--output=PATH`: 输出图形的路径
37
+ - `--repo=REPO`: Gitee仓库路径,例如:bestwebprimary/MagicSortDemo
38
+ - `--branch=BRANCH`: Gitee分支名称,默认为master
39
+ - `--work-dir=DIR`: 工作目录,默认为~/gitee_draw
40
+ - `--execute-method=METHOD`: Unity执行方法,默认为SpineAutoImporter.CIRunner
41
+ - `--unity-path=PATH`: 指定Unity可执行文件路径,默认自动查找
42
+ - `--compress`: 是否压缩生成的截图
43
+
21
44
  ### 自动构建
22
45
 
23
46
  自动构建项目:
@@ -26,6 +49,18 @@ easyci unitydraw --project-path=/path/to/unity/project --output=dependencies.png
26
49
  easyci autobuild --project-path=/path/to/project --build-target=iOS --output=/path/to/output --version=1.0.0
27
50
  ```
28
51
 
52
+ ## 特性
53
+
54
+ ### Unity可执行文件自动查找
55
+
56
+ EasyCI内置了UnityExeHelper模块,可以根据项目信息自动查找匹配的Unity可执行文件:
57
+
58
+ - 自动从ProjectVersion.txt文件中读取项目的Unity版本
59
+ - 在标准安装路径中查找匹配版本的Unity
60
+ - 支持macOS、Windows和Linux系统
61
+ - 如果找不到匹配版本,会自动使用最新版本的Unity
62
+ - 可以通过`--unity-path`选项手动指定Unity路径
63
+
29
64
  ## 选项
30
65
 
31
66
  全局选项:
File without changes
@@ -1,37 +1,119 @@
1
+ require 'fileutils'
2
+
1
3
  module EasyCI
2
4
  class Command
3
5
  class Unitydraw < Command
4
6
  self.summary = '绘制Unity项目图形'
5
- self.description = '分析Unity项目并生成依赖关系图'
7
+ self.description = '分析Unity项目并生成依赖关系图和截图'
6
8
 
7
9
  def self.options
8
10
  [
9
- ['--project-path=PATH', '指定Unity项目路径'],
10
- ['--output=PATH', '输出图形的路径']
11
+ ['--runner-repo=REPO', 'Runner仓库路径,例如:mygroup/FGUIWorkRunner'],
12
+ ['--https', '使用HTTPS方式克隆仓库,默认使用SSH方式'],
11
13
  ].concat(super)
12
14
  end
13
15
 
14
16
  def initialize(argv)
15
- @project_path = argv.option('project-path')
16
- @output_path = argv.option('output')
17
17
  super
18
+ @runner_repo = argv.option('runner-repo')
19
+ @use_https = argv.flag?('https', false)
18
20
  end
19
21
 
20
22
  def validate!
21
23
  super
22
- help! '必须提供项目路径' unless @project_path
23
24
  end
24
25
 
25
26
  def run
26
- puts "分析Unity项目: #{@project_path}" if @verbose
27
- # 这里是实际执行Unity项目分析和绘图的代码
28
- puts "生成项目依赖图..."
29
- # 模拟工作
30
- sleep(1)
27
+ puts "开始Unity项目绘制流程..."
28
+
29
+ work_dir = File.expand_path('~/gitee_draw')
30
+ gitee_repo = ENV['GITEE_REPO'] || 'fundesignexport/MagicSortDemoDesignExport'
31
+ gitee_branch = ENV['GITEE_BRANCH'] || 'master'
32
+
33
+ # 如果未提供runner-repo参数,使用默认值
34
+ @runner_repo ||= ENV['GITEE_REPO'] || 'bestwebprimary/FGUIWorkRunner'
35
+
36
+ if gitee_repo.empty? || gitee_branch.empty?
37
+ puts "GITEE_REPO 和 GITEE_BRANCH 不能为空"
38
+ exit 1
39
+ end
40
+
41
+
42
+ puts "gitee_repo: #{gitee_repo}"
43
+ puts "gitee_branch: #{gitee_branch}"
44
+ puts "work_dir: #{work_dir}"
45
+
46
+ # 清理工作目录
47
+ FileUtils.mkdir_p(work_dir)
48
+ runner_dir = File.join(work_dir, 'FGUIWorkRunner')
49
+ FileUtils.rm_rf(runner_dir) if File.exist?(runner_dir)
50
+ git_url = @use_https ? "https://gitee.com/#{@runner_repo}.git" : "git@gitee.com:#{@runner_repo}.git"
51
+ puts "git_url: #{git_url}"
52
+ clone_runner_result = system("cd #{work_dir} && git clone --depth 1 -b #{gitee_branch} #{git_url} FGUIWorkRunner")
53
+ unless clone_runner_result
54
+ puts "克隆Runner仓库失败,请检查网络和权限设置"
55
+ exit 1
56
+ end
57
+ unless File.exist?(runner_dir)
58
+ puts "Runner目录不存在,克隆可能失败"
59
+ exit 1
60
+ end
61
+
62
+ FileUtils.chdir(runner_dir)
63
+ resources_dir = File.join(runner_dir, 'Assets/Resources')
64
+ if File.exist?(resources_dir)
65
+ FileUtils.rm_rf(resources_dir)
66
+ end
67
+ puts "下载截图仓库..."
68
+ git_url = @use_https ? "https://gitee.com/#{gitee_repo}.git" : "git@gitee.com:#{gitee_repo}.git"
69
+ puts "git_url: #{git_url}"
70
+ clone_result = system("cd #{runner_dir} && git clone --depth 1 -b #{gitee_branch} #{git_url} Assets/Resources")
71
+
72
+ unless clone_result
73
+ puts "克隆Assets仓库失败,请检查网络和权限设置"
74
+ exit 1
75
+ end
76
+
77
+ # 运行Unity截图任务
78
+ unity_path = find_unity_path(runner_dir)
79
+ puts "运行Unity截图任务..."
80
+ FileUtils.chdir(runner_dir)
81
+ system("#{unity_path} -projectPath . -executeMethod #{@execute_method} -logFile screenshot-log.txt")
82
+
83
+ # 压缩截图
84
+ puts "开始压缩截图..."
85
+ system("find . -path \"*/Screenshots/*.png\" -exec pngquant --quality=70-95 --ext .png --force {} \\;")
86
+ # 运行Node脚本(如果需要)
87
+ puts "运行后处理脚本..."
88
+ system("docker run --rm -v \"$(pwd):/app\" -w /app node:22.0.0 bash -c \"cd Scripts && yarn install && npx ts-node index.ts\"")
89
+
90
+ end
91
+
92
+ private
93
+
94
+ def find_unity_path(project_path)
95
+ # 如果提供了Unity路径,验证它
96
+ if @unity_path && !@unity_path.empty?
97
+ if UnityExeHelper.valid_unity_path?(@unity_path)
98
+ puts "使用指定的Unity路径: #{@unity_path}"
99
+ return @unity_path
100
+ else
101
+ puts "警告: 指定的Unity路径无效,将尝试自动查找"
102
+ end
103
+ end
31
104
 
32
- output = @output_path || "unity_dependencies.png"
33
- puts "项目依赖图已生成至: #{output}"
105
+ # 使用UnityExeHelper查找Unity
106
+ begin
107
+ unity_path = UnityExeHelper.find_unity_executable(project_path, @verbose)
108
+ puts "找到Unity路径: #{unity_path}"
109
+ return unity_path
110
+ rescue => e
111
+ puts "查找Unity路径失败: #{e.message}"
112
+ exit 1
113
+ end
114
+ return nil
34
115
  end
116
+
35
117
  end
36
118
  end
37
119
  end
File without changes
@@ -0,0 +1,164 @@
1
+ module EasyCI
2
+ # UnityExeHelper模块,用于查找和验证Unity可执行文件路径
3
+ module UnityExeHelper
4
+ # 查找Unity可执行文件路径
5
+ # @param project_path [String] Unity项目路径
6
+ # @param verbose [Boolean] 是否显示详细信息
7
+ # @return [String] Unity可执行文件路径
8
+ def self.find_unity_executable(project_path = nil, verbose = false)
9
+ unity_path = nil
10
+ project_version = nil
11
+
12
+ # 如果提供了项目路径,尝试从ProjectVersion.txt中读取版本
13
+ if project_path && !project_path.empty?
14
+ version_file = File.join(project_path, 'ProjectSettings', 'ProjectVersion.txt')
15
+ if File.exist?(version_file)
16
+ content = File.read(version_file)
17
+ if content =~ /m_EditorVersion:\s*([\d\.]+[a-zA-Z\d]*)/
18
+ project_version = $1
19
+ puts "项目Unity版本: #{project_version}" if verbose
20
+ end
21
+ end
22
+ end
23
+
24
+ # 如果找到项目版本,尝试定位对应的Unity
25
+ if project_version
26
+ # 检查macOS路径
27
+ if RUBY_PLATFORM =~ /darwin/
28
+ mac_path = "/Applications/Unity/Hub/Editor/#{project_version}/Unity.app/Contents/MacOS/Unity"
29
+ if File.exist?(mac_path)
30
+ unity_path = mac_path
31
+ puts "找到匹配版本的Unity: #{unity_path}" if verbose
32
+ end
33
+ # 检查Windows路径
34
+ elsif RUBY_PLATFORM =~ /mswin|mingw|cygwin/
35
+ win_path = "C:/Program Files/Unity/Hub/Editor/#{project_version}/Editor/Unity.exe"
36
+ if File.exist?(win_path)
37
+ unity_path = win_path
38
+ puts "找到匹配版本的Unity: #{unity_path}" if verbose
39
+ end
40
+ # 检查Linux路径
41
+ elsif RUBY_PLATFORM =~ /linux/
42
+ linux_path = "/opt/unity/hub/editor/#{project_version}/Editor/Unity"
43
+ if File.exist?(linux_path)
44
+ unity_path = linux_path
45
+ puts "找到匹配版本的Unity: #{unity_path}" if verbose
46
+ end
47
+ end
48
+ end
49
+
50
+ # 如果没有找到匹配版本,尝试查找最新版本
51
+ if unity_path.nil?
52
+ puts "没有找到匹配的Unity版本,尝试查找最新版本" if verbose
53
+ unity_path = find_latest_unity(verbose)
54
+ end
55
+
56
+ # 如果仍然找不到,抛出错误
57
+ raise "无法找到Unity可执行文件,请确保Unity已正确安装" if unity_path.nil?
58
+
59
+ unity_path
60
+ end
61
+
62
+ # 查找最新版本的Unity
63
+ # @param verbose [Boolean] 是否显示详细信息
64
+ # @return [String] Unity可执行文件路径
65
+ def self.find_latest_unity(verbose = false)
66
+ # 检查macOS路径
67
+ if RUBY_PLATFORM =~ /darwin/
68
+ hub_path = "/Applications/Unity/Hub/Editor"
69
+ if Dir.exist?(hub_path)
70
+ # 获取所有版本并按版本号排序
71
+ versions = Dir.entries(hub_path).select { |e| e =~ /[\d\.]+/ }.sort_by do |v|
72
+ v.split('.').map(&:to_i)
73
+ end
74
+
75
+ if versions.any?
76
+ latest_version = versions.last
77
+ mac_path = "#{hub_path}/#{latest_version}/Unity.app/Contents/MacOS/Unity"
78
+ if File.exist?(mac_path)
79
+ puts "使用最新Unity版本 #{latest_version}: #{mac_path}" if verbose
80
+ return mac_path
81
+ end
82
+ end
83
+ end
84
+
85
+ # 查找传统路径
86
+ traditional_path = "/Applications/Unity/Unity.app/Contents/MacOS/Unity"
87
+ if File.exist?(traditional_path)
88
+ puts "使用传统路径Unity: #{traditional_path}" if verbose
89
+ return traditional_path
90
+ end
91
+ # 检查Windows路径
92
+ elsif RUBY_PLATFORM =~ /mswin|mingw|cygwin/
93
+ hub_path = "C:/Program Files/Unity/Hub/Editor"
94
+ if Dir.exist?(hub_path)
95
+ versions = Dir.entries(hub_path).select { |e| e =~ /[\d\.]+/ }.sort_by do |v|
96
+ v.split('.').map(&:to_i)
97
+ end
98
+
99
+ if versions.any?
100
+ latest_version = versions.last
101
+ win_path = "#{hub_path}/#{latest_version}/Editor/Unity.exe"
102
+ if File.exist?(win_path)
103
+ puts "使用最新Unity版本 #{latest_version}: #{win_path}" if verbose
104
+ return win_path
105
+ end
106
+ end
107
+ end
108
+
109
+ # 查找传统路径
110
+ traditional_path = "C:/Program Files/Unity/Editor/Unity.exe"
111
+ if File.exist?(traditional_path)
112
+ puts "使用传统路径Unity: #{traditional_path}" if verbose
113
+ return traditional_path
114
+ end
115
+ # 检查Linux路径
116
+ elsif RUBY_PLATFORM =~ /linux/
117
+ hub_path = "/opt/unity/hub/editor"
118
+ if Dir.exist?(hub_path)
119
+ versions = Dir.entries(hub_path).select { |e| e =~ /[\d\.]+/ }.sort_by do |v|
120
+ v.split('.').map(&:to_i)
121
+ end
122
+
123
+ if versions.any?
124
+ latest_version = versions.last
125
+ linux_path = "#{hub_path}/#{latest_version}/Editor/Unity"
126
+ if File.exist?(linux_path)
127
+ puts "使用最新Unity版本 #{latest_version}: #{linux_path}" if verbose
128
+ return linux_path
129
+ end
130
+ end
131
+ end
132
+ end
133
+
134
+ nil
135
+ end
136
+
137
+ # 验证Unity可执行文件路径是否有效
138
+ # @param unity_path [String] Unity可执行文件路径
139
+ # @return [Boolean] 是否有效
140
+ def self.valid_unity_path?(unity_path)
141
+ return false if unity_path.nil? || unity_path.empty?
142
+ File.exist?(unity_path) && File.executable?(unity_path)
143
+ end
144
+
145
+ # 获取Unity版本信息
146
+ # @param unity_path [String] Unity可执行文件路径
147
+ # @return [String] Unity版本信息
148
+ def self.get_unity_version(unity_path)
149
+ return nil unless valid_unity_path?(unity_path)
150
+
151
+ begin
152
+ # 使用-version参数获取版本信息
153
+ version_output = `"#{unity_path}" -version 2>&1`
154
+ if version_output =~ /([\d\.]+[a-zA-Z\d]*)/
155
+ return $1
156
+ end
157
+ rescue => e
158
+ puts "获取Unity版本信息失败: #{e.message}"
159
+ end
160
+
161
+ nil
162
+ end
163
+ end
164
+ end
@@ -1,3 +1,3 @@
1
1
  module EasyCI
2
- VERSION = '0.1.0'
2
+ VERSION = '0.4.0'
3
3
  end
data/lib/easyci.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require 'easyci/version'
2
+ require 'easyci/unity_exe_helper'
2
3
  require 'easyci/command'
3
4
  require 'easyci/command/unitydraw'
4
5
  require 'easyci/command/autobuild'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: easyci
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Wade
@@ -80,6 +80,7 @@ files:
80
80
  - lib/easyci/command.rb
81
81
  - lib/easyci/command/autobuild.rb
82
82
  - lib/easyci/command/unitydraw.rb
83
+ - lib/easyci/unity_exe_helper.rb
83
84
  - lib/easyci/version.rb
84
85
  homepage: https://github.com/yourusername/easyci
85
86
  licenses: