lib/tapioca/commands/annotations.rb in tapioca-0.11.8 vs lib/tapioca/commands/annotations.rb in tapioca-0.11.9

- old
+ new

@@ -21,29 +21,33 @@ netrc_file: nil, central_repo_index_path: CENTRAL_REPO_INDEX_PATH, typed_overrides: {} ) super() + @outpath = T.let(Pathname.new(DEFAULT_ANNOTATIONS_DIR), Pathname) @central_repo_root_uris = central_repo_root_uris @auth = auth @netrc_file = netrc_file @netrc_info = T.let(nil, T.nilable(Netrc)) @tokens = T.let(repo_tokens, T::Hash[String, T.nilable(String)]) @indexes = T.let({}, T::Hash[String, RepoIndex]) @typed_overrides = typed_overrides end + private + sig { override.void } def execute @indexes = fetch_indexes project_gems = list_gemfile_gems + remove_expired_annotations(project_gems) fetch_annotations(project_gems) + ensure + GitAttributes.create_vendored_attribute_file(@outpath) end - private - sig { returns(T::Array[String]) } def list_gemfile_gems say("Listing gems from Gemfile.lock... ", [:blue, :bold]) gemfile = Bundler.read_file("Gemfile.lock") parser = Bundler::LockfileParser.new(gemfile) @@ -54,22 +58,22 @@ sig { params(project_gems: T::Array[String]).void } def remove_expired_annotations(project_gems) say("Removing annotations for gems that have been removed... ", [:blue, :bold]) - annotations = Pathname.glob("#{DEFAULT_ANNOTATIONS_DIR}/*.rbi").map { |f| f.basename(".*").to_s } + annotations = Pathname.glob(@outpath.join("*.rbi")).map { |f| f.basename(".*").to_s } expired = annotations - project_gems if expired.empty? say(" Nothing to do") return end say("\n") expired.each do |gem_name| say("\n") - path = "#{DEFAULT_ANNOTATIONS_DIR}/#{gem_name}.rbi" + path = @outpath.join("#{gem_name}.rbi") remove_file(path) end say("\nDone\n\n", :green) end @@ -138,13 +142,11 @@ return unless content content = apply_typed_override(gem_name, content) content = add_header(gem_name, content) - dir = DEFAULT_ANNOTATIONS_DIR - FileUtils.mkdir_p(dir) say("\n Fetched #{set_color(gem_name, :yellow, :bold)}", :green) - create_file("#{dir}/#{gem_name}.rbi", content) + create_file(@outpath.join("#{gem_name}.rbi"), content) end sig { params(repo_uri: String, path: String).returns(T.nilable(String)) } def fetch_file(repo_uri, path) if repo_uri.start_with?(%r{https?://})