gemaker 0.3.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (43) hide show
  1. checksums.yaml +5 -5
  2. data/.circleci/config.yml +103 -0
  3. data/.circleci/setup-rubygems.sh +3 -0
  4. data/.rubocop.yml +72 -614
  5. data/.ruby-version +1 -1
  6. data/CHANGELOG.md +33 -0
  7. data/README.md +16 -1
  8. data/gemaker.gemspec +9 -15
  9. data/lib/gemaker.rb +2 -1
  10. data/lib/gemaker/cli.rb +8 -6
  11. data/lib/gemaker/commands/add_cli_structure.rb +1 -0
  12. data/lib/gemaker/commands/add_install_generator.rb +30 -6
  13. data/lib/gemaker/commands/configure_continuous_integration.rb +23 -0
  14. data/lib/gemaker/commands/configure_editor_config.rb +10 -0
  15. data/lib/gemaker/commands/configure_git.rb +13 -2
  16. data/lib/gemaker/commands/configure_test_env.rb +9 -6
  17. data/lib/gemaker/commands/create_gem.rb +11 -5
  18. data/lib/gemaker/commands/customize_engine.rb +31 -4
  19. data/lib/gemaker/config.rb +1 -9
  20. data/lib/gemaker/templates/circle_config.yml.erb +103 -0
  21. data/lib/gemaker/templates/circleci-setup-script.sh +3 -0
  22. data/lib/gemaker/templates/editorconfig +24 -0
  23. data/lib/gemaker/templates/engine/Guardfile +6 -9
  24. data/lib/gemaker/templates/engine/README.md.erb +45 -2
  25. data/lib/gemaker/templates/engine/development.rb.erb +81 -0
  26. data/lib/gemaker/templates/engine/engine.rb.erb +1 -1
  27. data/lib/gemaker/templates/engine/gemspec.erb +9 -5
  28. data/lib/gemaker/templates/engine/gitignore +10 -0
  29. data/lib/gemaker/templates/engine/install_generator.rb.erb +0 -2
  30. data/lib/gemaker/templates/engine/rails_helper.rb.erb +24 -9
  31. data/lib/gemaker/templates/engine/rubocop.yml.erb +503 -0
  32. data/lib/gemaker/templates/normal/README.md.erb +14 -0
  33. data/lib/gemaker/templates/normal/gemspec.erb +9 -5
  34. data/lib/gemaker/templates/normal/rubocop.yml.erb +496 -0
  35. data/lib/gemaker/templates/normal/spec_helper.rb.erb +11 -0
  36. data/lib/gemaker/templates/ruby-version.erb +1 -1
  37. data/lib/gemaker/util.rb +3 -2
  38. data/lib/gemaker/version.rb +7 -1
  39. metadata +65 -50
  40. data/.coveralls.yml +0 -1
  41. data/.hound.yml +0 -4
  42. data/.travis.yml +0 -13
  43. data/lib/gemaker/commands/add_hound_rules.rb +0 -12
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 2.3
1
+ 2.7
data/CHANGELOG.md CHANGED
@@ -2,6 +2,39 @@
2
2
  All notable changes to this project will be documented in this file.
3
3
  This project adheres to [Semantic Versioning](http://semver.org/).
4
4
 
5
+ ### 1.0.0
6
+ ##### Changed
7
+
8
+ - Generate gems with Circle CI instead of Travis.
9
+ - Generate dummy app with Rails 6.
10
+ - Use Review Dog instead of Hound.
11
+ - Always create mountable engines.
12
+ - Move specs out of dummy app.
13
+
14
+ ### 0.6.0
15
+
16
+ ##### Changed
17
+
18
+ * Replace travis with circleci.
19
+
20
+ ### v0.5.0
21
+
22
+ ##### Added
23
+
24
+ * Replace factory_girl with factory_bot.
25
+ * Generate engines with Rails 5.
26
+
27
+ ### v0.4.0
28
+
29
+ ##### Added
30
+
31
+ * Add command to configure Travis CI.
32
+ * Change test command to configure coveralls.
33
+
34
+ ##### Fixed
35
+
36
+ * Run engine creation with specific Rails version to avoid unsupported Rails 5 structure.
37
+
5
38
  ### v0.3.0
6
39
 
7
40
  ##### Added
data/README.md CHANGED
@@ -1,4 +1,9 @@
1
- # Gemaker [![Gem Version](https://badge.fury.io/rb/gemaker.svg)](https://badge.fury.io/rb/gemaker) [![Build Status](https://travis-ci.org/platanus/gemaker.svg?branch=master)](https://travis-ci.org/platanus/gemaker) [![Coverage Status](https://coveralls.io/repos/github/platanus/gemaker/badge.svg)](https://coveralls.io/github/platanus/gemaker)
1
+ # Gemaker
2
+
3
+ [![Gem Version](https://badge.fury.io/rb/gemaker.svg)](https://badge.fury.io/rb/gemaker)
4
+ [![CircleCI](https://circleci.com/gh/platanus/gemaker.svg?style=shield)](https://app.circleci.com/pipelines/github/platanus/gemaker)
5
+ [![Coverage Status](https://coveralls.io/repos/github/platanus/gemaker/badge.svg)](https://coveralls.io/github/platanus/gemaker)
6
+
2
7
  Ruby CLI created to build Platanus' gems.
3
8
 
4
9
  ## Installation
@@ -23,6 +28,16 @@ gemaker new my_gem
23
28
  4. Push to the branch (`git push origin my-new-feature`)
24
29
  5. Create new Pull Request
25
30
 
31
+ ## Publishing
32
+
33
+ On master/main branch...
34
+
35
+ 1. Change `VERSION` in `lib/gemaker/version.rb`.
36
+ 2. Change `Unreleased` title to current version in `CHANGELOG.md`.
37
+ 3. Commit new release. For example: `Releasing v0.1.0`.
38
+ 4. Create tag. For example: `git tag v0.1.0`.
39
+ 5. Push tag. For example: `git push origin v0.1.0`.
40
+
26
41
  ## Credits
27
42
 
28
43
  Thank you [contributors](https://github.com/platanus/gemaker/graphs/contributors)!
data/gemaker.gemspec CHANGED
@@ -1,4 +1,3 @@
1
- # coding: utf-8
2
1
  lib = File.expand_path('../lib', __FILE__)
3
2
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
3
  require 'gemaker/version'
@@ -13,26 +12,21 @@ Gem::Specification.new do |spec|
13
12
  spec.description = "Ruby CLI created to build Platanus' gems"
14
13
  spec.homepage = "https://github.com/platanus/gemaker"
15
14
 
16
- # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
17
- # to allow pushing to a single host or delete this section to allow pushing to any host.
18
- if spec.respond_to?(:metadata)
19
- spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
20
- else
21
- raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
22
- end
23
-
24
15
  spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
25
16
  spec.bindir = "exe"
26
17
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
27
18
  spec.require_paths = ["lib"]
28
19
 
29
- spec.add_dependency "power-types", "~> 0.1", ">= 0.1.0"
30
- spec.add_dependency "commander", "~> 4.4", ">= 4.4.0"
31
- spec.add_dependency "activesupport", "~> 4.2", ">= 4.2.6"
32
- spec.add_dependency "colorize", "~> 0.7", ">= 0.7.7"
20
+ spec.add_dependency "activesupport"
33
21
  spec.add_dependency "artii", "~> 2.1", ">= 2.1.1"
34
- spec.add_development_dependency "bundler", "~> 1.12"
22
+ spec.add_dependency "colorize", "~> 0.7", ">= 0.7.7"
23
+ spec.add_dependency "commander"
24
+ spec.add_dependency "power-types"
25
+
26
+ spec.add_development_dependency "bundler", "~> 2.2.15"
27
+ spec.add_development_dependency "coveralls"
35
28
  spec.add_development_dependency "rake", "~> 10.0"
36
29
  spec.add_development_dependency "rspec", "~> 3.0"
37
- spec.add_development_dependency "coveralls"
30
+ spec.add_development_dependency "rspec_junit_formatter"
31
+ spec.add_development_dependency "rubocop", "~> 1.9"
38
32
  end
data/lib/gemaker.rb CHANGED
@@ -10,6 +10,7 @@ require "gemaker/commands/base"
10
10
  require "gemaker/commands/create_gem"
11
11
  require "gemaker/commands/add_readme"
12
12
  require "gemaker/commands/add_changelog"
13
+ require "gemaker/commands/configure_editor_config"
13
14
  require "gemaker/commands/customize_gemspec"
14
15
  require "gemaker/commands/add_license"
15
16
  require "gemaker/commands/add_cli_structure"
@@ -20,7 +21,7 @@ require "gemaker/commands/customize_engine"
20
21
  require "gemaker/commands/customize_rakefile"
21
22
  require "gemaker/commands/customize_main_lib_file"
22
23
  require "gemaker/commands/add_install_generator"
23
- require "gemaker/commands/add_hound_rules"
24
+ require "gemaker/commands/configure_continuous_integration"
24
25
 
25
26
  module Gemaker
26
27
  end
data/lib/gemaker/cli.rb CHANGED
@@ -25,7 +25,7 @@ module Gemaker
25
25
  end
26
26
  end
27
27
 
28
- # rubocop:disable Metrics/MethodLength
28
+ # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
29
29
  def fill_config(gem_name, config)
30
30
  config.gem_name = gem_name
31
31
 
@@ -34,24 +34,26 @@ module Gemaker
34
34
  end
35
35
 
36
36
  config.human_gem_name = ask(
37
- "Enter the human readable version of the name. e.g. \"#{config.human_gem_name}\":")
37
+ "Enter the human readable version of the name. e.g. \"#{config.human_gem_name}\":"
38
+ )
38
39
  config.summary = ask("Enter gem's summary: ")
39
40
  config.description = ask("Enter gem's description: ")
40
41
  config.homepage = ask(
41
- "Enter gem's homepage. e.g. https://github.com/platanus/#{config.gem_name}: ")
42
+ "Enter gem's homepage. e.g. https://github.com/platanus/#{config.gem_name}: "
43
+ )
42
44
  config.authors = ask("Enter gem's authors. e.g. Sherlock Holmes,James Moriarty: ")
43
45
  config.emails = ask(
44
- "Enter the authors' emails. e.g. sherlock@platan.us,james@platan.us: ")
46
+ "Enter the authors' emails. e.g. sherlock@platan.us,james@platan.us: "
47
+ )
45
48
  config.engine = agree("Is the gem a Rails engine?")
46
49
 
47
50
  if config.engine?
48
- config.mountable = agree("Is the engine mountable?")
49
51
  config.installable = agree("Need an installer?")
50
52
  else
51
53
  config.cli = agree("Is it a CLI (Command-line interface)?")
52
54
  end
53
55
  end
54
- # rubocop:enable Metrics/MethodLength
56
+ # rubocop:enable Metrics/MethodLength, Metrics/AbcSize
55
57
 
56
58
  def draw_artii(text)
57
59
  a = Artii::Base.new font: 'slant'
@@ -3,6 +3,7 @@ module Gemaker
3
3
  class AddCliStructure < Gemaker::Cmd::Base
4
4
  def perform
5
5
  return unless @config.cli?
6
+
6
7
  copy_template("exe", "exe/#{@config.gem_name}", config: @config)
7
8
  copy_template("cli.rb", "lib/#{@config.gem_name}/cli.rb", config: @config)
8
9
  info "Add CLI structure"
@@ -3,14 +3,38 @@ module Gemaker
3
3
  class AddInstallGenerator < Gemaker::Cmd::Base
4
4
  def in_engine_context
5
5
  return unless @config.installable?
6
- copy_template("engine/initializer.rb",
7
- "lib/generators/#{@config.gem_name}/install/templates/initializer.rb", config: @config)
8
- copy_template("engine/install_generator.rb",
9
- "lib/generators/#{@config.gem_name}/install/install_generator.rb", config: @config)
10
- copy_template("engine/install_usage",
11
- "lib/generators/#{@config.gem_name}/install/USAGE", config: @config)
6
+
7
+ copy_initializer
8
+ copy_install_generator
9
+ copy_install_usage_file
12
10
  info "Add Installer"
13
11
  end
12
+
13
+ private
14
+
15
+ def copy_initializer
16
+ copy_template(
17
+ "engine/initializer.rb",
18
+ "lib/generators/#{@config.gem_name}/install/templates/initializer.rb",
19
+ config: @config
20
+ )
21
+ end
22
+
23
+ def copy_install_generator
24
+ copy_template(
25
+ "engine/install_generator.rb",
26
+ "lib/generators/#{@config.gem_name}/install/install_generator.rb",
27
+ config: @config
28
+ )
29
+ end
30
+
31
+ def copy_install_usage_file
32
+ copy_template(
33
+ "engine/install_usage",
34
+ "lib/generators/#{@config.gem_name}/install/USAGE",
35
+ config: @config
36
+ )
37
+ end
14
38
  end
15
39
  end
16
40
  end
@@ -0,0 +1,23 @@
1
+ module Gemaker
2
+ module Cmd
3
+ class ConfigureContinuousIntegration < Gemaker::Cmd::Base
4
+ def in_normal_context
5
+ configure_ci("normal")
6
+ end
7
+
8
+ def in_engine_context
9
+ configure_ci("engine")
10
+ end
11
+
12
+ private
13
+
14
+ def configure_ci(tpl_dir)
15
+ copy_template("#{tpl_dir}/rubocop.yml", ".rubocop.yml", config: @config)
16
+ create_dir(".circleci")
17
+ copy_template("circle_config.yml", ".circleci/config.yml", config: @config)
18
+ copy_file("circleci-setup-script.sh", ".circleci/setup-rubygems.sh")
19
+ info "Configure CricleCI"
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,10 @@
1
+ module Gemaker
2
+ module Cmd
3
+ class ConfigureEditorConfig < Gemaker::Cmd::Base
4
+ def perform
5
+ copy_file("editorconfig", ".editorconfig")
6
+ info "Configure editorconfig"
7
+ end
8
+ end
9
+ end
10
+ end
@@ -1,8 +1,19 @@
1
1
  module Gemaker
2
2
  module Cmd
3
3
  class ConfigureGit < Gemaker::Cmd::Base
4
- def perform
5
- remove_in_gem(".git") unless @config.engine?
4
+ def in_normal_context
5
+ remove_in_gem(".git")
6
+ do_initial_commit
7
+ end
8
+
9
+ def in_engine_context
10
+ copy_file("engine/gitignore", ".gitignore")
11
+ do_initial_commit
12
+ end
13
+
14
+ private
15
+
16
+ def do_initial_commit
6
17
  execute_in_gem("git init")
7
18
  execute_in_gem("bundle install")
8
19
  execute_in_gem("git add .")
@@ -12,12 +12,15 @@ module Gemaker
12
12
  def in_engine_context
13
13
  copy_template("engine/spec_helper.rb", "spec/spec_helper.rb", config: @config)
14
14
  copy_template("engine/rails_helper.rb", "spec/rails_helper.rb", config: @config)
15
- copy_template("engine/test_example.rb",
16
- "spec/dummy/spec/#{@config.gem_name}_spec.rb", config: @config)
17
- create_dir("spec/dummy/spec/factories")
18
- copy_file("test_helpers.rb", "spec/dummy/spec/support/test_helpers.rb")
19
- copy_file("image.png", "spec/dummy/spec/assets/image.png")
20
- copy_file("video.mp4", "spec/dummy/spec/assets/video.mp4")
15
+ copy_template(
16
+ "engine/test_example.rb",
17
+ "spec/#{@config.gem_name}_spec.rb",
18
+ config: @config
19
+ )
20
+ create_dir("spec/factories")
21
+ copy_file("test_helpers.rb", "spec/support/test_helpers.rb")
22
+ copy_file("image.png", "spec/fixtures/files/image.png")
23
+ copy_file("video.mp4", "spec/fixtures/files/video.mp4")
21
24
  copy_file("engine/rspec", ".rspec")
22
25
  copy_file("engine/Guardfile", "Guardfile")
23
26
  info "Configure Rspec"
@@ -2,10 +2,15 @@ module Gemaker
2
2
  module Cmd
3
3
  class CreateGem < Gemaker::Cmd::Base
4
4
  def in_engine_context
5
- mountable_opt = "--mountable" if @config.mountable?
6
- create_customized_gem(
7
- "rails plugin new #{@config.gem_name} -T #{mountable_opt} --dummy-path=spec/dummy"
8
- )
5
+ commands = [
6
+ "echo \"source 'https://rubygems.org'\" > GemakerGemfile",
7
+ "echo \"gem 'rails', '~> #{Gemaker::RAILS_VERSION}'\" > GemakerGemfile",
8
+ "BUNDLE_GEMFILE=GemakerGemfile bundle install",
9
+ "BUNDLE_GEMFILE=GemakerGemfile bundle exec rails plugin new #{@config.gem_name} -T --mountable --dummy-path=spec/dummy", # rubocop:disable Metrics/LineLength
10
+ "rm -f GemakerGemfile GemakerGemfile.lock"
11
+ ]
12
+
13
+ create_customized_gem(commands.join('; '))
9
14
  end
10
15
 
11
16
  def in_normal_context
@@ -18,6 +23,7 @@ module Gemaker
18
23
  execute(cmd)
19
24
  Gemaker::Cmd::AddReadme.for(config: @config)
20
25
  Gemaker::Cmd::AddChangelog.for(config: @config)
26
+ Gemaker::Cmd::ConfigureEditorConfig.for(config: @config)
21
27
  Gemaker::Cmd::CustomizeGemspec.for(config: @config)
22
28
  Gemaker::Cmd::AddLicense.for(config: @config)
23
29
  Gemaker::Cmd::AddCliStructure.for(config: @config)
@@ -27,7 +33,7 @@ module Gemaker
27
33
  Gemaker::Cmd::CustomizeRakefile.for(config: @config)
28
34
  Gemaker::Cmd::CustomizeMainLibFile.for(config: @config)
29
35
  Gemaker::Cmd::AddInstallGenerator.for(config: @config)
30
- Gemaker::Cmd::AddHoundRules.for(config: @config)
36
+ Gemaker::Cmd::ConfigureContinuousIntegration.for(config: @config)
31
37
  Gemaker::Cmd::ConfigureGit.for(config: @config)
32
38
  info("Done!")
33
39
  end
@@ -2,12 +2,39 @@ module Gemaker
2
2
  module Cmd
3
3
  class CustomizeEngine < Gemaker::Cmd::Base
4
4
  def in_engine_context
5
- copy_template("engine/engine.rb",
6
- "lib/#{@config.gem_name}/engine.rb", config: @config)
7
- copy_template("engine/example_class.rb",
8
- "lib/#{@config.gem_name}/example_class.rb", config: @config)
5
+ replace_development_file
6
+ replace_engine_file
7
+ add_example_class
8
+
9
9
  info "Customize engine.rb"
10
10
  end
11
+
12
+ private
13
+
14
+ def replace_development_file
15
+ remove_in_gem("spec/dummy/config/environments/development.rb")
16
+ copy_template(
17
+ "engine/development.rb",
18
+ "spec/dummy/config/environments/development.rb",
19
+ config: @config
20
+ )
21
+ end
22
+
23
+ def replace_engine_file
24
+ copy_template(
25
+ "engine/engine.rb",
26
+ "lib/#{@config.gem_name}/engine.rb",
27
+ config: @config
28
+ )
29
+ end
30
+
31
+ def add_example_class
32
+ copy_template(
33
+ "engine/example_class.rb",
34
+ "lib/#{@config.gem_name}/example_class.rb",
35
+ config: @config
36
+ )
37
+ end
11
38
  end
12
39
  end
13
40
  end
@@ -2,7 +2,7 @@ module Gemaker
2
2
  class Config
3
3
  RUBY_VERSION = 2.3
4
4
 
5
- attr_accessor :gem_name, :summary, :engine, :cli, :mountable, :installable
5
+ attr_accessor :gem_name, :summary, :engine, :cli, :installable
6
6
  attr_reader :authors, :emails
7
7
  attr_writer :human_gem_name, :description, :homepage
8
8
 
@@ -45,18 +45,10 @@ module Gemaker
45
45
  !!cli
46
46
  end
47
47
 
48
- def mountable?
49
- !!mountable
50
- end
51
-
52
48
  def installable?
53
49
  !!installable
54
50
  end
55
51
 
56
- def ruby_version
57
- RUBY_VERSION
58
- end
59
-
60
52
  private
61
53
 
62
54
  def string_to_array(value)
@@ -0,0 +1,103 @@
1
+ version: 2.1
2
+
3
+ env-vars: &env-vars
4
+ RAILS_ENV: test
5
+ NODE_ENV: test
6
+ BUNDLE_PATH: vendor/bundle
7
+
8
+ orbs:
9
+ ruby: circleci/ruby@0.1.2
10
+
11
+ executors:
12
+ main-executor:
13
+ parameters:
14
+ ruby-version:
15
+ description: "Ruby version"
16
+ default: "<%= Gemaker::RUBY_VERSION %>"
17
+ type: string
18
+ docker:
19
+ - image: circleci/ruby:<<parameters.ruby-version>>-node
20
+ environment: *env-vars
21
+
22
+ commands:
23
+ setup:
24
+ description: checkout code and install dependencies
25
+ steps:
26
+ - checkout
27
+ - run:
28
+ name: Install bundle dependencies
29
+ command: |
30
+ BUNDLER_VERSION=$(cat Gemfile.lock | tail -1 | tr -d " ")
31
+ gem install bundler:$BUNDLER_VERSION
32
+ bundle _$(echo $BUNDLER_VERSION)_ install
33
+
34
+ jobs:
35
+ lint:
36
+ executor: main-executor
37
+ steps:
38
+ - setup
39
+ - run:
40
+ name: Install reviewdog
41
+ command: |
42
+ curl -sfL https://raw.githubusercontent.com/reviewdog/reviewdog/master/install.sh | sh -s -- -b ./bin
43
+ - run:
44
+ name: Get files to lint
45
+ command: |
46
+ mkdir tmp
47
+ git diff origin/master --name-only --diff-filter=d > tmp/files_to_lint
48
+ - run:
49
+ name: Run rubocop
50
+ shell: /bin/bash
51
+ command: |
52
+ cat tmp/files_to_lint | grep -E '.+\.(rb)$' | xargs bundle exec rubocop --force-exclusion \
53
+ | ./bin/reviewdog -reporter=github-pr-review -f=rubocop
54
+ test:
55
+ parameters:
56
+ ruby-version:
57
+ description: "Ruby version"
58
+ default: "<%= Gemaker::RUBY_VERSION %>"
59
+ type: string
60
+ executor:
61
+ name: main-executor
62
+ ruby-version: <<parameters.ruby-version>>
63
+ steps:
64
+ - setup
65
+ - run:
66
+ name: Run Tests
67
+ command: |
68
+ RSPEC_JUNIT_ARGS="-r rspec_junit_formatter -f RspecJunitFormatter -o test_results/rspec.xml"
69
+ RSPEC_FORMAT_ARGS="-f progress --no-color -p 10"
70
+ bundle exec rspec ./spec $RSPEC_FORMAT_ARGS $RSPEC_JUNIT_ARGS
71
+ - store_test_results:
72
+ path: test_results
73
+ deploy:
74
+ executor: main-executor
75
+ steps:
76
+ - setup
77
+ - run:
78
+ name: Setup rubygems
79
+ command: bash .circleci/setup-rubygems.sh
80
+ - run:
81
+ name: Publish to rubygems
82
+ command: |
83
+ gem build active_job_log.gemspec
84
+ version_tag=$(git describe --tags)
85
+ gem push active_job_log-${version_tag#v}.gem
86
+
87
+ workflows:
88
+ version: 2
89
+ main:
90
+ jobs:
91
+ - lint:
92
+ context: org-global
93
+ - test:
94
+ matrix:
95
+ parameters:
96
+ ruby-version: <%= Gemaker::RUBY_VERSIONS %>
97
+ - deploy:
98
+ context: org-global
99
+ filters:
100
+ tags:
101
+ only: /.*/
102
+ branches:
103
+ ignore: /.*/