piotrmurach / tty

Toolkit for developing sleek command line apps.
https://ttytoolkit.org
MIT License
2.5k stars 78 forks source link

Only require `tty-...` gems that are used in the app #70

Open slowbro opened 3 years ago

slowbro commented 3 years ago

Describe the problem

Perhaps more of a feature suggestion than a problem :) I noticed that when making a new app with teletype, it adds all of the 'tty' gems as dependencies, even though (by default) none of them are used or required:

  spec.add_dependency "tty-box", "~> 0.4.1"
  spec.add_dependency "tty-color", "~> 0.5"
  spec.add_dependency "tty-command", "~> 0.9.0"
  spec.add_dependency "tty-config", "~> 0.3.2"
  spec.add_dependency "tty-cursor", "~> 0.7"
  spec.add_dependency "tty-editor", "~> 0.5"
  spec.add_dependency "tty-file", "~> 0.8.0"
  spec.add_dependency "tty-font", "~> 0.4.0"
  spec.add_dependency "tty-logger", "~> 0.2.0"
  spec.add_dependency "tty-markdown", "~> 0.6.0"
  spec.add_dependency "tty-pager", "~> 0.12"
  spec.add_dependency "tty-pie", "~> 0.3.0"
  spec.add_dependency "tty-platform", "~> 0.2"
  spec.add_dependency "tty-progressbar", "~> 0.17"
  spec.add_dependency "tty-prompt", "~> 0.19"
  spec.add_dependency "tty-screen", "~> 0.7"
  spec.add_dependency "tty-spinner", "~> 0.9"
  spec.add_dependency "tty-table", "~> 0.11.0"
  spec.add_dependency "tty-tree", "~> 0.3"
  spec.add_dependency "tty-which", "~> 0.4"

This seems inefficient; if I install this gem straight out of the box - no commands added, etc - I'd get 20 other gems along with it, even though none of them are used (seemingly).

Steps to reproduce the problem

teletype new test-app
grep 'dependency' test-app/test-app.gemspec

Expected Suggested behaviour

My initial thoughts were:

a) use the 'teletype' command to add a new component. for example, teletype require prompt (???) b) when running rake build, scrape any requires that reference a tty gem

Option "b" sounds more automated (yay!) but hacky (boo!). Option "a" feels clunky (i.e. why would i need to run teletype instead of just adding a require 'tty/prompt' line..?)... so I'm not sure either suggestion is the best. Opening this more for discussion than anything!

Describe your environment

piotrmurach commented 3 years ago

💯 agree, teleteype needs to only add what's needed. There is a short and long term plan for handling this.

The short term plan is to inject tty dependencies as comments in the gemspec file for user to pick and choose. This is currently implemented in the master branch. If you could test against master branch that would be better as the v0.10.0 is pretty outdated and in dire need of new release as evidenced in Bundler issue.

The long term plan is to use tty-prompt to ask the user multiple choice question about which dependencies they would like to use and add these to the generated gemspec and as requirements in the command.rb file or some other place. However, this would need to wait for when I replace Bundler with custom gemspec generator. I want to as quickly as possible get to release v0.11.0 that has all the updated components(only 2 still left to do).

This comment I made in the referenced issue above explains the 3 stage plan of where I think I want to go with this project. So in the first stage, all tty components would be injected as commented out dependencies. It's kind of similar to how rails setups some of its dependencies.

Please let me know if you like this approach as a first step?