nimbu 0.11.8 → 0.13.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b1eb33b251ea07c2aab945e4d0038a0432fe2330a82dcca0ad0a7b4039e08c6c
4
- data.tar.gz: 37dcc3ef636d54e09c078ad74ed1ff84ac626c5d4f6cf3f63453539a78462889
3
+ metadata.gz: fcaf454345adbb424c6f94c09a304e98d8a3a76cf76ca2d9df76a9f991f867c1
4
+ data.tar.gz: 33ec694a0be3a929f9612629d43451389fee686a9789574356018da1ee536744
5
5
  SHA512:
6
- metadata.gz: 8cd7503608566aa7d60932e94d9b29addd91685d71c0e1a8358e7981f30f9249c8165b2edd283e53eeff421caf9533cc23f531e7a6c40fcca6072d4bf67ee91f
7
- data.tar.gz: cf9fd2438239840c3c3c63bfc00414ee7c507b9c0efc837a1500d9b0168cd8ca81b42568ecc5cbb5641bc40b53e43fcb2d2854aa6ccc1dc35048e8fcdbe4be2b
6
+ metadata.gz: fe4bb037e2ea41168414108bb662618f942fb5d4507591bfe2c317725199772244434b1a5c2536f551e1d98c1fab0fa0bfb03870045f016a3e3014330805e3bb
7
+ data.tar.gz: a93d431f551918a465378f55b6a03e06389797bcfbad13dfedff952cc8679488707c6a19bcbb8126bf792810b63a0f7a18423ea7bf611815c297573a07e18ae7
data/lib/nimbu/auth.rb CHANGED
@@ -1,26 +1,24 @@
1
- # -*- encoding : utf-8 -*-
2
- require "yaml"
3
- require "nimbu"
4
- require "nimbu/helpers"
1
+ require 'yaml'
2
+ require 'nimbu'
3
+ require 'nimbu/helpers'
5
4
  require 'term/ansicolor'
5
+ require 'netrc'
6
6
 
7
7
  class Nimbu::Auth
8
8
  class << self
9
-
10
9
  include Nimbu::Helpers
11
- attr_accessor :credentials
12
- attr_accessor :configuration
10
+ attr_accessor :credentials, :configuration
13
11
 
14
12
  def simulator_id
15
13
  return @simulator_id if defined? @simulator_id
16
14
 
17
- ranges = [('a'..'z'),('A'..'Z'),(0..9)].map{|i| i.to_a}.flatten
18
- @simulator_id ||= (1..40).map{ ranges[rand(ranges.length)] }.join
15
+ ranges = [('a'..'z'), ('A'..'Z'), (0..9)].map { |i| i.to_a }.flatten
16
+ @simulator_id ||= (1..40).map { ranges[rand(ranges.length)] }.join
19
17
  end
20
18
 
21
19
  def client
22
20
  @client ||= begin
23
- Nimbu::Client.new(:oauth_token => token, :endpoint => host, :user_agent => self.user_agent, :auto_pagination => true)
21
+ Nimbu::Client.new(oauth_token: token, endpoint: host, user_agent: user_agent, auto_pagination: true)
24
22
  end
25
23
  end
26
24
 
@@ -47,15 +45,19 @@ class Nimbu::Auth
47
45
  end
48
46
 
49
47
  def host
50
- ENV['NIMBU_HOST'] || "https://api.nimbu.io"
48
+ ENV['NIMBU_HOST'] || 'https://api.nimbu.io'
51
49
  end
52
50
 
53
51
  def default_host
54
- "https://api.nimbu.io"
52
+ 'https://api.nimbu.io'
55
53
  end
56
54
 
57
55
  def admin_host
58
- @admin_host ||= host.gsub(/https?\:\/\/api\./,'')
56
+ @admin_host ||= host.gsub(%r{https?://api\.}, '')
57
+ end
58
+
59
+ def api_host
60
+ @api_host ||= host.gsub(%r{https?://}, '')
59
61
  end
60
62
 
61
63
  def site
@@ -67,11 +69,11 @@ class Nimbu::Auth
67
69
  end
68
70
 
69
71
  def get_nimbu_site
70
- get_configuration["site"]
72
+ get_configuration['site']
71
73
  end
72
74
 
73
75
  def get_nimbu_theme
74
- get_configuration["theme"] || "default-theme"
76
+ get_configuration['theme'] || 'default-theme'
75
77
  end
76
78
 
77
79
  def get_configuration
@@ -94,192 +96,205 @@ class Nimbu::Auth
94
96
  end
95
97
 
96
98
  def ask_for_configuration
97
-
98
99
  subdomain = nil
99
100
  sites = client.sites.list
100
101
 
101
- unless sites.respond_to?(:any?) && sites.any?
102
- display "You don't have access to any Nimbu sites you can edit yet..."
103
- display ""
104
- display "Please visit http://nimbu.io, start your 30-day trial and discover our amazing platform!"
105
- exit(1)
106
- else
102
+ if sites.respond_to?(:any?) && sites.any?
107
103
  print_separator
108
104
  display "\nLet's first setup the configuration for this directory..."
109
105
  display "\nYou have access to following sites:\n"
110
- sites.each_with_index do |site,i|
111
- display " #{i+1}) #{site.name.white.bold} => http://#{site.domain}"
106
+ sites.each_with_index do |site, i|
107
+ display " #{i + 1}) #{site.name.white.bold} => http://#{site.domain}"
112
108
  end
113
109
  site_number = 0
114
110
  retry_site = false
115
111
  while site_number < 1 || site_number > sites.length
116
- unless retry_site
117
- print "\nOn which site would you like to work? "
118
- else
112
+ if retry_site
119
113
  print "\nPlease enter the number of your site (between 1-#{sites.length}): "
114
+ else
115
+ print "\nOn which site would you like to work? "
120
116
  end
121
117
  site_number_string = ask
122
- site_number = site_number_string.to_i rescue 0
118
+ site_number = begin
119
+ site_number_string.to_i
120
+ rescue StandardError
121
+ 0
122
+ end
123
123
  retry_site = true
124
124
  end
125
- puts ""
126
- site = sites[site_number-1]
125
+ puts ''
126
+ site = sites[site_number - 1]
127
127
  display "Site chosen => #{site.name.white.bold} (http://#{site.domain})"
128
128
  subdomain = site.subdomain
129
129
  @site = subdomain
130
+ else
131
+ display "You don't have access to any Nimbu sites you can edit yet..."
132
+ exit(1)
130
133
  end
131
134
 
132
- themes = client.themes(:subdomain => subdomain).list
135
+ themes = client.themes(subdomain: subdomain).list
133
136
  current_theme = if themes.length > 1
134
- theme_number = 0
135
- retry_theme = false
136
- while theme_number < 1 || theme_number > themes.length
137
- unless retry_theme
138
- print "\nOn which theme would you like to work in this directory? "
139
- else
140
- print "\nPlease enter the number of your theme (between 1-#{themes.length}): "
141
- end
142
- theme_number_string = ask
143
- theme_number = theme_number_string.to_i rescue 0
144
- retry_theme = true
145
- end
146
- puts ""
147
- display "Theme chosen => #{themes[theme_number-1].name}"
148
- themes[theme_number-1]
149
- else
150
- themes.first
151
- end
137
+ theme_number = 0
138
+ retry_theme = false
139
+ while theme_number < 1 || theme_number > themes.length
140
+ if retry_theme
141
+ print "\nPlease enter the number of your theme (between 1-#{themes.length}): "
142
+ else
143
+ print "\nOn which theme would you like to work in this directory? "
144
+ end
145
+ theme_number_string = ask
146
+ theme_number = begin
147
+ theme_number_string.to_i
148
+ rescue StandardError
149
+ 0
150
+ end
151
+ retry_theme = true
152
+ end
153
+ puts ''
154
+ display "Theme chosen => #{themes[theme_number - 1].name}"
155
+ themes[theme_number - 1]
156
+ else
157
+ themes.first
158
+ end
152
159
  @theme = current_theme.short
153
160
  print_separator
154
161
 
155
- { "site" => subdomain, "theme" => current_theme.short }
162
+ { 'site' => subdomain, 'theme' => current_theme.short }
156
163
  end
157
164
 
158
165
  def read_configuration
159
- existing_config = YAML::load(File.open( configuration_file )) if File.exists?(configuration_file)
160
- if existing_config && ! existing_config["site"].nil?
161
- existing_config
162
- else
163
- nil
164
- end
166
+ existing_config = YAML.load(File.open(configuration_file)) if File.exist?(configuration_file)
167
+ existing_config if existing_config && !existing_config['site'].nil?
165
168
  end
166
169
 
167
170
  def write_configuration
168
171
  FileUtils.mkdir_p(File.dirname(configuration_file))
169
- File.open(configuration_file, 'w') {|credentials| credentials.puts(YAML.dump(self.configuration))}
170
- FileUtils.chmod(0700, File.dirname(configuration_file))
171
- FileUtils.chmod(0600, configuration_file)
172
+ File.open(configuration_file, 'w') { |credentials| credentials.puts(YAML.dump(configuration)) }
173
+ FileUtils.chmod(0o700, File.dirname(configuration_file))
174
+ FileUtils.chmod(0o600, configuration_file)
172
175
  end
173
176
 
174
177
  def reauthorize
175
178
  @credentials = ask_for_and_save_credentials
176
179
  end
177
180
 
178
- def token # :nodoc:
181
+ def token # :nodoc:
179
182
  ENV['NIMBU_API_KEY'] || get_credentials
180
183
  end
181
184
 
182
- def credentials_file
183
- if host == default_host
184
- "#{home_directory}/.nimbu/credentials"
185
- else
186
- "#{home_directory}/.nimbu/credentials.#{CGI.escape(host.gsub(/https?\:\/\//,''))}"
187
- end
188
- end
189
-
190
- def get_credentials # :nodoc:
185
+ def get_credentials # :nodoc:
191
186
  @credentials ||= (read_credentials || ask_for_and_save_credentials)
187
+ @credentials[:token]
192
188
  end
193
189
 
194
190
  def delete_credentials
195
- FileUtils.rm_f(credentials_file)
196
- @client, @credentials = nil, nil
191
+ n = Netrc.read
192
+ n.delete(api_host)
193
+ n.save
194
+ @client = nil
195
+ @credentials = nil
197
196
  end
198
197
 
199
198
  def read_credentials
200
- credentials = File.read(credentials_file).force_encoding('UTF-8') if File.exists?(credentials_file)
201
- if credentials && credentials =~ /^(bearer|oauth2|token) ([\w]+)$/i
202
- $2
203
- else
204
- nil
205
- end
199
+ n = Netrc.read
200
+ user, token = n[api_host]
201
+ { user: user, token: token } if user && token
206
202
  end
207
203
 
208
204
  def write_credentials
209
- FileUtils.mkdir_p(File.dirname(credentials_file))
210
- File.open(credentials_file, 'w') {|credentials| credentials.print("token #{self.credentials}")}
211
- FileUtils.chmod(0700, File.dirname(credentials_file))
212
- FileUtils.chmod(0600, credentials_file)
205
+ n = Netrc.read
206
+ n[api_host] = @credentials[:user], @credentials[:token]
207
+ n.save
213
208
  end
214
209
 
215
210
  def echo_off
216
211
  with_tty do
217
- system "stty -echo"
212
+ system 'stty -echo'
218
213
  end
219
214
  end
220
215
 
221
216
  def echo_on
222
217
  with_tty do
223
- system "stty echo"
218
+ system 'stty echo'
224
219
  end
225
220
  end
226
221
 
227
- def ask_for_credentials
228
- print "Login: "
229
- user = ask
222
+ def ask_for_credentials(user = nil, password = nil, two_factor_code = nil)
223
+ unless user
224
+ print 'Login: '
225
+ user = ask
226
+ end
230
227
 
231
- print "Password: "
232
- password = running_on_windows? ? ask_for_password_on_windows : ask_for_password
228
+ unless password
229
+ print 'Password: '
230
+ password = running_on_windows? ? ask_for_password_on_windows : ask_for_password
231
+ end
233
232
 
234
233
  begin
234
+ request_headers = {}
235
+ request_headers['X-Nimbu-Two-Factor'] = two_factor_code.to_s.strip unless two_factor_code.nil?
236
+
235
237
  basic_client = Nimbu::Client.new(
236
- :basic_auth => "#{user}:#{password}",
237
- :endpoint => host,
238
- :user_agent => self.user_agent
238
+ basic_auth: "#{user}:#{password}",
239
+ endpoint: host,
240
+ user_agent: user_agent,
241
+ headers: request_headers
239
242
  )
240
- basic_client.authenticate.token
243
+ { user: user, token: basic_client.authenticate.token }
241
244
  rescue Exception => e
242
245
  if e.respond_to?(:http_status_code) && e.http_status_code == 401
243
- display " => could not login... please check your username and/or password!\n\n"
246
+ if e.message =~ /two factor authentication/
247
+ print '2FA Token: '
248
+ two_factor_code = ask
249
+ ask_for_credentials(user, password, two_factor_code)
250
+ else
251
+ display " => could not login... please check your username and/or password!\n\n"
252
+ nil
253
+ end
244
254
  else
245
255
  display " => hmmmm... an error occurred: #{e}. \n\n\nIf this continues to occur, please report \nthe error at https://github.com/nimbu/nimbu/issues.\n\n"
256
+ nil
246
257
  end
247
- nil
248
258
  end
249
259
  end
250
260
 
251
261
  def ask_for_password_on_windows
252
- require "Win32API"
262
+ require 'Win32API'
253
263
  char = nil
254
264
  password = ''
255
265
 
256
- while char = Win32API.new("msvcrt", "_getch", [ ], "L").Call do
257
- break if char == 10 || char == 13 # received carriage return or newline
258
- if char == 127 || char == 8 # backspace and delete
266
+ while char = Win32API.new('msvcrt', '_getch', [], 'L').Call
267
+ break if [10, 13].include?(char) # received carriage return or newline
268
+
269
+ if [10, 13, 10, 13, 127, 8].include?(char) # backspace and delete
259
270
  password.slice!(-1, 1)
260
271
  else
261
272
  # windows might throw a -1 at us so make sure to handle RangeError
262
- (password << char.chr) rescue RangeError
273
+ begin
274
+ (password << char.chr)
275
+ rescue StandardError
276
+ RangeError
277
+ end
263
278
  end
264
279
  end
265
280
  puts
266
- return password
281
+ password
267
282
  end
268
283
 
269
284
  def ask_for_password
270
285
  echo_off
271
- trap("INT") do
286
+ trap('INT') do
272
287
  echo_on
273
288
  exit
274
289
  end
275
290
  password = ask
276
291
  puts
277
292
  echo_on
278
- return password
293
+ password
279
294
  end
280
295
 
281
296
  def ask_for_and_save_credentials
282
- display "Please authenticate with Nimbu.io:"
297
+ display "Please authenticate with #{admin_host}:"
283
298
  begin
284
299
  @credentials = ask_for_credentials
285
300
  write_credentials
@@ -299,7 +314,7 @@ class Nimbu::Auth
299
314
 
300
315
  def print_separator
301
316
  print "\n"
302
- 60.times { print "#"}
317
+ 60.times { print '#' }
303
318
  print "\n"
304
319
  end
305
320
 
@@ -309,7 +324,7 @@ class Nimbu::Auth
309
324
 
310
325
  def invalid_access_message
311
326
  "Error! You do not have access to #{Nimbu::Auth.site}.#{Nimbu::Auth.admin_host}! " +
312
- "Please check your site id or request access to your site owner."
327
+ 'Please check your site id or request access to your site owner.'
313
328
  end
314
329
  end
315
330
  end
@@ -1,8 +1,5 @@
1
1
  # -*- encoding : utf-8 -*-
2
2
  require "nimbu/command/base"
3
- require "nimbu/server/base"
4
- require 'term/ansicolor'
5
- require 'thin'
6
3
 
7
4
  # running a local server to speed up designing Nimbu themes
8
5
  #
@@ -22,6 +19,14 @@ class Nimbu::Command::Server < Nimbu::Command::Base
22
19
  # --nocookies # disable session refresh cookie check
23
20
  #
24
21
  def index
22
+ require 'rubygems'
23
+ require "nimbu/server/base"
24
+ require 'term/ansicolor'
25
+ require 'thin'
26
+ require 'filewatcher'
27
+ require 'pathname'
28
+ require 'lolcat'
29
+
25
30
  # Check if config file is present?
26
31
  if !Nimbu::Auth.read_configuration
27
32
  print red(bold("ERROR")), ": this directory does not seem to contain any Nimbu theme configuration. \n ==> Run \"", bold { "nimbu init"}, "\" to initialize this directory."
@@ -59,13 +64,13 @@ class Nimbu::Command::Server < Nimbu::Command::Base
59
64
  services = []
60
65
  services << "HAML" if @with_haml
61
66
  services << "Compass" if @with_compass
62
- title = "Starting up Nimbu Server"
63
- title << " (with local #{services.join(' and ')} watcher)" if @with_compass || @with_haml
64
- title << " (skipping cookies check)" if @no_cookies
65
- title << " (proxying webpack resources to #{Nimbu.cli_options[:webpack_url]})" if @webpack_resources
67
+ title = "Starting up local Nimbu Toolbelt Server (v#{Nimbu::VERSION}, using Ruby #{RUBY_VERSION}-p#{RUBY_PATCHLEVEL}):"
68
+ title << "\n - with local #{services.join(' and ')} watcher" if @with_compass || @with_haml
69
+ title << "\n - skipping cookies check" if @no_cookies
70
+ title << "\n - proxying webpack resources to #{Nimbu.cli_options[:webpack_url]}" if @webpack_resources
66
71
  title << " ..."
67
72
  puts white("\n#{title}")
68
- puts green(nimbu_header)
73
+ puts nimbu_header
69
74
  puts green("\nConnnected to '#{Nimbu::Auth.site}.#{Nimbu::Auth.admin_host}', using '#{Nimbu::Auth.theme}' theme#{Nimbu.debug ? ' (in debug mode)'.red : nil}.\n")
70
75
 
71
76
  if Nimbu::Helpers.running_on_windows?
@@ -112,32 +117,42 @@ class Nimbu::Command::Server < Nimbu::Command::Base
112
117
  }
113
118
  server_options.merge!({:Host => options[:host]}) if options[:host]
114
119
  Rack::Handler::Thin.run Nimbu::Server::Base, server_options do |server|
115
- [:INT, :TERM].each { |sig| trap(sig) { server.respond_to?(:stop!) ? server.stop! : server.stop } }
120
+ [:INT, :TERM].each do |sig|
121
+ trap(sig) do
122
+ server.respond_to?(:stop!) ? server.stop! : server.stop
123
+ exit(0)
124
+ end
125
+ end
116
126
  end
117
127
  end
118
128
 
119
129
  haml_thread = Thread.new do
120
- # $stdout.reopen(compiler_write)
121
- # compiler_read.close
130
+ Process.setproctitle("#{$0} => nimbu-toolbelt haml")
122
131
  puts "Starting watcher..."
123
132
  HamlWatcher.watch
124
133
  end if @with_haml
125
134
 
126
- if @with_compass
135
+ compass_pid = if @with_compass
136
+ Process.setproctitle("#{$0} => nimbu-toolbelt compass")
127
137
  puts "Starting..."
128
138
  cmd = "bundle exec nimbu server:compass"
129
- compass_pid = Process.spawn(cmd, out: $stdout, err: [:child, :out])
139
+ Process.spawn(cmd, out: $stdout, err: [:child, :out])
130
140
  end
131
141
 
132
142
  server_thread.join
133
143
  haml_thread.join if @with_haml
134
144
 
135
- [:INT, :TERM].each do |sig|
145
+ [:HUP, :INT, :TERM].each do |sig|
136
146
  trap(sig) do
137
- puts yellow("\n== Waiting for all processes to finish...")
138
- Process.kill('INT', compass_pid) if compass_pid && running?(compass_pid)
139
- Process.waitall
140
- puts green("== Nimbu has ended its work " + bold("(crowd applauds!)\n"))
147
+ should_wait = false
148
+
149
+ if compass_pid && running?(compass_pid)
150
+ should_wait = true
151
+ Process.kill('INT', compass_pid)
152
+ end
153
+
154
+ Process.waitall if should_wait
155
+ exit(0)
141
156
  end
142
157
  end
143
158
 
@@ -160,8 +175,15 @@ class Nimbu::Command::Server < Nimbu::Command::Base
160
175
  :DocumentRoot => Dir.pwd
161
176
  }
162
177
  server_options.merge!({:Host => options[:host]}) if options[:host]
163
- Rack::Handler::Thin.run Nimbu::Server::Base, server_options do |server|
164
- [:INT, :TERM].each { |sig| trap(sig) { server.respond_to?(:stop!) ? server.stop! : server.stop } }
178
+ Rack::Handler::Thin.run Nimbu::Server::Base, **server_options do |server|
179
+ Process.setproctitle("#{$0} => nimbu-toolbelt server")
180
+
181
+ [:INT, :TERM].each do |sig|
182
+ trap(sig) do
183
+ server.respond_to?(:stop!) ? server.stop! : server.stop
184
+ exit(0)
185
+ end
186
+ end
165
187
  end
166
188
  end
167
189
 
@@ -170,7 +192,8 @@ class Nimbu::Command::Server < Nimbu::Command::Base
170
192
  haml_read.close
171
193
  puts "Starting..."
172
194
  haml_listener = HamlWatcher.watch
173
- [:INT, :TERM].each do |sig|
195
+ Process.setproctitle("#{$0} => nimbu-toolbelt haml")
196
+ [:HUP, :INT, :TERM].each do |sig|
174
197
  Signal.trap(sig) do
175
198
  puts green("== Stopping HAML watcher\n")
176
199
  Thread.new { haml_listener.stop }
@@ -180,6 +203,7 @@ class Nimbu::Command::Server < Nimbu::Command::Base
180
203
  end if @with_haml
181
204
 
182
205
  compass_pid = Process.fork do
206
+ Process.setproctitle("#{$0} => nimbu-toolbelt compass")
183
207
  $stdout.reopen(compass_write)
184
208
  compass_read.close
185
209
  puts "Starting..."
@@ -187,7 +211,10 @@ class Nimbu::Command::Server < Nimbu::Command::Base
187
211
  end if @with_compass
188
212
 
189
213
  watch_server_pid = Process.fork do
190
- trap('INT') { exit }
214
+ Process.setproctitle("#{$0} => nimbu-toolbelt server-watcher")
215
+
216
+ [:HUP, :INT, :TERM].each { |sig| trap(sig) { exit } }
217
+
191
218
  server_write.close
192
219
  server_read.each do |line|
193
220
  print cyan("SERVER: ") + white(line) + ""
@@ -195,7 +222,9 @@ class Nimbu::Command::Server < Nimbu::Command::Base
195
222
  end
196
223
 
197
224
  watch_haml_pid = Process.fork do
198
- trap('INT') { exit }
225
+ Process.setproctitle("#{$0} => nimbu-toolbelt haml-watcher")
226
+ [:HUP, :INT, :TERM].each { |sig| trap(sig) { exit } }
227
+
199
228
  haml_write.close
200
229
  haml_read.each do |line|
201
230
  print magenta("HAML: ") + white(line) + ""
@@ -203,34 +232,65 @@ class Nimbu::Command::Server < Nimbu::Command::Base
203
232
  end if @with_haml
204
233
 
205
234
  watch_compass_pid = Process.fork do
206
- trap('INT') { exit }
235
+ Process.setproctitle("#{$0} => nimbu-toolbelt haml-compass")
236
+ [:HUP, :INT, :TERM].each { |sig| trap(sig) { exit } }
237
+
207
238
  compass_write.close
208
239
  compass_read.each do |line|
209
240
  print yellow("COMPASS: ") + white(line) + ""
210
241
  end
211
242
  end if @with_compass
212
243
 
213
- [:INT, :TERM].each do |sig|
244
+ [:HUP, :INT, :TERM].each do |sig|
214
245
  trap(sig) do
215
- puts yellow("\n== Waiting for all processes to finish...")
216
- Process.kill('INT', haml_pid) if haml_pid && running?(haml_pid)
217
- Process.waitall
218
- puts green("== Nimbu has ended its work " + bold("(crowd applauds!)\n"))
246
+ should_wait = false
247
+ @child_pids_running.each do |pid|
248
+ if running?(server_pid)
249
+ should_wait = true
250
+ Process.kill('INT', pid)
251
+ end
252
+ end
253
+
254
+ Process.waitall if should_wait
255
+ exit(0)
219
256
  end
220
257
  end
221
258
 
259
+ @child_pids_running = [
260
+ server_pid,
261
+ haml_pid,
262
+ compass_pid,
263
+ watch_server_pid,
264
+ watch_haml_pid,
265
+ watch_compass_pid
266
+ ].compact!
267
+
222
268
  Process.waitall
223
269
  end
224
270
 
271
+ def nimbu_ascii_art
272
+ %{
273
+ _ _ _ _ _____ _ _ _ _
274
+ | \\ | (_)_ __ ___ | |__ _ |_ _|__ ___ | | |__ ___| | |_
275
+ | \\| | | '_ ` _ \\| '_ \\| | | || |/ _ \\ / _ \\| | '_ \\ / _ \\ | __|
276
+ | |\\ | | | | | | | |_) | |_| || | (_) | (_) | | |_) | __/ | |_
277
+ |_| \\_|_|_| |_| |_|_.__/ \\__,_||_|\\___/ \\___/|_|_.__/ \\___|_|\\__|}
278
+ end
279
+
225
280
  def nimbu_header
226
- h = ""
227
- h << "\n o8o .o8"
228
- h << "\n `\"' \"888"
229
- h << "\nooo. .oo. oooo ooo. .oo. .oo. 888oooo. oooo oooo"
230
- h << "\n`888P\"Y88b `888 `888P\"Y88bP\"Y88b d88' `88b `888 `888"
231
- h << "\n 888 888 888 888 888 888 888 888 888 888"
232
- h << "\n 888 888 888 888 888 888 888 888 888 888"
233
- h << "\no888o o888o o888o o888o o888o o888o `Y8bod8P' `V88V\"V8P'"
281
+ length = nimbu_ascii_art.split("\n").last.length
282
+ print white("\n" + "=" * length)
283
+ buf = StringIO.new(nimbu_ascii_art)
284
+ opts = {
285
+ :animate => false,
286
+ :duration => 12,
287
+ :os => rand * 8192,
288
+ :speed => 20,
289
+ :spread => 8.0,
290
+ :freq => 0.3
291
+ }
292
+ Lol.cat buf, opts
293
+ print white("\n\n" + "=" * length)
234
294
  end
235
295
 
236
296
  def running?(pid)
@@ -243,10 +303,6 @@ class Nimbu::Command::Server < Nimbu::Command::Base
243
303
  end
244
304
  end
245
305
 
246
- require 'rubygems'
247
- require 'filewatcher'
248
- require 'pathname'
249
-
250
306
  class HamlWatcher
251
307
  class << self
252
308
  include Term::ANSIColor
data/lib/nimbu/command.rb CHANGED
@@ -1,8 +1,7 @@
1
- # -*- encoding : utf-8 -*-
2
1
  require 'nimbu/helpers'
3
2
  require 'nimbu/version'
4
3
  require 'term/ansicolor'
5
- require "optparse"
4
+ require 'optparse'
6
5
 
7
6
  class String
8
7
  include Term::ANSIColor
@@ -10,12 +9,12 @@ end
10
9
 
11
10
  module Nimbu
12
11
  module Command
13
- class CommandFailed < RuntimeError; end
12
+ class CommandFailed < RuntimeError; end
14
13
 
15
14
  extend Nimbu::Helpers
16
15
 
17
16
  def self.load
18
- Dir[File.join(File.dirname(__FILE__), "command", "*.rb")].each do |file|
17
+ Dir[File.join(File.dirname(__FILE__), 'command', '*.rb')].sort.each do |file|
19
18
  require file
20
19
  end
21
20
  end
@@ -29,7 +28,7 @@ module Nimbu
29
28
  end
30
29
 
31
30
  def self.files
32
- @@files ||= Hash.new {|hash,key| hash[key] = File.readlines(key).map {|line| line.strip}}
31
+ @@files ||= Hash.new { |hash, key| hash[key] = File.readlines(key).map { |line| line.strip } }
33
32
  end
34
33
 
35
34
  def self.namespaces
@@ -65,7 +64,7 @@ module Nimbu
65
64
  end
66
65
 
67
66
  def self.global_option(name, *args, &blk)
68
- global_options << { :name => name.to_s, :args => args.sort.reverse, :proc => blk }
67
+ global_options << { name: name.to_s, args: args.sort.reverse, proc: blk }
69
68
  end
70
69
 
71
70
  def self.warnings
@@ -73,15 +72,13 @@ module Nimbu
73
72
  end
74
73
 
75
74
  def self.display_warnings
76
- unless warnings.empty?
77
- $stderr.puts(warnings.map {|warning| " ! #{warning}"}.join("\n"))
78
- end
75
+ warn(warnings.map { |warning| " ! #{warning}" }.join("\n")) unless warnings.empty?
79
76
  end
80
77
 
81
- global_option :help, "--help", "-h"
82
- global_option :debug, "--debug"
78
+ global_option :help, '--help', '-h'
79
+ global_option :debug, '--debug'
83
80
 
84
- def self.prepare_run(cmd, args=[])
81
+ def self.prepare_run(cmd, args = [])
85
82
  command = parse(cmd)
86
83
 
87
84
  if args.include?('-h') || args.include?('--help')
@@ -90,13 +87,14 @@ module Nimbu
90
87
  command = parse(cmd)
91
88
  end
92
89
 
93
- if cmd == '--version'
90
+ if ['--version', '-v'].include?(cmd)
94
91
  cmd = 'version'
95
92
  command = parse(cmd)
96
93
  end
97
94
 
98
95
  @current_command = cmd
99
- @anonymized_args, @normalized_args = [], []
96
+ @anonymized_args = []
97
+ @normalized_args = []
100
98
 
101
99
  opts = {}
102
100
  invalid_options = []
@@ -105,25 +103,25 @@ module Nimbu
105
103
  parser.base.long.delete('version')
106
104
  (global_options + (command && command[:options] || [])).each do |option|
107
105
  parser.on(*option[:args]) do |value|
108
- if option[:proc]
109
- option[:proc].call(value)
110
- end
106
+ option[:proc].call(value) if option[:proc]
111
107
  opts[option[:name].gsub('-', '_').to_sym] = value
112
- ARGV.join(' ') =~ /(#{option[:args].map {|arg| arg.split(' ', 2).first}.join('|')})/
113
- @anonymized_args << "#{$1} _"
108
+ ARGV.join(' ') =~ /(#{option[:args].map { |arg| arg.split(' ', 2).first }.join('|')})/
109
+ @anonymized_args << "#{Regexp.last_match(1)} _"
114
110
  @normalized_args << "#{option[:args].last.split(' ', 2).first} _"
115
111
  end
116
112
  end
117
113
  end
118
114
 
115
+ parser.version = Nimbu::VERSION
116
+
119
117
  begin
120
118
  parser.order!(args) do |nonopt|
121
119
  invalid_options << nonopt
122
120
  @anonymized_args << '!'
123
121
  @normalized_args << '!'
124
122
  end
125
- rescue OptionParser::InvalidOption => ex
126
- invalid_options << ex.args.first
123
+ rescue OptionParser::InvalidOption => e
124
+ invalid_options << e.args.first
127
125
  @anonymized_args << '!'
128
126
  @normalized_args << '!'
129
127
  retry
@@ -135,52 +133,54 @@ module Nimbu
135
133
  @current_options = opts
136
134
  @invalid_arguments = invalid_options
137
135
 
138
- if opts[:debug]
139
- Nimbu.debug = true
140
- end
136
+ Nimbu.debug = true if opts[:debug]
141
137
 
142
138
  @anonymous_command = [ARGV.first, *@anonymized_args].join(' ')
143
139
  begin
144
140
  usage_directory = "#{home_directory}/.nimbu/usage"
145
141
  FileUtils.mkdir_p(usage_directory)
146
142
  usage_file = usage_directory << "/#{Nimbu::VERSION}"
147
- usage = if File.exists?(usage_file)
148
- json_decode(File.read(usage_file).force_encoding('UTF-8'))
149
- else
150
- {}
151
- end
143
+ usage = if File.exist?(usage_file)
144
+ json_decode(File.read(usage_file).force_encoding('UTF-8'))
145
+ else
146
+ {}
147
+ end
152
148
  usage[@anonymous_command] ||= 0
153
149
  usage[@anonymous_command] += 1
154
150
  File.write(usage_file, json_encode(usage) + "\n")
155
- rescue
151
+ rescue StandardError
156
152
  # usage writing is not important, allow failures
157
153
  end
158
154
 
159
155
  if command
160
156
  command_instance = command[:klass].new(args.dup, opts.dup)
161
157
 
162
- if !@normalized_args.include?('--app _') && (implied_app = command_instance.app rescue nil)
158
+ if !@normalized_args.include?('--app _') && (implied_app = begin
159
+ command_instance.app
160
+ rescue StandardError
161
+ nil
162
+ end)
163
163
  @normalized_args << '--app _'
164
164
  end
165
- @normalized_command = [ARGV.first, @normalized_args.sort_by {|arg| arg.gsub('-', '')}].join(' ')
165
+ @normalized_command = [ARGV.first, @normalized_args.sort_by { |arg| arg.gsub('-', '') }].join(' ')
166
166
 
167
- [ command_instance, command[:method] ]
167
+ [command_instance, command[:method]]
168
168
  else
169
169
  error([
170
170
  "`#{cmd}` is not a Nimbu command.",
171
171
  suggestion(cmd, commands.keys + command_aliases.keys),
172
- "See `Nimbu help` for a list of available commands."
172
+ 'See `Nimbu help` for a list of available commands.'
173
173
  ].compact.join("\n"))
174
174
  end
175
175
  end
176
176
 
177
- def self.run(cmd, arguments=[])
177
+ def self.run(cmd, arguments = [])
178
178
  begin
179
179
  object, method = prepare_run(cmd, arguments.dup)
180
180
  object.send(method)
181
- rescue Interrupt, StandardError, SystemExit => error
181
+ rescue Interrupt, StandardError, SystemExit => e
182
182
  # load likely error classes, as they may not be loaded yet due to defered loads
183
- raise(error)
183
+ raise(e)
184
184
  end
185
185
  # rescue Nimbu::API::Errors::Unauthorized, RestClient::Unauthorized
186
186
  # puts "Authentication failure"
@@ -219,10 +219,10 @@ module Nimbu
219
219
  rescue CommandFailed => e
220
220
  error e.message
221
221
  rescue OptionParser::ParseError
222
- commands[cmd] ? run("help", [cmd]) : run("help")
222
+ commands[cmd] ? run('help', [cmd]) : run('help')
223
223
  rescue Excon::Errors::SocketError => e
224
224
  if e.message == 'getaddrinfo: nodename nor servname provided, or not known (SocketError)'
225
- error("Unable to connect to Nimbu API, please check internet connectivity and try again.")
225
+ error('Unable to connect to Nimbu API, please check internet connectivity and try again.')
226
226
  else
227
227
  raise(e)
228
228
  end
@@ -234,25 +234,30 @@ module Nimbu
234
234
  commands[cmd] || commands[command_aliases[cmd]]
235
235
  end
236
236
 
237
- def self.extract_error(body, options={})
237
+ def self.extract_error(body, _options = {})
238
238
  default_error = block_given? ? yield : "Internal server error.\nRun 'nimbu status' to check for known platform issues."
239
239
  parse_error_xml(body) || parse_error_json(body) || parse_error_plain(body) || default_error
240
240
  end
241
241
 
242
242
  def self.parse_error_xml(body)
243
- xml_errors = REXML::Document.new(body).elements.to_a("//errors/error")
244
- msg = xml_errors.map { |a| a.text }.join(" / ")
243
+ xml_errors = REXML::Document.new(body).elements.to_a('//errors/error')
244
+ msg = xml_errors.map { |a| a.text }.join(' / ')
245
245
  return msg unless msg.empty?
246
246
  rescue Exception
247
247
  end
248
248
 
249
249
  def self.parse_error_json(body)
250
- json = json_decode(body.to_s) rescue false
250
+ json = begin
251
+ json_decode(body.to_s)
252
+ rescue StandardError
253
+ false
254
+ end
251
255
  json ? json['error'] : nil
252
256
  end
253
257
 
254
258
  def self.parse_error_plain(body)
255
- return unless body.respond_to?(:headers) && body.headers[:content_type].to_s.include?("text/plain")
259
+ return unless body.respond_to?(:headers) && body.headers[:content_type].to_s.include?('text/plain')
260
+
256
261
  body.to_s
257
262
  end
258
263
  end
data/lib/nimbu/version.rb CHANGED
@@ -1,4 +1,3 @@
1
- # -*- encoding : utf-8 -*-
2
1
  module Nimbu
3
- VERSION = "0.11.8"
2
+ VERSION = '0.13.1'.freeze
4
3
  end
data/lib/nimbu.rb CHANGED
@@ -1,6 +1,4 @@
1
- # -*- encoding : utf-8 -*-
2
- require "nimbu/version"
3
- require "nimbu-api"
1
+ require 'nimbu-api'
4
2
 
5
3
  module Nimbu
6
4
  def self.debug=(value)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nimbu
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.11.8
4
+ version: 0.13.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Zenjoy BVBA
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-05-14 00:00:00.000000000 Z
11
+ date: 2022-02-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: term-ansicolor
@@ -58,14 +58,14 @@ dependencies:
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: 2.0.2
61
+ version: 2.1.0
62
62
  type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: 2.0.2
68
+ version: 2.1.0
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: sinatra-contrib
71
71
  requirement: !ruby/object:Gem::Requirement
@@ -126,16 +126,16 @@ dependencies:
126
126
  name: rack
127
127
  requirement: !ruby/object:Gem::Requirement
128
128
  requirements:
129
- - - "~>"
129
+ - - ">="
130
130
  - !ruby/object:Gem::Version
131
- version: 2.0.3
131
+ version: 2.1.4
132
132
  type: :runtime
133
133
  prerelease: false
134
134
  version_requirements: !ruby/object:Gem::Requirement
135
135
  requirements:
136
- - - "~>"
136
+ - - ">="
137
137
  - !ruby/object:Gem::Version
138
- version: 2.0.3
138
+ version: 2.1.4
139
139
  - !ruby/object:Gem::Dependency
140
140
  name: json
141
141
  requirement: !ruby/object:Gem::Requirement
@@ -178,6 +178,20 @@ dependencies:
178
178
  - - ">="
179
179
  - !ruby/object:Gem::Version
180
180
  version: '0'
181
+ - !ruby/object:Gem::Dependency
182
+ name: netrc
183
+ requirement: !ruby/object:Gem::Requirement
184
+ requirements:
185
+ - - ">="
186
+ - !ruby/object:Gem::Version
187
+ version: '0'
188
+ type: :runtime
189
+ prerelease: false
190
+ version_requirements: !ruby/object:Gem::Requirement
191
+ requirements:
192
+ - - ">="
193
+ - !ruby/object:Gem::Version
194
+ version: '0'
181
195
  - !ruby/object:Gem::Dependency
182
196
  name: filewatcher
183
197
  requirement: !ruby/object:Gem::Requirement
@@ -192,20 +206,34 @@ dependencies:
192
206
  - - ">="
193
207
  - !ruby/object:Gem::Version
194
208
  version: '0'
209
+ - !ruby/object:Gem::Dependency
210
+ name: lolcat
211
+ requirement: !ruby/object:Gem::Requirement
212
+ requirements:
213
+ - - ">="
214
+ - !ruby/object:Gem::Version
215
+ version: '0'
216
+ type: :runtime
217
+ prerelease: false
218
+ version_requirements: !ruby/object:Gem::Requirement
219
+ requirements:
220
+ - - ">="
221
+ - !ruby/object:Gem::Version
222
+ version: '0'
195
223
  - !ruby/object:Gem::Dependency
196
224
  name: bundler
197
225
  requirement: !ruby/object:Gem::Requirement
198
226
  requirements:
199
- - - "~>"
227
+ - - ">="
200
228
  - !ruby/object:Gem::Version
201
- version: '1.3'
229
+ version: '0'
202
230
  type: :development
203
231
  prerelease: false
204
232
  version_requirements: !ruby/object:Gem::Requirement
205
233
  requirements:
206
- - - "~>"
234
+ - - ">="
207
235
  - !ruby/object:Gem::Version
208
- version: '1.3'
236
+ version: '0'
209
237
  - !ruby/object:Gem::Dependency
210
238
  name: rake
211
239
  requirement: !ruby/object:Gem::Requirement
@@ -310,7 +338,7 @@ files:
310
338
  homepage: https://www.nimbu.io
311
339
  licenses: []
312
340
  metadata: {}
313
- post_install_message:
341
+ post_install_message:
314
342
  rdoc_options: []
315
343
  require_paths:
316
344
  - lib
@@ -325,9 +353,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
325
353
  - !ruby/object:Gem::Version
326
354
  version: '0'
327
355
  requirements: []
328
- rubyforge_project:
329
- rubygems_version: 2.7.6.2
330
- signing_key:
356
+ rubygems_version: 3.3.3
357
+ signing_key:
331
358
  specification_version: 4
332
359
  summary: Client library and CLI to design websites on the Nimbu platform.
333
360
  test_files: []