Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions bundler/lib/bundler/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 <your_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"
Expand Down
8 changes: 7 additions & 1 deletion bundler/lib/bundler/cli/gem.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,14 +82,14 @@ 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)

templates = {
"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",
Expand Down Expand Up @@ -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]
Expand Down
6 changes: 6 additions & 0 deletions bundler/lib/bundler/man/bundle-gem.1
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions bundler/lib/bundler/man/bundle-gem.1.ronn
Original file line number Diff line number Diff line change
Expand Up @@ -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)
16 changes: 16 additions & 0 deletions spec/commands/newgem_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand Down
Loading