Class: Makit::Setup::Runner

Inherits:
Object
  • Object
show all
Defined in:
lib/makit/setup/runner.rb

Class Method Summary collapse

Class Method Details

.runObject



11
12
13
14
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
# File 'lib/makit/setup/runner.rb', line 11

def self.run

  # if a .git directory exists, then make sure we have a .gitignore

  if File.exist?(".git")
    if !File.exist?(".gitignore")
      File.write(".gitignore", Makit::Content::GITIGNORE)
    end
  end
  # open .makit.json and get project type, to determine which setup to run

  return unless File.exist?(".makit.json")

  begin
    project = Makit::Serializer.open(".makit.json", Makit::Configuration::Project)

    # Update version to match VERSION constant only if project version is truly empty

    if defined?(Makit::VERSION) && (project.version.nil? || project.version.empty?)
      project.version = Makit::VERSION
    end

    # Check if the file contains compact JSON and resave as pretty JSON

    current_content = File.read(".makit.json")
    pretty_content = project.to_json_pretty

    # Only rewrite if the content is different (i.e., if it was compact or version changed)

    File.write(".makit.json", pretty_content) if current_content.strip != pretty_content.strip
  rescue StandardError
    raise "Error opening .makit.json"
  end
  project_type = project.project_type
  case project_type
  when "classlib"
    Makit::Setup::ClassLib.run
  when "razorclasslib"
    Makit::Setup::RazorClassLib.run
  when "gem"
    Makit::Setup::Gem.run
  else
    Makit::Logging.default_logger.warn("Unsupported project type: #{project_type}")
    # puts "Unsupported project type: #{project_type}"

  end
end