Class: Foobara::RemoteGenerator::WriteTypescriptToDisk

Inherits:
Generators::WriteGeneratedFilesToDisk show all
Defined in:
foobara-typescript-remote-command-generator-1.3.1/src/write_typescript_to_disk.rb

Constant Summary

Constants included from TruncatedInspect

TruncatedInspect::MAX_LENGTH

Instance Attribute Summary

Attributes inherited from Generators::WriteGeneratedFilesToDisk

#paths_to_source_code

Attributes included from CommandPatternImplementation::Concerns::Subcommands

#is_subcommand

Attributes included from CommandPatternImplementation::Concerns::Runtime

#exception, #outcome, #raw_result

Attributes included from CommandPatternImplementation::Concerns::Errors

#error_collection

Attributes included from CommandPatternImplementation::Concerns::Inputs

#inputs, #raw_inputs

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Generators::WriteGeneratedFilesToDisk

#delete_old_files_if_needed, #generate_generated_files_json, #generated_files_json_filename, #run_cmd_and_return_output, #run_cmd_and_write_output, #stats, #write_all_files_to_disk, #write_file_to_disk

Methods inherited from Command

install!

Methods included from Concern

foobara_class_methods_module_for, foobara_concern?, included

Methods included from CommandPatternImplementation::Concerns::DomainMappers

#domain_map, #domain_map!, #run_mapped_subcommand!

Methods included from CommandPatternImplementation::Concerns::Subcommands

#subcommand?, #verify_depends_on!

Methods included from CommandPatternImplementation::Concerns::Entities

#load_entities, #load_records

Methods included from CommandPatternImplementation::Concerns::Transactions

#relevant_entity_classes

Methods included from NestedTransactionable

#auto_detect_current_transactions, #commit_transaction, #commit_transaction_if_open, #open_transaction, #opened_transactions, #relevant_entity_classes, relevant_entity_classes_for_type, #relevant_entity_classes_for_type, #rollback_transaction, #transactions, #use_transaction, with_needed_transactions_for_type

Methods included from CommandPatternImplementation::Concerns::StateMachine

#state_machine

Methods included from CommandPatternImplementation::Concerns::Callbacks

#state_machine_callback_registry

Methods included from CommandPatternImplementation::Concerns::Runtime

#halt!, #run, #run!, #success?

Methods included from CommandPatternImplementation::Concerns::Errors

#has_errors?, #initialize

Methods included from CommandPatternImplementation::Concerns::Inputs

#cast_and_validate_inputs, #initialize, #method_missing, #respond_to_missing?, #respond_to_missing_for_inputs?

Methods included from CommandPatternImplementation::Concerns::ResultType

#result_type

Methods included from CommandPatternImplementation::Concerns::InputsType

#inputs_type

Methods included from TruncatedInspect

#inspect, truncating

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Foobara::CommandPatternImplementation::Concerns::Inputs

Class Method Details

.generator_keyObject



6
# File 'src/write_typescript_to_disk.rb', line 6

def self.generator_key = "typescript-remote-commands"

Instance Method Details

#auto_dirty_queries?Boolean

Returns:

  • (Boolean)


60
61
62
# File 'src/write_typescript_to_disk.rb', line 60

def auto_dirty_queries?
  auto_dirty_queries
end

#eslint_fixObject



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'src/write_typescript_to_disk.rb', line 70

def eslint_fix
  cmd = "npx eslint 'src/**/*.{js,jsx,ts,tsx}' --fix"

  Open3.popen3(cmd) do |_stdin, stdout, stderr, wait_thr|
    exit_status = wait_thr.value

    unless exit_status.success?
      # :nocov:
      out = stdout.read
      err = stderr.read

      if fail_if_does_not_pass_linter?
        add_runtime_error :failed_to_lint, stdout: out, stderr: err
      else
        warn "WARNING: could not #{cmd}\n#{out}\n#{err}"
      end
      # :nocov:
    end
  end
end

#executeObject



25
26
27
28
29
30
31
32
33
# File 'src/write_typescript_to_disk.rb', line 25

def execute
  generate_typescript
  generate_generated_files_json
  delete_old_files_if_needed
  write_all_files_to_disk
  run_post_generation_tasks

  stats
end

#fail_if_does_not_pass_linter?Boolean

Returns:

  • (Boolean)


91
# File 'src/write_typescript_to_disk.rb', line 91

def fail_if_does_not_pass_linter? = fail_if_does_not_pass_linter

#generate_typescriptObject



49
50
51
52
53
54
55
56
57
58
# File 'src/write_typescript_to_disk.rb', line 49

def generate_typescript
  # TODO: we need a way to allow values to be nil in type declarations
  inputs = raw_manifest ? { raw_manifest: } : { manifest_url: }

  if auto_dirty_queries?
    inputs[:auto_dirty_queries] = auto_dirty_queries
  end

  self.paths_to_source_code = run_subcommand!(GenerateTypescript, inputs)
end

#run_post_generation_tasksObject



64
65
66
67
68
# File 'src/write_typescript_to_disk.rb', line 64

def run_post_generation_tasks
  Dir.chdir(project_directory || output_directory) do
    eslint_fix
  end
end

#validateObject



35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'src/write_typescript_to_disk.rb', line 35

def validate
  # TODO: kind of strange that we have to use a runtime error here. Maybe if input errors
  # supported the concept of multiple inputs this would be cleaner?
  if raw_manifest.nil? && manifest_url.nil?
    # TODO: we should support a sugar like:
    # add_runtime_error(
    #   :missing_manifest,
    #   "Must provide either raw_manifest or manifest_url",
    #   some_context_item: "blah"
    # )
    add_runtime_error(symbol: :missing_manifest, message: "Must provide either raw_manifest or manifest_url")
  end
end