homesteading 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,44 +1,44 @@
1
- class Homesteading
2
- class Init
3
- class << self
1
+ require "homesteading/command"
4
2
 
5
- def default(constellation_dir)
6
- puts
7
- puts "* Setting up all apps"
8
- puts
3
+ module Homesteading
4
+ class Init < Command
5
+ register "init"
9
6
 
10
- Dir.glob("#{Dir.pwd}/#{constellation_dir}/homesteading-*/").each do |app_dir|
11
- app = app_dir.split("/").last.sub(/homesteading-/, "").downcase
12
- app_file_path = app_dir + "app.json"
7
+ def default(constellation_dir)
8
+ puts
9
+ puts "* Setting up all apps"
10
+ puts
13
11
 
14
- puts "* Setting up: #{app}"
12
+ Dir.glob("#{Dir.pwd}/#{constellation_dir}/homesteading-*/").each do |app_dir|
13
+ app = app_dir.split("/").last.sub(/homesteading-/, "").downcase
14
+ app_file_path = app_dir + "app.json"
15
15
 
16
- if File.exist?(app_file_path)
17
- app_file = JSON.parse(File.read(app_file_path))
18
- app_postdeploy = app_file["scripts"]["postdeploy"]
16
+ puts "* Setting up: #{app}"
19
17
 
20
- FileUtils.cd app_dir do
21
- if File.exist?("#{app_dir}/config/database.example.yml")
22
- puts "* Copying database config file"
23
- system "rake hs:db:config"
24
- end
18
+ if File.exist?(app_file_path)
19
+ app_file = JSON.parse(File.read(app_file_path))
20
+ app_postdeploy = app_file["scripts"]["postdeploy"]
25
21
 
26
- unless app_postdeploy.nil? && app_postdeploy.empty?
27
- puts "* Running postdeploy command on #{app}:"
28
- puts
29
- system app_postdeploy if app_postdeploy
30
- end
22
+ FileUtils.cd app_dir do
23
+ if File.exist?("#{app_dir}/config/database.example.yml")
24
+ puts "* Copying database config file"
25
+ system "rake hs:db:config"
26
+ end
31
27
 
28
+ unless app_postdeploy.nil? && app_postdeploy.empty?
29
+ puts "* Running postdeploy command on #{app}:"
32
30
  puts
31
+ system app_postdeploy if app_postdeploy
33
32
  end
34
- end
35
33
 
36
- puts "* Setup up complete for: #{app}"
37
- puts
38
- puts
34
+ puts
35
+ end
39
36
  end
40
- end
41
37
 
38
+ puts "* Setup up complete for: #{app}"
39
+ puts
40
+ puts
41
+ end
42
42
  end
43
43
  end
44
44
  end
@@ -1,84 +1,68 @@
1
+ require "homesteading/command"
1
2
  require "homesteading/commands/init"
2
3
 
3
- class Homesteading
4
- class New
5
- class << self
6
- PUBLISHER_APPS = ["article", "bookmark", "event", "note", "photo", "sound", "video", "walk", "weight"]
7
- NONPUBLISHER_APPS = ["router-rack"] # TODO "hub", "syndicator"
4
+ module Homesteading
5
+ class New < Command
6
+ register "new"
8
7
 
9
- def default
10
- puts
8
+ PUBLISHER_APPS = ["article", "bookmark", "event", "note", "photo", "sound", "video", "walk", "weight"]
9
+ NONPUBLISHER_APPS = ["router-rack"] # TODO "hub", "syndicator"
11
10
 
12
- options = parse_options
11
+ def default
12
+ puts
13
13
 
14
- # Install location
15
- constellation_dir = ARGV.shift
16
- constellation_path = "#{Dir.pwd}/#{constellation_dir}"
14
+ options = parse_options
17
15
 
18
- if File.exist?(constellation_path)
19
- unless options[:quiet]
20
- puts "* #{constellation_path} already exists"
21
- puts "* Using #{constellation_path}"
22
- end
23
- else
24
- unless options[:quiet]
25
- puts "* Creating homesteading directory: #{constellation_dir}"
26
- end
27
- unless options[:pretend]
28
- FileUtils.mkpath constellation_dir
29
- end
30
- end
16
+ # Install location
17
+ constellation_dir = ARGV.shift
18
+ constellation_path = "#{Dir.pwd}/#{constellation_dir}"
31
19
 
32
- # Apps to install
33
- apps = [NONPUBLISHER_APPS, PUBLISHER_APPS].flatten
34
- if options[:only]
35
- apps = options[:only].split(",").map { |a| a.downcase }
20
+ if File.exist?(constellation_path)
21
+ unless options[:quiet]
22
+ puts "* #{constellation_path} already exists"
23
+ puts "* Using #{constellation_path}"
36
24
  end
37
- if options[:except]
38
- only_list = options[:except].split(",").map { |a| a.downcase }
39
- apps = apps.delete_if { |a| only_list.include?(a) }
25
+ else
26
+ unless options[:quiet]
27
+ puts "* Creating homesteading directory: #{constellation_dir}"
40
28
  end
29
+ unless options[:pretend]
30
+ FileUtils.mkpath constellation_dir
31
+ end
32
+ end
41
33
 
42
- apps.each do |app|
43
- unless options[:pretend]
44
- puts
45
- end
46
-
47
- app_dir = "#{constellation_path}/homesteading-#{app}"
48
-
49
- if File.exist?(app_dir)
50
- if options[:skip]
51
- unless options[:quiet]
52
- puts "* #{app_dir} already exists"
53
- puts "* Skipping homesteading-#{app}"
54
- end
55
- elsif options[:force]
56
- unless options[:quiet]
57
- puts "* #{app_dir} already exists"
58
- puts "* Removing homesteading-#{app}"
59
- end
34
+ # Apps to install
35
+ apps = [NONPUBLISHER_APPS, PUBLISHER_APPS].flatten
36
+ if options[:only]
37
+ apps = options[:only].split(",").map { |a| a.downcase }
38
+ end
39
+ if options[:except]
40
+ only_list = options[:except].split(",").map { |a| a.downcase }
41
+ apps = apps.delete_if { |a| only_list.include?(a) }
42
+ end
60
43
 
61
- unless options[:pretend]
62
- FileUtils.rm_rf app_dir
63
- end
44
+ apps.each do |app|
45
+ unless options[:pretend]
46
+ puts
47
+ end
64
48
 
65
- unless options[:quiet]
66
- puts "* Cloning homesteading app from GitHub: #{app}"
67
- end
49
+ app_dir = "#{constellation_path}/homesteading-#{app}"
68
50
 
69
- unless options[:pretend]
70
- FileUtils.cd constellation_dir do
71
- system "git clone git@github.com:homesteading/homesteading-#{app}.git"
72
- end
73
- end
74
- else
75
- unless options[:quiet]
76
- puts "* #{app_dir} already exists"
77
- puts "* TODO gets user input on what to do about the conflict"
78
- end
51
+ if File.exist?(app_dir)
52
+ if options[:skip]
53
+ unless options[:quiet]
54
+ puts "* #{app_dir} already exists"
55
+ puts "* Skipping homesteading-#{app}"
56
+ end
57
+ elsif options[:force]
58
+ unless options[:quiet]
59
+ puts "* #{app_dir} already exists"
60
+ puts "* Removing homesteading-#{app}"
79
61
  end
80
62
 
81
- else
63
+ unless options[:pretend]
64
+ FileUtils.rm_rf app_dir
65
+ end
82
66
 
83
67
  unless options[:quiet]
84
68
  puts "* Cloning homesteading app from GitHub: #{app}"
@@ -89,56 +73,73 @@ class Homesteading
89
73
  system "git clone git@github.com:homesteading/homesteading-#{app}.git"
90
74
  end
91
75
  end
76
+ else
77
+ unless options[:quiet]
78
+ puts "* #{app_dir} already exists"
79
+ puts "* TODO gets user input on what to do about the conflict"
80
+ end
92
81
  end
93
- end
94
82
 
95
- puts
96
- Homesteading::Init.default(constellation_dir)
83
+ else
97
84
 
98
- unless options[:quiet]
99
- puts "* Next up, do this:"
100
- puts " cd #{constellation_dir}"
101
- puts " homesteading server"
85
+ unless options[:quiet]
86
+ puts "* Cloning homesteading app from GitHub: #{app}"
87
+ end
88
+
89
+ unless options[:pretend]
90
+ FileUtils.cd constellation_dir do
91
+ system "git clone git@github.com:homesteading/homesteading-#{app}.git"
92
+ end
93
+ end
102
94
  end
95
+ end
103
96
 
104
- puts
97
+ puts
98
+ Homesteading::Init.default(constellation_dir)
99
+
100
+ unless options[:quiet]
101
+ puts "* Next up, do this:"
102
+ puts " cd #{constellation_dir}"
103
+ puts " homesteading server"
105
104
  end
106
105
 
107
- private
108
- def parse_options
109
- # Parse command line options
110
- options = {}
106
+ puts
107
+ end
111
108
 
112
- optparse = OptionParser.new do |opts|
113
- opts.on("-e", "--except EXCEPT", "Comma separated list of apps to not install") do |except|
114
- options[:except] = except
115
- end
109
+ private
110
+ def parse_options
111
+ # Parse command line options
112
+ options = {}
116
113
 
117
- opts.on("-f", "--force", "Overwrite apps that already exist") do |force|
118
- options[:force] = force
119
- end
114
+ optparse = OptionParser.new do |opts|
115
+ opts.on("-e", "--except EXCEPT", "Comma separated list of apps to not install") do |except|
116
+ options[:except] = except
117
+ end
120
118
 
121
- opts.on("-o", "--only ONLY", "Comma separated list of apps to install") do |only|
122
- options[:only] = only
123
- end
119
+ opts.on("-f", "--force", "Overwrite apps that already exist") do |force|
120
+ options[:force] = force
121
+ end
124
122
 
125
- opts.on("-p", "--pretend", "Run but do not make any changes") do |pretend|
126
- options[:pretend] = pretend
127
- end
123
+ opts.on("-o", "--only ONLY", "Comma separated list of apps to install") do |only|
124
+ options[:only] = only
125
+ end
128
126
 
129
- opts.on("-q", "--quiet", "Suppress status output") do |quiet|
130
- options[:quiet] = quiet
131
- end
127
+ opts.on("-p", "--pretend", "Run but do not make any changes") do |pretend|
128
+ options[:pretend] = pretend
129
+ end
132
130
 
133
- opts.on("-s", "--skip", "Skip apps that already exist") do |skip|
134
- options[:skip] = skip
135
- end
131
+ opts.on("-q", "--quiet", "Suppress status output") do |quiet|
132
+ options[:quiet] = quiet
136
133
  end
137
134
 
138
- optparse.parse!
139
- options
135
+ opts.on("-s", "--skip", "Skip apps that already exist") do |skip|
136
+ options[:skip] = skip
137
+ end
140
138
  end
141
139
 
140
+ optparse.parse!
141
+ options
142
142
  end
143
+
143
144
  end
144
145
  end
@@ -1,48 +1,49 @@
1
- class Homesteading
2
- class Run
3
- class << self
4
-
5
- def default
6
- puts
7
- options = parse_options
8
- app = options[:app]
9
- command = ARGV.join(" ")
10
-
11
- app_dirs = if app
12
- ["#{Dir.pwd}/homesteading-#{app}/"]
13
- else
14
- Dir.glob("#{Dir.pwd}/homesteading-*/")
15
- end
1
+ require "homesteading/command"
2
+
3
+ module Homesteading
4
+ class Run < Command
5
+ register "run"
6
+
7
+ def default
8
+ puts
9
+ options = parse_options
10
+ app = options[:app]
11
+ command = ARGV.join(" ")
12
+
13
+ app_dirs = if app
14
+ ["#{Dir.pwd}/homesteading-#{app}/"]
15
+ else
16
+ Dir.glob("#{Dir.pwd}/homesteading-*/")
17
+ end
16
18
 
17
- app_dirs.each do |app_dir|
18
- app = app_dir.split("/").last.sub(/homesteading-/, "").downcase
19
+ app_dirs.each do |app_dir|
20
+ app = app_dir.split("/").last.sub(/homesteading-/, "").downcase
19
21
 
20
- puts "* Running command on #{app}:"
21
- puts " #{command}"
22
- puts
22
+ puts "* Running command on #{app}:"
23
+ puts " #{command}"
24
+ puts
23
25
 
24
- FileUtils.cd app_dir do
25
- system command
26
- end
27
- puts
26
+ FileUtils.cd app_dir do
27
+ system command
28
28
  end
29
+ puts
29
30
  end
31
+ end
30
32
 
31
- private
32
- def parse_options
33
- # Parse command line options
34
- options = {}
33
+ private
34
+ def parse_options
35
+ # Parse command line options
36
+ options = {}
35
37
 
36
- optparse = OptionParser.new do |opts|
37
- opts.on("-a", "--app APP", "Name of Homesteading app on GitHub") do |app|
38
- options[:app] = app
39
- end
38
+ optparse = OptionParser.new do |opts|
39
+ opts.on("-a", "--app APP", "Name of Homesteading app on GitHub") do |app|
40
+ options[:app] = app
40
41
  end
41
-
42
- optparse.parse!
43
- options
44
42
  end
45
43
 
44
+ optparse.parse!
45
+ options
46
46
  end
47
+
47
48
  end
48
49
  end
@@ -1,117 +1,118 @@
1
- class Homesteading
2
- class Server
3
- class << self
4
-
5
- def default
6
- puts
7
- options = parse_options
8
-
9
- router_port = options[:port] || 3000
10
-
11
- # Kill all Homesteading apps when `hs server` is stopped
12
- servers = []
13
- Signal.trap("INT") do
14
- servers.each do |io|
15
- puts "Stopping HS:Publisher app at PID: #{io.pid}"
16
- Process.kill "SIGINT", io.pid
17
- end
1
+ require "homesteading/command"
2
+ require "puma"
3
+
4
+ module Homesteading
5
+ class Server < Command
6
+ register "server", "s"
7
+
8
+ def default
9
+ puts
10
+ options = parse_options
11
+
12
+ router_port = options[:port] || 3000
18
13
 
19
- system "homesteading server:stop"
20
- exit
14
+ # Kill all Homesteading apps when `hs server` is stopped
15
+ servers = []
16
+ Signal.trap("INT") do
17
+ servers.each do |io|
18
+ puts "Stopping HS:Publisher app at PID: #{io.pid}"
19
+ Process.kill "SIGINT", io.pid
21
20
  end
22
21
 
23
- # TODO
24
- homesteading_info = "0.1.0, codename: Rooftop"
25
- ruby_info = RUBY_VERSION
26
- puma_info = "2.10.2 (ruby 2.1.5-p273), codename: Robots on Comets"
27
- env_info = "development"
28
-
29
- puts "* Homesteading: #{homesteading_info}"
30
- puts "* Puma: #{puma_info}"
31
- puts "* Ruby: #{RUBY_VERSION}"
32
- puts "* Environment: #{env_info}"
33
- puts "* Running on: http://0.0.0.0:#{router_port}"
34
- puts
35
-
36
- puts "* Homesteading servers starting..."
37
- puts
38
-
39
- routes = []
40
-
41
- app_port = 3000
42
- Dir.glob("#{Dir.pwd}/homesteading-*/").each_with_index do |directory, index|
43
- app_file_path = directory + "app.json"
44
-
45
- if File.exist?(app_file_path)
46
- app_file = JSON.parse(File.read(app_file_path))
47
- app_route = app_file["routes"]
48
-
49
- if app_route
50
- app_name = directory.split("/").last
51
-
52
- app_path = app_route["path"]
53
- if app_name =~ /feed/
54
- app_path = "feed"
55
- end
56
-
57
- unless app_name == "homesteading-router-rack"
58
- app_port += 1
59
- routes << "#{app_path}:#{app_port}"
60
- end
61
-
62
- if app_name =~ /homesteading-assets|homesteading-router-rack/
63
- # TODO TEMP FIXME serve assets from hub
64
- # skipping assets and router
65
- elsif app_name == "homesteading-feed"
66
- # TODO TEMP FIXME no bin/rails
67
- puts "* Starting on port #{app_port} : #{app_name.sub(/homesteading-/, "")}"
68
- servers << IO.popen("cd #{directory} && rails server -p #{app_port}", "w")
69
- else
70
- puts "* Starting on port #{app_port} : #{app_name.sub(/homesteading-/, "")}"
71
- servers << IO.popen("cd #{directory} && bin/rails server -d --port #{app_port}", "w")
72
- end
22
+ system "homesteading server:stop"
23
+ exit
24
+ end
25
+
26
+ homesteading_info = "#{Homesteading::VERSION}, codename: #{Homesteading::CODENAME}"
27
+ ruby_info = RUBY_DESCRIPTION
28
+ puma_info = "#{Puma::Const::PUMA_VERSION}, codename: #{Puma::Const::CODE_NAME}"
29
+ env_info = "development"
30
+
31
+ puts "* Homesteading: #{homesteading_info}"
32
+ puts "* Puma: #{puma_info}"
33
+ puts "* Ruby: #{ruby_info}"
34
+ puts "* Environment: #{env_info}"
35
+ puts "* Running on: http://0.0.0.0:#{router_port}"
36
+ puts
37
+
38
+ puts "* Homesteading servers starting..."
39
+ puts
40
+
41
+ routes = []
42
+
43
+ app_port = 3000
44
+ Dir.glob("#{Dir.pwd}/homesteading-*/").each_with_index do |directory, index|
45
+ app_file_path = directory + "app.json"
46
+
47
+ if File.exist?(app_file_path)
48
+ app_file = JSON.parse(File.read(app_file_path))
49
+ app_route = app_file["routes"]
50
+
51
+ if app_route
52
+ app_name = directory.split("/").last
53
+
54
+ app_path = app_route["path"]
55
+ if app_name =~ /feed/
56
+ app_path = "feed"
73
57
  end
74
58
 
59
+ unless app_name == "homesteading-router-rack"
60
+ app_port += 1
61
+ routes << "#{app_path}:#{app_port}"
62
+ end
63
+
64
+ if app_name =~ /homesteading-assets|homesteading-router-rack/
65
+ # TODO TEMP FIXME serve assets from hub
66
+ # skipping assets and router
67
+ elsif app_name == "homesteading-feed"
68
+ # TODO TEMP FIXME no bin/rails
69
+ puts "* Starting on port #{app_port} : #{app_name.sub(/homesteading-/, "")}"
70
+ servers << IO.popen("cd #{directory} && rails server -p #{app_port}", "w")
71
+ else
72
+ puts "* Starting on port #{app_port} : #{app_name.sub(/homesteading-/, "")}"
73
+ servers << IO.popen("cd #{directory} && bin/rails server -d --port #{app_port}", "w")
74
+ end
75
75
  end
76
+
76
77
  end
78
+ end
77
79
 
78
- # write routes to an env var for hs:router's routes table
79
- ENV["HOMESTEADING_ROUTES"] = routes.join(",")
80
+ # write routes to an env var for hs:router's routes table
81
+ ENV["HOMESTEADING_ROUTES"] = routes.join(",")
80
82
 
81
- # start up router after ENV var is set
82
- puts
83
- puts "* Starting on port #{router_port} : router"
84
- servers << IO.popen("cd #{Dir.pwd}/homesteading-router-rack/ && rackup -p #{router_port}", "w")
83
+ # start up router after ENV var is set
84
+ puts
85
+ puts "* Starting on port #{router_port} : router"
86
+ servers << IO.popen("cd #{Dir.pwd}/homesteading-router-rack/ && rackup -p #{router_port}", "w")
85
87
 
86
88
 
87
- puts
88
- puts "* To stop Homesteading servers:"
89
- puts " ctrl-c"
90
- puts " homesteading server:stop"
91
- puts
92
- end
89
+ puts
90
+ puts "* To stop Homesteading servers:"
91
+ puts " ctrl-c"
92
+ puts " homesteading server:stop"
93
+ puts
94
+ end
93
95
 
94
- def stop
95
- # TEMP HACK TODO FIXME
96
- # This is overly aggressive, but Signal.trap isn't working
97
- system "killall ruby"
98
- end
96
+ def stop
97
+ # TEMP HACK TODO FIXME
98
+ # This is overly aggressive, but Signal.trap isn't working
99
+ system "killall ruby"
100
+ end
99
101
 
100
- private
101
- def parse_options
102
- # Parse command line options
103
- options = {}
102
+ private
103
+ def parse_options
104
+ # Parse command line options
105
+ options = {}
104
106
 
105
- optparse = OptionParser.new do |opts|
106
- opts.on("-p", "--port PORT", "Run homesteading site on a specific port (default: 3000)") do |port|
107
- options[:port] = port
108
- end
107
+ optparse = OptionParser.new do |opts|
108
+ opts.on("-p", "--port PORT", "Run homesteading site on a specific port (default: 3000)") do |port|
109
+ options[:port] = port
109
110
  end
110
-
111
- optparse.parse!
112
- options
113
111
  end
114
112
 
113
+ optparse.parse!
114
+ options
115
115
  end
116
+
116
117
  end
117
118
  end