dopstick 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (65) hide show
  1. checksums.yaml +4 -4
  2. data/.github/CODEOWNERS +4 -0
  3. data/.rubocop.yml +11 -6
  4. data/CHANGELOG.md +11 -0
  5. data/CONTRIBUTING.md +1 -1
  6. data/README.md +6 -3
  7. data/dopstick.gemspec +2 -1
  8. data/lib/dopstick.rb +7 -1
  9. data/lib/dopstick/cli.rb +40 -11
  10. data/lib/dopstick/generator.rb +3 -208
  11. data/lib/dopstick/{templates → generator/base/templates}/bug_report.erb +1 -1
  12. data/lib/dopstick/{templates/CHANGELOG.md → generator/base/templates/changelog.erb} +0 -0
  13. data/lib/dopstick/{templates → generator/base/templates}/coc.erb +1 -1
  14. data/lib/dopstick/generator/base/templates/codeowners.erb +4 -0
  15. data/lib/dopstick/{templates → generator/base/templates}/contributing.erb +5 -5
  16. data/lib/dopstick/generator/base/templates/dependabot.erb +15 -0
  17. data/lib/dopstick/{templates → generator/base/templates}/feature_request.erb +0 -0
  18. data/lib/dopstick/generator/base/templates/funding.erb +4 -0
  19. data/lib/dopstick/{templates → generator/base/templates}/gitignore.erb +0 -0
  20. data/lib/dopstick/{templates → generator/base/templates}/issue.erb +0 -0
  21. data/lib/dopstick/{templates → generator/base/templates}/license.erb +1 -1
  22. data/lib/dopstick/{templates → generator/base/templates}/pull_request.erb +0 -0
  23. data/lib/dopstick/{templates → generator/base/templates}/setup.erb +0 -0
  24. data/lib/dopstick/generator/gem/generator.rb +160 -0
  25. data/lib/dopstick/generator/gem/options.rb +34 -0
  26. data/lib/dopstick/{templates → generator/gem/templates}/active_record.erb +25 -0
  27. data/lib/dopstick/generator/gem/templates/bin.erb +5 -0
  28. data/lib/dopstick/{templates → generator/gem/templates}/cli.erb +0 -0
  29. data/lib/dopstick/{templates → generator/gem/templates}/cli_class.erb +0 -0
  30. data/lib/dopstick/{templates → generator/gem/templates}/console.erb +1 -1
  31. data/lib/dopstick/generator/gem/templates/entry_file.erb +3 -0
  32. data/lib/dopstick/generator/gem/templates/gem_entry_file.erb +3 -0
  33. data/lib/dopstick/{templates → generator/gem/templates}/gemfile.erb +0 -0
  34. data/lib/dopstick/{templates → generator/gem/templates}/gemspec.erb +14 -14
  35. data/lib/dopstick/{templates → generator/gem/templates}/generator.erb +0 -0
  36. data/lib/dopstick/{templates → generator/gem/templates}/generator_class.erb +0 -0
  37. data/lib/dopstick/{templates → generator/gem/templates}/rakefile.erb +0 -0
  38. data/lib/dopstick/generator/gem/templates/readme.erb +50 -0
  39. data/lib/dopstick/generator/gem/templates/rubocop.erb +12 -0
  40. data/lib/dopstick/{templates → generator/gem/templates}/test_file.erb +1 -1
  41. data/lib/dopstick/{templates → generator/gem/templates}/test_helper.erb +1 -1
  42. data/lib/dopstick/{templates → generator/gem/templates}/tests_workflow.erb +6 -4
  43. data/lib/dopstick/{templates → generator/gem/templates}/version.erb +0 -0
  44. data/lib/dopstick/generator/npm/generator.rb +100 -0
  45. data/lib/dopstick/generator/npm/options.rb +26 -0
  46. data/lib/dopstick/generator/npm/templates/babel.erb +15 -0
  47. data/lib/dopstick/generator/npm/templates/eslint.erb +4 -0
  48. data/lib/dopstick/generator/npm/templates/index.erb +12 -0
  49. data/lib/dopstick/generator/npm/templates/index_test.erb +7 -0
  50. data/lib/dopstick/generator/npm/templates/jest.erb +12 -0
  51. data/lib/dopstick/generator/npm/templates/package.erb +42 -0
  52. data/lib/dopstick/generator/npm/templates/prettier.erb +1 -0
  53. data/lib/dopstick/generator/npm/templates/readme.erb +52 -0
  54. data/lib/dopstick/generator/npm/templates/tests_workflow.erb +46 -0
  55. data/lib/dopstick/generator/npm/templates/tsconfig.erb +14 -0
  56. data/lib/dopstick/generator/npm/templates/webpack.erb +33 -0
  57. data/lib/dopstick/generator/options.rb +65 -0
  58. data/lib/dopstick/version.rb +1 -1
  59. metadata +56 -37
  60. data/lib/dopstick/templates/bin.erb +0 -5
  61. data/lib/dopstick/templates/entry_file.erb +0 -3
  62. data/lib/dopstick/templates/funding.erb +0 -4
  63. data/lib/dopstick/templates/gem_entry_file.erb +0 -3
  64. data/lib/dopstick/templates/readme.erb +0 -50
  65. data/lib/dopstick/templates/rubocop.erb +0 -12
@@ -55,7 +55,7 @@ further defined and clarified by project maintainers.
55
55
  ## Enforcement
56
56
 
57
57
  Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
- reported by contacting the project team at <%= user_email %>. All
58
+ reported by contacting the project team at <%= options.user_email %>. All
59
59
  complaints will be reviewed and investigated and will result in a response that
60
60
  is deemed necessary and appropriate to the circumstances. The project team is
61
61
  obligated to maintain confidentiality with regard to the reporter of an incident.
@@ -0,0 +1,4 @@
1
+ # You can read more about CODEOWNERS at
2
+ # https://help.github.com/github/creating-cloning-and-archiving-repositories/about-code-owners
3
+
4
+ * @<%= options.github_user %>
@@ -1,4 +1,4 @@
1
- # Contributing to <%= gem_name %>
1
+ # Contributing to <%= options.package_name %>
2
2
 
3
3
  👍🎉 First off, thanks for taking the time to contribute! 🎉👍
4
4
 
@@ -9,7 +9,7 @@ changes to this document in a pull request.
9
9
  ## Code of Conduct
10
10
 
11
11
  Everyone interacting in this project's codebases, issue trackers, chat rooms and
12
- mailing lists is expected to follow the [code of conduct](<%= github_url
12
+ mailing lists is expected to follow the [code of conduct](<%= options.github_url
13
13
  %>/blob/main/CODE_OF_CONDUCT.md).
14
14
 
15
15
  ## Reporting bugs
@@ -27,19 +27,19 @@ the behavior, and find related reports.
27
27
  ## Contributing with code
28
28
 
29
29
  Before making any radicals changes, please make sure you discuss your intention
30
- by [opening an issue on Github](<%= github_url %>/issues).
30
+ by [opening an issue on Github](<%= options.github_url %>/issues).
31
31
 
32
32
  When you're ready to make your pull request, follow checklist below to make sure
33
33
  your contribution is according to how this project works.
34
34
 
35
- 1. [Fork](https://help.github.com/forking/) <%= gem_name %>
35
+ 1. [Fork](https://help.github.com/forking/) <%= options.package_name %>
36
36
  2. Create a topic branch - `git checkout -b my_branch`
37
37
  3. Make your changes using [descriptive commit messages](#commit-messages)
38
38
  4. Update CHANGELOG.md describing your changes by adding an entry to the
39
39
  "Unreleased" section. If this section is not available, create one right
40
40
  before the last version.
41
41
  5. Push to your branch - `git push origin my_branch`
42
- 6. [Create a pull request](https://docs.github.com/articles/creating-a-pull-request)
42
+ 6. [Create a pull request](https://help.github.com/articles/creating-a-pull-request)
43
43
  7. That's it!
44
44
 
45
45
  ## Styleguides
@@ -0,0 +1,15 @@
1
+ ---
2
+ # Documentation:
3
+ # https://help.github.com/github/administering-a-repository/configuration-options-for-dependency-updates
4
+
5
+ version: 2
6
+ updates:
7
+ - package-ecosystem: "github-actions"
8
+ directory: "/"
9
+ schedule:
10
+ interval: "daily"
11
+
12
+ - package-ecosystem: "bundler"
13
+ directory: "/"
14
+ schedule:
15
+ interval: "daily"
@@ -0,0 +1,4 @@
1
+ # These are supported funding model platforms
2
+
3
+ github: [<%= options.github_user %>]
4
+ custom: ["https://paypal.me/<%= options.paypal_user %>/🍕"]
@@ -1,6 +1,6 @@
1
1
  # The MIT License (MIT)
2
2
 
3
- Copyright (c) <%= Date.today.year %> <%= user_name %>
3
+ Copyright (c) <%= Date.today.year %> <%= options.user_name %>
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy of
6
6
  this software and associated documentation files (the "Software"), to deal in
@@ -0,0 +1,160 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Dopstick
4
+ module Generator
5
+ module Gem
6
+ Generator.registered["gem"] = self
7
+
8
+ class Generator < Thor::Group
9
+ using Dopstick::Refinements
10
+ include Thor::Actions
11
+
12
+ attr_accessor :options
13
+
14
+ desc "Generate a new gem folder structure"
15
+
16
+ def self.exit_on_failure?
17
+ true
18
+ end
19
+
20
+ def self.source_paths
21
+ [
22
+ source_root,
23
+ File.join(__dir__, "../base/templates")
24
+ ]
25
+ end
26
+
27
+ def self.source_root
28
+ File.join(__dir__, "templates")
29
+ end
30
+
31
+ def copy_ruby_templates
32
+ template "gemspec.erb", "#{options.package_name}.gemspec"
33
+ template "rakefile.erb", "Rakefile"
34
+ template "rubocop.erb", ".rubocop.yml"
35
+ template "gemfile.erb", "Gemfile"
36
+ template "tests_workflow.erb", ".github/workflows/ruby-tests.yml"
37
+ end
38
+
39
+ def copy_generic_templates
40
+ template "license.erb", "LICENSE.md"
41
+ template "coc.erb", "CODE_OF_CONDUCT.md"
42
+ template "readme.erb", "README.md"
43
+ template "changelog.erb", "CHANGELOG.md"
44
+ template "contributing.erb", "CONTRIBUTING.md"
45
+ template "gitignore.erb", ".gitignore"
46
+ end
47
+
48
+ def copy_github_templates
49
+ template "funding.erb", ".github/FUNDING.yml"
50
+ template "bug_report.erb", ".github/ISSUE_TEMPLATE/bug_report.md"
51
+ template "feature_request.erb",
52
+ ".github/ISSUE_TEMPLATE/feature_request.md"
53
+ template "pull_request.erb", ".github/PULL_REQUEST_TEMPLATE.md"
54
+ template "dependabot.erb", ".github/dependabot.yml"
55
+ template "codeowners.erb", ".github/CODEOWNERS"
56
+ end
57
+
58
+ def copy_bins
59
+ template "console.erb", "bin/console"
60
+ template "setup.erb", "bin/setup"
61
+ in_root { run "chmod +x bin/*" }
62
+ end
63
+
64
+ def create_entry_file
65
+ if options.entry_path.include?("/")
66
+ template "gem_entry_file.erb", "lib/#{options.package_name}.rb"
67
+ end
68
+
69
+ template "entry_file.erb", "lib/#{options.entry_path}.rb"
70
+ end
71
+
72
+ def create_version_file
73
+ template "version.erb", "lib/#{options.entry_path}/version.rb"
74
+ end
75
+
76
+ def copy_test_files
77
+ template "test_helper.erb", "test/test_helper.rb"
78
+ template "test_file.erb", "test/#{options.entry_path}_test.rb"
79
+ end
80
+
81
+ def copy_binary_files
82
+ return unless options.bin?
83
+
84
+ template "cli.erb", "lib/#{options.entry_path}/cli.rb"
85
+ template "generator.erb", "lib/#{options.entry_path}/generator.rb"
86
+ template "bin.erb", "exe/#{options.bin}"
87
+ create_file "lib/#{options.entry_path}/templates/.keep"
88
+ in_root { run "chmod +x exe/*" }
89
+ end
90
+
91
+ def copy_active_record_files
92
+ return unless options[:active_record]
93
+
94
+ template "active_record.erb", "test/support/active_record.rb"
95
+ end
96
+
97
+ def bundle_install
98
+ return if options.skip_install?
99
+
100
+ in_root do
101
+ run "bundle install"
102
+ end
103
+ end
104
+
105
+ def initialize_repo
106
+ in_root do
107
+ run "git init --initial-branch=main", capture: true
108
+ run "git add bin --force", capture: true
109
+ run "git add .", capture: true
110
+ end
111
+ end
112
+
113
+ no_commands do
114
+ def render_tree(skip_content_spaces = false, &block)
115
+ content = []
116
+
117
+ options.namespace_names.each_with_index do |name, count|
118
+ content << (" " * count) + "module #{name}"
119
+ end
120
+
121
+ spacer = skip_content_spaces ? "" : " "
122
+
123
+ content << (spacer * options.namespace_size) + block.call
124
+
125
+ (options.namespace_size - 1).downto(0) do |count|
126
+ content << "#{' ' * count}end"
127
+ end
128
+
129
+ content.join("\n")
130
+ end
131
+
132
+ def render_cli
133
+ cli_class = erb("cli_class.erb")
134
+ .chomp
135
+ .gsub(/^(.)/m, "#{' ' * options.namespace_size}\\1")
136
+
137
+ render_tree(true) { cli_class }
138
+ end
139
+
140
+ def render_generator
141
+ generator_class = erb("generator_class.erb")
142
+ .chomp
143
+ .gsub(
144
+ /^(.)/m,
145
+ "#{' ' * options.namespace_size}\\1"
146
+ )
147
+
148
+ render_tree(true) { generator_class }
149
+ end
150
+
151
+ def erb(file)
152
+ ERB.new(
153
+ File.read("#{self.class.source_root}/#{file}")
154
+ ).result(binding)
155
+ end
156
+ end
157
+ end
158
+ end
159
+ end
160
+ end
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Dopstick
4
+ module Generator
5
+ module Gem
6
+ class Options < Generator::Options
7
+ def bin?
8
+ !@options[:bin].empty?
9
+ end
10
+
11
+ def active_record?
12
+ @options[:active_record]
13
+ end
14
+
15
+ def namespace_names
16
+ @namespace_names ||= @options[:namespace].split("::")
17
+ end
18
+
19
+ def namespace_size
20
+ @namespace_size ||= namespace_names.size
21
+ end
22
+
23
+ def oldest_ruby_version
24
+ version = ruby_versions
25
+ .map {|v| ::Gem::Version.new(v) }
26
+ .min
27
+ .canonical_segments
28
+
29
+ [*version, 0].take(3).join(".")
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
@@ -21,3 +21,28 @@ ActiveRecord::Base.logger = nil
21
21
  def schema(&block)
22
22
  ActiveRecord::Schema.define(version: 0, &block)
23
23
  end
24
+
25
+ # Create a new migration, which can be executed up and down.
26
+ #
27
+ # test "do something" do
28
+ # migration = with_migration do
29
+ # def up
30
+ # # do something
31
+ # end
32
+ #
33
+ # def down
34
+ # # undo something
35
+ # end
36
+ # end
37
+ #
38
+ # migration.up
39
+ # migration.down
40
+ # end
41
+ #
42
+ def with_migration(&block)
43
+ migration_class = ActiveRecord::Migration[
44
+ ActiveRecord::Migration.current_version
45
+ ]
46
+
47
+ Class.new(migration_class, &block).new
48
+ end
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require_relative "../lib/<%= options.package_name %>"
5
+ <%= options.namespace %>::CLI.start
@@ -2,7 +2,7 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  require "bundler/setup"
5
- require <%= gem_name.inspect %>
5
+ require <%= options.package_name.inspect %>
6
6
 
7
7
  # You can add fixtures and/or initialization code here to make experimenting
8
8
  # with your gem easier. You can also use a different console, if you like.
@@ -0,0 +1,3 @@
1
+ # frozen_string_literal: true
2
+
3
+ <%= render_tree { %[require "#{options.entry_path}/version"] } %>
@@ -0,0 +1,3 @@
1
+ # frozen_string_literal: true
2
+
3
+ require <%= options.entry_path.inspect %>
@@ -1,20 +1,20 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative "./lib/<%= entry_path %>/version"
3
+ require_relative "./lib/<%= options.entry_path %>/version"
4
4
 
5
5
  Gem::Specification.new do |spec|
6
- spec.name = "<%= gem_name %>"
7
- spec.version = <%= options[:namespace] %>::VERSION
8
- spec.authors = [<%= user_name.inspect %>]
9
- spec.email = [<%= user_email.inspect %>]
6
+ spec.name = "<%= options.package_name %>"
7
+ spec.version = <%= options.namespace %>::VERSION
8
+ spec.authors = [<%= options.user_name.inspect %>]
9
+ spec.email = [<%= options.user_email.inspect %>]
10
10
 
11
- spec.summary = "Add some description"
11
+ spec.summary = <%= options.description.inspect %>
12
12
  spec.description = spec.summary
13
13
  spec.license = "MIT"
14
- spec.required_ruby_version = Gem::Requirement.new(">= <%= oldest_ruby_version %>")
14
+ spec.required_ruby_version = Gem::Requirement.new(">= <%= options.oldest_ruby_version %>")
15
15
 
16
- github_url = <%= github_url.inspect %>
17
- github_tree_url = "#{github_url}/tree/v#{spec.version}"
16
+ github_url = <%= options.github_url.inspect %>
17
+ github_tree_url = "#{options.github_url}/tree/v#{spec.version}"
18
18
 
19
19
  spec.homepage = github_url
20
20
  spec.metadata["homepage_uri"] = spec.homepage
@@ -34,20 +34,20 @@ Gem::Specification.new do |spec|
34
34
  spec.executables = spec.files.grep(%r{^exe/}) {|f| File.basename(f) }
35
35
  spec.require_paths = ["lib"]
36
36
 
37
- <%- if options[:active_record] -%>
37
+ <%- if options.active_record -%>
38
38
  spec.add_dependency "activerecord"
39
39
  <%- end -%>
40
- <%- unless options[:bin].empty? -%>
40
+ <%- if options.bin? -%>
41
41
  spec.add_dependency "thor"
42
42
  <%- end -%>
43
43
  spec.add_development_dependency "minitest"
44
44
  spec.add_development_dependency "minitest-utils"
45
+ <%- if options.active_record? -%>
46
+ spec.add_development_dependency "pg"
47
+ <%- end -%>
45
48
  spec.add_development_dependency "pry-meta"
46
49
  spec.add_development_dependency "rake"
47
50
  spec.add_development_dependency "rubocop"
48
51
  spec.add_development_dependency "rubocop-fnando"
49
52
  spec.add_development_dependency "simplecov"
50
- <%- if options[:active_record] -%>
51
- spec.add_development_dependency "pg"
52
- <%- end -%>
53
53
  end
@@ -0,0 +1,50 @@
1
+ # <%= options.package_name %>
2
+
3
+ [![Tests](<%= options.github_url %>/workflows/ruby-tests/badge.svg)](https://github.com/fnando/<%= options.package_name %>)
4
+ [![Code Climate](https://codeclimate.com/github/<%= options.github_user %>/<%= options.package_name %>/badges/gpa.svg)](https://codeclimate.com/github/<%= options.github_user %>/<%= options.package_name %>)
5
+ [![Gem](https://img.shields.io/gem/v/<%= options.package_name %>.svg)](https://rubygems.org/gems/<%= options.package_name %>)
6
+ [![Gem](https://img.shields.io/gem/dt/<%= options.package_name %>.svg)](https://rubygems.org/gems/<%= options.package_name %>)
7
+
8
+ <%= options.description %>
9
+
10
+ ## Installation
11
+
12
+ ```bash
13
+ gem install <%= options.package_name %>
14
+ ```
15
+
16
+ Or add the following line to your project's Gemfile:
17
+
18
+ ```ruby
19
+ gem "<%= options.package_name %>"
20
+ ```
21
+
22
+ ## Usage
23
+
24
+ TODO: Write gem usage
25
+
26
+ ## Maintainer
27
+
28
+ - [<%= options.user_name %>](https://github.com/<%= options.github_user %>)
29
+
30
+ ## Contributors
31
+
32
+ - <%= options.github_url %>/contributors
33
+
34
+ ## Contributing
35
+
36
+ For more details about how to contribute, please read
37
+ <%= options.github_url %>/blob/main/CONTRIBUTING.md.
38
+
39
+
40
+ ## License
41
+
42
+ The gem is available as open source under the terms of the
43
+ [MIT License](https://opensource.org/licenses/MIT). A copy of the license can be
44
+ found at <%= options.github_url %>/blob/main/LICENSE.md.
45
+
46
+ ## Code of Conduct
47
+
48
+ Everyone interacting in the <%= options.package_name %> project's codebases, issue trackers,
49
+ chat rooms and mailing lists is expected to follow the
50
+ [code of conduct](<%= options.github_url %>/blob/main/CODE_OF_CONDUCT.md).