Class: Homesteading::New

Inherits:
Command show all
Defined in:
lib/homesteading/commands/new.rb

Constant Summary collapse

PUBLISHER_APPS =

PUBLISHER_APPS = [“article”, “bookmark”, “event”, “note”, “photo”, “sound”, “video”, “walk”, “weight”]

["publisher-note"]
NONPUBLISHER_APPS =

TODO “hub”, “syndicator”

["router-rack"]

Constants inherited from Command

Command::COMMANDS

Instance Method Summary collapse

Methods inherited from Command

create, register

Instance Method Details

#defaultObject



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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# File 'lib/homesteading/commands/new.rb', line 12

def default
  puts

  options = parse_options

  # Install location
  constellation_dir  = ARGV.shift
  constellation_path = "#{Dir.pwd}/#{constellation_dir}"

  if File.exist?(constellation_path)
    unless options[:quiet]
      puts "* #{constellation_path} already exists"
      puts "* Using #{constellation_path}"
    end
  else
    unless options[:quiet]
      puts "* Creating homesteading directory: #{constellation_dir}"
    end
    unless options[:pretend]
      FileUtils.mkpath constellation_dir
    end
  end

  # Apps to install
  apps = [NONPUBLISHER_APPS, PUBLISHER_APPS].flatten
  if options[:only]
    apps = options[:only].split(",").map { |a| a.downcase }
  end
  if options[:except]
    only_list = options[:except].split(",").map { |a| a.downcase }
    apps      = apps.delete_if { |a| only_list.include?(a) }
  end

  apps.each do |app|
    unless options[:pretend]
      puts
    end

    app_dir = "#{constellation_path}/homesteading-#{app}"

    if File.exist?(app_dir)
      if options[:skip]
        unless options[:quiet]
          puts "* #{app_dir} already exists"
          puts "* Skipping homesteading-#{app}"
        end
      elsif options[:force]
        unless options[:quiet]
          puts "* #{app_dir} already exists"
          puts "* Removing homesteading-#{app}"
        end

        unless options[:pretend]
          FileUtils.rm_rf app_dir
        end

        unless options[:quiet]
          puts "* Cloning homesteading app from GitHub: #{app}"
        end

        unless options[:pretend]
          FileUtils.cd constellation_dir do
            system "git clone [email protected]:homesteading/homesteading-#{app}.git"
          end
        end
      else
        unless options[:quiet]
          puts "* #{app_dir} already exists"
          puts "* TODO gets user input on what to do about the conflict"
        end
      end

    else

      unless options[:quiet]
        puts "* Cloning homesteading app from GitHub: #{app}"
      end

      unless options[:pretend]
        FileUtils.cd constellation_dir do
          system "git clone [email protected]:homesteading/homesteading-#{app}.git"
        end
      end
    end
  end

  puts
  Homesteading::Command.create("init").default(constellation_dir)

  unless options[:quiet]
    puts "* Next up, do this:"
    puts "  cd #{constellation_dir}"
    puts "  homesteading server"
  end

  puts
end