README.md in tapioca-0.5.6 vs README.md in tapioca-0.6.0
- old
+ new
@@ -6,11 +6,11 @@
Tapioca is a library used to generate RBI (Ruby interface) files for use with [Sorbet](https://sorbet.org). RBI files provide the structure (classes, modules, methods, parameters) of the gem/library to Sorbet to assist with typechecking.
As yet, no gem exports type information in a consumable format and it would be a huge effort to manually maintain such an interface file for all the gems that your codebase depends on. Thus, there is a need for an automated way to generate the appropriate RBI file for a given gem. The `tapioca` gem, developed at Shopify, is able to do exactly that to almost 99% accuracy. It can generate the definitions for all statically defined types and most of the runtime defined types exported from Ruby gems (non-Ruby gems are not handled yet).
-When you run `tapioca sync` in a project, `tapioca` loads all the gems that are in your dependency list from the Gemfile into memory. It then performs runtime introspection on the loaded types to understand their structure and generates an appropriate RBI file for each gem with a versioned filename.
+When you run `tapioca gem` in a project, `tapioca` loads all the gems that are in your dependency list from the Gemfile into memory. It then performs runtime introspection on the loaded types to understand their structure and generates an appropriate RBI file for each gem with a versioned filename.
## Manual gem requires
For gems that have a normal default `require` and load all of their constants through such a require, everything works seamlessly. However, for gems that are marked as `require: false` in the Gemfile, or for gems that export optionally loaded types via different requires, where a single require does not load the whole gem code into memory, `tapioca` will not be able to load some of the types into memory and, thus, won't be able to generate complete RBIs for them. For this reason, we need to keep a small external file named `sorbet/tapioca/require.rb` that is executed after all the gems in the Gemfile have been required and before generation of gem RBIs have started. This file is responsible for adding the requires for additional files from gems, which are not covered by the default require.
@@ -31,11 +31,11 @@
=> BetterHtml::Parser
```
In order to make sure that `tapioca` can reflect on that type, we need to add the line `require "better_html/parser"` to the `sorbet/tapioca/require.rb` file. This will make sure `BetterHtml::Parser` is loaded into memory and a type annotation is generated for it in the `better_html.rbi` file. If this extra `require` line is not added to `sorbet/tapioca/require.rb` file, then the definition for that type will be missing from the RBI file.
-If you ever run into a case, where you add a gem or update the version of a gem and run `tapioca sync` but don't have some types you expect in the generated gem RBI files, you will need to make sure you have added the necessary requires to the `sorbet/tapioca/require.rb` file.
+If you ever run into a case, where you add a gem or update the version of a gem and run `tapioca gem` but don't have some types you expect in the generated gem RBI files, you will need to make sure you have added the necessary requires to the `sorbet/tapioca/require.rb` file.
You can use the command `tapioca require` to auto-populate the `sorbet/tapioca/require.rb` file with all the requires found
in your application. Once the file generated, you should review it, remove all unnecessary requires and commit it.
## How does tapioca compare to "srb rbi gems" ?
@@ -53,68 +53,159 @@
```
and do not forget to execute `tapioca` using `bundler`:
```shell
-$ bundle exec tapioca
+$ bundle exec tapioca help
Commands:
tapioca --version, -v # show version
+ tapioca clean-shims # clean duplicated definitions in shim RBIs
tapioca dsl [constant...] # generate RBIs for dynamic methods
- tapioca generate [gem...] # generate RBIs from gems
+ tapioca gem [gem...] # generate RBIs from gems
tapioca help [COMMAND] # Describe available commands or one specific command
tapioca init # initializes folder structure
tapioca require # generate the list of files to be required by tapioca
- tapioca sync # sync RBIs to Gemfile
tapioca todo # generate the list of unresolved constants
Options:
- --pre, -b, [--prerequire=file] # A file to be required before Bundler.require is called
- --post, -a, [--postrequire=file] # A file to be required after Bundler.require is called
- --out, -o, [--outdir=directory] # The output directory for generated RBI files
- --cmd, -c, [--generate-command=command] # The command to run to regenerate RBI files
- -x, [--exclude=gem [gem ...]] # Excludes the given gem(s) from RBI generation
- --typed, -t, [--typed-overrides=gem:level [gem:level ...]] # Overrides for typed sigils for generated gem RBIs
+ -c, [--config=<config file path>] # Path to the Tapioca configuration file
+ # Default: sorbet/tapioca/config.yml
+ -V, [--verbose], [--no-verbose] # Verbose output for debugging purposes
```
## Usage
### Initialize folder structure
Command: `tapioca init`
This will create the `sorbet/config` and `sorbet/tapioca/require.rb` files for you, if they don't exist. If any of the files already exist, they will not be changed.
-### Generate for gems
+```shell
+$ bundle exec tapioca help init
+Usage:
+ tapioca init
-Command: `tapioca generate [gems...]`
+Options:
+ -c, [--config=<config file path>] # Path to the Tapioca configuration file
+ # Default: sorbet/tapioca/config.yml
+ -V, [--verbose], [--no-verbose] # Verbose output for debugging purposes
+initializes folder structure
+```
+
+### Generate RBI files for gems
+
+Command: `tapioca gem [gems...]`
+
This will generate RBIs for the specified gems and place them in the RBI directory.
-### Generate for all gems in Gemfile
+```shell
+$ bundle exec tapioca help gem
+Usage:
+ tapioca gem [gem...]
-Command: `tapioca sync`
+Options:
+ --out, -o, [--outdir=directory] # The output directory for generated RBI files
+ # Default: sorbet/rbi/gems
+ [--file-header], [--no-file-header] # Add a "This file is generated" header on top of each generated RBI file
+ # Default: true
+ [--all], [--no-all] # Regenerate RBI files for all gems
+ --pre, -b, [--prerequire=file] # A file to be required before Bundler.require is called
+ --post, -a, [--postrequire=file] # A file to be required after Bundler.require is called
+ # Default: sorbet/tapioca/require.rb
+ -x, [--exclude=gem [gem ...]] # Excludes the given gem(s) from RBI generation
+ --typed, -t, [--typed-overrides=gem:level [gem:level ...]] # Overrides for typed sigils for generated gem RBIs
+ # Default: {"activesupport"=>"false"}
+ [--verify], [--no-verify] # Verifies RBIs are up-to-date
+ [--doc], [--no-doc] # Include YARD documentation from sources when generating RBIs. Warning: this might be slow
+ [--exported-gem-rbis], [--no-exported-gem-rbis] # Include RBIs found in the `rbi/` directory of the gem
+ # Default: true
+ -w, [--workers=N] # EXPERIMENTAL: Number of parallel workers to use when generating RBIs
+ # Default: 1
+ -c, [--config=<config file path>] # Path to the Tapioca configuration file
+ # Default: sorbet/tapioca/config.yml
+ -V, [--verbose], [--no-verbose] # Verbose output for debugging purposes
-This will sync the RBIs with the gems in the Gemfile and will add, update, and remove RBIs as necessary.
+generate RBIs from gems
+```
### Generate the list of all unresolved constants
Command: `tapioca todo`
This will generate the file `sorbet/rbi/todo.rbi` defining all unresolved constants as empty modules.
+```shell
+$ bundle exec tapioca help todo
+Usage:
+ tapioca todo
+
+Options:
+ [--todo-file=TODO_FILE]
+ # Default: sorbet/rbi/todo.rbi
+ [--file-header], [--no-file-header] # Add a "This file is generated" header on top of each generated RBI file
+ # Default: true
+ -c, [--config=<config file path>] # Path to the Tapioca configuration file
+ # Default: sorbet/tapioca/config.yml
+ -V, [--verbose], [--no-verbose] # Verbose output for debugging purposes
+
+generate the list of unresolved constants
+```
+
### Generate DSL RBI files
Command: `tapioca dsl [constant...]`
This will generate DSL RBIs for specified constants (or for all handled constants, if a constant name is not supplied). You can read about DSL RBI generators supplied by `tapioca` in [the manual](manual/generators.md).
-### Flags
+```shell
+$ bundle exec tapioca help dsl
+Usage:
+ tapioca dsl [constant...]
-- `--prerequire [file]`: A file to be required before `Bundler.require` is called.
-- `--postrequire [file]`: A file to be required after `Bundler.require` is called.
-- `--out [directory]`: The output directory for generated RBI files, default to `sorbet/rbi/gems`.
-- `--generate-command [command]`: **[DEPRECATED]** The command to run to regenerate RBI files (used in header comment of the RBI files), defaults to the current command.
-- `--typed-overrides [gem:level]`: Overrides typed sigils for generated gem RBIs for gem `gem` to level `level` (`level` can be one of `ignore`, `false`, `true`, `strict`, or `strong`, see [the Sorbet docs](https://sorbet.org/docs/static#file-level-granularity-strictness-levels) for more details).
+Options:
+ --out, -o, [--outdir=directory] # The output directory for generated RBI files
+ # Default: sorbet/rbi/dsl
+ [--file-header], [--no-file-header] # Add a "This file is generated" header on top of each generated RBI file
+ # Default: true
+ [--only=generator [generator ...]] # Only run supplied DSL generators
+ [--exclude=generator [generator ...]] # Exclude supplied DSL generators
+ [--verify], [--no-verify] # Verifies RBIs are up-to-date
+ -q, [--quiet], [--no-quiet] # Supresses file creation output
+ -w, [--workers=N] # EXPERIMENTAL: Number of parallel workers to use when generating RBIs
+ # Default: 1
+ -c, [--config=<config file path>] # Path to the Tapioca configuration file
+ # Default: sorbet/tapioca/config.yml
+ -V, [--verbose], [--no-verbose] # Verbose output for debugging purposes
+
+generate RBIs for dynamic methods
+```
+## Configuration
+
+Tapioca supports loading command defaults from a configuration file. The default configuration
+file location is `sorbet/tapioca/config.yml` but this default can be changed using the `--config` flag
+and supplying an alternative configuration file path.
+
+A configuration file must be a well-formed YAML file with top-level keys for the various Tapioca commands. Keys under each such top-level command should be the underscore version of a long option name for that command and the value for that key should be the value of the option.
+
+For example, if you always want to generate gem RBIs with inline documentation, then you would create the file `sorbet/tapioca/config.yml` as:
+
+```yaml
+gem:
+ docs: true
+```
+
+Additionally, if you always want to exclude the `AASM` and `ActiveRecordFixtures` DSL compilers in your DSL RBI generation runs, your config file would then look like this:
+
+```yaml
+gem:
+ docs: true
+dsl:
+ exclude:
+ - UrlHelpers
+ - ActiveRecordFixtures
+```
## Contributing
Bug reports and pull requests are welcome on GitHub at https://github.com/Shopify/tapioca. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](https://github.com/Shopify/tapioca/blob/main/CODE_OF_CONDUCT.md) code of conduct.