heroku_whiz 0.2.0 → 0.2.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: f70cf65decd9910c18bb065d30defe5a9f30e61ea8dbe7adf95995c5838d3c15
4
- data.tar.gz: bb3ce5eecb89cf1ec143b9b8a5c3082a36ebd55b9c8bd588375058baf7c0f96f
3
+ metadata.gz: c8fa80bb83fdb773d2b05d79c4df5e1f176de51608c90eb8e24506e88c22027f
4
+ data.tar.gz: 2a3c0e94b9737149aefa1e10148e88bb1875c62be15775807d33edb75859e155
5
5
  SHA512:
6
- metadata.gz: d7378be0f617fc11166e1c682a31c45a65aa5beb8df5e0731a3431989fa39f9d774f1664ac86c453f2f65add103b676ea3065cfdcc408d7edc0bf4d8595c1847
7
- data.tar.gz: 34f5f3db437981f68c8748f0138555f53a7378b847551b2b66d7e71d398368cbb02176592c46eeb3f368a481eef12897cccaa5fd6cd2bf77671fe761831b2780
6
+ metadata.gz: 1f00da4e02b5bd3ec99079d64a085b08581d2f1ce326e4a293e5931f59eae480b81854b33e0c9930c14d9dc0604894e1de662008cbd2d25246cd06bddee09397
7
+ data.tar.gz: 6f9fbaa7facaf1227583a364f19c29be59ba7a6ab136e929e11fd8d386af995e8fe28b9897ece4cb25c7c5e14825d565ccc6c34f70657f9f636badbca128b3ef
checksums.yaml.gz.sig CHANGED
Binary file
data/lib/heroku_whiz.rb CHANGED
@@ -8,6 +8,26 @@
8
8
  # description: Handy (experimental) Heroku gem for noobs to create a
9
9
  # simple Heroku app in a whiz!
10
10
 
11
+ # Q: Why Heroku?
12
+ #
13
+ # A: With a quick Twitter search for Free wen hosting, a
14
+ # popular Tweet mentioned Heroku
15
+ #
16
+ # 10 FREE Hosting/Clouds for Your website:
17
+ #
18
+ # ➡️ GitHub Pages
19
+ # ➡️ Heroku
20
+ # ➡️ Amazon Web Services (AWS)
21
+ # ➡️ Vercel
22
+ # ➡️ Firebase Hosting
23
+ # ➡️ Awardspace
24
+ # ➡️ Netlify
25
+ # ➡️ Google Cloud
26
+ # ➡️ Cloudflare
27
+ # ➡️ Weebly
28
+ #
29
+
30
+
11
31
  # note: If this gem becomes outdated because of a change in the Heroku app
12
32
  # setup process, please inform the owner of this project via *Issues*
13
33
  # on GitHub (https://github.com/jrobertson/heroku_whiz).
@@ -39,13 +59,13 @@ require 'launchy'
39
59
 
40
60
  class WhizBase
41
61
 
42
- def initialize(app_path, debug: false)
62
+ def initialize(app_path, verbose: true, debug: false)
43
63
 
44
- @app_path, debug = app_path, debug
64
+ @app_path, @verbose, debug = app_path, verbose, debug
45
65
 
46
66
  end
47
67
 
48
- def create()
68
+ def create(add: nil)
49
69
 
50
70
  config = %q(
51
71
  run lambda {|env|
@@ -81,14 +101,20 @@ gem 'puma'
81
101
 
82
102
  end
83
103
 
104
+ appname = heroku_app()
105
+
106
+ if setup == :both then
107
+
108
+ Clipboard.copy appname
109
+ puts 'App name ' + appname + ' copied to clipboard'
110
+ `heroku apps:destroy #{appname}`
111
+
112
+ end
113
+
84
114
  rm_rf File.join(@app_path, '.git')
85
115
  rmdir File.join(@app_path, '.git')
86
116
  rmdir @app_path
87
117
 
88
- return unless setup == :both
89
-
90
- `heroku apps:destroy --confirm #{heroku_app()}`
91
-
92
118
  end
93
119
 
94
120
  def deploy()
@@ -108,10 +134,13 @@ gem 'puma'
108
134
  # high probability the appname you have chosen has already been taken
109
135
  # e.g. hello2 => hello2.herokuapp.com
110
136
 
137
+ puts 'Running *heroku create*' if @verbose
111
138
  `heroku create`
112
- sleep 2
139
+ sleep 3
113
140
 
141
+ puts 'Running *git push heroku master*' if @verbose
114
142
  r = `git push heroku master`
143
+ sleep 10
115
144
 
116
145
  end
117
146
 
@@ -166,7 +195,8 @@ gem 'puma'
166
195
  end
167
196
 
168
197
  def heroku_app()
169
- `heroku config`.lines.first.split[1]
198
+ s = `heroku config`
199
+ s.lines.first.split[1] if s
170
200
  end
171
201
 
172
202
  def rm(file)
@@ -183,38 +213,85 @@ gem 'puma'
183
213
 
184
214
  end
185
215
 
216
+ class SinatraWhizError < Exception
217
+ end
218
+
186
219
  class SinatraWhiz < WhizBase
187
220
 
188
- def initialize(app_path, debug: false)
189
- super(app_path, debug: debug)
221
+ def initialize(app_path, verbose: true, debug: false)
222
+ super(app_path, verbose: verbose, debug: debug)
190
223
  end
191
224
 
192
- def create()
225
+ def create(add: nil)
193
226
 
194
- config = %q(
227
+ if add then
228
+
229
+ FileUtils.mkdir_p @app_path
230
+ FileUtils.chdir @app_path
231
+
232
+ # copying the files into file directory @app_path
233
+ # ensure the files config.ru, Gemfile, and Procfile exist
234
+ #
235
+ a = Dir.glob(File.join(add,'*'))
236
+ files = a.map {|x| File.basename(x)}
237
+
238
+ expected = %w(config.ru Gemfile Procfile)
239
+ found = (files & expected)
240
+
241
+ if found.length < 3 then
242
+ raise SinatraWhizError, 'missing ' + (expected - found).join(', ')
243
+ end
244
+
245
+ puts 'copying files ' + a.inspect if @debug
246
+
247
+ a.each {|x| FileUtils.cp x, @app_path }
248
+
249
+ else
250
+
251
+ config = %q(
195
252
  require './hello'
196
253
  run Sinatra::Application
197
254
  )
198
-
199
- gemfile = %q(
255
+ gemfile = %q(
200
256
  source 'https://rubygems.org'
201
257
  gem 'sinatra'
202
258
  gem 'puma'
203
259
  )
204
260
 
205
- procfile = 'web: bundle exec rackup config.ru -p $PORT'
206
-
207
- create_basefiles(config, gemfile, procfile)
261
+ procfile = 'web: bundle exec rackup config.ru -p $PORT'
262
+ create_basefiles(config, gemfile, procfile)
208
263
 
209
- hello_rb = %q(
264
+ hello_rb = %q(
210
265
  require 'sinatra'
211
266
 
212
267
  get '/' do
213
268
  "Hello World!"
214
269
  end
215
270
  )
216
- File.write File.join(@app_path, 'hello.rb'), hello_rb
217
- sleep 0.3
271
+ File.write File.join(@app_path, 'hello.rb'), hello_rb
272
+ sleep 0.3
273
+
274
+ end
275
+
276
+ end
277
+
278
+ def local_testrun()
279
+ r = IO.popen("bundle exec rackup -p 9292 config.ru")
280
+ puts 'r: ' + r.inspect if @debug
281
+ sleep 2
282
+
283
+ s = URI.open('http://127.0.0.1:9292').read
284
+ sleep 1
285
+
286
+ Process.kill('QUIT', r.pid)
287
+
288
+ puts 'SUCCESS! Ready to deploy' if s == "Hello World!"
289
+ end
290
+
291
+ def wipe_clean(setup=nil)
292
+
293
+ rm File.join(@app_path, 'hello.rb')
294
+ super(setup)
218
295
 
219
296
  end
220
297
 
@@ -222,18 +299,19 @@ end
222
299
 
223
300
  class HerokuWhiz
224
301
 
225
- def initialize(dir: '.', template: 'rack', appname: 'myapp',
302
+ def initialize(dir: '.', template: 'rack', appname: File.basename(Dir.pwd),
226
303
  verbose: true, debug: false)
227
304
 
228
305
  @dir, @template, @appname, @verbose = dir, template, appname, verbose
229
306
 
230
307
  @app_path = File.join(@dir, @appname)
308
+ FileUtils.chdir @app_path if File.exists? @app_path
231
309
 
232
310
  case @template.to_sym
233
311
  when :rack
234
- @tapp = WhizBase.new @app_path, debug: debug
312
+ @tapp = WhizBase.new @app_path, verbose: verbose, debug: debug
235
313
  when :sinatra
236
- @tapp = SinatraWhiz.new @app_path, debug: debug
314
+ @tapp = SinatraWhiz.new @app_path, verbose: verbose, debug: debug
237
315
  end
238
316
 
239
317
  end
@@ -253,11 +331,11 @@ class HerokuWhiz
253
331
  `heroku open`
254
332
  end
255
333
 
256
- def create()
334
+ def create(add: nil)
257
335
 
258
336
  return unless @tapp
259
337
 
260
- @tapp.create
338
+ @tapp.create add: add
261
339
 
262
340
  # build
263
341
  `bundle install`
@@ -282,7 +360,7 @@ class HerokuWhiz
282
360
 
283
361
  return unless @tapp
284
362
 
285
- @tapp.wipe_clean
363
+ @tapp.wipe_clean setup
286
364
 
287
365
  end
288
366
 
@@ -313,7 +391,8 @@ class HerokuWhiz
313
391
  private
314
392
 
315
393
  def heroku_app()
316
- `heroku config`.lines.first.split[1]
394
+ s = `heroku config`
395
+ s.lines.first.split[1] if s
317
396
  end
318
397
 
319
398
  end
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: heroku_whiz
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Robertson
metadata.gz.sig CHANGED
Binary file