diff --git a/bundler/lib/bundler/cli.rb b/bundler/lib/bundler/cli.rb index 40a9dc35b82c..21b93bb3cd2c 100644 --- a/bundler/lib/bundler/cli.rb +++ b/bundler/lib/bundler/cli.rb @@ -584,6 +584,7 @@ def viz method_option :linter, type: :string, lazy_default: Bundler.settings["gem.linter"] || "", enum: %w[rubocop standard], banner: "Add a linter and code formatter, either RuboCop or Standard. Set a default with `bundle config set --global gem.linter (rubocop|standard)`" method_option :github_username, type: :string, default: Bundler.settings["gem.github_username"], banner: "Set your username on GitHub", desc: "Fill in GitHub username on README so that you don't have to do it manually. Set a default with `bundle config set --global gem.github_username `." method_option :bundle, type: :boolean, default: Bundler.settings["gem.bundle"], banner: "Automatically run `bundle install` after creation. Set a default with `bundle config set --global gem.bundle true`" + method_option :sig, type: :boolean, default: true, banner: "Generate signatures for your library." def gem(name) require_relative "cli/gem" diff --git a/bundler/lib/bundler/cli/gem.rb b/bundler/lib/bundler/cli/gem.rb index 3f9432db3a81..b1dbe6b61881 100644 --- a/bundler/lib/bundler/cli/gem.rb +++ b/bundler/lib/bundler/cli/gem.rb @@ -82,6 +82,7 @@ def run homepage_uri: homepage_uri, source_code_uri: source_code_uri, changelog_uri: changelog_uri, + sig: options[:sig], } ensure_safe_gem_name(name, constant_array) @@ -89,7 +90,6 @@ def run "Gemfile.tt" => Bundler.preferred_gemfile_name, "lib/newgem.rb.tt" => "lib/#{namespaced_path}.rb", "lib/newgem/version.rb.tt" => "lib/#{namespaced_path}/version.rb", - "sig/newgem.rbs.tt" => "sig/#{namespaced_path}.rbs", "newgem.gemspec.tt" => "#{name}.gemspec", "Rakefile.tt" => "Rakefile", "README.md.tt" => "README.md", @@ -249,6 +249,12 @@ def run config[:go_module_username] = config[:github_username] == DEFAULT_GITHUB_USERNAME ? "username" : config[:github_username] end + if config[:sig] + templates.merge!( + "sig/newgem.rbs.tt" => "sig/#{namespaced_path}.rbs", + ) + end + if target.exist? && !target.directory? Bundler.ui.error "Couldn't create a new gem named `#{gem_name}` because there's an existing file named `#{gem_name}`." exit Bundler::BundlerError.all_errors[Bundler::GenericSystemCallError] diff --git a/bundler/lib/bundler/man/bundle-gem.1 b/bundler/lib/bundler/man/bundle-gem.1 index 87d756824698..c389c4789749 100644 --- a/bundler/lib/bundler/man/bundle-gem.1 +++ b/bundler/lib/bundler/man/bundle-gem.1 @@ -100,6 +100,12 @@ Run \fBbundle install\fR after creating the gem\. .TP \fB\-\-no\-bundle\fR Do not run \fBbundle install\fR after creating the gem\. +.TP +\fB\-\-sig\fR +Create RBS signatures (in \fBsig/\fR, matching the structure in \fBlib/\fR)\. This behavior is enabled by default\. +.TP +\fB\-\-no\-sig\fR +Do not add RBS signatures\. .SH "SEE ALSO" .IP "\(bu" 4 bundle config(1) \fIbundle\-config\.1\.html\fR diff --git a/bundler/lib/bundler/man/bundle-gem.1.ronn b/bundler/lib/bundler/man/bundle-gem.1.ronn index 488c8113e4f2..97daf83f1fe3 100644 --- a/bundler/lib/bundler/man/bundle-gem.1.ronn +++ b/bundler/lib/bundler/man/bundle-gem.1.ronn @@ -145,6 +145,13 @@ configuration file using the following names: * `--no-bundle`: Do not run `bundle install` after creating the gem. +* `--sig`: + Create RBS signatures (in `sig/`, matching the structure in `lib/`). This + behavior is enabled by default. + +* `--no-sig`: + Do not add RBS signatures. + ## SEE ALSO * [bundle config(1)](bundle-config.1.html) diff --git a/spec/commands/newgem_spec.rb b/spec/commands/newgem_spec.rb index 3024a2486f79..c919010f914d 100644 --- a/spec/commands/newgem_spec.rb +++ b/spec/commands/newgem_spec.rb @@ -1367,6 +1367,22 @@ def create_temporary_dir(dir) end end + context "--sig option" do + context "with --sig" do + it "includes rbs signatures" do + bundle "gem #{gem_name} --sig" + expect(bundled_app("#{gem_name}/sig/#{gem_name}.rbs")).to exist + end + end + + context "with --no-sig" do + it "does not include rbs signatures" do + bundle "gem #{gem_name} --no-sig" + expect(bundled_app("#{gem_name}/sig/#{gem_name}.rbs")).not_to exist + end + end + end + shared_examples_for "paths that depend on gem name" do it "generates entrypoint, version file and signatures file at the proper path, with the proper content" do bundle "gem #{gem_name}"