generamba 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (49) hide show
  1. checksums.yaml +7 -0
  2. data/.rspec +2 -0
  3. data/.travis.yml +4 -0
  4. data/Gemfile +4 -0
  5. data/Gemfile.lock +64 -0
  6. data/LICENSE.txt +21 -0
  7. data/Rakefile +6 -0
  8. data/Readme.md +51 -0
  9. data/bin/GenerambaSandbox/Rambafile +17 -0
  10. data/bin/console +14 -0
  11. data/bin/generamba +5 -0
  12. data/bin/setup +7 -0
  13. data/generamba.gemspec +31 -0
  14. data/lib/generamba.rb +17 -0
  15. data/lib/generamba/cli/cli.rb +15 -0
  16. data/lib/generamba/cli/gen_command.rb +26 -0
  17. data/lib/generamba/cli/setup_command.rb +80 -0
  18. data/lib/generamba/cli/template/template_create_command.rb +29 -0
  19. data/lib/generamba/cli/template/template_group.rb +12 -0
  20. data/lib/generamba/cli/template/template_install_command.rb +10 -0
  21. data/lib/generamba/cli/thor_extension.rb +34 -0
  22. data/lib/generamba/code_generation/Rambafile.liquid +37 -0
  23. data/lib/generamba/code_generation/code_module.rb +32 -0
  24. data/lib/generamba/code_generation/content_generator.rb +42 -0
  25. data/lib/generamba/code_generation/module_template.rb +20 -0
  26. data/lib/generamba/code_generation/rambafile_generator.rb +22 -0
  27. data/lib/generamba/configuration/project_configuration.rb +9 -0
  28. data/lib/generamba/configuration/user_preferences.rb +50 -0
  29. data/lib/generamba/constants/constants.rb +12 -0
  30. data/lib/generamba/constants/rambafile_constants.rb +24 -0
  31. data/lib/generamba/constants/rambaspec_constants.rb +16 -0
  32. data/lib/generamba/constants/user_preferences_constants.rb +5 -0
  33. data/lib/generamba/helpers/template_helper.rb +32 -0
  34. data/lib/generamba/helpers/xcodeproj_helper.rb +87 -0
  35. data/lib/generamba/module_generator.rb +97 -0
  36. data/lib/generamba/template/creator/new_template/Code/Service/service.h.liquid +11 -0
  37. data/lib/generamba/template/creator/new_template/Code/Service/service.m.liquid +13 -0
  38. data/lib/generamba/template/creator/new_template/Tests/Service/service_tests.m.liquid +35 -0
  39. data/lib/generamba/template/creator/new_template/template.rambaspec.liquid +20 -0
  40. data/lib/generamba/template/creator/template_creator.rb +38 -0
  41. data/lib/generamba/template/helpers/rambaspec_validator.rb +47 -0
  42. data/lib/generamba/template/installer/abstract_installer.rb +9 -0
  43. data/lib/generamba/template/installer/catalog_installer.rb +40 -0
  44. data/lib/generamba/template/installer/local_installer.rb +32 -0
  45. data/lib/generamba/template/installer/remote_installer.rb +43 -0
  46. data/lib/generamba/template/processor/template_declaration.rb +34 -0
  47. data/lib/generamba/template/processor/template_processor.rb +77 -0
  48. data/lib/generamba/version.rb +3 -0
  49. metadata +221 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: ffb2a6a54f2534abe4a3a94904ac75c4dfc375cf
4
+ data.tar.gz: beef4c78efff15575167171b8ac21293ee34d092
5
+ SHA512:
6
+ metadata.gz: bb416b0ca779e1bc359734e2082a4f4b91e2e078b85ff93ae8d6313f074ca1720a716020f490efa264c83c8439161f63f2fd2f357856d0b4d0424ce10d6b0d1f
7
+ data.tar.gz: 9147cf3e069cb1d99d3984979943d45d725c80d74fb6831be704b949e904c20b196d17a25ce340f8ca491c2f8b2bd6137e6d0435298efa2e721e9b0cf0db6bee
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.1.6
4
+ before_install: gem install bundler -v 1.10.6
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in generamba.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,64 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ generamba (0.5.0)
5
+ git
6
+ liquid
7
+ settingslogic
8
+ thor
9
+ tilt
10
+ xcodeproj
11
+
12
+ GEM
13
+ remote: https://rubygems.org/
14
+ specs:
15
+ activesupport (4.2.4)
16
+ i18n (~> 0.7)
17
+ json (~> 1.7, >= 1.7.7)
18
+ minitest (~> 5.1)
19
+ thread_safe (~> 0.3, >= 0.3.4)
20
+ tzinfo (~> 1.1)
21
+ claide (0.9.1)
22
+ colored (1.2)
23
+ diff-lcs (1.2.5)
24
+ git (1.2.9.1)
25
+ i18n (0.7.0)
26
+ json (1.8.3)
27
+ liquid (3.0.6)
28
+ minitest (5.8.1)
29
+ rake (10.4.2)
30
+ rspec (3.3.0)
31
+ rspec-core (~> 3.3.0)
32
+ rspec-expectations (~> 3.3.0)
33
+ rspec-mocks (~> 3.3.0)
34
+ rspec-core (3.3.2)
35
+ rspec-support (~> 3.3.0)
36
+ rspec-expectations (3.3.1)
37
+ diff-lcs (>= 1.2.0, < 2.0)
38
+ rspec-support (~> 3.3.0)
39
+ rspec-mocks (3.3.2)
40
+ diff-lcs (>= 1.2.0, < 2.0)
41
+ rspec-support (~> 3.3.0)
42
+ rspec-support (3.3.0)
43
+ settingslogic (2.0.9)
44
+ thor (0.19.1)
45
+ thread_safe (0.3.5)
46
+ tilt (2.0.1)
47
+ tzinfo (1.2.2)
48
+ thread_safe (~> 0.1)
49
+ xcodeproj (0.28.2)
50
+ activesupport (>= 3)
51
+ claide (~> 0.9.1)
52
+ colored (~> 1.2)
53
+
54
+ PLATFORMS
55
+ ruby
56
+
57
+ DEPENDENCIES
58
+ bundler (~> 1.10)
59
+ generamba!
60
+ rake (~> 10.0)
61
+ rspec
62
+
63
+ BUNDLED WITH
64
+ 1.10.6
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Egor Tolstoy
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/Readme.md ADDED
@@ -0,0 +1,51 @@
1
+ ### Overview
2
+
3
+ **Generamba** - это генератор кода, заточенный под работу с Xcode. В первую очередь предназначен для генерации модулей VIPER - но достаточно легко настраивается и для генерации любых других классов.
4
+
5
+ ### Основные особенности
6
+
7
+ - Из коробки поддерживает работу с *.xcodeproj* файлами - все сгенерированные классы автоматически распределяются как по файловой структуре, так и по группам в проекте.
8
+ - Умеет генерировать как непосредственно код, так и тесты, автоматически распределяя их по правильным таргетам.
9
+ - Основан на работе с [liquid-шаблонами](https://github.com/Shopify/liquid) - синтаксис простой и понятный, особенно в сравнении с шаблонами для Xcode.
10
+ - Создать новый модуль очень просто: `generamba gen MyModule`. Не требуется каждый раз вводить кучу данных - каждому проекту соответствует один конфигурационный файл, содержащий в себе стандартные пути в файловой системе и Xcode-проекте, названия таргетов, информацию об авторе.
11
+
12
+
13
+ ### Установка
14
+ Проект пока что находится в стадии beta-версии, поэтому не добавлен в общий каталог ruby-gem'ов. Локальная установка осуществляется следующим образом:
15
+
16
+ 1. Склонируйте репозиторий себе на компьютер
17
+ 2. В консоли перейдите в директорию проекта
18
+ 3. Вызовите команду `gem install generamba`
19
+
20
+ ### Использование
21
+ В настоящий момент Generamba поддерживает две команды:
22
+
23
+ 1. `generamba setup` - вызывается в корневой директории проекта. Помогает автоматически создать и настроить *Rambafile*, описывающий всю конфигурацию, необходимую для генерации кода. В дальнейшем этот файл может быть модифицирован вручную.
24
+ 2. `generamba gen MODULE_NAME` - генерирует модуль с указанным названием. В качестве стандартного используется шаблон *viper_module*. Команда поддерживает несколбко дополнительных опций - узнать о них больше поможет команда `generamba help gen`.
25
+
26
+ В текущей версии нет возможности создавать локальные шаблоны и использовать их для генерации. Пока что используем следующий workaround:
27
+
28
+ 1. `open ~/.rvm/gems/ruby-2.1.6/gems`
29
+ 2. Находим директорию *Generamba-x.x.x*
30
+ 3. Переходим в *lib/generamba/default_templates/*
31
+ 4. Создаем папку с названием нового модуля. В остальном модуль создается по образцу стандартного.
32
+
33
+ Оптимизация добавления шаблонов является главным приоритетом на данный момент.
34
+
35
+ ### Авторы
36
+
37
+ - Егор Толстой
38
+ - Андрей Зарембо-Годзяцкий
39
+
40
+ ### Лицензия
41
+
42
+ MIT
43
+
44
+ ### TODO
45
+
46
+ - Дать возможность использовать локальный шаблон, указав полный путь до него
47
+ - В Rambafile держать информацию обо всех используемых в проекте шаблонах
48
+ - Вынести из Rambafile информацию, специфичную для текущего автора (имя)
49
+ - Добавить для каждого шаблона возможность модифицировать Podfile проекта
50
+ - Добавить GUI
51
+ - Добавить возможность генерирования тестов по указанным интерфейсным файлам
@@ -0,0 +1,17 @@
1
+ ---
2
+ author: Egor Tolstoy
3
+ company: Rambler&Co
4
+ project_name: GenerambaSandbox
5
+ prefix:
6
+ xcodeproj_path: "/Users/etolstoy/Generamba/GenerambaSandbox/GenerambaSandbox.xcodeproj"
7
+ project_target: GenerambaSandbox
8
+ project_file_path: GenerambaSandbox/Classes/Modules/
9
+ project_group_path: GenerambaSandbox/Classes/Modules/
10
+ test_target: GenerambaSandboxTests
11
+ test_file_path: GenerambaSandboxTests/Classes/Modules/
12
+ test_group_path: GenerambaSandboxTests/Classes/Modules/
13
+ templates:
14
+ - {name: default_template, git: 'https://github.com/igrekde/default_template.git'}
15
+ - {name: rambler_viper_controller, local: '/Users/etolstoy/Generamba/rambler_viper_controller'}
16
+ - {name: rambler_viper_controller2, local: '/Users/etolstoy/Generamba/rambler_viper_controller2'}
17
+ - {name: default}
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "generamba"
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
data/bin/generamba ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'generamba'
4
+
5
+ Generamba::CLI::Application.start(ARGV)
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
data/generamba.gemspec ADDED
@@ -0,0 +1,31 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'generamba/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'generamba'
8
+ spec.version = Generamba::VERSION
9
+ spec.authors = ['Egor Tolstoy', 'Andrey Zarembo']
10
+ spec.email = 'e.tolstoy@rambler-co.ru'
11
+
12
+ spec.summary = 'Advanced code generator for Xcode projects with a nice and flexible template system.'
13
+ spec.description = 'Generamba is a powerful and easy-to-use Xcode code generator. It provides a project-based configuration, flexible templates system, the ability to generate code and tests simultaneously.'
14
+ spec.homepage = 'https://github.com/rambler-ios/Generamba'
15
+ spec.license = 'MIT'
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.executables = ['generamba']
19
+ spec.require_paths = ['lib']
20
+
21
+ spec.add_dependency 'thor'
22
+ spec.add_dependency 'xcodeproj'
23
+ spec.add_dependency 'liquid'
24
+ spec.add_dependency 'tilt'
25
+ spec.add_dependency 'settingslogic'
26
+ spec.add_dependency 'git'
27
+
28
+ spec.add_development_dependency 'bundler', '~> 1.10'
29
+ spec.add_development_dependency 'rake', '~> 10.0'
30
+ spec.add_development_dependency 'rspec'
31
+ end
data/lib/generamba.rb ADDED
@@ -0,0 +1,17 @@
1
+ require 'xcodeproj'
2
+
3
+ module Generamba
4
+ require 'generamba/constants/constants.rb'
5
+ require 'generamba/constants/rambafile_constants.rb'
6
+ require 'generamba/constants/rambaspec_constants.rb'
7
+ require 'generamba/cli/cli.rb'
8
+ require 'generamba/code_generation/code_module.rb'
9
+ require 'generamba/code_generation/module_template.rb'
10
+ require 'generamba/configuration/project_configuration'
11
+ require 'generamba/code_generation/content_generator.rb'
12
+ require 'generamba/code_generation/rambafile_generator.rb'
13
+ require 'generamba/module_generator.rb'
14
+ require 'generamba/template/processor/template_processor.rb'
15
+ require 'generamba/configuration/user_preferences.rb'
16
+ require 'generamba/template/creator/template_creator.rb'
17
+ end
@@ -0,0 +1,15 @@
1
+ require 'thor'
2
+ require 'xcodeproj'
3
+ require 'liquid'
4
+ require 'tilt'
5
+ require 'git'
6
+ require 'generamba/cli/gen_command.rb'
7
+ require 'generamba/cli/setup_command.rb'
8
+ require 'generamba/cli/thor_extension.rb'
9
+ require 'generamba/cli/template/template_group.rb'
10
+
11
+ module Generamba::CLI
12
+ class Application < Thor
13
+
14
+ end
15
+ end
@@ -0,0 +1,26 @@
1
+ require 'thor'
2
+
3
+ module Generamba::CLI
4
+ class Application < Thor
5
+
6
+ desc 'gen [MODULE_NAME] [TEMPLATE_NAME_KEY]', 'Creates a new VIPER module with a given name from a specific template'
7
+ method_option :description, :aliases => '-d', :desc => 'Provides a full description to the module'
8
+ def gen(module_name, template_name)
9
+
10
+ does_rambafile_exist = Dir[RAMBAFILE_NAME].count > 0
11
+
12
+ if (does_rambafile_exist == false)
13
+ puts('Rambafile not found! Run `generamba setup` in the working directory instead!')
14
+ return
15
+ end
16
+
17
+ default_module_description = "#{module_name} module"
18
+ module_description = options[:description] ? options[:description] : default_module_description
19
+
20
+ generator = Generamba::ModuleGenerator.new()
21
+ generator.generate_module(template_name, module_name, module_description)
22
+
23
+ end
24
+
25
+ end
26
+ end
@@ -0,0 +1,80 @@
1
+ require 'thor'
2
+ require 'xcodeproj'
3
+ require 'liquid'
4
+ require 'tilt'
5
+ require 'git'
6
+ require 'generamba/constants/rambafile_constants.rb'
7
+
8
+ module Generamba::CLI
9
+ class Application < Thor
10
+ include Generamba
11
+
12
+ desc 'setup', 'Creates a Rambafile with a config for a given project'
13
+ def setup
14
+ properties = {}
15
+
16
+ git_username = Git.init.config['user.name']
17
+
18
+ if git_username != nil && yes?("Your name in git is configured as #{git_username}. Do you want to use it in code headers? (yes/no)")
19
+ username = git_username
20
+ else
21
+ username = ask_non_empty_string('The author name which will be used in the headers:', 'User name should not be empty')
22
+ end
23
+
24
+ Generamba::UserPreferences.save_username(username)
25
+
26
+ properties[COMPANY_KEY] = ask('The company name which will be used in the headers:')
27
+
28
+ project_name = Pathname.new(Dir.getwd).basename.to_s
29
+ is_right_project_name = yes?("The name of your project is #{project_name}. Do you want to use it? (yes/no)")
30
+ properties[PROJECT_NAME_KEY] = is_right_project_name ? project_name : ask_non_empty_string('The project name:', 'Project name should not be empty')
31
+ properties[PROJECT_PREFIX_KEY] = ask('The project prefix (if any):')
32
+
33
+ project_files = Dir['*.xcodeproj']
34
+ count = project_files.count
35
+ if count == 1
36
+ is_right_path = yes?("The path to a .xcodeproj file of the project is #{project_files[0]}. Do you want to use it? (yes/no)")
37
+ xcode_path = is_right_path ? project_files[0] : ask('The path to a .xcodeproj file of the project:')
38
+ else
39
+ xcode_path = ask('The path to a .xcodeproj file of the project:')
40
+ end
41
+
42
+ properties[XCODEPROJ_PATH_KEY] = xcode_path
43
+ project = Xcodeproj::Project.open(xcode_path)
44
+
45
+ targets_prompt = ''
46
+ project.targets.each_with_index { |element, i| targets_prompt += ("#{i}. #{element.name}" + "\n") }
47
+
48
+ project_target = ask_index("Select the appropriate target for adding your MODULES (type the index):\n" + targets_prompt,project.targets)
49
+ test_target = ask_index("Select the appropriate target for adding your TESTS (type the index):\n" + targets_prompt,project.targets)
50
+
51
+ should_use_same_paths = yes?('Do you want to use the same paths for your files both in Xcode and the filesystem? (yes/no)')
52
+ if should_use_same_paths
53
+ project_group_path = ask('The default path for creating new modules:')
54
+ project_file_path = project_group_path
55
+
56
+ test_group_path = ask('The default path for creating tests:')
57
+ test_file_path = test_group_path
58
+ else
59
+ project_group_path = ask('The default path for creating new modules (in Xcode groups):')
60
+ project_file_path = ask('The default path for creating new modules (in the filesystem):')
61
+
62
+ test_group_path = ask('The default path for creating tests (in Xcode groups):')
63
+ test_file_path = ask('The default path for creating tests (in the filesystem):')
64
+ end
65
+
66
+ properties[PODFILE_PATH_KEY] = ask('The Podfile path (if any):')
67
+ properties[CARTFILE_PATH_KEY] = ask('The Cartfile path (if any):')
68
+
69
+ properties[PROJECT_TARGET_KEY] = project_target.name
70
+ properties[PROJECT_FILE_PATH_KEY] = project_file_path
71
+ properties[PROJECT_GROUP_PATH_KEY] = project_group_path
72
+ properties[TEST_TARGET_KEY] = test_target.name
73
+ properties[TEST_FILE_PATH_KEY] = test_file_path
74
+ properties[TEST_GROUP_PATH_KEY] = test_group_path
75
+
76
+ Generamba::RambafileGenerator.create_rambafile(properties)
77
+ say('Rambafile successfully created! Now add some templates to the Rambafile and run `generamba template install`.')
78
+ end
79
+ end
80
+ end
@@ -0,0 +1,29 @@
1
+ module Generamba::CLI
2
+ class Template < Thor
3
+ include Generamba
4
+
5
+ desc 'create [TEMPLATE_NAME]', 'Creates a new Generamba template with a given name'
6
+ def create(template_name)
7
+ summary = ask('The brief description of your new template:')
8
+ author = ask('Who is the author of this template:')
9
+ license = ask('What license will be used (e.g. MIT):')
10
+
11
+ has_dependencies = yes?('Will your template contain any third-party dependencies (available via Cocoapods or Carthage)? (yes/no)')
12
+ if has_dependencies
13
+ dependencies = ask_loop('Enter the name of your dependency (empty string to stop):')
14
+ end
15
+
16
+ properties = {
17
+ TEMPLATE_NAME_KEY => template_name,
18
+ TEMPLATE_SUMMARY_KEY => summary,
19
+ TEMPLATE_AUTHOR_KEY => author,
20
+ TEMPLATE_LICENSE_KEY => license,
21
+ TEMPLATE_DEPENDENCIES_KEY => dependencies
22
+ }
23
+
24
+ template_creator = Generamba::TemplateCreator.new
25
+ template_creator.create_template(properties)
26
+ say("The template #{template_name} is successfully generated! Now add some file templates into it.")
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,12 @@
1
+ require 'generamba/cli/template/template_install_command.rb'
2
+ require 'generamba/cli/template/template_create_command.rb'
3
+
4
+ module Generamba::CLI
5
+ class Application < Thor
6
+ register(Generamba::CLI::Template, 'template', 'template <command>', 'Provides a set of commands for working with templates')
7
+ end
8
+
9
+ class Template < Thor
10
+
11
+ end
12
+ end