tane 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,19 +1,38 @@
1
1
  class Tane::Commands::Create < Tane::Commands::Base
2
-
3
2
  class << self
4
3
  def process(args)
4
+ verbose_say("Authenticating you...")
5
5
  authenticate_user
6
+ verbose_say("done!")
7
+
6
8
  app_name = args[0] ||= term.ask("Please enter a name for your new app: ") { |app_name| app_name }
7
9
  template_url = ENV['KIMONO_URL'] || "https://raw.github.com/Bushido/kimono/master/kimono.rb"
8
10
 
9
- print "Creating a new Bushido rails app in #{ app_name } ... "
11
+ print "Creating a new Bushido rails app in ./#{ app_name } (please wait, it'll take a few minutes) ... "
12
+
13
+ start_throbber!
10
14
 
11
- system("rails new #{app_name} -m #{ template_url } > tane.log")
15
+ File.open("tane.log", "w") do |file|
16
+ IO.popen("rails new #{app_name} -m #{ template_url }", :error => [:child, :out]) do |io|
17
+ file.puts(io.read)
18
+ end
19
+ end
20
+ verbose_say("Finished creating rails app, initializing Bushido resources...")
12
21
 
13
22
  Dir.chdir("./#{app_name}")do
14
- system("bundle exec tane init > ../tane.log")
23
+ File.open("tane.log", "w") do |file|
24
+ verbose = "--verbose" if opts.verbose
25
+ verbose ||= ""
26
+ IO.popen("bundle exec tane init #{verbose}", :error => [:child, :out]) do |io|
27
+ file.puts(io.read)
28
+ end
29
+ end
15
30
  end
16
31
 
32
+ verbose_say("done!")
33
+
34
+ stop_throbber!
35
+
17
36
  success_messages = ["Let the hacking commence!",
18
37
  "Hacks and glory await!",
19
38
  "Hack and be merry!",
@@ -21,24 +40,50 @@ class Tane::Commands::Create < Tane::Commands::Base
21
40
  "May the source be with you!",
22
41
  "Take this demi-REPL, dear friend, and may it serve you well.",
23
42
  "Lemonodor-fame is but a hack away!",
24
- "Go forth to #{ app_name }, and hack for all you're worth - for all mankind!"]
43
+ "Go forth to #{ app_name }, and hack for all you're worth - for all humankind!"]
44
+
45
+ bushirens = ["Sean", "Kevin", "Akash"]
25
46
 
26
47
  success_message = success_messages[ rand(success_messages.length) ]
48
+ bushiren = bushirens [ rand(bushirens.length) ]
27
49
 
28
50
  FileUtils.mv("./tane.log", "./#{ app_name }/log/tane.log")
29
- puts "Finished successfully!"
30
- puts "Your app is now in ./#{ app_name } . #{ success_message }"
51
+ term.say " Finished successfully!"
52
+ term.say "Your app is now in ./#{ app_name }"
53
+
54
+
55
+ Dir.chdir("./#{app_name}") do
56
+ term.say "Launching your new app!"
57
+ term.say "Check out once rails has finished booting http://localhost:3000"
58
+ term.say "#{bushiren} says, \"#{ success_message }\""
59
+ begin
60
+ # Do this in the background, it'll wait up to 120 seconds
61
+ # for the rails server to start up and launch a browser as
62
+ # soon as it's ready
63
+ verbose_say("Launching `tane open' in the background..")
64
+ system("tane open&")
65
+ verbose_say("done!")
66
+
67
+ suppress_env_vars("BUNDLE_BIN_PATH", "BUNDLE_GEMFILE", "RUBYOPT") do
68
+ verbose_say("launching rails app!")
69
+ exec("bundle exec tane exec rails s")
70
+ end
71
+ rescue Exception => ex
72
+ term.say "Oh no we tried to launch the app but failed. Please try launching it yourself with \n bundle exec tane exec rails s \n if you have problems let us know at support@bushi.do"
73
+ end
74
+ end
75
+
31
76
  end
32
77
 
33
78
  def help_text
34
79
  <<-EOL
35
80
  Usage:
36
81
 
37
- tane claim email ido_id
82
+ tane create 'app_name'
38
83
 
39
- Notifies the app of an App.claimed event to the locally running app when the email and ido_id are passed.
84
+ Creates a new Bushido-enabled rails app from scratch and launches it. Use this to get started with Bushido quickly and easily
40
85
 
41
- tane claim john@example.com 6h284ah92jcj9m2sv21f
86
+ tane create my_example_app
42
87
  EOL
43
88
  end
44
89
  end
@@ -2,9 +2,13 @@ class Tane::Commands::Init < Tane::Commands::Base
2
2
 
3
3
  class << self
4
4
  def process(args)
5
+ verbose_say("authenticating you...")
5
6
  authenticate_user
7
+ verbose_say("done!")
6
8
  if in_rails_dir?
9
+ verbose_say("In a rails directory, tane initializing...")
7
10
  Tane::Helpers::Init.initialize_app
11
+ verbose_say("finished initializing!")
8
12
  else
9
13
  term.say("You have to be in the local rails app's root directory when running `tane init`")
10
14
  exit 1
@@ -31,7 +31,7 @@ class Tane::Commands::Login < Tane::Commands::Base
31
31
  term.say("Invalid username, or password, sorry! Don't worry though, we'll get you through this!")
32
32
 
33
33
  # returns auth_token on success
34
- return signup_and_notify(email, password) if term.agree("would you like to try signing up with those credentials?")
34
+ return signup_and_notify(email, password) if term.agree("would you like to try signing up with those credentials? Y/N")
35
35
 
36
36
  display_help_messages_and_exit
37
37
  end
@@ -0,0 +1,33 @@
1
+ require 'launchy'
2
+
3
+ class Tane::Commands::Open < Tane::Commands::Base
4
+ class << self
5
+ def process(args)
6
+ timeout = opts.timeout || 120
7
+
8
+ started = try_for(:seconds => timeout) do
9
+ begin
10
+ RestClient.get("http://localhost:3000/")
11
+ true
12
+ rescue => e
13
+ false
14
+ end
15
+ end
16
+
17
+ Launchy.open("http://localhost:3000/") if started
18
+ end
19
+
20
+ def help_text
21
+ <<-EOL
22
+ Usage:
23
+
24
+ tane open
25
+
26
+ Waits until there's a webserver running at port 3000 and then opens the browser to it.
27
+
28
+ tane open
29
+ EOL
30
+ end
31
+ end
32
+
33
+ end
@@ -9,7 +9,7 @@ class Tane::Helpers::Init
9
9
  else
10
10
  app = create_app
11
11
  make_app_bushido_dir
12
- save_envs(get_app_envs(app['name']))
12
+ save_envs(get_app_envs(app['app']['name']))
13
13
  save_emails
14
14
  end
15
15
 
@@ -23,9 +23,7 @@ class Tane::Helpers::Init
23
23
  # TODO: Replace envs_template with values retrieved from Bushido side
24
24
  def save_envs(env_vars)
25
25
  if File.exists?('.bushido/tane.yml')
26
- if not term.agree('.bushido/tane.yml already exists! Are you sure you want to overwrite it?')
27
- return
28
- end
26
+ return if not term.agree('.bushido/tane.yml already exists! Are you sure you want to overwrite it? Y/N')
29
27
  end
30
28
 
31
29
  File.open('.bushido/tane.yml', 'w+') { |file| file.puts YAML.dump(envs_template(env_vars)) }
@@ -33,9 +31,7 @@ class Tane::Helpers::Init
33
31
 
34
32
  def save_emails
35
33
  if File.exists?("#{email_templates_path}/#{example_email_template.keys.first}")
36
- if not term.agree("#{example_email_template.keys.first} already exists! Are you sure you want to overwrite it?")
37
- return
38
- end
34
+ return if not term.agree("#{example_email_template.keys.first} already exists! Are you sure you want to overwrite it? Y/N")
39
35
  end
40
36
 
41
37
  File.open("#{email_templates_path}/#{example_email_template.keys.first}", "w") do |file|
@@ -47,15 +43,15 @@ class Tane::Helpers::Init
47
43
  def envs_template(app_envs)
48
44
  envs = {}
49
45
  env_var_keys = [
50
- 'APP_TLD', 'BUNDLE_WITHOUT', 'BUSHIDO_APP', 'BUSHIDO_APP_KEY',
51
- 'BUSHIDO_DOMAIN', 'BUSHIDO_EVENTS', 'BUSHIDO_HOST', 'BUSHIDO_NAME',
52
- 'BUSHIDO_PROJECT_NAME', 'BUSHIDO_SALT', 'BUSHIDO_SUBDOMAIN',
53
- 'B_SQL_DB', 'B_SQL_PASS', 'B_SQL_USER', 'DATABASE_URL',
54
- 'HOSTING_PLATFORM', 'LANG', 'PUBLIC_URL', 'RACK_ENV',
55
- 'RAILS_ENV', 'S3_ACCESS_KEY_ID', 'S3_ARN', 'S3_BUCKET',
56
- 'SHARED_DATABASE_URL', 'S3_PREFIX', 'S3_SECRET_ACCESS_KEY',
46
+ 'APP_TLD', 'BUNDLE_WITHOUT', 'BUSHIDO_APP', 'BUSHIDO_APP_KEY',
47
+ 'BUSHIDO_DOMAIN', 'BUSHIDO_EVENTS', 'BUSHIDO_HOST', 'BUSHIDO_NAME',
48
+ 'BUSHIDO_PROJECT_NAME', 'BUSHIDO_SALT', 'BUSHIDO_SUBDOMAIN',
49
+ 'B_SQL_DB', 'B_SQL_PASS', 'B_SQL_USER', 'DATABASE_URL',
50
+ 'HOSTING_PLATFORM', 'LANG', 'PUBLIC_URL', 'RACK_ENV',
51
+ 'RAILS_ENV', 'S3_ACCESS_KEY_ID', 'S3_ARN', 'S3_BUCKET',
52
+ 'SHARED_DATABASE_URL', 'S3_PREFIX', 'S3_SECRET_ACCESS_KEY', 'STS_SESSION_TOKEN',
57
53
  'SMTP_AUTHENTICATION', 'SMTP_DOMAIN', 'SMTP_PASSWORD',
58
- 'SMTP_PORT', 'SMTP_SERVER', 'SMTP_TLS', 'SMTP_USER'
54
+ 'SMTP_PORT', 'SMTP_SERVER', 'SMTP_TLS', 'SMTP_USER'
59
55
  ]
60
56
 
61
57
  env_var_keys.each { |env_var_key| envs[env_var_key] = app_envs[env_var_key] }
data/lib/tane/helpers.rb CHANGED
@@ -11,6 +11,8 @@ module Tane
11
11
  end
12
12
 
13
13
  module ClassMethods
14
+ @should_throb = false
15
+
14
16
  def term
15
17
  @hl ||= HighLine.new
16
18
  end
@@ -64,7 +66,7 @@ module Tane
64
66
  end
65
67
 
66
68
  def bushido_app_exists?
67
- File.exists?('.bushido/tane.yml') and File.exists?('.bushido/email.yml')
69
+ File.exists?('.bushido/tane.yml') and File.directory?('.bushido/emails')
68
70
  end
69
71
 
70
72
  def username
@@ -163,6 +165,83 @@ module Tane
163
165
 
164
166
  result
165
167
  end
168
+
169
+ def repeat_every(interval, &block)
170
+ Thread.new do
171
+ loop do
172
+ start_time = Time.now
173
+ yield
174
+ elapsed = Time.now - start_time
175
+ sleep([interval - elapsed, 0].max)
176
+ end
177
+ end
178
+ end
179
+
180
+ def start_throbber!
181
+ throbber_frames = ['|', '/', '-', '\\', 'X']
182
+ frame_counter = 0
183
+
184
+ @should_throb = true
185
+
186
+ thread = repeat_every(0.5) do
187
+ if @should_throb
188
+ print "\x08\x08\x08"
189
+ frame_counter += 1
190
+ frame_counter = 0 if frame_counter == throbber_frames.length
191
+ print "#{throbber_frames[frame_counter]} "
192
+ end
193
+ end
194
+
195
+ end
196
+
197
+ def stop_throbber!
198
+ @should_throb = false
199
+ end
200
+
201
+ def should_throb
202
+ @should_throb
203
+ end
204
+
205
+ def should_throb=(value)
206
+ @should_throb = value
207
+ end
208
+
209
+ # Takes a list of ENV vars, records their value,
210
+ # sets them to null, runs the block, then ensures
211
+ # the ENV vars are restored at the end.
212
+ def suppress_env_vars(*vars, &block)
213
+ cache = {}
214
+ vars.each do |var|
215
+ cache[var] = ENV[var]
216
+ end
217
+
218
+ begin
219
+ vars.each do |var|
220
+ ENV[var] = nil
221
+ end
222
+ yield block
223
+ ensure
224
+ cache.each_pair do |key, value|
225
+ ENV[key] = value
226
+ end
227
+ end
228
+ end
229
+
230
+ def try_for(options, &block)
231
+ options[:seconds] ||= 30
232
+ options[:sleep] ||= 5
233
+
234
+ start = Time.now
235
+ elapsed = 0
236
+
237
+ while elapsed < options[:seconds]
238
+ return true if yield elapsed
239
+ sleep options[:sleep]
240
+ elapsed = Time.now - start
241
+ end
242
+
243
+ return false
244
+ end
166
245
  end
167
246
  end
168
247
  end
data/lib/tane/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Tane
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -64,14 +64,14 @@ describe Tane::Helpers::Init do
64
64
  end
65
65
 
66
66
  describe "save_emails" do
67
- it "should write a .bushido/emails.yml file if it does not exist" do
67
+ it "should create a sample email template file to .bushido/emails dir if it does not exist" do
68
68
  File.should_receive(:exists?).and_return(false)
69
69
  File.should_receive(:open)
70
70
 
71
71
  Tane::Helpers::Init.save_emails
72
72
  end
73
73
 
74
- it "should write a .bushido/emails.yml file if it already exists and if the user agrees to an overwrite" do
74
+ it "should create a sample email template file if it already exists and if the user agrees to an overwrite" do
75
75
  File.should_receive(:exists?).and_return(true)
76
76
  Tane::Helpers::Init.term.should_receive(:agree).and_return(true)
77
77
  File.should_receive(:open)
@@ -79,7 +79,7 @@ describe Tane::Helpers::Init do
79
79
  Tane::Helpers::Init.save_emails
80
80
  end
81
81
 
82
- it "should not write a .bushido/emails.yml file if the user says no to an overwrite" do
82
+ it "should not create a sample email template file if the user says no to an overwrite" do
83
83
  File.should_receive(:exists?).and_return(true)
84
84
  Tane::Helpers::Init.term.should_receive(:agree).and_return(false)
85
85
  File.should_not_receive(:open)
data/spec/helpers_spec.rb CHANGED
@@ -81,8 +81,9 @@ describe "Tane::Helpers" do
81
81
  end
82
82
 
83
83
  describe "bushido_app_exists?" do
84
- it "it should return true if the tane.yml and email.yml exists in the current directory" do
85
- File.should_receive(:exists?).twice.and_return(true)
84
+ it "it should return true if the .bushido/tane.yml file and .bushido/emails dir exists in the current directory" do
85
+ File.should_receive(:exists?).and_return(true)
86
+ File.should_receive(:directory?).and_return(true)
86
87
  Tane::Helpers::Example.bushido_app_exists?.should be_true
87
88
  end
88
89
  end
@@ -111,7 +112,7 @@ describe "Tane::Helpers" do
111
112
  describe "make_app_bushido_dir" do
112
113
  it "should create a .bushido dir in the current dir if it does not have one" do
113
114
  Tane::Helpers::Example.should_receive(:bushido_app_exists?).and_return(false)
114
- FileUtils.should_receive(:mkdir_p).with(".bushido")
115
+ FileUtils.should_receive(:mkdir_p).with(".bushido/emails")
115
116
  Tane::Helpers::Example.make_app_bushido_dir
116
117
  end
117
118
 
data/tane.gemspec CHANGED
@@ -22,7 +22,8 @@ Gem::Specification.new do |s|
22
22
  s.add_development_dependency "rspec"
23
23
  s.add_dependency "awesome_print"
24
24
  s.add_dependency "rake"
25
- s.add_dependency "rails", "<=3.1.0"
25
+ s.add_dependency "launchy"
26
+ s.add_dependency "rails", "~> 3.1.0"
26
27
  s.add_runtime_dependency "erubis"
27
28
  s.add_runtime_dependency "rest-client"
28
29
  s.add_runtime_dependency "highline"
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: tane
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.0.1
5
+ version: 0.0.2
6
6
  platform: ruby
7
7
  authors:
8
8
  - Bushido Team
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-12-23 00:00:00 Z
13
+ date: 2012-01-28 00:00:00 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rspec
@@ -46,29 +46,29 @@ dependencies:
46
46
  type: :runtime
47
47
  version_requirements: *id003
48
48
  - !ruby/object:Gem::Dependency
49
- name: rails
49
+ name: launchy
50
50
  prerelease: false
51
51
  requirement: &id004 !ruby/object:Gem::Requirement
52
52
  none: false
53
53
  requirements:
54
- - - <=
54
+ - - ">="
55
55
  - !ruby/object:Gem::Version
56
- version: 3.1.0
56
+ version: "0"
57
57
  type: :runtime
58
58
  version_requirements: *id004
59
59
  - !ruby/object:Gem::Dependency
60
- name: erubis
60
+ name: rails
61
61
  prerelease: false
62
62
  requirement: &id005 !ruby/object:Gem::Requirement
63
63
  none: false
64
64
  requirements:
65
- - - ">="
65
+ - - ~>
66
66
  - !ruby/object:Gem::Version
67
- version: "0"
67
+ version: 3.1.0
68
68
  type: :runtime
69
69
  version_requirements: *id005
70
70
  - !ruby/object:Gem::Dependency
71
- name: rest-client
71
+ name: erubis
72
72
  prerelease: false
73
73
  requirement: &id006 !ruby/object:Gem::Requirement
74
74
  none: false
@@ -79,7 +79,7 @@ dependencies:
79
79
  type: :runtime
80
80
  version_requirements: *id006
81
81
  - !ruby/object:Gem::Dependency
82
- name: highline
82
+ name: rest-client
83
83
  prerelease: false
84
84
  requirement: &id007 !ruby/object:Gem::Requirement
85
85
  none: false
@@ -89,6 +89,17 @@ dependencies:
89
89
  version: "0"
90
90
  type: :runtime
91
91
  version_requirements: *id007
92
+ - !ruby/object:Gem::Dependency
93
+ name: highline
94
+ prerelease: false
95
+ requirement: &id008 !ruby/object:Gem::Requirement
96
+ none: false
97
+ requirements:
98
+ - - ">="
99
+ - !ruby/object:Gem::Version
100
+ version: "0"
101
+ type: :runtime
102
+ version_requirements: *id008
92
103
  description: This gem provides all the tools necessary to develop a rails app meant for deployment on Bushido locally
93
104
  email:
94
105
  - support@gobushido.com
@@ -117,6 +128,7 @@ files:
117
128
  - lib/tane/commands/init.rb
118
129
  - lib/tane/commands/login.rb
119
130
  - lib/tane/commands/logout.rb
131
+ - lib/tane/commands/open.rb
120
132
  - lib/tane/commands/refresh.rb
121
133
  - lib/tane/commands/signup.rb
122
134
  - lib/tane/commands/support.rb
@@ -166,7 +178,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
166
178
  requirements: []
167
179
 
168
180
  rubyforge_project: tane
169
- rubygems_version: 1.8.11
181
+ rubygems_version: 1.8.15
170
182
  signing_key:
171
183
  specification_version: 3
172
184
  summary: Enables local development of Bushido apps