mt_tool 0.1.3 → 1.0.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.
Files changed (42) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +6 -1
  3. data/README.md +74 -10
  4. data/Rakefile +14 -1
  5. data/bin/console +15 -0
  6. data/bin/setup +8 -0
  7. data/lib/mt_tool/commands.rb +43 -229
  8. data/lib/mt_tool/module/module.rb +275 -0
  9. data/lib/mt_tool/module/template/swift/Entity.swift +15 -0
  10. data/lib/mt_tool/module/template/swift/Interactor.swift +16 -0
  11. data/lib/mt_tool/module/template/swift/Presenter.swift +28 -0
  12. data/lib/mt_tool/module/template/swift/Router.swift +50 -0
  13. data/lib/mt_tool/module/template/swift/ViewController.swift +97 -0
  14. data/lib/mt_tool/version.rb +1 -1
  15. data/mt_tool.gemspec +23 -26
  16. metadata +81 -111
  17. data/.MTModuleFilesConfig.yml +0 -5
  18. data/.idea/.gitignore +0 -8
  19. data/.idea/misc.xml +0 -4
  20. data/.idea/modules.xml +0 -8
  21. data/.idea/mt_tool.iml +0 -45
  22. data/.idea/vcs.xml +0 -7
  23. data/Gemfile.lock +0 -134
  24. data/lib/mt_tool/analyze.rb +0 -126
  25. data/lib/mt_tool/template/objc/Bundle.h +0 -21
  26. data/lib/mt_tool/template/objc/Bundle.m +0 -28
  27. data/lib/mt_tool/template/objc/CategoryHeader.h +0 -15
  28. data/lib/mt_tool/template/objc/PrefixHeader.pch +0 -36
  29. data/lib/mt_tool/template/objc/RouterDefine.h +0 -14
  30. data/lib/mt_tool/template/objc/RouterRegister.h +0 -16
  31. data/lib/mt_tool/template/objc/RouterRegister.m +0 -33
  32. data/lib/mt_tool/template/objc/ServiceProtocol.h +0 -15
  33. data/lib/mt_tool/template/objc/ServiceRegister.h +0 -16
  34. data/lib/mt_tool/template/objc/ServiceRegister.m +0 -25
  35. data/lib/mt_tool/template/objc/ToolsHeader.h +0 -13
  36. data/lib/mt_tool/template/objc/VendorHeader.h +0 -13
  37. data/lib/mt_tool/template/objc/demo/DemoViewController.h +0 -17
  38. data/lib/mt_tool/template/objc/demo/DemoViewController.m +0 -28
  39. data/lib/mt_tool/template/objc/demo/DemoViewModel.h +0 -14
  40. data/lib/mt_tool/template/objc/demo/DemoViewModel.m +0 -19
  41. data/sig/mt_tool.rbs +0 -4
  42. /data/lib/mt_tool/{template → module/template}/swift/RouterDefine.swift +0 -0
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ca57bd0d4463ef855c164f414da4a25d00c535340e647d23001df1ad21273eec
4
- data.tar.gz: 10037e4818e9a08eb3451d7afd3acf82d3053780ef742850029529540b50111b
3
+ metadata.gz: 2671c087892b569fe4925329354c5211b46cc409879167a4a20e6e3b7548380a
4
+ data.tar.gz: 2999d07e97a347e65513bb01c9e1a8ca675c36c71a26b2581d4f7cb5cdc01db6
5
5
  SHA512:
6
- metadata.gz: 73e7e99cf89c345b4c276be4bf73f3d1181aca067a11087a45f5253065f051d6d9c23f5b59999a3a91acdcce15588bb4aeea662a9384f020e28554bdc62d7d97
7
- data.tar.gz: a9a42acdcb1c78cf115c2c6e62d2c3fac6e479f1ad9fcf407543d66b984fab36474990076be7279840db6e05bb1c7e796bd101bf667eef8493b0b02506bfe8c3
6
+ metadata.gz: 3caa9622bf7aec720a073aa9d24322adb8744a6451936ed931b25c3cfa25f543392627b1414fb439c978bc799c65c08201615e1e61919c3b5a2d05721aedf772
7
+ data.tar.gz: 4afa9862815131168293066842634a4435de43ca46da56c9399b5fc952ae10ce01005d0c3d7ff458437ca519f870b99dcfa02712e04905efe40746838c846964
data/Gemfile CHANGED
@@ -5,4 +5,9 @@ source "https://rubygems.org"
5
5
  # Specify your gem's dependencies in mt_tool.gemspec
6
6
  gemspec
7
7
 
8
- gem "rake", "~> 13.0"
8
+ # Development dependencies are specified in gemspec
9
+ group :development do
10
+ gem "rake", "~> 13.0"
11
+ gem "pry"
12
+ gem "pry-byebug"
13
+ end
data/README.md CHANGED
@@ -1,29 +1,93 @@
1
1
  # MtTool
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/mt_tool`. To experiment with that code, run `bin/console` for an interactive prompt.
3
+ A Ruby gem for generating VIPER architecture modules for iOS projects. Supports both Swift and Objective-C.
4
4
 
5
- TODO: Delete this and the text above, and describe your gem
5
+ <img src="img/69786f8e2a527b8c26f2c1311e230e5f.webp.png" alt="Module File Generator" height="150" width="150">
6
+
7
+ ## Features
8
+
9
+ - Generate complete VIPER module structure
10
+ - Support for both Swift and Objective-C
11
+ - Customizable templates
12
+ - Command-line interface
13
+ - Detailed logging for debugging
6
14
 
7
15
  ## Installation
8
16
 
9
- Install the gem and add to the application's Gemfile by executing:
17
+ Add this line to your application's Gemfile:
10
18
 
11
- $ bundle add mt_tool
19
+ ```ruby
20
+ gem 'mt_tool'
21
+ ```
12
22
 
13
- If bundler is not being used to manage dependencies, install the gem by executing:
23
+ And then execute:
24
+ ```bash
25
+ $ bundle install
26
+ ```
14
27
 
15
- $ gem install mt_tool
28
+ Or install it yourself as:
29
+ ```bash
30
+ $ gem install mt_tool
31
+ ```
16
32
 
17
33
  ## Usage
18
34
 
19
- TODO: Write usage instructions here
35
+ ### Generating a VIPER Module
36
+
37
+ ```bash
38
+ # Generate a VIPER module
39
+ mt_tool vmod -n ModuleName -a "Author Name" -p ./path/to/module
40
+
41
+ # Example
42
+ mt_tool vmod -n HomeScreen -a "Tom Liu" -p ./Modules
43
+ ```
44
+
45
+ ### Command Options
46
+
47
+ - `-n, --name`: Module name (required)
48
+ - `-a, --author`: Author name (required)
49
+ - `-p, --path`: Target path for generation (required)
50
+
51
+ ### Generated Structure
52
+
53
+ ```
54
+ ModuleName/
55
+ ├── ModuleNameEntity.swift
56
+ ├── ModuleNameInteractor.swift
57
+ ├── ModuleNamePresenter.swift
58
+ ├── ModuleNameRouter.swift
59
+ └── ModuleNameViewController.swift
60
+ ```
20
61
 
21
62
  ## Development
22
63
 
23
- After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
64
+ After checking out the repo, run `bundle install` to install dependencies.
65
+
66
+ To run the test suite:
67
+ ```bash
68
+ bundle exec rake test
69
+ ```
24
70
 
25
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
71
+ To install this gem onto your local machine:
72
+ ```bash
73
+ bundle exec rake install
74
+ ```
26
75
 
27
76
  ## Contributing
28
77
 
29
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/mt_tool.
78
+ 1. Fork it
79
+ 2. Create your feature branch (`git checkout -b feature/my-new-feature`)
80
+ 3. Add tests for your changes
81
+ 4. Make your changes
82
+ 5. Run the tests (`bundle exec rake test`)
83
+ 6. Commit your changes (`git commit -am 'Add some feature'`)
84
+ 7. Push to the branch (`git push origin feature/my-new-feature`)
85
+ 8. Create new Pull Request
86
+
87
+ ## License
88
+
89
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
90
+
91
+ ## Code of Conduct
92
+
93
+ Everyone interacting in the MtTool project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/lylelh/mt_tool/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile CHANGED
@@ -1,4 +1,17 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "bundler/gem_tasks"
4
- task default: %i[]
4
+ require "rspec/core/rake_task"
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ task :clean do
9
+ FileUtils.rm_rf('pkg')
10
+ FileUtils.rm_rf('test_output')
11
+ end
12
+
13
+ task :build => :clean
14
+
15
+ task :test => [:clean, :spec]
16
+
17
+ task :default => :test
data/bin/console ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "bundler/setup"
5
+ require "mt_tool"
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require "irb"
15
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -1,243 +1,57 @@
1
- require 'colored2'
2
1
  require 'thor'
3
- require 'fileutils'
4
- require 'psych'
5
- require 'yaml'
6
- require 'mt_tool/analyze'
2
+ require 'mt_tool/module/module'
3
+ require 'logger'
4
+
7
5
  module MtTool
8
6
  class CLI < Thor
9
7
  include Thor::Actions
10
8
 
11
- CONFIG_FILE = '.MTModuleFilesConfig.yml'.freeze
12
-
13
- desc 'generate <Path> <Module Name> <Language> <Prefix - 前缀> <Author - 作者>', '直接生成项目 例子: yk_command generate . HomeModule oc MT Tom.Liu '
14
- method_option :generate, aliases: '-g'
15
-
16
- def generate(path = nil, name, lang, class_prefix, author)
17
- @name = name
18
- @module = @name
19
- @lang = lang
20
- @class_prefix = class_prefix
21
- @final_path = "#{path}/#{@name}"
22
- @author = author
23
- @prefixed_module = @class_prefix + @module
24
-
25
- say "generating file in path:#{@final_path}", :green
26
-
27
- if File.exist?(@final_path.to_s)
28
- say "#{@final_path} 已存在:", :red
29
- else
30
- prepare_folder
31
- if File.exist?("#{@final_path}/configure")
32
- system("#{@final_path}/configure", @name, @lang, @class_prefix, *@additional_args)
33
- else
34
- say 'Template does not have a configure file', :red
35
- end
36
- yk_module_folders
37
- yk_template_files
9
+ def initialize(*args)
10
+ super
11
+ @logger = Logger.new(STDOUT)
12
+ @logger.level = Logger::DEBUG
13
+ @logger.formatter = proc do |severity, datetime, progname, msg|
14
+ "[#{severity}][#{datetime.strftime('%Y-%m-%d %H:%M:%S.%L')}] #{msg}\n"
38
15
  end
39
16
  end
40
17
 
41
- desc 'create <Path>', '在某个路径下交互式生成项目'
42
- method_option :create, aliases: '-c'
43
-
44
- def create(path = nil)
45
- path = Dir.pwd if path.nil?
46
-
47
- say '模块名:', :green
48
- config_file_path = "#{path}/#{CONFIG_FILE}"
49
- config = File.exist?(config_file_path) ? YAML.load_file(config_file_path) : {}
50
- input_name = ask("Project name [#{config[:project]}] ?")
51
-
52
- if input_name != ''
53
- @name = input_name
54
- config[:project] = input_name if input_name != config[:project]
55
- else
56
- @name = config[:project]
57
- end
58
-
59
- File.open(config_file_path, 'w') do |f|
60
- f.write config.to_yaml
61
- end
62
-
63
- @final_path = "#{path}/#{@name}"
64
-
65
- if File.exist?(@final_path.to_s)
66
- say "#{@final_path} 已存在:", :red
67
- else
68
- prepare_folder
69
- read_config(path)
70
-
71
- if File.exist?("#{@final_path}/configure")
72
- system("#{@final_path}/configure", @name, @lang, @class_prefix, *@additional_args)
73
- else
74
- say 'Template does not have a configure file', :red
75
- end
76
-
77
- yk_module_folders
78
- yk_template_files
79
-
80
- end
18
+ def self.exit_on_failure?
19
+ true
81
20
  end
82
21
 
83
- no_commands do
84
- def read_config(path)
85
- config_file_path = "#{path}/#{CONFIG_FILE}"
86
- config = File.exist?(config_file_path) ? YAML.load_file(config_file_path) : {}
87
-
88
- project = @name
89
- say '语言:', :green
90
- language = ask("Project language [#{config[:language]}] ?", limited_to: ['objc', 'swift', ''])
91
- say '类名前缀:', :green
92
- class_prefix = ask("Class prefix [#{config[:class_prefix]}] ?")
93
- say '文件作者:', :green
94
- author = ask("Author [#{config[:author]}] ?")
95
-
96
- config[:project] = project.empty? ? config[:project] || '' : project
97
- config[:language] = language.empty? ? config[:language] || 'objc' : language
98
- config[:class_prefix] = class_prefix.empty? ? config[:class_prefix] || '' : class_prefix
99
- config[:author] = author.empty? ? config[:author] || '' : author
100
-
101
- File.open(config_file_path, 'w') do |f|
102
- f.write config.to_yaml
103
- # f.write YAML.to_yaml(config)
104
- end
105
-
106
- @module = @name
107
- @class_prefix = config[:class_prefix]
108
- @prefixed_module = config[:class_prefix] + @module
109
- @project = config[:project]
110
- @author = config[:author]
111
- @date = Time.now.strftime('%d/%m/%y')
112
- @lang = config[:language]
22
+ desc 'vmod', '生成viper模块文件'
23
+ method_option :name, aliases: '-n', desc: 'Module name', required: true
24
+ method_option :author, aliases: '-a', desc: 'Author name', required: true
25
+ method_option :path, aliases: '-p', desc: 'Target path', required: true
26
+ def vmod
27
+ name = options[:name]
28
+ author = options[:author]
29
+ path = options[:path]
30
+
31
+ @logger.debug "====== VIPER Module Generation Started ======"
32
+ @logger.debug "Command Parameters:"
33
+ @logger.debug " - Module name: #{name}"
34
+ @logger.debug " - Author: #{author}"
35
+ @logger.debug " - Path: #{path}"
36
+ @logger.debug "Thor Options: #{options.inspect}"
37
+ @logger.debug "Thor Arguments: #{args.inspect}"
38
+
39
+ begin
40
+ @logger.debug "Creating new Module instance..."
41
+ module_instance = Module.new(self.args, self.options)
42
+
43
+ @logger.debug "Calling create_viper_module..."
44
+ module_instance.create_viper_module(path, name, "swift", "", author)
45
+
46
+ @logger.info "Successfully generated VIPER module: #{name}"
47
+ @logger.debug "====== VIPER Module Generation Completed ======"
48
+ rescue => e
49
+ @logger.error "Failed to generate VIPER module: #{e.message}"
50
+ @logger.debug "Error backtrace:"
51
+ @logger.debug e.backtrace.join("\n")
52
+ @logger.debug "====== VIPER Module Generation Failed ======"
53
+ raise e
113
54
  end
114
-
115
- def prepare_folder
116
-
117
- template_repo_url = 'https://github.com/lyleLH/MTTemplate.git'
118
- system("git clone #{template_repo_url} #{@final_path}")
119
-
120
- # FileUtils.remove_dir(@final_path, true)
121
- # FileUtils.cp_r('/Users/imacn24/Documents/dev/YKProjectTemplate', @final_path)
122
- # FileUtils.remove_dir("#{@final_path}/.git", true)
123
- end
124
-
125
- def yk_module_folders
126
- class_folder_path = "#{@final_path}/#{@name}/Classes"
127
-
128
- first_level_folders = %w[Public Private]
129
-
130
- # public_level_folders = ['Register']
131
- # public_level_folders.each do |folder|
132
- # path = "#{class_folder_path}/Public/#{folder}"
133
- # empty_directory path
134
- # end
135
-
136
- private_level_folders = %w[Business Category Vendor Tools]
137
-
138
- first_level_folders.each do |folder|
139
- path = "#{class_folder_path}/#{folder}"
140
- empty_directory path
141
- end
142
-
143
- private_level_folders.each do |folder|
144
- path = "#{class_folder_path}/Private/#{folder}"
145
- empty_directory path
146
- end
147
- end
148
-
149
- CLI.source_root(File.dirname(__FILE__))
150
-
151
- def yk_template_files
152
- register_path = "#{@final_path}/#{@name}/Classes/Private/Register"
153
- registger = {
154
- 'RouterRegister.h' => 'RouterRegister',
155
- 'RouterRegister.m' => 'RouterRegister',
156
- 'ServiceRegister.h' => 'ServiceRegister',
157
- 'ServiceRegister.m' => 'ServiceRegister'
158
- }
159
-
160
- registger.each do |file_name, _folder|
161
- final_file = "#{register_path}/#{@prefixed_module}#{file_name}"
162
- template "#{__dir__}/template/objc/#{file_name}", final_file
163
- end
164
-
165
- public_folder_path = "#{@final_path}/#{@name}/Classes/Public"
166
-
167
- template_code_filename = ['ServiceProtocol.h', 'RouterDefine.h']
168
- template_code_filename.each do |file_name|
169
- final_file = "#{public_folder_path}/#{@prefixed_module}#{file_name}"
170
- source = "#{__dir__}/template/objc/#{file_name}"
171
- template source, final_file
172
- end
173
-
174
- swift_template_code_filename = ['RouterDefine.swift']
175
- swift_template_code_filename.each do |file_name|
176
- final_file = "#{public_folder_path}/#{@prefixed_module}_Swift_#{file_name}"
177
- source = "#{__dir__}/template/swift/#{file_name}"
178
- template source, final_file
179
- end
180
-
181
- private_folder_path = "#{@final_path}/#{@name}/Classes/Private"
182
- #pch file
183
- # pch_file_name = "PrefixHeader.pch"
184
- # final_file = "#{private_folder_path}/#{@prefixed_module}#{pch_file_name}"
185
- # source = "#{__dir__}/template/objc/#{pch_file_name}"
186
- # template source, final_file
187
-
188
- private_level_folder_files = {
189
- 'PrefixHeader.pch' => 'Business',
190
- 'CategoryHeader.h' => 'Category',
191
- 'ToolsHeader.h' => 'Tools',
192
- 'vendorHeader.h' => 'Vendor'
193
- }
194
-
195
- private_level_folder_files.each do |file_name, folder|
196
- final_prefix = @prefixed_module
197
- if file_name == 'PrefixHeader.pch'
198
- final_prefix = @module
199
- end
200
-
201
- final_file = "#{private_folder_path}/#{folder}/#{final_prefix}#{file_name}"
202
- source = "#{__dir__}/template/objc/#{file_name}"
203
- template source, final_file
204
- end
205
-
206
- tools_files_path = "#{@final_path}/#{@name}/Classes/Private/Tools"
207
-
208
- tool_files = ['Bundle.h','Bundle.m']
209
- tool_files.each do |file_name|
210
- final_file = "#{tools_files_path}/#{@prefixed_module}#{file_name}"
211
- source = "#{__dir__}/template/objc/#{file_name}"
212
- template source, final_file
213
- end
214
-
215
- business_demo_path = "#{@final_path}/#{@name}/Classes/Private/Business"
216
- demo_replace_file = ['DemoViewController.h', 'DemoViewController.m', 'DemoViewModel.h', 'DemoViewModel.m']
217
- demo_replace_file.each do |file_name|
218
- final_file = "#{business_demo_path}/Demo/#{@prefixed_module}#{file_name}"
219
- source = "#{__dir__}/template/objc/demo/#{file_name}"
220
- template source, final_file
221
- end
222
-
223
- Dir.chdir("#{@final_path}/Example") do
224
- system 'pod install'
225
- system "open './#{@name}.xcworkspace'"
226
- end
227
- end
228
-
229
- end
230
-
231
- desc 'dependency <Podfile.lock Path>', '解析Podfile.lock'
232
- method_option :dependency, aliases: '-d'
233
-
234
- def dependency(path = nil)
235
- say 'start resolve dependency', :green
236
-
237
- analyzer = Analyzer.new
238
- result = analyzer.analyze(path)
239
- pp result
240
-
241
55
  end
242
56
  end
243
57
  end