dopstick 0.0.3 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (68) hide show
  1. checksums.yaml +4 -4
  2. data/.github/CODEOWNERS +4 -0
  3. data/.github/FUNDING.yml +1 -1
  4. data/.github/dependabot.yml +15 -0
  5. data/.github/workflows/tests.yml +10 -12
  6. data/.rubocop.yml +12 -7
  7. data/CHANGELOG.md +26 -0
  8. data/CONTRIBUTING.md +1 -1
  9. data/README.md +6 -3
  10. data/dopstick.gemspec +4 -2
  11. data/lib/dopstick/cli.rb +41 -12
  12. data/lib/dopstick/{templates → generator/base/templates}/bug_report.erb +1 -1
  13. data/lib/dopstick/{templates/CHANGELOG.md → generator/base/templates/changelog.erb} +0 -0
  14. data/lib/dopstick/{templates → generator/base/templates}/coc.erb +1 -1
  15. data/lib/dopstick/generator/base/templates/codeowners.erb +4 -0
  16. data/lib/dopstick/{templates → generator/base/templates}/contributing.erb +5 -5
  17. data/lib/dopstick/generator/base/templates/dependabot.erb +15 -0
  18. data/lib/dopstick/{templates → generator/base/templates}/feature_request.erb +0 -0
  19. data/lib/dopstick/generator/base/templates/funding.erb +4 -0
  20. data/lib/dopstick/{templates → generator/base/templates}/gitignore.erb +0 -0
  21. data/lib/dopstick/{templates → generator/base/templates}/issue.erb +0 -0
  22. data/lib/dopstick/{templates → generator/base/templates}/license.erb +1 -1
  23. data/lib/dopstick/{templates → generator/base/templates}/pull_request.erb +0 -0
  24. data/lib/dopstick/{templates → generator/base/templates}/setup.erb +0 -0
  25. data/lib/dopstick/generator/gem/generator.rb +173 -0
  26. data/lib/dopstick/generator/gem/options.rb +34 -0
  27. data/lib/dopstick/{templates → generator/gem/templates}/active_record.erb +25 -0
  28. data/lib/dopstick/generator/gem/templates/bin.erb +5 -0
  29. data/lib/dopstick/{templates → generator/gem/templates}/cli.erb +0 -0
  30. data/lib/dopstick/{templates → generator/gem/templates}/cli_class.erb +0 -0
  31. data/lib/dopstick/{templates → generator/gem/templates}/console.erb +1 -1
  32. data/lib/dopstick/generator/gem/templates/entry_file.erb +3 -0
  33. data/lib/dopstick/generator/gem/templates/gem_entry_file.erb +3 -0
  34. data/lib/dopstick/{templates → generator/gem/templates}/gemfile.erb +0 -0
  35. data/lib/dopstick/{templates → generator/gem/templates}/gemspec.erb +14 -13
  36. data/lib/dopstick/{templates → generator/gem/templates}/generator.erb +0 -0
  37. data/lib/dopstick/{templates → generator/gem/templates}/generator_class.erb +0 -0
  38. data/lib/dopstick/{templates → generator/gem/templates}/rakefile.erb +0 -0
  39. data/lib/dopstick/generator/gem/templates/readme.erb +50 -0
  40. data/lib/dopstick/generator/gem/templates/rubocop.erb +12 -0
  41. data/lib/dopstick/{templates → generator/gem/templates}/test_file.erb +1 -1
  42. data/lib/dopstick/{templates → generator/gem/templates}/test_helper.erb +1 -1
  43. data/lib/dopstick/{templates → generator/gem/templates}/tests_workflow.erb +9 -12
  44. data/lib/dopstick/{templates → generator/gem/templates}/version.erb +0 -0
  45. data/lib/dopstick/generator/npm/generator.rb +106 -0
  46. data/lib/dopstick/generator/npm/options.rb +26 -0
  47. data/lib/dopstick/generator/npm/templates/babel.erb +15 -0
  48. data/lib/dopstick/generator/npm/templates/eslint.erb +4 -0
  49. data/lib/dopstick/generator/npm/templates/index.erb +12 -0
  50. data/lib/dopstick/generator/npm/templates/index_test.erb +7 -0
  51. data/lib/dopstick/generator/npm/templates/jest.erb +12 -0
  52. data/lib/dopstick/generator/npm/templates/package.erb +42 -0
  53. data/lib/dopstick/generator/npm/templates/prettier.erb +1 -0
  54. data/lib/dopstick/generator/npm/templates/readme.erb +52 -0
  55. data/lib/dopstick/generator/npm/templates/tests_workflow.erb +49 -0
  56. data/lib/dopstick/generator/npm/templates/tsconfig.erb +14 -0
  57. data/lib/dopstick/generator/npm/templates/webpack.erb +33 -0
  58. data/lib/dopstick/generator/options.rb +65 -0
  59. data/lib/dopstick/generator.rb +3 -208
  60. data/lib/dopstick/version.rb +1 -1
  61. data/lib/dopstick.rb +7 -1
  62. metadata +60 -39
  63. data/lib/dopstick/templates/bin.erb +0 -5
  64. data/lib/dopstick/templates/entry_file.erb +0 -3
  65. data/lib/dopstick/templates/funding.erb +0 -4
  66. data/lib/dopstick/templates/gem_entry_file.erb +0 -3
  67. data/lib/dopstick/templates/readme.erb +0 -50
  68. data/lib/dopstick/templates/rubocop.erb +0 -12
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 845c70abf80cfc35d701755ccb884541712a51932992335a029262259acb3224
4
- data.tar.gz: f99884fb97532ab7c311bca815686138c1b8076e6707188ada8d65afc368cca0
3
+ metadata.gz: 32408bef26c9cac4f69fd929fa86a84c0ad7eab9528573f649c720d57c1b7e7d
4
+ data.tar.gz: e412045ce7e9ea82ecd9bdbd74fa7863be86a62aac87ebdf397104e34c85a0b5
5
5
  SHA512:
6
- metadata.gz: 52673c29a2ff5cb40cf8d188234e469657c7dc7715ca43deac9ac6d0f3a8d67d2b26c501396f510c38b782052940cc4acf8ba64f34ce82af48171fa30d925183
7
- data.tar.gz: ff3d572d6c593bc6b1a38e48f6d3e830f408a8ec32c06e6e8eb6ba3406abb0003375ae335c4cb2eea43b2aafa756ebe39e0f82ef5d28de54d89bc653828d3a79
6
+ metadata.gz: 90f33a149c994f693d5fce46ee19de6f7656d28378bd1147fc572010f630ec8b9ca06c2f4bdc8c34163525a5ad58760de72e00c06b9337f56d646ae7139b9b76
7
+ data.tar.gz: aeca3ecf5d6324b50139f1461b760769ae11015430078d8c72ff25e8f3a3436ea7ffdb3fe952b7d29ef097b6b6788c5ce7f093978cea3be0fcb4f875fe28b50d
@@ -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
+ * @fnando
data/.github/FUNDING.yml CHANGED
@@ -1,4 +1,4 @@
1
1
  # These are supported funding model platforms
2
-
2
+ ---
3
3
  github: [fnando]
4
4
  custom: ["https://www.paypal.me/nandovieira/🍕"]
@@ -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"
@@ -1,15 +1,11 @@
1
+ ---
1
2
  name: Tests
2
3
 
3
4
  on:
4
5
  pull_request:
5
- branches:
6
- - main
7
6
  push:
8
- branches:
9
- - main
10
-
11
- schedule:
12
- - cron: "0 10 * * *"
7
+ workflow_dispatch:
8
+ inputs: {}
13
9
 
14
10
  jobs:
15
11
  build:
@@ -18,23 +14,25 @@ jobs:
18
14
  strategy:
19
15
  fail-fast: false
20
16
  matrix:
21
- ruby: [2.6.x, 2.7.x]
17
+ ruby: ["2.7", "3.0"]
22
18
  gemfile:
23
19
  - Gemfile
24
20
 
25
21
  steps:
26
- - uses: actions/checkout@v1
22
+ - uses: actions/checkout@v2.4.0
27
23
 
28
24
  - uses: actions/cache@v2
29
25
  with:
30
26
  path: vendor/bundle
31
27
  key: >
32
- ${{ runner.os }}-${{ matrix.ruby }}-gems-${{ hashFiles(matrix.gemfile) }}
28
+ ${{ runner.os }}-${{ matrix.ruby }}-gems-${{
29
+ hashFiles(matrix.gemfile) }}
33
30
  restore-keys: >
34
- ${{ runner.os }}-${{ matrix.ruby }}-gems-${{ hashFiles(matrix.gemfile) }}
31
+ ${{ runner.os }}-${{ matrix.ruby }}-gems-${{
32
+ hashFiles(matrix.gemfile) }}
35
33
 
36
34
  - name: Set up Ruby
37
- uses: actions/setup-ruby@v1
35
+ uses: ruby/setup-ruby@v1
38
36
  with:
39
37
  ruby-version: ${{ matrix.ruby }}
40
38
 
data/.rubocop.yml CHANGED
@@ -3,7 +3,7 @@ inherit_gem:
3
3
  rubocop-fnando: .rubocop.yml
4
4
 
5
5
  AllCops:
6
- TargetRubyVersion: 2.6
6
+ TargetRubyVersion: 2.7
7
7
  NewCops: enable
8
8
  Exclude:
9
9
  - tmp/**/*
@@ -11,11 +11,16 @@ AllCops:
11
11
  - vendor/**/*
12
12
 
13
13
  Metrics/BlockLength:
14
- Exclude:
15
- - test/**/*
16
- - "**/*.gemspec"
14
+ Enabled: false
17
15
 
18
16
  Metrics/ClassLength:
19
- Exclude:
20
- - test/**/*
21
- - "**/*.gemspec"
17
+ Enabled: false
18
+
19
+ Metrics/MethodLength:
20
+ Enabled: false
21
+
22
+ Metrics/AbcSize:
23
+ Enabled: false
24
+
25
+ Style/OptionalBooleanParameter:
26
+ Enabled: false
data/CHANGELOG.md CHANGED
@@ -11,6 +11,32 @@ Prefix your message with one of the following:
11
11
  - [Security] in case of vulnerabilities.
12
12
  -->
13
13
 
14
+ ## v0.0.7 - 2021-12-04
15
+
16
+ - [Fixed] Set proper package ecosystem on dependabot's config file.
17
+ - [Changed] Update ruby default versions to 2.7 and 3.0.
18
+ - [Changed] Update node default versions to 16 and 17.
19
+
20
+ ## v0.0.6 - 2020-12-09
21
+
22
+ - [Fixed] Babel loader's order is backwards, so TypeScript first, then
23
+ JavaScript.
24
+
25
+ ## v0.0.5 - 2020-11-14
26
+
27
+ - [Fixed] Jest configuration wasn't considering the full import path.
28
+
29
+ ## v0.0.4 - 2020-11-14
30
+
31
+ - [Added] Generate
32
+ [dependabot](https://help.github.com/github/administering-a-repository/configuration-options-for-dependency-updates)
33
+ configuration.
34
+ - [Changed] Add Postgres env vars so tests can run smoothly.
35
+ - [Added] Add helper method to create migration classes with `--active-record`.
36
+ - [Added] Generate `.github/CODEOWNERS` template.
37
+ - [Changed] Generate Ruby packages with `--type gem`
38
+ - [Added] Generate NPM packages with `--type npm`.
39
+
14
40
  ## v0.0.3 - 2020-11-03
15
41
 
16
42
  - [Changed] Remove unused `--repository` switch.
data/CONTRIBUTING.md CHANGED
@@ -38,7 +38,7 @@ your contribution is according to how this project works.
38
38
  "Unreleased" section. If this section is not available, create one right
39
39
  before the last version.
40
40
  5. Push to your branch - `git push origin my_branch`
41
- 6. [Create a pull request](https://docs.github.com/articles/creating-a-pull-request)
41
+ 6. [Create a pull request](https://help.github.com/articles/creating-a-pull-request)
42
42
  7. That's it!
43
43
 
44
44
  ## Styleguides
data/README.md CHANGED
@@ -5,7 +5,7 @@
5
5
  </p>
6
6
 
7
7
  <p align="center">
8
- Generate a project skeleton for creating a rubygem.
8
+ Generate a project skeleton for creating a Ruby/Node package.
9
9
  </p>
10
10
 
11
11
  <p align="center">
@@ -21,8 +21,11 @@ Features:
21
21
 
22
22
  - Github templates
23
23
  - Changelog
24
- - ActiveRecord setup (via `--active-record`)
25
- - CLI setup (via `--bin NAME`)
24
+ - Generate Ruby packages
25
+ + ActiveRecord setup (via `--active-record`)
26
+ + CLI setup (via `--bin NAME`)
27
+ - Generate NPM packages
28
+ + Setup TypeScript, Jest, and more!
26
29
 
27
30
  ## Installation
28
31
 
data/dopstick.gemspec CHANGED
@@ -7,11 +7,13 @@ Gem::Specification.new do |spec|
7
7
  spec.version = Dopstick::VERSION
8
8
  spec.authors = ["Nando Vieira"]
9
9
  spec.email = ["me@fnando.com"]
10
+ spec.metadata = {"rubygems_mfa_required" => "true"}
10
11
 
11
- spec.summary = "Generate a project skeleton for creating a rubygem"
12
+ spec.summary = "Generate a project skeleton for creating a Ruby/NPM " \
13
+ "package."
12
14
  spec.description = spec.summary
13
15
  spec.license = "MIT"
14
- spec.required_ruby_version = Gem::Requirement.new(">= 2.6.0")
16
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.7.0")
15
17
 
16
18
  github_url = "https://github.com/fnando/dopstick"
17
19
  github_tree_url = "#{github_url}/tree/v#{spec.version}"
data/lib/dopstick/cli.rb CHANGED
@@ -9,10 +9,14 @@ module Dopstick
9
9
  true
10
10
  end
11
11
 
12
- desc "new PATH", "Create a new gem"
12
+ desc "new PATH", "Create a new package"
13
+ option :type,
14
+ default: "",
15
+ desc: "Set the package type you want to create. Must be one of " \
16
+ "#{Generator.registered.keys.inspect}."
13
17
  option :name,
14
18
  default: "",
15
- desc: "Set the gem name. Defaults to path's basename."
19
+ desc: "Set the package name. Defaults to path's basename."
16
20
  option :active_record,
17
21
  default: false,
18
22
  type: :boolean,
@@ -31,8 +35,8 @@ module Dopstick
31
35
  desc: "Set Paypal account for donations. Defaults to " \
32
36
  "`git config user.paypal`."
33
37
  option :description,
34
- default: "",
35
- desc: "Set gem description."
38
+ default: "TODO: add a description",
39
+ desc: "Set package description."
36
40
  option :version,
37
41
  default: "0.0.0",
38
42
  desc: "Set package initial version."
@@ -44,10 +48,19 @@ module Dopstick
44
48
  desc: "Set the codebase namespace. By default, it's inferred from " \
45
49
  "the gem name."
46
50
  option :ruby_versions,
47
- default: %w[2.6 2.7],
51
+ default: %w[2.7 3.0],
48
52
  type: :array,
49
53
  desc: "Set Ruby versions that are officially supported. Multiple " \
50
54
  "versions must separated by space."
55
+ option :node_versions,
56
+ default: %w[16.x 17.x],
57
+ type: :array,
58
+ desc: "Set Node versions that are officially supported. Multiple " \
59
+ "versions must separated by space."
60
+ option :skip_install,
61
+ default: false,
62
+ type: :boolean,
63
+ desc: "Skip `bundle install` (gem) and `yarn install` (npm)"
51
64
  option :help,
52
65
  aliases: "-h",
53
66
  type: :boolean,
@@ -55,14 +68,25 @@ module Dopstick
55
68
  def new(path = nil)
56
69
  interrupt_with_help(:new) if options[:help] || path.to_s.strip.empty?
57
70
 
58
- gem_name, namespace = expand_gem_name_and_namespace(path)
71
+ unless Generator.registered.include?(options[:type])
72
+ interrupt_with_error(
73
+ "--type must be one of #{Generator.registered.keys.inspect}"
74
+ )
75
+ end
76
+
77
+ package_name, namespace = expand_gem_name_and_namespace(path)
59
78
 
60
- generator = Generator.new
79
+ generator_module = Generator.registered[options[:type]]
80
+ generator_class = generator_module.const_get(:Generator)
81
+ options_class = generator_module.const_get(:Options)
82
+ generator = generator_class.new
61
83
  generator.destination_root = File.expand_path(path)
62
- generator.options = dup_options.merge(
63
- gem_name: gem_name,
64
- namespace: namespace,
65
- entry_path: namespace.underscore("/")
84
+ generator.options = options_class.new(
85
+ dup_options.merge(
86
+ package_name: package_name,
87
+ namespace: namespace,
88
+ entry_path: namespace.underscore("/")
89
+ )
66
90
  )
67
91
 
68
92
  generator.invoke_all
@@ -74,13 +98,18 @@ module Dopstick
74
98
  exit
75
99
  end
76
100
 
101
+ private def interrupt_with_error(message)
102
+ shell.say "ERROR: #{message}", :red
103
+ exit 1
104
+ end
105
+
77
106
  private def dup_options
78
107
  options.each_with_object({}) do |(key, value), buffer|
79
108
  buffer[key.to_sym] = value
80
109
  end
81
110
  end
82
111
 
83
- private def expand_gem_name_and_namespace(path) # rubocop:disable Metrics/AbcSize
112
+ private def expand_gem_name_and_namespace(path)
84
113
  if options[:name].presence && options[:namespace].presence
85
114
  [options[:name], options[:namespace]]
86
115
  elsif options[:name].presence
@@ -9,7 +9,7 @@ labels: 'Status: Unconfirmed'
9
9
  <!--
10
10
  - Please provide a clear and concise description of what the bug is.
11
11
  - If possible, add an example reproducing your issue.
12
- - Please test using the latest version of <%= gem_name %>
12
+ - Please test using the latest version of <%= options.package_name %>
13
13
  to make sure your issue has not already been fixed.
14
14
  -->
15
15
 
@@ -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: <%= dependabot_package_ecosystem %>
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,173 @@
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)
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) + yield)
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
+
157
+ def dependabot_package_ecosystem
158
+ "bundler"
159
+ end
160
+
161
+ def ruby_versions_for_workflow
162
+ options.ruby_versions.map do |v|
163
+ canonical_segments = ::Gem::Version.new(v).canonical_segments
164
+ canonical_segments << 0 if canonical_segments.size < 2
165
+
166
+ canonical_segments.join(".").inspect
167
+ end.join(", ")
168
+ end
169
+ end
170
+ end
171
+ end
172
+ end
173
+ 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