Class: Foobara::RemoteGenerator::WriteTypescriptToDisk

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

Defined Under Namespace

Classes: MissingManifestError

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

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!, reset_all

Methods included from Concern

foobara_class_methods_module_for, foobara_concern?, included

Methods included from CommandPatternImplementation::Concerns::Reflection

#initialize

Methods included from CommandPatternImplementation::Concerns::DomainMappers

#domain_map, #domain_map!, #run_mapped_subcommand!

Methods included from CommandPatternImplementation::Concerns::Subcommands

#run_subcommand!, #subcommand?

Methods included from CommandPatternImplementation::Concerns::Entities

#load_entities, #load_records

Methods included from CommandPatternImplementation::Concerns::Transactions

#auto_detect_current_transactions, #commit_transaction, #open_transaction, #opened_transactions, #relevant_entity_classes, #rollback_transaction, #transactions

Methods included from CommandPatternImplementation::Concerns::StateMachine

#state_machine

Methods included from CommandPatternImplementation::Concerns::Runtime

#halt!, #run, #run!, #run_execute, #succeed, #success?, #validate_records

Methods included from CommandPatternImplementation::Concerns::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 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



7
8
9
# File 'foobara-typescript-remote-command-generator-0.0.18/src/remote_generator/write_typescript_to_disk.rb', line 7

def generator_key
  "typescript-remote-commands"
end

Instance Method Details

#eslint_fixObject



64
65
66
67
68
69
70
71
72
73
74
75
# File 'foobara-typescript-remote-command-generator-0.0.18/src/remote_generator/write_typescript_to_disk.rb', line 64

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:
      warn "WARNING: could not #{cmd}\n#{stderr.read}"
      # :nocov:
    end
  end
end

#executeObject



32
33
34
35
36
37
38
39
40
# File 'foobara-typescript-remote-command-generator-0.0.18/src/remote_generator/write_typescript_to_disk.rb', line 32

def execute
  generate_typescript
  generate_generated_files_json
  delete_old_files_if_needed
  write_all_files_to_disk
  run_post_generation_tasks

  stats
end

#generate_typescriptObject



53
54
55
56
57
58
# File 'foobara-typescript-remote-command-generator-0.0.18/src/remote_generator/write_typescript_to_disk.rb', line 53

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

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

#run_post_generation_tasksObject



60
61
62
# File 'foobara-typescript-remote-command-generator-0.0.18/src/remote_generator/write_typescript_to_disk.rb', line 60

def run_post_generation_tasks
  eslint_fix
end

#validateObject



42
43
44
45
46
47
48
49
50
51
# File 'foobara-typescript-remote-command-generator-0.0.18/src/remote_generator/write_typescript_to_disk.rb', line 42

def validate
  if raw_manifest.nil? && manifest_url.nil?
    add_input_error(
      MissingManifestError.new(
        message: "Must provide either raw_manifest or manifest_url",
        context: {}
      )
    )
  end
end