Module: Arkana

Defined in:
lib/arkana.rb,
lib/arkana/version.rb

Overview

Top-level namespace for Arkana’s execution entry point. When ran from CLI, ‘Arkana.run` is what is invoked.

Constant Summary collapse

VERSION =
"2.0.0"

Class Method Summary collapse

Class Method Details

.run(arguments) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/arkana.rb', line 15

def self.run(arguments)
  config = ConfigParser.parse(arguments)
  salt = SaltGenerator.generate
  DotenvHelper.load(config)

  begin
    environment_secrets = Encoder.encode!(
      keys: config.environment_keys,
      salt: salt,
      current_flavor: config.current_flavor,
      environments: config.environments,
    )
    global_secrets = Encoder.encode!(
      keys: config.global_secrets,
      salt: salt,
      current_flavor: config.current_flavor,
      environments: config.environments,
    )
  rescue StandardError => e
    # TODO: Improve this by creating an Env/Debug helper
    UI.warn("Something went wrong when parsing and encoding your secrets.")
    UI.warn("Current Flavor: #{config.current_flavor}")
    UI.warn("Dotenv Filepath: #{config.dotenv_filepath}")
    UI.warn("Config Filepath: #{arguments.config_filepath}")
    UI.crash(e.message)
  end
  template_arguments = TemplateArguments.new(
    environment_secrets: environment_secrets,
    global_secrets: global_secrets,
    config: config,
    salt: salt,
  )

  generator = case config.current_lang.downcase
    when "swift" then SwiftCodeGenerator
    when "kotlin" then KotlinCodeGenerator
    else UI.crash("Unknown output lang selected: #{config.current_lang}")
  end

  generator.method(:generate).call(
    template_arguments: template_arguments,
    config: config,
  )
end