vipera 1.0.1

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 5b34dc1066885afcb9611ecd17950b26cc3c5f9963db20ce8b0b9292b54a15b3
4
+ data.tar.gz: 3b8838f57012e8eaad117f18c9711e0231253bfed5d3cf0b07910a294bed7cf8
5
+ SHA512:
6
+ metadata.gz: 127ceb55499713d8f8ee98555c515f0323caf574fdb1b3f046b01b1eee1998dd82d3d00e5a83b40a68079017ada94e6cc4833dde3d717431e19eb7c2e5247c39
7
+ data.tar.gz: 1aef14256b5dddadb5dc1530a217cc6e449915681c5c77955056e3fc02347eaba3843c63b314f69fc0aad5c9828255e32bdb93b6059bc22512bace381578c425
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+ /.idea/
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in vipera.gemspec
6
+ gem 'xcodeproj'
7
+ gemspec
@@ -0,0 +1,35 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ vipera (1.0.0)
5
+ xcodeproj
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ CFPropertyList (3.0.2)
11
+ atomos (0.1.3)
12
+ claide (1.0.3)
13
+ colored2 (3.1.2)
14
+ minitest (5.14.1)
15
+ nanaimo (0.2.6)
16
+ rake (10.5.0)
17
+ xcodeproj (1.16.0)
18
+ CFPropertyList (>= 2.3.3, < 4.0)
19
+ atomos (~> 0.1.3)
20
+ claide (>= 1.0.2, < 2.0)
21
+ colored2 (~> 3.1)
22
+ nanaimo (~> 0.2.6)
23
+
24
+ PLATFORMS
25
+ ruby
26
+
27
+ DEPENDENCIES
28
+ bundler (~> 1.17)
29
+ minitest (~> 5.0)
30
+ rake (~> 10.0)
31
+ vipera!
32
+ xcodeproj
33
+
34
+ BUNDLED WITH
35
+ 1.17.2
@@ -0,0 +1,43 @@
1
+ # Viper
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/viper`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'vipera'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install viper
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ 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 tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/viper. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
36
+
37
+ ## License
38
+
39
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
40
+
41
+ ## Code of Conduct
42
+
43
+ Everyone interacting in the Viper project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/viper/blob/master/CODE_OF_CONDUCT.md).
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "vipera"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
@@ -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
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ require "vipera/main"
3
+ run_main
@@ -0,0 +1,25 @@
1
+ require 'json'
2
+ require 'xcodeproj'
3
+
4
+ CONFIG_DIR = "#{Dir.pwd}/vipera-config.json"
5
+
6
+ def create_new_config(module_root_dir)
7
+
8
+ if File.exists? CONFIG_DIR then raise "Already initialized!" end
9
+ unless File.exists? "#{Dir.pwd}/#{module_root_dir}" then raise "Module root directory not exists!" end
10
+
11
+ config_object = {"module-root": module_root_dir}
12
+ File.write CONFIG_DIR, JSON.generate(config_object)
13
+ end
14
+
15
+ def read_config
16
+ unless File.exists? CONFIG_DIR then raise "Config file required!" end
17
+ JSON.parse File.read CONFIG_DIR
18
+ end
19
+
20
+ def read_xcodeproj(config)
21
+ xcodeproj_file = config["xcodeproj"]
22
+ unless File.exists? "#{Dir.pwd}/#{xcodeproj_file}" then raise "xcodeproj file not found!" end
23
+
24
+ Xcodeproj::Project.open("#{Dir.pwd}/#{xcodeproj_file}")
25
+ end
@@ -0,0 +1,26 @@
1
+ require "vipera/config"
2
+ require "vipera/sources/sources"
3
+
4
+ def main
5
+ if ARGV.count < 1 then raise "Invalid arguments!" end
6
+
7
+ module_name = ARGV[0]
8
+
9
+ config = read_config
10
+ xcodeproj = read_xcodeproj config
11
+
12
+ source_map = Sources::create_sources_map module_name
13
+ Sources::generate_sources module_name, xcodeproj, read_config, source_map
14
+
15
+ xcodeproj.save
16
+
17
+ puts "Module #{module_name} generated!"
18
+ end
19
+
20
+ def run_main
21
+ begin
22
+ main
23
+ rescue StandardError => e
24
+ puts e.message
25
+ end
26
+ end
@@ -0,0 +1,18 @@
1
+ module Sources
2
+ def self.interactor(name)
3
+ return "#{name}Interactor.swift", <<~INTERACTOR
4
+ import UIKit
5
+
6
+ class #{name}Interactor: #{name}InteractorInputProtocol {
7
+ var presenter: #{name}InteractorOutputProtocol?
8
+ var localStorage: #{name}LocalStorageInputProtocol?
9
+ var webService: #{name}WebServiceInputProtocol?
10
+ }
11
+
12
+ // MARK: WEB_SERVICE -> INTERACTOR
13
+ extension #{name}Interactor: #{name}WebServiceOutputProtocol {
14
+
15
+ }
16
+ INTERACTOR
17
+ end
18
+ end
@@ -0,0 +1,11 @@
1
+ module Sources
2
+ def self.localstorage(name)
3
+ return "#{name}LocalStorage.swift", <<~LOCALSTORAGE
4
+ import Foundation
5
+
6
+ class #{name}LocalStorage: #{name}LocalStorageInputProtocol {
7
+
8
+ }
9
+ LOCALSTORAGE
10
+ end
11
+ end
@@ -0,0 +1,18 @@
1
+ module Sources
2
+ def self.presenter(name)
3
+ return "#{name}Presenter.swift", <<~PRESENTER
4
+ import UIKit
5
+
6
+ class #{name}Presenter: #{name}PresenterInputProtocol {
7
+ var view: #{name}ViewProtocol?
8
+ var interactor: #{name}InteractorInputProtocol?
9
+ var router: #{name}RouterProtocol?
10
+ }
11
+
12
+ // MARK: INTERACTOR -> PRESENTER
13
+ extension #{name}Presenter: #{name}InteractorOutputProtocol {
14
+
15
+ }
16
+ PRESENTER
17
+ end
18
+ end
@@ -0,0 +1,53 @@
1
+ module Sources
2
+ def self.protocols(name)
3
+ return "#{name}Protocols.swift", <<~PROTOCOLS
4
+ import UIKit
5
+
6
+ protocol #{name}ViewProtocol {
7
+ var presenter: #{name}PresenterInputProtocol? { get set }
8
+
9
+ // PRESENTER -> VIEW
10
+ }
11
+
12
+ protocol #{name}PresenterInputProtocol {
13
+ var view: #{name}ViewProtocol? { get set }
14
+ var interactor: #{name}InteractorInputProtocol? { get set }
15
+ var router: #{name}RouterProtocol? { get set }
16
+
17
+ // VIEW -> PRESENTER
18
+ }
19
+
20
+ protocol #{name}InteractorInputProtocol {
21
+ var presenter: #{name}InteractorOutputProtocol? { get set }
22
+ var localStorage: #{name}LocalStorageInputProtocol? { get set }
23
+ var webService: #{name}WebServiceInputProtocol? { get set }
24
+
25
+ // PRESENTER -> INTERACTOR
26
+ }
27
+
28
+ protocol #{name}InteractorOutputProtocol {
29
+ // INTERACTOR -> PRESENTER
30
+ }
31
+
32
+ protocol #{name}RouterProtocol {
33
+ // PRESENTER -> ROUTER
34
+ static func createModule() -> UIViewController?
35
+ }
36
+
37
+ protocol #{name}LocalStorageInputProtocol {
38
+ // INTERACTOR -> LOCALSTORAGE
39
+ }
40
+
41
+ protocol #{name}WebServiceInputProtocol {
42
+ var interactor: #{name}WebServiceOutputProtocol? { get set }
43
+
44
+ // INTERACTOR -> WEBSERVICE
45
+ }
46
+
47
+ protocol #{name}WebServiceOutputProtocol {
48
+ // WEBSERVICE -> INTERACTOR
49
+ }
50
+ PROTOCOLS
51
+ end
52
+ end
53
+
@@ -0,0 +1,30 @@
1
+ module Sources
2
+ def self.router(name)
3
+ return "#{name}Router.swift", <<~ROUTER
4
+ import UIKit
5
+
6
+ class #{name}Router: #{name}RouterProtocol {
7
+ static func createModule() -> UIViewController? {
8
+ let navController = // TODO: Set navController
9
+
10
+ guard let view = navController?.children.first as? #{name}ViewController else { return nil }
11
+
12
+ let router: #{name}RouterProtocol = #{name}Router()
13
+ var presenter: #{name}PresenterProtocol & #{name}InteractorOutputProtocol = #{name}Presenter()
14
+ var interactor: #{name}InteractorInputProtocol = #{name}Interactor()
15
+ let localStorage: #{name}LocalStorageProtocol = #{name}LocalStorage()
16
+ let webService: #{name}WebServiceInputProtocol = #{name}WebService()
17
+
18
+ view.presenter = presenter
19
+ presenter.view = view
20
+ presenter.router = router
21
+ presenter.interactor = interactor
22
+ interactor.presenter = presenter
23
+ interactor.localStorage = localStorage
24
+
25
+ return navController
26
+ }
27
+ }
28
+ ROUTER
29
+ end
30
+ end
@@ -0,0 +1,96 @@
1
+ require 'vipera/sources/protocols'
2
+ require 'vipera/sources/router'
3
+ require 'vipera/sources/presenter'
4
+ require 'vipera/sources/interactor'
5
+ require 'vipera/sources/view'
6
+ require 'vipera/sources/webservice'
7
+ require 'vipera/sources/localstorage'
8
+
9
+ module Sources
10
+ PASCAL_CASE_REGEX = /^[A-Z][a-z]+(?:[A-Z][a-z]+)*$/
11
+ DIRECTORIES = %w[Data Presenter Interactor Protocol Router View]
12
+
13
+ def self.create_sources_map(name)
14
+ unless name.match(PASCAL_CASE_REGEX) then raise "Invalid module name!" end
15
+
16
+ sources_map = {}
17
+ DIRECTORIES.each do |directory|
18
+ case directory
19
+ when "Data"
20
+ web_service = self.webservice(name)
21
+ local_storage = self.localstorage(name)
22
+ sources_map[directory] = {
23
+ web_service[0] => web_service[1],
24
+ local_storage[0] => local_storage[1]
25
+ }
26
+ when "Presenter"
27
+ presenter = self.presenter(name)
28
+ sources_map[directory] = {
29
+ presenter[0] => presenter[1]
30
+ }
31
+ when "Interactor"
32
+ interactor = self.interactor(name)
33
+ sources_map[directory] = {
34
+ interactor[0] => interactor[1]
35
+ }
36
+ when "Protocol"
37
+ protocols = self.protocols(name)
38
+ sources_map[directory] = {
39
+ protocols[0] => protocols[1]
40
+ }
41
+ when "Router"
42
+ router = self.router(name)
43
+ sources_map[directory] = {
44
+ router[0] => router[1]
45
+ }
46
+ else
47
+ view = self.view(name)
48
+ sources_map[directory] = {
49
+ view[0] => view[1]
50
+ }
51
+ end
52
+ end
53
+
54
+ sources_map
55
+ end
56
+
57
+ def self.generate_sources(name, xcodeproj, config, source_map)
58
+ target_path = "#{Dir.pwd}/#{config["module-root"]}/#{name}/"
59
+ if File.exists? target_path then raise "Module already exists!" end
60
+
61
+ # get target group from config
62
+ group_path = config["module-root"].split '/'
63
+ target_group = nil
64
+
65
+ group_path.each do |group_name|
66
+ if target_group == nil
67
+ filters = xcodeproj.groups.filter { |gp| gp.display_name == group_name }
68
+ if filters.count >= 1 then target_group = filters[0] else raise "Target group not found!" end
69
+ else
70
+ filters = target_group.groups.filter { |gp| gp.display_name == group_name }
71
+
72
+ if filters.count >= 1 then target_group = filters[0] else raise "Target group not found!" end
73
+ end
74
+ end
75
+
76
+ target_group = target_group.new_group(name, target_path)
77
+ Dir.mkdir target_path
78
+ source_map.each_key { |key_path|
79
+ key_full_path = target_path + key_path + "/"
80
+ key_group = target_group.new_group(key_path, key_full_path)
81
+
82
+ Dir.mkdir key_full_path
83
+
84
+ source_map[key_path].each_key { |file_name|
85
+ file_path = key_full_path + file_name
86
+ content = source_map[key_path][file_name]
87
+
88
+ File.write file_path, content
89
+
90
+ key_group.new_file file_name
91
+ }
92
+ }
93
+
94
+ target_path
95
+ end
96
+ end
@@ -0,0 +1,20 @@
1
+ module Sources
2
+ def self.view(name)
3
+ return "#{name}ViewController.swift", <<~VIEW
4
+ import UIKit
5
+
6
+ class #{name}ViewController: UIViewController {
7
+ var presenter: #{name}InteractorOutputProtocol?
8
+ var localStorage: #{name}LocalStorageInputProtocol?
9
+ var webService: #{name}WebServiceInputProtocol?
10
+ }
11
+
12
+ // MARK: PRESENTER -> VIEW
13
+ extension #{name}ViewController: #{name}ViewProtocol {
14
+
15
+ }
16
+
17
+
18
+ VIEW
19
+ end
20
+ end
@@ -0,0 +1,11 @@
1
+ module Sources
2
+ def self.webservice(name)
3
+ return "#{name}WebService.swift", <<~WEBSERVICE
4
+ import UIKit
5
+
6
+ class #{name}WebService: #{name}WebServiceInputProtocol {
7
+ var interactor: #{name}WebServiceOutputProtocol?
8
+ }
9
+ WEBSERVICE
10
+ end
11
+ end
@@ -0,0 +1,3 @@
1
+ module Viper
2
+ VERSION = "1.0.1"
3
+ end
@@ -0,0 +1,18 @@
1
+ require 'xcodeproj'
2
+
3
+ project_path = '/Users/channyeinthaw/Documents/Lab/pagewerkz-reader-ios/GlobalEdu.xcodeproj'
4
+ project = Xcodeproj::Project.open(project_path)
5
+
6
+ global_edu_gp = (project.groups.filter { |group| group.display_name == 'GlobalEdu' })[0]
7
+ puts global_edu_gp.real_path
8
+
9
+ test_gp = global_edu_gp.new_group('testGp', "#{global_edu_gp.real_path}/testGp")
10
+ # test_gp.new_file("test.swift")
11
+ # project.groups.each do |group|
12
+ # puts group.display_name
13
+ # # group.new_file("file.swift")
14
+ # testGp = group.new_group("testGp", "/Users/channyeinthaw/Documents/Lab/pagewerkz-reader-ios/GlobalEdu")
15
+ # testGp.new_file("file.swift")
16
+ # end
17
+ #
18
+ project.save
@@ -0,0 +1,27 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "vipera/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "vipera"
8
+ spec.version = Viper::VERSION
9
+ spec.authors = ["Chan Nyein Thaw"]
10
+ spec.email = ["chanyeinthaw@outlook.com"]
11
+
12
+ spec.summary = "Viper Module Generator"
13
+ spec.description = "Viper Module Generator"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
17
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ end
19
+
20
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
21
+ spec.require_paths = ["lib"]
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.17"
24
+ spec.add_development_dependency "rake", "~> 10.0"
25
+ spec.add_development_dependency "minitest", "~> 5.0"
26
+ spec.add_dependency "xcodeproj"
27
+ end
metadata ADDED
@@ -0,0 +1,122 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: vipera
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Chan Nyein Thaw
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2020-06-15 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.17'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.17'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: minitest
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '5.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '5.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: xcodeproj
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: Viper Module Generator
70
+ email:
71
+ - chanyeinthaw@outlook.com
72
+ executables:
73
+ - console
74
+ - setup
75
+ - vipera
76
+ extensions: []
77
+ extra_rdoc_files: []
78
+ files:
79
+ - ".gitignore"
80
+ - Gemfile
81
+ - Gemfile.lock
82
+ - README.md
83
+ - bin/console
84
+ - bin/setup
85
+ - bin/vipera
86
+ - lib/vipera/config.rb
87
+ - lib/vipera/main.rb
88
+ - lib/vipera/sources/interactor.rb
89
+ - lib/vipera/sources/localstorage.rb
90
+ - lib/vipera/sources/presenter.rb
91
+ - lib/vipera/sources/protocols.rb
92
+ - lib/vipera/sources/router.rb
93
+ - lib/vipera/sources/sources.rb
94
+ - lib/vipera/sources/view.rb
95
+ - lib/vipera/sources/webservice.rb
96
+ - lib/vipera/version.rb
97
+ - lib/xcode_test.rb
98
+ - vipera.gemspec
99
+ homepage:
100
+ licenses:
101
+ - MIT
102
+ metadata: {}
103
+ post_install_message:
104
+ rdoc_options: []
105
+ require_paths:
106
+ - lib
107
+ required_ruby_version: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - ">="
110
+ - !ruby/object:Gem::Version
111
+ version: '0'
112
+ required_rubygems_version: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - ">="
115
+ - !ruby/object:Gem::Version
116
+ version: '0'
117
+ requirements: []
118
+ rubygems_version: 3.0.3
119
+ signing_key:
120
+ specification_version: 4
121
+ summary: Viper Module Generator
122
+ test_files: []