Class: Monoz::Services::InitService

Inherits:
BaseService show all
Defined in:
lib/monoz/services/init_service.rb

Instance Method Summary collapse

Methods inherited from BaseService

call, #initialize

Constructor Details

This class inherits a constructor from Monoz::Services::BaseService

Instance Method Details

#call(path) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/monoz/services/init_service.rb', line 9

def call(path)
  config_file_path = File.join(File.expand_path(path), "monoz.yml")
  project_dir = File.dirname(config_file_path)

  if File.exist?(config_file_path)
    say "Error: monoz.yaml already exists in #{config_file_path}", :red
    return
  end

  FileUtils.mkdir_p(project_dir)
  FileUtils.mkdir_p(File.join(project_dir, "apps"))
  FileUtils.mkdir_p(File.join(project_dir, "gems"))
  FileUtils.touch(File.join(project_dir, "apps/.keep"))
  FileUtils.touch(File.join(project_dir, "gems/.keep"))
  File.write(config_file_path, Monoz::Configuration.default_config.to_yaml)

  FileUtils.chdir(project_dir) do
    system "git", "init"
  end

  say "Successfully initialized Monoz in #{project_dir}", :green
end