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.
- checksums.yaml +4 -4
- data/Gemfile +6 -1
- data/README.md +74 -10
- data/Rakefile +14 -1
- data/bin/console +15 -0
- data/bin/setup +8 -0
- data/lib/mt_tool/commands.rb +43 -229
- data/lib/mt_tool/module/module.rb +275 -0
- data/lib/mt_tool/module/template/swift/Entity.swift +15 -0
- data/lib/mt_tool/module/template/swift/Interactor.swift +16 -0
- data/lib/mt_tool/module/template/swift/Presenter.swift +28 -0
- data/lib/mt_tool/module/template/swift/Router.swift +50 -0
- data/lib/mt_tool/module/template/swift/ViewController.swift +97 -0
- data/lib/mt_tool/version.rb +1 -1
- data/mt_tool.gemspec +23 -26
- metadata +81 -111
- data/.MTModuleFilesConfig.yml +0 -5
- data/.idea/.gitignore +0 -8
- data/.idea/misc.xml +0 -4
- data/.idea/modules.xml +0 -8
- data/.idea/mt_tool.iml +0 -45
- data/.idea/vcs.xml +0 -7
- data/Gemfile.lock +0 -134
- data/lib/mt_tool/analyze.rb +0 -126
- data/lib/mt_tool/template/objc/Bundle.h +0 -21
- data/lib/mt_tool/template/objc/Bundle.m +0 -28
- data/lib/mt_tool/template/objc/CategoryHeader.h +0 -15
- data/lib/mt_tool/template/objc/PrefixHeader.pch +0 -36
- data/lib/mt_tool/template/objc/RouterDefine.h +0 -14
- data/lib/mt_tool/template/objc/RouterRegister.h +0 -16
- data/lib/mt_tool/template/objc/RouterRegister.m +0 -33
- data/lib/mt_tool/template/objc/ServiceProtocol.h +0 -15
- data/lib/mt_tool/template/objc/ServiceRegister.h +0 -16
- data/lib/mt_tool/template/objc/ServiceRegister.m +0 -25
- data/lib/mt_tool/template/objc/ToolsHeader.h +0 -13
- data/lib/mt_tool/template/objc/VendorHeader.h +0 -13
- data/lib/mt_tool/template/objc/demo/DemoViewController.h +0 -17
- data/lib/mt_tool/template/objc/demo/DemoViewController.m +0 -28
- data/lib/mt_tool/template/objc/demo/DemoViewModel.h +0 -14
- data/lib/mt_tool/template/objc/demo/DemoViewModel.m +0 -19
- data/sig/mt_tool.rbs +0 -4
- /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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2671c087892b569fe4925329354c5211b46cc409879167a4a20e6e3b7548380a
|
4
|
+
data.tar.gz: 2999d07e97a347e65513bb01c9e1a8ca675c36c71a26b2581d4f7cb5cdc01db6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3caa9622bf7aec720a073aa9d24322adb8744a6451936ed931b25c3cfa25f543392627b1414fb439c978bc799c65c08201615e1e61919c3b5a2d05721aedf772
|
7
|
+
data.tar.gz: 4afa9862815131168293066842634a4435de43ca46da56c9399b5fc952ae10ce01005d0c3d7ff458437ca519f870b99dcfa02712e04905efe40746838c846964
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,29 +1,93 @@
|
|
1
1
|
# MtTool
|
2
2
|
|
3
|
-
|
3
|
+
A Ruby gem for generating VIPER architecture modules for iOS projects. Supports both Swift and Objective-C.
|
4
4
|
|
5
|
-
|
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
|
-
|
17
|
+
Add this line to your application's Gemfile:
|
10
18
|
|
11
|
-
|
19
|
+
```ruby
|
20
|
+
gem 'mt_tool'
|
21
|
+
```
|
12
22
|
|
13
|
-
|
23
|
+
And then execute:
|
24
|
+
```bash
|
25
|
+
$ bundle install
|
26
|
+
```
|
14
27
|
|
15
|
-
|
28
|
+
Or install it yourself as:
|
29
|
+
```bash
|
30
|
+
$ gem install mt_tool
|
31
|
+
```
|
16
32
|
|
17
33
|
## Usage
|
18
34
|
|
19
|
-
|
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 `
|
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
|
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
|
-
|
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
|
-
|
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
data/lib/mt_tool/commands.rb
CHANGED
@@ -1,243 +1,57 @@
|
|
1
|
-
require 'colored2'
|
2
1
|
require 'thor'
|
3
|
-
require '
|
4
|
-
require '
|
5
|
-
|
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
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
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
|
-
|
42
|
-
|
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
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
@
|
108
|
-
@
|
109
|
-
|
110
|
-
@
|
111
|
-
@
|
112
|
-
@
|
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
|