Class: Sfn::Command::Init

Inherits:
Sfn::Command show all
Includes:
Sfn::CommandModule::Base
Defined in:
lib/sfn/command/init.rb

Overview

Init command

Constant Summary collapse

INIT_DIRECTORIES =
[
  "sparkleformation/dynamics",
  "sparkleformation/components",
  "sparkleformation/registry",
]

Constants inherited from Sfn::Command

CONFIG_BASE_NAME, VALID_CONFIG_EXTENSIONS

Instance Method Summary collapse

Methods included from Sfn::CommandModule::Base

included

Methods inherited from Sfn::Command

#config, #initialize

Methods included from Sfn::CommandModule::Callbacks

#api_action!, #callbacks_for, #run_callbacks_for

Constructor Details

This class inherits a constructor from Sfn::Command

Instance Method Details

#execute!Object

Run the init command to initialize new project



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
# File 'lib/sfn/command/init.rb', line 17

def execute!
  unless name_args.size == 1
    raise ArgumentError.new "Please provide path argument only for project initialization"
  else
    path = name_args.first
  end
  if File.file?(path)
    raise "Cannot create project directory. Given path is a file. (`#{path}`)"
  end
  if File.directory?(path)
    ui.warn "Project directory already exists at given path. (`#{path}`)"
    ui.confirm "Overwrite existing files?"
  end
  run_action "Creating base project directories" do
    INIT_DIRECTORIES.each do |new_dir|
      FileUtils.mkdir_p(File.join(path, new_dir))
    end
    nil
  end
  run_action "Creating project bundle" do
    File.open(File.join(path, "Gemfile"), "w") do |file|
      file.puts "source 'https://rubygems.org'\n\ngem 'sfn'"
    end
    nil
  end
  ui.info "Generating .sfn configuration file"
  Dir.chdir(path) do
    Conf.new({:generate => true}, []).execute!
  end
  ui.info "Installing project bundle"
  Dir.chdir(path) do
    if defined?(Bundler)
      Bundler.clean_system("bundle install")
    else
      system("bundle install")
    end
  end
  ui.info "Project initialization complete!"
  ui.puts "  Project path -> #{File.expand_path(path)}"
end